@@ -46,7 +46,7 @@ disableCopatterns :: C a -> C a
4646disableCopatterns = local $ \ e -> e { copatternsEnabled = False }
4747
4848
49- -- | Enable the approriate extensions for a given Haskell deriving strategy.
49+ -- | Enable the appropriate extensions for a given Haskell deriving strategy.
5050enableStrategy :: Maybe (Hs. DerivStrategy () ) -> C ()
5151enableStrategy Nothing = return ()
5252enableStrategy (Just s) = do
@@ -66,14 +66,14 @@ compileInstance (ToDerivation strategy) def@Defn{..} =
6666 text " compiling instance" <+> prettyTCM defName <+> text " to standalone deriving"
6767 tellExtension Hs. StandaloneDeriving
6868 enableStrategy strategy
69- ir <- compileInstRule [] (unEl defType)
69+ ir <- compileInstRule [] [] (unEl defType)
7070 return $ Hs. DerivDecl () strategy Nothing ir
7171
7272compileInstance ToDefinition def@ Defn {.. } =
7373 enableCopatterns $ setCurrentRangeQ defName $ do
7474 reportSDoc " agda2hs.compile.instance" 13 $
7575 text " compiling instance" <+> prettyTCM defName <+> text " to instance definition"
76- ir <- compileInstRule [] (unEl defType)
76+ ir <- compileInstRule [] [] (unEl defType)
7777 withFunctionLocals defName $ do
7878 reportSDoc " agda2hs.compile.instance" 20 $ vcat $
7979 text " compileInstance clauses: " :
@@ -83,11 +83,11 @@ compileInstance ToDefinition def@Defn{..} =
8383 tel <- lookupSection mod
8484 addContext tel $ do
8585 liftTCM $ setModuleCheckpoint mod
86- pars <- getContextArgs
87- ty <- defType `piApplyM` pars
88- let clauses = funClauses `apply` pars
86+ -- We intentionally do not apply getContextArgs eagerly here so dotted
87+ -- patterns corresponding to module parameters are correctly detected
88+ -- (https://github.com/agda/agda2hs/issues/306)
8989 (ds, rs) <- concatUnzip
90- <$> mapM (\ c -> withClauseLocals mod c $ compileInstanceClause mod ty c) clauses
90+ <$> mapM (\ c -> withClauseLocals mod c $ compileInstanceClause mod defType c) funClauses
9191 reportSDoc " agda2hs.compile.instance" 20 $ vcat $
9292 text " compileInstance compiled clauses: " :
9393 map (nest 2 . text . pp) ds
@@ -97,16 +97,16 @@ compileInstance ToDefinition def@Defn{..} =
9797 where Function {.. } = theDef
9898
9999
100- compileInstRule :: [Hs. Asst () ] -> Term -> C (Hs. InstRule () )
101- compileInstRule cs ty = do
100+ compileInstRule :: [Hs. TyVarBind () ] -> [ Hs. Asst () ] -> Term -> C (Hs. InstRule () )
101+ compileInstRule xs cs ty = do
102102 reportSDoc " agda2hs.compile.instance" 20 $ text " compileInstRule" <+> prettyTCM ty
103103 case unSpine1 ty of
104104 Def f es | Just args <- allApplyElims es -> do
105105 fty <- defType <$> getConstInfo f
106106 vs <- compileTypeArgs fty args
107107 f <- compileQName f
108108 return $
109- Hs. IRule () Nothing (ctx cs) $ foldl (Hs. IHApp () ) (Hs. IHCon () f) (map pars vs)
109+ Hs. IRule () ( Just xs) (ctx cs) $ foldl (Hs. IHApp () ) (Hs. IHCon () f) (map pars vs)
110110 where ctx [] = Nothing
111111 ctx cs = Just (Hs. CxTuple () cs)
112112 -- put parens around anything except a var or a constant
@@ -115,11 +115,12 @@ compileInstRule 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 cs . unEl)
118+ DomDropped -> underAbstr a b (compileInstRule xs cs . unEl)
119119 DomConstraint hsA ->
120- underAbstraction a b (compileInstRule (cs ++ [hsA]) . unEl)
120+ underAbstraction a b (compileInstRule xs (cs ++ [hsA]) . unEl)
121121 DomType _ t -> __IMPOSSIBLE__
122- DomForall _ -> __IMPOSSIBLE__
122+ DomForall x ->
123+ underAbstraction a b (compileInstRule (xs ++ [x]) cs . unEl)
123124 _ -> __IMPOSSIBLE__
124125
125126
@@ -170,7 +171,7 @@ compileInstanceClause curModule ty c = ifNotM (keepClause c) (return ([], [])) $
170171-- abuse compileClause:
171172-- 1. drop any patterns before record projection to suppress the instance arg
172173-- 2. use record proj. as function name
173- -- 3. process remaing patterns as usual
174+ -- 3. process remaining patterns as usual
174175compileInstanceClause' :: ModuleName -> Type -> NAPs -> Clause -> C ([Hs. InstDecl () ], [QName ])
175176compileInstanceClause' curModule ty [] c = __IMPOSSIBLE__
176177compileInstanceClause' curModule ty (p: ps) c
@@ -289,7 +290,7 @@ compileInstanceClause' curModule ty (p:ps) c
289290 -- No minimal dictionary used, proceed with compiling as a regular clause.
290291 | otherwise -> do
291292 reportSDoc " agda2hs.compile.instance" 20 $ text " Compiling instance clause" <+> prettyTCM c'
292- ms <- disableCopatterns $ compileClause curModule Nothing uf ty' c'
293+ ms <- disableCopatterns $ compileClause curModule [] Nothing uf ty' c'
293294 let cc = Hs. FunBind () (toList ms)
294295 reportSDoc " agda2hs.compile.instance" 20 $ vcat
295296 [ text " compileInstanceClause compiled clause"
@@ -302,6 +303,7 @@ compileInstanceClause' curModule ty (p:ps) c
302303-- if there is something other than erased parameters
303304compileInstanceClause' curModule ty (p: ps) c = do
304305 (a, b) <- mustBePi ty
306+ checkIllegalForced a (namedArg p)
305307 compileInstanceClause' curModule (absApp b (patternToTerm $ namedArg p)) ps c
306308
307309fieldArgInfo :: QName -> C ArgInfo
0 commit comments