@@ -23,15 +23,29 @@ toDefs decl =
23 Datatype name tvars constructors -> concatMap toDefs constructors
23 Datatype name tvars constructors -> concatMap toDefs constructors
25 toDefs (ctor, tipes) =
25 toDefs (ctor, tipes) =
26− let vars = take (length tipes) $ map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
26+ let vars = take (length tipes) arguments
27− loc = Src.none
27+ tbody = Type.Data name $ map Type.Var tvars
28− body = loc . Src.Data ctor $ map (loc . Src.Var) vars
28+ body = Src.none . Src.Data ctor $ map (Src.none . Src.Var) vars
29− in [ Src.TypeAnnotation ctor $
29+ in [ Src.TypeAnnotation ctor $ foldr Type.Lambda tbody tipes
30− foldr Type.Lambda (Type.Data name $ map Type.Var tvars) tipes
31− , Src.Def (Src.PVar ctor) $
30+ , Src.Def (Src.PVar ctor) $ buildFunction body vars
32− foldr (\p e -> loc $ Src.Lambda p e) body (map Src.PVar vars)
33+ TypeAlias name tvars tipe@(Type.Record fields ext) ->
34+ [ Src.TypeAnnotation name $ foldr Type.Lambda tipe args
35+ , Src.Def (Src.PVar name) $ buildFunction record vars ]
38+ Type.EmptyRecord -> map snd fields
39+ _ -> map snd fields ++ [ext]
41+ var = Src.none . Src.Var
42+ vars = take (length args) arguments
44+ efields = zip (map fst fields) (map var vars)
45+ record = Src.none $ case ext of
46+ Type.EmptyRecord -> Src.Record efields
47+ _ -> Src.Modify (var $ last vars) efields
35 -- Type aliases must be added to an extended equality dictionary,
49 -- Type aliases must be added to an extended equality dictionary,
36 -- but they do not require any basic constraints.
50 -- but they do not require any basic constraints.
37 TypeAlias _ _ _ -> []
51 TypeAlias _ _ _ -> []
@@ -45,3 +59,10 @@ toDefs decl =
46 -- no constraints are needed for fixity declarations
60 -- no constraints are needed for fixity declarations
47 Fixity _ _ _ -> []
61 Fixity _ _ _ -> []
65+arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
67+buildFunction body vars =
68+ foldr (\p e -> Src.none (Src.Lambda p e)) body (map Src.PVar vars)