1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
13import qualified Data.Map as Map
14import qualified Data.Maybe as Maybe
16import qualified AST.Module.Name as ModuleName
17import qualified Elm.Name as N
18import qualified Reporting.Helpers as H
19import qualified Reporting.Render.Type as RT
27 = Lambda Type Type [Type]
34 | Type ModuleName.Canonical N.Name [Type]
35 | Record (Map.Map N.Name Type) Extension
37 | Tuple Type Type (Maybe Type)
38 | Alias ModuleName.Canonical N.Name [(N.Name, Type)] Type
47iteratedDealias :: Type -> Type
50 Alias _ _ _ realType ->
51 iteratedDealias realType
61type Localizer = Map.Map (ModuleName.Canonical, N.Name) (Maybe N.Name)
64toDoc :: Localizer -> RT.Context -> Type -> H.Doc
65toDoc localizer context tipe =
69 (toDoc localizer RT.Func a)
70 (toDoc localizer RT.Func b)
71 (map (toDoc localizer RT.Func) cs)
91 Type home name args ->
93 (toLocal localizer home name)
94 (map (toDoc localizer RT.App) args)
98 entryToDocs (fieldName, fieldType) =
99 ( H.nameToDoc fieldName, toDoc localizer RT.None fieldType )
102 map entryToDocs (Map.toList fields)
104 RT.record fieldDocs $
107 FlexOpen x -> Just (H.nameToDoc x)
108 RigidOpen x -> Just (H.nameToDoc x)
116 (toDoc localizer RT.None a)
117 (toDoc localizer RT.None b)
118 (map (toDoc localizer RT.None) (Maybe.maybeToList maybeC))
120 Alias home name args _ ->
122 (toLocal localizer home name)
123 (map (toDoc localizer RT.App . snd) args)
126toLocal :: Localizer -> ModuleName.Canonical -> N.Name -> H.Doc
127toLocal localizer home name =
128 error "TODO toLocal" localizer home name
142-- DETECT MISSING ARGS
145detectMissingArgs :: Type -> Type -> Maybe (Type, [Type])
146detectMissingArgs actual expected =
147 detectMissingArgsHelp (reverseArgs actual) (reverseArgs expected)
150detectMissingArgsHelp :: [Type] -> [Type] -> Maybe (Type, [Type])
151detectMissingArgsHelp actuals expecteds =
152 case (actuals, expecteds) of
153 (x:xs, y:ys) -> if isMatchy x y then detectMissingArgsHelp xs ys else Nothing
154 (x:xs, []) -> Just (x, xs)
159reverseArgs :: Type -> [Type]
162 Lambda a b cs -> reverse (a:b:cs)
166 FlexSuper _ -> [tipe]
168 RigidSuper _ -> [tipe]
172 Tuple _ _ _ -> [tipe]
173 Alias _ _ _ t -> reverseArgs t
176isMatchy :: Type -> Type -> Bool
179 (Lambda a b cs, Lambda x y zs) ->
180 isMatchy a x && isMatchy b y && length cs == length zs && and (zipWith isMatchy cs zs)
182 (Infinite, Infinite) ->
194 (FlexSuper x, FlexSuper y) ->
197 (RigidVar x, RigidVar y) ->
200 (RigidSuper x, RigidSuper y) ->
203 (Type home1 name1 args1, Type home2 name2 args2) ->
204 home1 == home2 && name1 == name2 && and (zipWith isMatchy args1 args2)
206 (Record fields1 ext1, Record fields2 ext2) ->
208 (Map.size (Map.difference fields1 fields2))
209 (Map.intersectionWith isMatchy fields1 fields2)
210 (Map.size (Map.difference fields2 fields1))
215 (Tuple a b Nothing, Tuple x y Nothing) ->
216 isMatchy a x && isMatchy b y
218 (Tuple a b (Just c), Tuple x y (Just z)) ->
219 isMatchy a x && isMatchy b y && isMatchy c z
221 (Alias _ _ _ alias1, tipe2) ->
222 isMatchy alias1 tipe2
224 (tipe1, Alias _ _ _ alias2) ->
225 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