module Language.PureScript.Environment where
import Data.Data
import Language.PureScript.Names
import Language.PureScript.Types
import Language.PureScript.Kinds
import Language.PureScript.TypeClassDictionaries
import qualified Language.PureScript.Constants as C
import qualified Data.Map as M
data Environment = Environment {
names :: M.Map (ModuleName, Ident) (Type, NameKind)
, types :: M.Map (Qualified ProperName) (Kind, TypeKind)
, dataConstructors :: M.Map (Qualified ProperName) (ProperName, Type)
, typeSynonyms :: M.Map (Qualified ProperName) ([String], Type)
, typeClassDictionaries :: [TypeClassDictionaryInScope]
, typeClasses :: M.Map (Qualified ProperName) ([String], [(Ident, Type)], [(Qualified ProperName, [Type])])
} deriving (Show)
initEnvironment :: Environment
initEnvironment = Environment M.empty primTypes M.empty M.empty [] M.empty
data ForeignImportType
= ForeignImport
| InlineJavascript deriving (Show, Eq, Data, Typeable)
data NameKind
= Value
| TypeClassAccessorImport
| Extern ForeignImportType
| LocalVariable
| DataConstructor
| TypeInstanceDictionaryValue deriving (Show, Eq, Data, Typeable)
data TypeKind
= DataType [String] [(ProperName, [Type])]
| TypeSynonym
| ExternData
| LocalTypeVariable deriving (Show, Eq, Data, Typeable)
primName :: String -> Qualified ProperName
primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
primTy :: String -> Type
primTy = TypeConstructor . primName
tyFunction :: Type
tyFunction = primTy "Function"
tyString :: Type
tyString = primTy "String"
tyNumber :: Type
tyNumber = primTy "Number"
tyBoolean :: Type
tyBoolean = primTy "Boolean"
tyArray :: Type
tyArray = primTy "Array"
tyObject :: Type
tyObject = primTy "Object"
function :: Type -> Type -> Type
function t1 = TypeApp (TypeApp tyFunction t1)
primTypes :: M.Map (Qualified ProperName) (Kind, TypeKind)
primTypes = M.fromList [ (primName "Function" , (FunKind Star (FunKind Star Star), ExternData))
, (primName "Array" , (FunKind Star Star, ExternData))
, (primName "Object" , (FunKind (Row Star) Star, ExternData))
, (primName "String" , (Star, ExternData))
, (primName "Number" , (Star, ExternData))
, (primName "Boolean" , (Star, ExternData)) ]