@@ -44,7 +44,7 @@ makeTypes datatypes =
44 builtins :: [(String,Int)]
44 builtins :: [(String,Int)]
45 builtins = concat [ map tuple [0..9]
45 builtins = concat [ map tuple [0..9]
46 , kind 1 ["_List","Maybe","Signal"]
46 , kind 1 ["_List","Maybe","Signal"]
47− , kind 0 ["Int","Float","Char","Bool","Element"]
47+ , kind 0 ["Int","Float","Char","Bool","Element","Order"]
@@ -56,34 +56,42 @@ makeConstructors types = Map.fromList builtins
56 bool = types ! "Bool"
56 bool = types ! "Bool"
57 int = types ! "Int"
57 int = types ! "Int"
58 float = types ! "Float"
58 float = types ! "Float"
59+ order = types ! "Order"
61+ instance' :: IO Variable -> Int -> ([Type] -> ([Type], Type))
60− inst :: Int -> Int -> ([Type] -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
62+ -> IO (Int, [Variable], [Type], Type)
61− inst kind numTVars tipe = do
63+ instance' var numTVars tipe = do
62− vars <- forM [1..numTVars] $ \_ -> flexibleVar
64+ vars <- forM [1..numTVars] $ \_ -> var
63 let (args, result) = tipe (map VarN vars)
65 let (args, result) = tipe (map VarN vars)
64− return (kind, vars, args, result)
66+ return (length args, vars, args, result)
66− nmbr :: Int -> (Type -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
68+ inst = instance' flexibleVar
68− var <- number
69+ nmbr = instance' number 1
69− let (args, result) = tipe (VarN var)
70+ cmpr = instance' comparable 1
70− return (kind, [var], args, result)
71+ apnd = instance' appendable 1
72 tupleCtor n =
73 tupleCtor n =
73 let name = "_Tuple" ++ show n
74 let name = "_Tuple" ++ show n
74− in (name, inst n n $ \vs -> (vs, foldl (<|) (types ! name) vs))
75+ in (name, inst n $ \vs -> (vs, foldl (<|) (types ! name) vs))
76 builtins :: [ (String, IO (Int, [Variable], [Type], Type)) ]
77 builtins :: [ (String, IO (Int, [Variable], [Type], Type)) ]
77− builtins = [ ("Nothing", inst 0 1 $ \ [t] -> ([], maybe t))
78+ builtins = [ ("Nothing", inst 1 $ \ [t] -> ([], maybe t))
78− , ("Just" , inst 1 1 $ \ [t] -> ([t], maybe t))
79+ , ("Just" , inst 1 $ \ [t] -> ([t], maybe t))
79− , ("[]" , inst 0 1 $ \ [t] -> ([], list t))
80+ , ("[]" , inst 1 $ \ [t] -> ([], list t))
80− , ("::" , inst 2 1 $ \ [t] -> ([t, list t], list t))
81+ , ("::" , inst 1 $ \ [t] -> ([t, list t], list t))
81− , ("div" , inst 2 0 $ \ [] -> ([int, int], int))
82+ , ("div" , inst 0 $ \ [] -> ([int, int], int))
82− , ("/" , inst 2 0 $ \ [] -> ([float, float], float))
83+ , ("/" , inst 0 $ \ [] -> ([float, float], float))
83− , ("+" , nmbr 2 $ \t -> ([t, t], t))
84+ , ("+" , nmbr $ \ [t] -> ([t, t], t))
84− , ("-" , nmbr 2 $ \t -> ([t, t], t))
85+ , ("-" , nmbr $ \ [t] -> ([t, t], t))
85− , ("*" , nmbr 2 $ \t -> ([t, t], t))
86+ , ("*" , nmbr $ \ [t] -> ([t, t], t))
87+ , ("<" , cmpr $ \ [t] -> ([t, t], bool))
88+ , (">" , cmpr $ \ [t] -> ([t, t], bool))
89+ , ("<=" , cmpr $ \ [t] -> ([t, t], bool))
90+ , (">=" , cmpr $ \ [t] -> ([t, t], bool))
91+ , ("==" , cmpr $ \ [t] -> ([t, t], bool))
92+ , ("/=" , cmpr $ \ [t] -> ([t, t], bool))
93+ , ("compare", cmpr $ \ [t] -> ([t, t], order))
86− , ("otherwise", inst 0 0 $ \ [] -> ([], bool))
94+ , ("otherwise", inst 0 $ \ [] -> ([], bool))
87 ] ++ map tupleCtor [0..9]
95 ] ++ map tupleCtor [0..9]