@@ -198,7 +198,7 @@ gen (C _ span expr) =
198198 Str _ -> primitive string
199199 Boolean _ -> primitive bool
200200 Markdown _ -> primitive element
201− -- _ -> beta >>= primitive
201+
202202
203203primitive :: Type -> GuidCounter (TVarMap, ConstraintSet, Type)
204204primitive t = return (Map.empty, Set.empty, t)
@@ -258,38 +258,39 @@ defGenHelp name args e = do
258258 Forall (map snd argDict) (cs' ++ Set.toList cs) tipe
259259 return ( as', Set.empty, (name, scheme) )
260260
261−stmtGen (Definition def) = do (as,cs,hint) <- defGen def
262− return ( as, cs, [hint] )
263−
264−stmtGen (Datatype name xs tcs) = do schemes <- mapM gen' tcs'
265− return (Map.empty, Set.empty, schemes)
266− where var n = length xs + n
267− ( a, b, c) = ( var 1, var 2, var 3)
268− (va,vb,vc) = (VarT a, VarT b, VarT c)
269− rnm (ADT n []) | n == "Number" = va
270− | n == "Appendable" = vb
271− | n == "Comparable" = vc
272− rnm t = t
273− tcs' = map (second (map rnm)) tcs
274− supers t = map (ctx name NoSpan) $
275− zipWith (:<:) [va,vb,vc] [number,appendable t,comparable]
276− gen' (n,ts) = do t <- beta
277− let s = Forall (xs ++ [a,b,c]) (supers t) $
278− foldr (==>) (ADT name $ map VarT xs) ts
279− (,) n `liftM` generalize [] s
280−
281−stmtGen (ExportEvent js elm tipe) = do
282− x <- guid
283− return ( Map.singleton elm [x]
284− , Set.singleton . ctx elm NoSpan $ VarT x :=: tipe
285− , [] )
286−
287−stmtGen (ImportEvent js e@(C txt span base) elm tipe) = do
288− (as,cs,t) <- gen e
289− return ( as
290− , Set.insert (C txt span (signalOf t :=: tipe)) cs
291− , [ (elm, Forall [] [] tipe) ] )
292261
293−getDatatypeInfo (Datatype name args tcs) =
294− Just (name, args, tcs)
295−getDatatypeInfo _ = Nothing
262+stmtGen :: Statement -> GuidCounter (TVarMap, ConstraintSet, [(String,Scheme)])
263+stmtGen stmt =
264+ case stmt of
265+ Definition def -> do (as,cs,hint) <- defGen def
266+ return ( as, cs, [hint] )
267+
268+ TypeAlias alias t -> return (Map.empty, Set.empty, [])
269+
270+ TypeAnnotation name t ->
271+ do Forall _ _ t' <- generalize [] (Forall [] [] t)
272+ x <- guid
273+ return (Map.singleton name [x],
274+ Set.singleton (ctx name NoSpan $ VarT x :=: t'),
275+ [])
276+
277+ Datatype name xs tcs ->
278+ let toType ts = foldl (==>) (ADT name $ map VarT xs) ts in
279+ do schemes <- mapM (toScheme . second toType) tcs
280+ return (Map.empty, Set.empty, schemes)
281+
282+ ExportEvent js elm tipe ->
283+ do x <- guid
284+ return ( Map.singleton elm [x]
285+ , Set.singleton . ctx elm NoSpan $ VarT x :=: tipe
286+ , [] )
287+
288+ ImportEvent js e@(C txt span base) elm tipe ->
289+ do (as,cs,t) <- gen e
290+ return ( as
291+ , Set.insert (C txt span (signalOf t :=: tipe)) cs
292+ , [ (elm, Forall [] [] tipe) ] )
293+
294+toScheme :: (String,Type) -> GuidCounter (String,Scheme)
295+toScheme (name,tipe) = do scheme <- generalize [] (Forall [] [] tipe)
296+ return (name, scheme)