@@ -198,7 +198,7 @@ gen (C _ span expr) =
198 Str _ -> primitive string
198 Str _ -> primitive string
199 Boolean _ -> primitive bool
199 Boolean _ -> primitive bool
200 Markdown _ -> primitive element
200 Markdown _ -> primitive element
201− -- _ -> beta >>= primitive
201+
203primitive :: Type -> GuidCounter (TVarMap, ConstraintSet, Type)
203primitive :: Type -> GuidCounter (TVarMap, ConstraintSet, Type)
204primitive t = return (Map.empty, Set.empty, t)
204primitive t = return (Map.empty, Set.empty, t)
@@ -258,38 +258,39 @@ defGenHelp name args e = do
258 Forall (map snd argDict) (cs' ++ Set.toList cs) tipe
258 Forall (map snd argDict) (cs' ++ Set.toList cs) tipe
259 return ( as', Set.empty, (name, scheme) )
259 return ( as', Set.empty, (name, scheme) )
261−stmtGen (Definition def) = do (as,cs,hint) <- defGen def
262− return ( as, cs, [hint] )
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
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
281−stmtGen (ExportEvent js elm tipe) = do
283− return ( Map.singleton elm [x]
284− , Set.singleton . ctx elm NoSpan $ VarT x :=: tipe
287−stmtGen (ImportEvent js e@(C txt span base) elm tipe) = do
290− , Set.insert (C txt span (signalOf t :=: tipe)) cs
291− , [ (elm, Forall [] [] tipe) ] )
262+stmtGen :: Statement -> GuidCounter (TVarMap, ConstraintSet, [(String,Scheme)])
265+ Definition def -> do (as,cs,hint) <- defGen def
266+ return ( as, cs, [hint] )
268+ TypeAlias alias t -> return (Map.empty, Set.empty, [])
270+ TypeAnnotation name t ->
271+ do Forall _ _ t' <- generalize [] (Forall [] [] t)
273+ return (Map.singleton name [x],
274+ Set.singleton (ctx name NoSpan $ VarT x :=: t'),
293−getDatatypeInfo (Datatype name args tcs) =
277+ Datatype name xs tcs ->
294− Just (name, args, tcs)
278+ let toType ts = foldl (==>) (ADT name $ map VarT xs) ts in
295−getDatatypeInfo _ = Nothing
279+ do schemes <- mapM (toScheme . second toType) tcs
280+ return (Map.empty, Set.empty, schemes)
282+ ExportEvent js elm tipe ->
284+ return ( Map.singleton elm [x]
285+ , Set.singleton . ctx elm NoSpan $ VarT x :=: tipe
288+ ImportEvent js e@(C txt span base) elm tipe ->
289+ do (as,cs,t) <- gen e
291+ , Set.insert (C txt span (signalOf t :=: tipe)) cs
292+ , [ (elm, Forall [] [] tipe) ] )
294+toScheme :: (String,Type) -> GuidCounter (String,Scheme)
295+toScheme (name,tipe) = do scheme <- generalize [] (Forall [] [] tipe)
296+ return (name, scheme)