@@ -5,7 +5,9 @@ import SourceSyntax.Declaration
55import qualified SourceSyntax.Expression as E
66import qualified SourceSyntax.Location as L
77import qualified SourceSyntax.Pattern as P
8−import qualified SourceSyntax.Type as Type
8+import qualified SourceSyntax.Type as T
9+import qualified Type.Type as Type
10+import System.IO.Unsafe
911
1012toExpr :: [Declaration] -> [E.Def]
1113toExpr = concatMap toDefs
@@ -19,15 +21,15 @@ toDefs decl =
1921 where
2022 toDefs' (ctor, tipes) =
2123 let vars = take (length tipes) arguments
22− tbody = Type.Data name $ map Type.Var tvars
24+ tbody = T.Data name $ map T.Var tvars
2325 body = L.none . E.Data ctor $ map (L.none . E.Var) vars
24− in [ definition ctor (buildFunction body vars) (foldr Type.Lambda tbody tipes) ]
26+ in [ definition ctor (buildFunction body vars) (foldr T.Lambda tbody tipes) ]
2527
26− TypeAlias name _ tipe@(Type.Record fields ext) _ ->
27− [ definition name (buildFunction record vars) (foldr Type.Lambda tipe args) ]
28+ TypeAlias name _ tipe@(T.Record fields ext) _ ->
29+ [ definition name (buildFunction record vars) (foldr T.Lambda tipe args) ]
2830 where
2931 args = case ext of
30− Type.EmptyRecord -> map snd fields
32+ T.EmptyRecord -> map snd fields
3133 _ -> map snd fields ++ [ext]
3234
3335 var = L.none . E.Var
@@ -35,7 +37,7 @@ toDefs decl =
3537
3638 efields = zip (map fst fields) (map var vars)
3739 record = case ext of
38− Type.EmptyRecord -> L.none $ E.Record efields
40+ T.EmptyRecord -> L.none $ E.Record efields
3941 _ -> foldl (\r (f,v) -> L.none $ E.Insert r f v) (var $ last vars) efields
4042
4143 -- Type aliases must be added to an extended equality dictionary,
@@ -48,7 +50,9 @@ toDefs decl =
4850 Send name expr@(L.L s _) tipe ->
4951 [ definition name (L.L s $ E.PortOut name tipe expr) tipe ]
5052 Recv name expr@(L.L s _) tipe ->
51− [ definition name (L.L s $ E.PortIn name tipe undefined expr) tipe ]
53+ unsafePerformIO $ do
54+ tvar <- Type.var Type.Flexible
55+ return $ [ definition name (L.L s $ E.PortIn name tipe tvar expr) tipe ]
5256
5357 -- no constraints are needed for fixity declarations
5458 Fixity _ _ _ -> []
@@ -61,5 +65,5 @@ buildFunction :: E.LExpr -> [String] -> E.LExpr
6165buildFunction body@(L.L s _) vars =
6266 foldr (\p e -> L.L s (E.Lambda p e)) body (map P.PVar vars)
6367
64−definition :: String -> E.LExpr -> Type.Type -> E.Def
68+definition :: String -> E.LExpr -> T.Type -> E.Def
6569definition name expr tipe = E.Definition (P.PVar name) expr (Just tipe)