1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
7 , get, freshDataScheme, ctorNames
14import qualified Control.Monad.State.Strict as State
15import qualified Data.List as List
16import qualified Data.Map as Map
17import qualified Data.Set as Set
18import Data.Text (Text)
20import qualified AST.Helpers as Help
21import qualified AST.Type as T
22import qualified AST.Variable as Var
23import qualified AST.Module as Module
33 { _ctor :: Dict Instantiator
39 IO (Int, [Variable], [Type], Type)
46initialize :: [Module.CanonicalUnion] -> Env
48 Env (makeCtors unions) Map.empty
55makeCtors :: [Module.CanonicalUnion] -> Dict Instantiator
61 inst :: Int -> ([Type] -> ([Type], Type)) -> Instantiator
63 do vars <- mapM (\_ -> mkFlexVar) [1..numTVars]
64 let (args, result) = tipe (map (VarN) vars)
65 return (length args, vars, args, result)
72 (name, inst size $ \vs -> (vs, AppN (Var.tuple size) vs))
74 builtins :: Dict Instantiator
77 [ ("[]", inst 1 $ \ [t] -> ([], list t))
78 , ("::", inst 1 $ \ [t] -> ([t, list t], list t))
80 ++ map tupleCtor [0..9]
82 List.foldl' makeCtorsHelp builtins unions
89makeCtorsHelp :: Dict Instantiator -> Module.CanonicalUnion -> Dict Instantiator
90makeCtorsHelp constructorDict ( var, (rawTypeVars, ctors) ) =
92 inst :: Dict Instantiator -> (Var.Canonical, [T.Canonical]) -> Dict Instantiator
93 inst ctorDict (name, rawArgs) =
96 ( do ((args, tipe), dict) <- State.runStateT (go rawArgs) Map.empty
97 return ( length args, Map.elems dict, args, tipe )
102 map T.Var rawTypeVars
104 go :: [T.Canonical] -> State.StateT VarDict IO ([Type], Type)
106 do types <- mapM (instantiator nameToFlex Map.empty) args
107 returnType <- instantiator nameToFlex Map.empty (T.Type var tvars)
108 return (types, returnType)
110 List.foldl' inst constructorDict ctors
118get :: Dict a -> Text -> a
123freshDataScheme :: Env -> Text -> Instantiator
124freshDataScheme env var =
128ctorNames :: Env -> [Text]
137addValues :: VarDict -> Env -> Env
138addValues newValues env =
139 env { _value = Map.union (_value env) (Map.map VarN newValues) }
146instantiateFlex :: Env -> T.Canonical -> IO (Type, VarDict)
147instantiateFlex env sourceType =
148 State.runStateT (instantiator nameToFlex (_value env) sourceType) Map.empty
151instantiateRigid :: Env -> T.Canonical -> IO (Type, VarDict)
152instantiateRigid env sourceType =
153 State.runStateT (instantiator nameToRigid (_value env) sourceType) Map.empty
156instantiator :: (Text -> IO Variable) -> Dict Type -> T.Canonical -> State.StateT VarDict IO Type
157instantiator nameToVar values sourceType =
158 instantiatorHelp nameToVar values Set.empty sourceType
161instantiatorHelp :: (Text -> IO Variable) -> Dict Type -> Set.Set Text -> T.Canonical -> State.StateT VarDict IO Type
162instantiatorHelp nameToVar values aliasVars sourceType =
163 {-# SCC elm_compiler_type_instantiate #-}
166 instantiatorHelp nameToVar values aliasVars
170 FunN <$> go t1 <*> go t2
173 if Set.member name aliasVars then
174 return (PlaceHolder name)
177 case Map.lookup name values of
183 case Map.lookup name dict of
185 return (VarN variable)
188 do variable <- State.liftIO (nameToVar name)
189 State.put (Map.insert name variable dict)
190 return (VarN variable)
192 T.Aliased name args aliasType ->
193 do targs <- traverse (traverse go) args
197 instantiatorHelp nameToVar values Set.empty tipe
200 instantiatorHelp nameToVar values (Set.fromList (map fst args)) tipe
202 return (AliasN name targs realType)
205 AppN name <$> traverse go args
207 T.Record fields ext ->
208 do tfields <- traverse go (Map.fromList fields)
217 return $ RecordN tfields text
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