@@ -17,19 +17,25 @@ import qualified SourceSyntax.Expression as SE
1717import qualified SourceSyntax.Type as ST
1818
1919
20−toExpr decls =
21− SL.none $ SE.Let (concatMap toDefs decls) (SL.none $ SE.Literal (SL.IntNum 42))
20+toExpr :: [Declaration t v] -> [SE.Def t v]
21+toExpr = concatMap toDefs
2222
2323toDefs :: Declaration t v -> [SE.Def t v]
2424toDefs decl =
2525 case decl of
2626 Definition def -> [def]
2727
28− Datatype name tvars constructors -> map toAnnotation constructors
28+ Datatype name tvars constructors -> concatMap toDefs constructors
2929 where
30− toAnnotation (ctor, tipes) =
31− SE.TypeAnnotation ctor $
32− foldr ST.Lambda (ST.Data name $ map ST.Var tvars) tipes
30+ toDefs (ctor, tipes) =
31+ let vars = take (length tipes) $ map (\n -> "_" ++ show n) [0..]
32+ loc = SL.none
33+ body = loc . SE.Data name $ map (loc . SE.Var) vars
34+ in [ SE.TypeAnnotation ctor $
35+ foldr ST.Lambda (ST.Data name $ map ST.Var tvars) tipes
36+ , SE.Def (SP.PVar ctor) $
37+ foldr (\p e -> loc $ SE.Lambda p e) body (map SP.PVar vars)
38+ ]
3339
3440 -- Type aliases must be added to an extended equality dictionary,
3541 -- but they do not require any basic constraints.