Skip to content

Commit 9fe431d

Browse files
zeroeightysixjespercockx
authored andcommitted
Make DomForall's argument optional to represent implicit foralls
1 parent ef10a1a commit 9fe431d

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

src/Agda2Hs/Compile/ClassInstance.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ compileInstRule xs cs ty = do
115115
pars t@(Hs.TyCon () _) = t
116116
pars t = Hs.TyParen () t
117117
Pi a b -> compileDomType (absName b) a >>= \case
118-
DomDropped -> underAbstr a b (compileInstRule xs cs . unEl)
118+
DomDropped -> underAbstr a b skip
119119
DomConstraint hsA ->
120120
underAbstraction a b (compileInstRule xs (cs ++ [hsA]) . unEl)
121121
DomType _ t -> __IMPOSSIBLE__
122-
DomForall x ->
122+
DomForall Nothing -> underAbstr a b skip
123+
DomForall (Just x) ->
123124
underAbstraction a b (compileInstRule (xs ++ [x]) cs . unEl)
125+
where skip = compileInstRule xs cs . unEl
124126
_ -> __IMPOSSIBLE__
125127

126128

src/Agda2Hs/Compile/Data.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ compileConstructor params c = do
8181
compileConstructorArgs :: Telescope -> C [Hs.Type ()]
8282
compileConstructorArgs EmptyTel = return []
8383
compileConstructorArgs (ExtendTel a tel) = compileDomType (absName tel) a >>= \case
84-
DomType s hsA -> do
84+
DomType s hsA -> do
8585
ty <- addTyBang s hsA
8686
(ty :) <$> underAbstraction a tel compileConstructorArgs
87-
DomConstraint hsA -> agda2hsError "Not supported: constructors with class constraints"
88-
DomDropped -> underAbstraction a tel compileConstructorArgs
89-
DomForall{} -> __IMPOSSIBLE__
87+
DomConstraint hsA -> agda2hsError "Not supported: constructors with class constraints"
88+
DomDropped -> skip
89+
DomForall Nothing -> skip
90+
DomForall (Just _) -> __IMPOSSIBLE__
91+
where skip = underAbstraction a tel compileConstructorArgs
9092

9193
checkCompileToDataPragma :: Definition -> String -> C ()
9294
checkCompileToDataPragma def s = noCheckNames $ do

src/Agda2Hs/Compile/Function.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ compileModuleParams (ExtendTel a tel) = do
177177
(f , p) <- compileDomType (absName tel) a >>= \case
178178
DomDropped -> return (id, [])
179179
DomConstraint c -> return (constrainType c, [])
180-
DomForall a -> return (qualifyType a, [])
180+
DomForall Nothing -> return (id, [])
181+
DomForall (Just a) -> return (qualifyType a, [])
181182
DomType s a -> do
182183
let n = hsName $ absName tel
183184
checkValidVarName n

src/Agda2Hs/Compile/Record.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ compileRecord target def = do
166166
ToRecord{} -> agda2hsError $
167167
"Not supported: record/class with constraint fields"
168168
DomDropped -> return (hsAssts , hsFields)
169-
DomForall{} -> __IMPOSSIBLE__
169+
DomForall Nothing -> return (hsAssts , hsFields)
170+
DomForall (Just _) -> __IMPOSSIBLE__
170171
(_, _) -> __IMPOSSIBLE__
171172

172173
compileDataRecord

src/Agda2Hs/Compile/Type.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ compileType t = do
101101
DomType _ hsA -> Hs.TyFun () hsA <$> compileB
102102
DomConstraint hsA -> constrainType hsA <$> compileB
103103
DomDropped -> compileB
104-
DomForall hsA -> qualifyType hsA <$> compileB
104+
DomForall Nothing -> compileB
105+
DomForall (Just hsA) -> qualifyType hsA <$> compileB
105106

106107
Def f es -> maybeUnfoldCopy f es compileType $ \f es -> do
107108
def <- getConstInfo f
@@ -243,11 +244,12 @@ compileDomType x a =
243244
| isNested -> do
244245
tellExtension Hs.RankNTypes
245246
-- tellExtension Hs.ExistentialQuantification
246-
return $ DomForall $ Hs.UnkindedVar () $ Hs.Ident () x
247+
return $ DomForall $ Just $ Hs.UnkindedVar () $ Hs.Ident () x
247248
| ctx < npars -> do
248249
tellExtension Hs.ScopedTypeVariables
249-
return $ DomForall $ Hs.UnkindedVar () $ Hs.Ident () x
250-
| otherwise -> return DomDropped
250+
return $ DomForall $ Just $ Hs.UnkindedVar () $ Hs.Ident () x
251+
-- Return an implicit forall.
252+
| otherwise -> return $ DomForall Nothing
251253
DOTerm -> fmap (uncurry DomType) . withNestedType . compileTypeWithStrictness . unEl $ unDom a
252254

253255
compileTeleBinds :: Bool -> Telescope -> C [Hs.TyVarBind ()]

src/Agda2Hs/Compile/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ data CompiledDom
205205
-- ^ To a Haskell type (with perhaps a strictness annotation)
206206
| DomConstraint (Hs.Asst ())
207207
-- ^ To a typeclass constraint
208-
| DomForall (Hs.TyVarBind ())
209-
-- ^ To an explicit forall
208+
| DomForall (Maybe (Hs.TyVarBind ()))
209+
-- ^ To a forall, with an optional type variable declaration. If Nothing, this is an implicit forall; otherwise, explicit.
210210
| DomDropped
211211
-- ^ To nothing (e.g. erased proofs)
212212

0 commit comments

Comments
 (0)