@@ -14,10 +14,10 @@ import qualified SourceSyntax.Location as L
1414import qualified SourceSyntax.Pattern as P
1515import qualified SourceSyntax.Type as Type
1616
17−toExpr :: [Declaration t v] -> [Src.Def t v]
17+toExpr :: [Declaration] -> [Src.Def]
1818toExpr = concatMap toDefs
1919
20−toDefs :: Declaration t v -> [Src.Def t v]
20+toDefs :: Declaration -> [Src.Def]
2121toDefs decl =
2222 case decl of
2323 Definition def -> [def]
@@ -28,13 +28,10 @@ toDefs decl =
2828 let vars = take (length tipes) arguments
2929 tbody = Type.Data name $ map Type.Var tvars
3030 body = L.none . Src.Data ctor $ map (L.none . Src.Var) vars
31− in [ Src.TypeAnnotation ctor $ foldr Type.Lambda tbody tipes
32− , Src.Def (P.PVar ctor) $ buildFunction body vars
33− ]
31+ in [ definition ctor (buildFunction body vars) (foldr Type.Lambda tbody tipes) ]
3432
3533 TypeAlias name tvars tipe@(Type.Record fields ext) _ ->
36− [ Src.TypeAnnotation name $ foldr Type.Lambda tipe args
37− , Src.Def (P.PVar name) $ buildFunction record vars ]
34+ [ definition name (buildFunction record vars) (foldr Type.Lambda tipe args) ]
3835 where
3936 args = case ext of
4037 Type.EmptyRecord -> map snd fields
@@ -53,10 +50,11 @@ toDefs decl =
5350 -- TODO: with the ability to derive code, you may need to generate stuff!
5451 TypeAlias _ _ _ _ -> []
5552
56− Port name tipe maybe ->
57− Src.TypeAnnotation name tipe : case maybe of
58− Nothing -> []
59− Just expr -> [ Src.Def (P.PVar name) expr ]
53+ Port port ->
54+ case port of
55+ Send name expr tipe -> [ definition name expr tipe ]
56+ Recv name expr tipe -> -- [ definition name ]
57+ error "not sure how to generate constraints for recv yet"
6058
6159 -- no constraints are needed for fixity declarations
6260 Fixity _ _ _ -> []
@@ -66,4 +64,6 @@ arguments :: [String]
6664arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
6765
6866buildFunction body@(L.L s _) vars =
69− foldr (\p e -> L.L s (Src.Lambda p e)) body (map P.PVar vars)
67+ foldr (\p e -> L.L s (Src.Lambda p e)) body (map P.PVar vars)
68+
69+definition name expr tipe = Src.Definition (P.PVar name) expr (Just tipe)