1{-# OPTIONS_GHC -Wall #-}
2module Nitpick.TopLevelTypes (topLevelTypes) where
4import Prelude hiding (maybe)
5import qualified Data.Foldable as F
6import qualified Data.Map as Map
8import qualified AST.Expression.Valid as Valid
9import qualified AST.Declaration as Decl
10import qualified AST.Pattern as P
11import qualified AST.Type as Type
12import qualified AST.Variable as Var
13import qualified Reporting.Annotation as A
14import qualified Reporting.Error.Type as Error
15import qualified Reporting.Result as Result
16import qualified Reporting.Warning as Warning
20 :: Map.Map String Type.Canonical
22 -> Result.Result Warning.Warning Error.Error ()
23topLevelTypes typeEnv validDecls =
24 do F.traverse_ (warnMissingAnnotation typeEnv) validDecls
25 checkMainType typeEnv validDecls
31 :: Map.Map String Type.Canonical
33 -> Result.Result Warning.Warning Error.Error ()
34warnMissingAnnotation typeEnv (A.A (region,_) decl) =
36 Decl.Definition (Valid.Definition (A.A _ (P.Var name)) _ Nothing) ->
37 case Map.lookup name typeEnv of
41 Result.warn region (Warning.MissingTypeAnnotation name tipe)
49 :: Map.Map String Type.Canonical
51 -> Result.Result w Error.Error ()
52checkMainType typeEnv decls =
54 A.A (region,_) (Decl.Definition (Valid.Definition (A.A _ (P.Var "main")) _ _)) : _ ->
55 case Map.lookup "main" typeEnv of
60 let tipe = Type.deepDealias typeOfMain
62 if tipe `elem` validMainTypes
64 else Result.throw region (Error.BadMain typeOfMain)
67 checkMainType typeEnv remainingDecls
73validMainTypes :: [Type.Canonical]
81 fromModule :: [String] -> String -> Type.Canonical
82 fromModule home name =
83 Type.Type (Var.fromModule home name)
86 fromModule ["VirtualDom"] "Node"
89 Type.App (fromModule ["Signal"] "Signal") [ tipe ]
93 Type.Type (Var.builtin name)
96 Type.App (fromModule ["Maybe"] "Maybe") [ tipe ]
99 [ ("element", fromModule ["Graphics","Element"] "ElementPrim")
102 [ ("click" , builtin "_Tuple0")
103 , ("color" , maybe (fromModule ["Color"] "Color"))
104 , ("height" , builtin "Int")
105 , ("hover" , builtin "_Tuple0")
106 , ("href" , builtin "String")
107 , ("id" , builtin "Int")
108 , ("opacity", builtin "Float")
109 , ("tag" , builtin "String")
110 , ("width" , builtin "Int")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list