on master help sign in
Trim acceptable `main` types down to just `Node msg` for now
2d59c75Evan Czaplicki
src/Nitpick/TopLevelTypes.hs+13−40
@@ -56,14 +56,15 @@ checkMainType typeEnv decls =
56 A.A (region,_) (Decl.Def (Valid.Definition (A.A _ (P.Var "main")) _ _)) : _ ->
56 A.A (region,_) (Decl.Def (Valid.Definition (A.A _ (P.Var "main")) _ _)) : _ ->
57 case Map.lookup "main" typeEnv of
57 case Map.lookup "main" typeEnv of
58 Nothing ->
58 Nothing ->
59+ return ()
60+
61+ Just tipe ->
62+ case Type.deepDealias tipe of
63+ Type.App (Type.Type name) [_] | name == virtualDomNode ->
59− return ()
64+ return ()
60
65
61− Just typeOfMain ->
66+ _ ->
62− let tipe = Type.deepDealias typeOfMain
63− in
64− if tipe `elem` validMainTypes
65− then return ()
66− else Result.throw region (Error.BadMain typeOfMain)
67+ Result.throw region (Error.BadMain tipe)
67
68
68 _ : remainingDecls ->
69 _ : remainingDecls ->
69 checkMainType typeEnv remainingDecls
70 checkMainType typeEnv remainingDecls
@@ -72,37 +73,9 @@ checkMainType typeEnv decls =
72 return ()
73 return ()
73
74
74
75
75−validMainTypes :: [Type.Canonical]
76+virtualDomNode :: Var.Canonical
76−validMainTypes =
77+virtualDomNode =
77− [ element
78− , html
79− , signal element
80− , signal html
81− ]
82−
83−
84−html :: Type.Canonical
85−html =
86− Type.Type (Var.fromModule virtualDom "Node")
78+ Var.fromModule
87−
88−
89−virtualDom :: ModuleName.Canonical
90−virtualDom =
91− ModuleName.Canonical (Pkg.Name "evancz" "virtual-dom") ["VirtualDom"]
79+ (ModuleName.Canonical (Pkg.Name "evancz" "virtual-dom") ["VirtualDom"])
92−
80+ "Node"
93−
94−element :: Type.Canonical
95−element =
96− core ["Graphics","Element"] "Element"
97−
98−
99−signal :: Type.Canonical -> Type.Canonical
100−signal tipe =
101− Type.App (core ["Signal"] "Signal") [ tipe ]
102−
103−
104−core :: [String] -> String -> Type.Canonical
105−core home name =
106− Type.Type (Var.inCore home name)
107−
108
81