1{-# OPTIONS_GHC -Wall #-}
2module Nitpick.TopLevelTypes (topLevelTypes) where
4import Control.Monad (foldM, when)
6import qualified Data.Map as Map
7import qualified Data.Maybe as Maybe
9import qualified AST.Expression.Valid as Valid
10import qualified AST.Declaration as Decl
11import qualified AST.Module.Name as ModuleName
12import qualified AST.Pattern as P
13import qualified AST.Type as Type
14import qualified AST.Variable as Var
15import qualified Elm.Package as Pkg
16import qualified Reporting.Annotation as A
17import qualified Reporting.Error.Type as Error
18import qualified Reporting.Region as R
19import qualified Reporting.Result as Result
20import qualified Reporting.Warning as Warning
24-- CHECK TOP LEVEL TYPES
28 :: Map.Map String Type.Canonical
30 -> Result.Result Warning.Warning Error.Error ()
31topLevelTypes typeEnv validDecls =
32 do maybeMainRegion <- foldM (warnMissingAnnotation typeEnv) Nothing validDecls
33 maybe (return ()) (checkMainType typeEnv) maybeMainRegion
41 :: Map.Map String Type.Canonical
44 -> Result.Result Warning.Warning Error.Error (Maybe R.Region)
45warnMissingAnnotation typeEnv maybeMainRegion (A.A (region,_) decl) =
47 Decl.Def (Valid.Definition (A.A _ (P.Var name)) _ maybeType) ->
48 do when (Maybe.isNothing maybeType) $
49 Result.warn region (Warning.MissingTypeAnnotation name (typeEnv ! name))
51 return (if name == "main" then Just region else maybeMainRegion)
54 return maybeMainRegion
61checkMainType :: Map.Map String Type.Canonical -> R.Region -> Result.Result w Error.Error ()
62checkMainType typeEnv region =
67 case Type.deepDealias tipe of
68 Type.App name [_] | name `elem` [program, vdomNode] ->
72 Result.throw region (Error.BadMain tipe)
75program :: Type.Canonical
77 Type.Type (Var.inCore ["Platform"] "Program")
80vdomNode :: Type.Canonical
84 ModuleName.Canonical (Pkg.Name "evancz" "virtual-dom") ["VirtualDom"]
86 Type.Type (Var.fromModule vdom "Node")
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