@@ -44,7 +44,7 @@ makeTypes datatypes =
4444 builtins :: [(String,Int)]
4545 builtins = concat [ map tuple [0..9]
4646 , kind 1 ["_List","Maybe","Signal"]
47− , kind 0 ["Int","Float","Char","Bool","Element"]
47+ , kind 0 ["Int","Float","Char","Bool","Element","Order"]
4848 ]
4949
5050
@@ -56,34 +56,42 @@ makeConstructors types = Map.fromList builtins
5656 bool = types ! "Bool"
5757 int = types ! "Int"
5858 float = types ! "Float"
59+ order = types ! "Order"
5960
60− inst :: Int -> Int -> ([Type] -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
61− inst kind numTVars tipe = do
62− vars <- forM [1..numTVars] $ \_ -> flexibleVar
61+ instance' :: IO Variable -> Int -> ([Type] -> ([Type], Type))
62+ -> IO (Int, [Variable], [Type], Type)
63+ instance' var numTVars tipe = do
64+ vars <- forM [1..numTVars] $ \_ -> var
6365 let (args, result) = tipe (map VarN vars)
64− return (kind, vars, args, result)
66+ return (length args, vars, args, result)
6567
66− nmbr :: Int -> (Type -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
67− nmbr kind tipe = do
68− var <- number
69− let (args, result) = tipe (VarN var)
70− return (kind, [var], args, result)
68+ inst = instance' flexibleVar
69+ nmbr = instance' number 1
70+ cmpr = instance' comparable 1
71+ apnd = instance' appendable 1
7172
7273 tupleCtor n =
7374 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))
7576
7677 builtins :: [ (String, IO (Int, [Variable], [Type], Type)) ]
77− builtins = [ ("Nothing", inst 0 1 $ \ [t] -> ([], maybe t))
78− , ("Just" , inst 1 1 $ \ [t] -> ([t], maybe t))
79− , ("[]" , inst 0 1 $ \ [t] -> ([], list t))
80− , ("::" , inst 2 1 $ \ [t] -> ([t, list t], list t))
81− , ("div" , inst 2 0 $ \ [] -> ([int, int], int))
82− , ("/" , inst 2 0 $ \ [] -> ([float, float], float))
83− , ("+" , nmbr 2 $ \t -> ([t, t], t))
84− , ("-" , nmbr 2 $ \t -> ([t, t], t))
85− , ("*" , nmbr 2 $ \t -> ([t, t], t))
86− , ("otherwise", inst 0 0 $ \ [] -> ([], bool))
78+ builtins = [ ("Nothing", inst 1 $ \ [t] -> ([], maybe t))
79+ , ("Just" , inst 1 $ \ [t] -> ([t], maybe t))
80+ , ("[]" , inst 1 $ \ [t] -> ([], list t))
81+ , ("::" , inst 1 $ \ [t] -> ([t, list t], list t))
82+ , ("div" , inst 0 $ \ [] -> ([int, int], int))
83+ , ("/" , inst 0 $ \ [] -> ([float, float], float))
84+ , ("+" , nmbr $ \ [t] -> ([t, t], t))
85+ , ("-" , nmbr $ \ [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))
94+ , ("otherwise", inst 0 $ \ [] -> ([], bool))
8795 ] ++ map tupleCtor [0..9]
8896
8997