@@ -1,13 +1,6 @@
1+{-# OPTIONS_GHC -Wall #-}
1module Type.Constrain.Declaration where
2module Type.Constrain.Declaration where
4−import Control.Applicative ((<$>))
6−import qualified Data.Map as Map
8−import qualified Type.Constrain.Expression as TcExpr
9−import qualified Type.Environment as Env
11import SourceSyntax.Declaration
4import SourceSyntax.Declaration
12import qualified SourceSyntax.Expression as Src
5import qualified SourceSyntax.Expression as Src
13import qualified SourceSyntax.Location as L
6import qualified SourceSyntax.Location as L
@@ -22,15 +15,15 @@ toDefs decl =
22 case decl of
15 case decl of
23 Definition def -> [def]
16 Definition def -> [def]
25− Datatype name tvars constructors _ -> concatMap toDefs constructors
18+ Datatype name tvars constructors _ -> concatMap toDefs' constructors
27− toDefs (ctor, tipes) =
20+ toDefs' (ctor, tipes) =
28 let vars = take (length tipes) arguments
21 let vars = take (length tipes) arguments
29 tbody = Type.Data name $ map Type.Var tvars
22 tbody = Type.Data name $ map Type.Var tvars
30 body = L.none . Src.Data ctor $ map (L.none . Src.Var) vars
23 body = L.none . Src.Data ctor $ map (L.none . Src.Var) vars
31 in [ definition ctor (buildFunction body vars) (foldr Type.Lambda tbody tipes) ]
24 in [ definition ctor (buildFunction body vars) (foldr Type.Lambda tbody tipes) ]
33− TypeAlias name tvars tipe@(Type.Record fields ext) _ ->
26+ TypeAlias name _ tipe@(Type.Record fields ext) _ ->
34 [ definition name (buildFunction record vars) (foldr Type.Lambda tipe args) ]
27 [ definition name (buildFunction record vars) (foldr Type.Lambda tipe args) ]
36 args = case ext of
29 args = case ext of
@@ -53,7 +46,7 @@ toDefs decl =
53 Port port ->
46 Port port ->
54 case port of
47 case port of
55 Send name expr tipe -> [ definition name expr tipe ]
48 Send name expr tipe -> [ definition name expr tipe ]
56− Recv name expr tipe -> -- [ definition name ]
49+ Recv _ _ _ -> -- [ definition name ]
57 error "not sure how to generate constraints for recv yet"
50 error "not sure how to generate constraints for recv yet"
59 -- no constraints are needed for fixity declarations
52 -- no constraints are needed for fixity declarations
@@ -61,9 +54,11 @@ toDefs decl =
63arguments :: [String]
56arguments :: [String]
64−arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
57+arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show (n :: Int)) [1..]
59+buildFunction :: Src.LExpr -> [String] -> Src.LExpr
66buildFunction body@(L.L s _) vars =
60buildFunction body@(L.L s _) vars =
67 foldr (\p e -> L.L s (Src.Lambda p e)) body (map P.PVar vars)
61 foldr (\p e -> L.L s (Src.Lambda p e)) body (map P.PVar vars)
63+definition :: String -> Src.LExpr -> Type.Type -> Src.Def
69definition name expr tipe = Src.Definition (P.PVar name) expr (Just tipe)
64definition name expr tipe = Src.Definition (P.PVar name) expr (Just tipe)