1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
13import qualified Data.Map as Map
14import qualified Data.Maybe as Maybe
15import Data.Monoid ((<>))
17import qualified AST.Module.Name as ModuleName
18import qualified Elm.Name as N
19import qualified Reporting.Helpers as H
20import qualified Reporting.Render.Type as RT
28 = Lambda Type Type [Type]
35 | Type ModuleName.Canonical N.Name [Type]
36 | Record (Map.Map N.Name Type) Extension
38 | Tuple Type Type (Maybe Type)
39 | Alias ModuleName.Canonical N.Name [(N.Name, Type)] Type
48iteratedDealias :: Type -> Type
51 Alias _ _ _ realType ->
52 iteratedDealias realType
62type Localizer = Map.Map (ModuleName.Canonical, N.Name) String
65nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> H.Doc
66nameToDoc localizer home@(ModuleName.Canonical _ moduleName) name =
67 case Map.lookup (home, name) localizer of
69 H.nameToDoc moduleName <> "." <> H.nameToDoc name
75toDoc :: Localizer -> RT.Context -> Type -> H.Doc
76toDoc localizer context tipe =
80 (toDoc localizer RT.Func a)
81 (toDoc localizer RT.Func b)
82 (map (toDoc localizer RT.Func) cs)
102 Type home name args ->
104 (nameToDoc localizer home name)
105 (map (toDoc localizer RT.App) args)
109 entryToDocs (fieldName, fieldType) =
110 ( H.nameToDoc fieldName, toDoc localizer RT.None fieldType )
113 map entryToDocs (Map.toList fields)
115 RT.record fieldDocs $
118 FlexOpen x -> Just (H.nameToDoc x)
119 RigidOpen x -> Just (H.nameToDoc x)
127 (toDoc localizer RT.None a)
128 (toDoc localizer RT.None b)
129 (map (toDoc localizer RT.None) (Maybe.maybeToList maybeC))
131 Alias home name args _ ->
133 (nameToDoc localizer home name)
134 (map (toDoc localizer RT.App . snd) args)
148-- DETECT MISSING ARGS
151detectMissingArgs :: Type -> Type -> Maybe (Type, [Type])
152detectMissingArgs actual expected =
153 detectMissingArgsHelp (reverseArgs actual) (reverseArgs expected)
156detectMissingArgsHelp :: [Type] -> [Type] -> Maybe (Type, [Type])
157detectMissingArgsHelp actuals expecteds =
158 case (actuals, expecteds) of
159 (x:xs, y:ys) -> if isMatchy x y then detectMissingArgsHelp xs ys else Nothing
160 (x:xs, []) -> Just (x, xs)
165reverseArgs :: Type -> [Type]
168 Lambda a b cs -> reverse (a:b:cs)
172 FlexSuper _ -> [tipe]
174 RigidSuper _ -> [tipe]
178 Tuple _ _ _ -> [tipe]
179 Alias _ _ _ t -> reverseArgs t
182isMatchy :: Type -> Type -> Bool
185 (Lambda a b cs, Lambda x y zs) ->
186 isMatchy a x && isMatchy b y && length cs == length zs && and (zipWith isMatchy cs zs)
188 (Infinite, Infinite) ->
200 (FlexSuper x, FlexSuper y) ->
203 (RigidVar x, RigidVar y) ->
206 (RigidSuper x, RigidSuper y) ->
209 (Type home1 name1 args1, Type home2 name2 args2) ->
210 home1 == home2 && name1 == name2 && and (zipWith isMatchy args1 args2)
212 (Record fields1 ext1, Record fields2 ext2) ->
214 (Map.size (Map.difference fields1 fields2))
215 (Map.intersectionWith isMatchy fields1 fields2)
216 (Map.size (Map.difference fields2 fields1))
221 (Tuple a b Nothing, Tuple x y Nothing) ->
222 isMatchy a x && isMatchy b y
224 (Tuple a b (Just c), Tuple x y (Just z)) ->
225 isMatchy a x && isMatchy b y && isMatchy c z
227 (Alias _ _ _ alias1, tipe2) ->
228 isMatchy alias1 tipe2
230 (tipe1, Alias _ _ _ alias2) ->
231 isMatchy tipe1 alias2
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