Skip to content

Commit 4e3b9a7

Browse files
flupeomelkonian
authored andcommitted
various fixes
1 parent 9e64826 commit 4e3b9a7

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

src/Agda2Hs/Compile/Data.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ checkNewtype :: Hs.Name () -> [Hs.QualConDecl ()] -> C ()
2424
checkNewtype name cs = do
2525
checkSingleElement name cs "Newtype must have exactly one constructor in definition"
2626
case head cs of
27-
Hs.QualConDecl () _ _ (Hs.ConDecl () cName types)
28-
-> checkSingleElement cName types "Newtype must have exactly one field in constructor"
27+
Hs.QualConDecl () _ _ (Hs.ConDecl () cName types) -> checkNewtypeCon cName types
2928

3029
compileData :: AsNewType -> [Hs.Deriving ()] -> Definition -> C [Hs.Decl ()]
3130
compileData newtyp ds def = do

src/Agda2Hs/Compile/Function.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE OverloadedStrings, ViewPatterns, NamedFieldPuns, BlockArguments #-}
1+
{-# LANGUAGE OverloadedStrings #-}
22
module Agda2Hs.Compile.Function where
33

44
import Control.Monad ( (>=>), filterM, forM_ )
@@ -116,6 +116,7 @@ compileFun withSig def@Defn{..} =
116116
$ withFunctionLocals defName
117117
$ compileFun' withSig def
118118

119+
-- inherit existing (instantiated) locals
119120
compileFun' withSig def@Defn{..} = do
120121
reportSDoc "agda2hs.compile" 6 $ "Compiling function: " <+> prettyTCM defName
121122

src/Agda2Hs/Compile/Record.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ compileRecord target def = do
110110
ToRecord newtyp ds -> do
111111
checkValidConName cName
112112
(constraints, fieldDecls) <- compileRecFields fieldDecl recFields fieldTel
113-
when newtyp $ checkSingleElement cName fieldDecls "Newtype must have exactly one field in constructor"
113+
when newtyp $ checkNewtypeCon cName fieldDecls
114114
let target = if newtyp then Hs.NewType () else Hs.DataType ()
115115
compileDataRecord constraints fieldDecls target hd ds
116116

src/Agda2Hs/Compile/Type.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Agda2Hs.HsUtils
4343

4444
-- | Type definitions from the prelude that get special translation rules.
4545
isSpecialType :: QName -> Maybe (Elims -> C (Hs.Type ()))
46-
isSpecialType x = case prettyShow x of
46+
isSpecialType = prettyShow >>> \case
4747
"Haskell.Prim.Tuple._×_" -> Just tupleType
4848
"Haskell.Prim.Tuple._×_×_" -> Just tupleType
4949
"Haskell.Extra.Erase.Erase" -> Just unitType
@@ -119,8 +119,8 @@ compileTopLevelType keepType t cont = do
119119

120120

121121
-- | Compile an Agda term into a Haskell type, along with its strictness.
122-
compileTypeStrictness :: Term -> C (Strictness, Hs.Type ())
123-
compileTypeStrictness t = do
122+
compileTypeWithStrictness :: Term -> C (Strictness, Hs.Type ())
123+
compileTypeWithStrictness t = do
124124
s <- case t of
125125
Def f es -> fromMaybe Lazy <$> isUnboxRecord f
126126
_ -> return Lazy
@@ -214,7 +214,7 @@ compileDom :: ArgName -> Dom Type -> C CompiledDom
214214
compileDom x a
215215
| usableModality a = case getHiding a of
216216
Instance{} -> DomConstraint . Hs.TypeA () <$> compileType (unEl $ unDom a)
217-
NotHidden -> uncurry DomType <$> compileTypeStrictness (unEl $ unDom a)
217+
NotHidden -> uncurry DomType <$> compileTypeWithStrictness (unEl $ unDom a)
218218
Hidden ->
219219
ifM (canErase $ unDom a)
220220
(return DomDropped)

src/Agda2Hs/Compile/Types.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE PatternSynonyms, FlexibleInstances, MultiParamTypeClasses, InstanceSigs, TypeFamilies #-}
1+
{-# LANGUAGE PatternSynonyms, FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-}
22
module Agda2Hs.Compile.Types where
33

44
import Control.Applicative ( liftA2 )
@@ -177,14 +177,14 @@ instance Semigroup a => Semigroup (C a) where (<>) = liftA2 (<>)
177177

178178

179179

180-
-- | Currently we can compile an Agda "Dom Type" in three ways:
181-
-- To a type in Haskell (with perhaps a strictness annotation)
182-
-- To a typeclass constraint in Haskell
183-
-- To nothing (e.g. for proofs)
180+
-- | Agda @Dom Type@ can get compiled in three ways.
184181
data CompiledDom
185182
= DomType Strictness (Hs.Type ())
183+
-- ^ To a Haskell type (with perhaps a strictness annotation)
186184
| DomConstraint (Hs.Asst ())
185+
-- ^ To a typeclass constraint
187186
| DomDropped
187+
-- ^ To nothing (e.g. erased proofs)
188188

189189
-- | Whether a datatype/record should be compiled as a @newtype@ haskell definition.
190190
type AsNewType = Bool

src/Agda2Hs/Compile/Utils.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ keepArg x = usableModality x && visible x
134134

135135

136136
keepClause :: Clause -> Bool
137-
keepClause = maybe False keepArg . clauseType
137+
keepClause = any keepArg . clauseType
138138

139139
-- Determine whether it is ok to erase arguments of this type,
140140
-- even in the absence of an erasure annotation.
@@ -302,6 +302,10 @@ checkSingleElement :: Hs.Name () -> [b] -> String -> C ()
302302
checkSingleElement name fs s = unless (length fs == 1) $ genericDocError =<< do
303303
text (s ++ ":") <+> text (Hs.prettyPrint name)
304304

305+
checkNewtypeCon :: Hs.Name () -> [b] -> C ()
306+
checkNewtypeCon name tys =
307+
checkSingleElement name tys "Newtype must have exactly one field in constructor"
308+
305309
checkingVars :: C a -> C a
306310
checkingVars = local $ \e -> e { checkVar = True }
307311

src/Agda2Hs/HsUtils.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ constrainType c = \case
297297

298298
-- | Add explicit quantification over a variable to a Haskell type.
299299
qualifyType
300-
:: String -- ^ Name of the variable.
300+
:: String -- ^ Name of the variable.
301301
-> Type () -- ^ Type to quantify.
302302
-> Type ()
303303
qualifyType s = \case

0 commit comments

Comments
 (0)