@@ -52,7 +52,7 @@ typeExpr = do
5252typeConstructor :: (Monad m) => ParsecT [Char] u m (String, [ParseType])
5353typeConstructor = (,) <$> (capVar <?> "another type constructor") <*> spacePrefix (typeSimple <|> typeUnambiguous)
5454
55−datatype :: (Monad m) => ParsecT [Char] u m ([String], [Expr], GuidCounter [Type])
55+datatype :: (Monad m) => ParsecT [Char] u m ([String], [Expr], [Scheme])
5656datatype = do
5757 reserved "data" <?> "datatype definition (data T = A | B | ...)"
5858 forcedWS ; name <- capVar <?> "name of data-type" ; args <- spacePrefix lowVar
@@ -65,22 +65,21 @@ beta = liftM VarT guid
6565toFunc (name,args) = foldr Lambda (Data name $ map Var argNames) argNames
6666 where argNames = map (("a"++) . show) [1..length args]
6767
68−toTypes name args constructors = do
69− pairs <- mapM (\x -> (,) x `liftM` guid) args
70− return $ map (toType pairs . ADT name $ map (VarT . snd) pairs) constructors
68+toTypes name args constructors =
69+ map (toType pairs . ADT name $ map (VarT . snd) pairs) constructors
70+ where pairs = zip args [1..length args]
7171
7272toType pairs outType (name,args) =
73− foldr (==>) outType (map toT args)
74− where toT (LambdaPT t1 t2) = toT t1 ==> toT t2
73+ Forall [1..n+2] cs $ foldr (==>) outType (map toT args)
74+ where n = length pairs
75+ cs = [ VarT (n+1) :<: time, VarT (n+2) :<: number ]
76+ toT (LambdaPT t1 t2) = toT t1 ==> toT t2
7577 toT (ADTPT name args) = ADT name $ map toT args
7678 toT (VarPT x@(c:_))
7779 | isLower c = VarT . fromMaybe (-1) $ lookup x pairs
78− | otherwise = case x of "Int" -> IntT
79− "Number" -> IntT
80− "String" -> StringT
81− "Char" -> CharT
82− "Bool" -> BoolT
83− _ -> ADT x []
80+ | x == "Time" = VarT (n+1)
81+ | x == "Number" = VarT (n+2)
82+ | otherwise = ADT x []
8483
8584toForeignType (LambdaPT t1 t2) =
8685 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++