@@ -23,15 +23,29 @@ toDefs decl =
2323 Datatype name tvars constructors -> concatMap toDefs constructors
2424 where
2525 toDefs (ctor, tipes) =
26− let vars = take (length tipes) $ map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
27− loc = Src.none
28− body = loc . Src.Data ctor $ map (loc . Src.Var) vars
29− in [ Src.TypeAnnotation ctor $
30− foldr Type.Lambda (Type.Data name $ map Type.Var tvars) tipes
31− , Src.Def (Src.PVar ctor) $
32− foldr (\p e -> loc $ Src.Lambda p e) body (map Src.PVar vars)
26+ let vars = take (length tipes) arguments
27+ tbody = Type.Data name $ map Type.Var tvars
28+ body = Src.none . Src.Data ctor $ map (Src.none . Src.Var) vars
29+ in [ Src.TypeAnnotation ctor $ foldr Type.Lambda tbody tipes
30+ , Src.Def (Src.PVar ctor) $ buildFunction body vars
3331 ]
3432
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 ]
36+ where
37+ args = case ext of
38+ Type.EmptyRecord -> map snd fields
39+ _ -> map snd fields ++ [ext]
40+
41+ var = Src.none . Src.Var
42+ vars = take (length args) arguments
43+
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
48+
3549 -- Type aliases must be added to an extended equality dictionary,
3650 -- but they do not require any basic constraints.
3751 TypeAlias _ _ _ -> []
@@ -45,3 +59,10 @@ toDefs decl =
4559
4660 -- no constraints are needed for fixity declarations
4761 Fixity _ _ _ -> []
62+
63+
64+arguments :: [String]
65+arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
66+
67+buildFunction body vars =
68+ foldr (\p e -> Src.none (Src.Lambda p e)) body (map Src.PVar vars)