@@ -52,7 +52,7 @@ typeExpr = do
52typeConstructor :: (Monad m) => ParsecT [Char] u m (String, [ParseType])
52typeConstructor :: (Monad m) => ParsecT [Char] u m (String, [ParseType])
53typeConstructor = (,) <$> (capVar <?> "another type constructor") <*> spacePrefix (typeSimple <|> typeUnambiguous)
53typeConstructor = (,) <$> (capVar <?> "another type constructor") <*> spacePrefix (typeSimple <|> typeUnambiguous)
55−datatype :: (Monad m) => ParsecT [Char] u m ([String], [Expr], GuidCounter [Type])
55+datatype :: (Monad m) => ParsecT [Char] u m ([String], [Expr], [Scheme])
56datatype = do
56datatype = do
57 reserved "data" <?> "datatype definition (data T = A | B | ...)"
57 reserved "data" <?> "datatype definition (data T = A | B | ...)"
58 forcedWS ; name <- capVar <?> "name of data-type" ; args <- spacePrefix lowVar
58 forcedWS ; name <- capVar <?> "name of data-type" ; args <- spacePrefix lowVar
@@ -65,22 +65,21 @@ beta = liftM VarT guid
65toFunc (name,args) = foldr Lambda (Data name $ map Var argNames) argNames
65toFunc (name,args) = foldr Lambda (Data name $ map Var argNames) argNames
66 where argNames = map (("a"++) . show) [1..length args]
66 where argNames = map (("a"++) . show) [1..length args]
68−toTypes name args constructors = do
68+toTypes name args constructors =
69− pairs <- mapM (\x -> (,) x `liftM` guid) args
70− return $ map (toType pairs . ADT name $ map (VarT . snd) pairs) constructors
69+ map (toType pairs . ADT name $ map (VarT . snd) pairs) constructors
70+ where pairs = zip args [1..length args]
72toType pairs outType (name,args) =
72toType pairs outType (name,args) =
73− foldr (==>) outType (map toT args)
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 ]
74− where toT (LambdaPT t1 t2) = toT t1 ==> toT t2
76+ toT (LambdaPT t1 t2) = toT t1 ==> toT t2
75 toT (ADTPT name args) = ADT name $ map toT args
77 toT (ADTPT name args) = ADT name $ map toT args
76 toT (VarPT x@(c:_))
78 toT (VarPT x@(c:_))
77 | isLower c = VarT . fromMaybe (-1) $ lookup x pairs
79 | isLower c = VarT . fromMaybe (-1) $ lookup x pairs
80+ | x == "Time" = VarT (n+1)
81+ | x == "Number" = VarT (n+2)
78− | otherwise = case x of "Int" -> IntT
82+ | otherwise = ADT x []
85toForeignType (LambdaPT t1 t2) =
84toForeignType (LambdaPT t1 t2) =
86 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++
85 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++