1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
7 , get, freshDataScheme, ctorNames
13import qualified Control.Monad.State.Strict as State
14import qualified Data.List as List
15import qualified Data.Map as Map
16import qualified Data.Set as Set
17import Data.Text (Text)
19import qualified AST.Helpers as Help
20import qualified AST.Type as T
21import qualified AST.Variable as Var
22import qualified AST.Module as Module
32 { _ctor :: Dict Instantiator
38 IO (Int, [Variable], [Type], Type)
45initialize :: [Module.CanonicalUnion] -> Env
47 Env (makeCtors unions) Map.empty
54makeCtors :: [Module.CanonicalUnion] -> Dict Instantiator
60 inst :: Int -> ([Type] -> ([Type], Type)) -> Instantiator
62 do vars <- mapM (\_ -> mkVar Nothing) [1..numTVars]
63 let (args, result) = tipe (map (VarN) vars)
64 return (length args, vars, args, result)
71 (name, inst size $ \vs -> (vs, AppN (Var.tuple size) vs))
73 builtins :: Dict Instantiator
76 [ ("[]", inst 1 $ \ [t] -> ([], list t))
77 , ("::", inst 1 $ \ [t] -> ([t, list t], list t))
79 ++ map tupleCtor [0..9]
81 List.foldl' makeCtorsHelp builtins unions
88makeCtorsHelp :: Dict Instantiator -> Module.CanonicalUnion -> Dict Instantiator
89makeCtorsHelp constructorDict ( var, (rawTypeVars, ctors) ) =
91 inst :: Dict Instantiator -> (Var.Canonical, [T.Canonical]) -> Dict Instantiator
92 inst ctorDict (name, rawArgs) =
95 ( do ((args, tipe), dict) <- State.runStateT (go rawArgs) Map.empty
96 return ( length args, Map.elems dict, args, tipe )
101 map T.Var rawTypeVars
103 go :: [T.Canonical] -> State.StateT VarDict IO ([Type], Type)
105 do types <- mapM (instantiator Flex Map.empty) args
106 returnType <- instantiator Flex Map.empty (T.Type var tvars)
107 return (types, returnType)
109 List.foldl' inst constructorDict ctors
117get :: Dict a -> Text -> a
122freshDataScheme :: Env -> Text -> Instantiator
123freshDataScheme env var =
127ctorNames :: Env -> [Text]
136addValues :: VarDict -> Env -> Env
137addValues newValues env =
138 env { _value = Map.union (_value env) (Map.map VarN newValues) }
145instantiateType :: Flex -> Env -> T.Canonical -> IO (Type, VarDict)
146instantiateType flex env sourceType =
147 State.runStateT (instantiator flex (_value env) sourceType) Map.empty
150instantiator :: Flex -> Dict Type -> T.Canonical -> State.StateT VarDict IO Type
151instantiator flex values sourceType =
152 instantiatorHelp flex values Set.empty sourceType
155instantiatorHelp :: Flex -> Dict Type -> Set.Set Text -> T.Canonical -> State.StateT VarDict IO Type
156instantiatorHelp flex values aliasVars sourceType =
159 instantiatorHelp flex values aliasVars
163 (==>) <$> go t1 <*> go t2
166 if Set.member name aliasVars then
167 return (PlaceHolder name)
170 case Map.lookup name values of
176 case Map.lookup name dict of
178 return (VarN variable)
181 do variable <- State.liftIO (mkNamedVar flex name)
182 State.put (Map.insert name variable dict)
183 return (VarN variable)
185 T.Aliased name args aliasType ->
186 do targs <- traverse (traverse go) args
190 instantiatorHelp flex values Set.empty tipe
193 instantiatorHelp flex values (Set.fromList (map fst args)) tipe
195 return (AliasN name targs realType)
198 AppN name <$> traverse go args
200 T.Record fields ext ->
201 do tfields <- traverse go (Map.fromList fields)
210 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