1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Prim
4-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Environment where
21import Language.PureScript.Names
22import Language.PureScript.Types
23import Language.PureScript.Kinds
24import Language.PureScript.Values
25import qualified Language.PureScript.Constants as C
27import qualified Data.Map as M
30-- The @Environment@ defines all values and types which are currently in scope:
32data Environment = Environment {
34 -- Value names currently in scope
36 names :: M.Map (ModuleName, Ident) (Type, NameKind)
38 -- Type names currently in scope
40 , types :: M.Map (Qualified ProperName) (Kind, TypeKind)
42 -- Data constructors currently in scope, along with their associated data type constructors
44 , dataConstructors :: M.Map (Qualified ProperName) (ProperName, Type)
46 -- Type synonyms currently in scope
48 , typeSynonyms :: M.Map (Qualified ProperName) ([String], Type)
50 -- Available type class dictionaries
52 , typeClassDictionaries :: [TypeClassDictionaryInScope]
56 , typeClasses :: M.Map (Qualified ProperName) ([String], [(Ident, Type)])
60-- The initial environment with no values and only the default javascript types defined
62initEnvironment :: Environment
63initEnvironment = Environment M.empty primTypes M.empty M.empty [] M.empty
66-- The type of a foreign import
70 -- A regular foreign import
74 -- A foreign import which contains inline Javascript as a string literal
78 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
80 | TypeClassAccessorImport deriving (Show, Eq, Data, Typeable)
87 -- A value introduced as a binding in a module
93 | Extern ForeignImportType
95 -- A local name introduced using a lambda abstraction, variable introduction or binder
103 -- A type class dictionary, generated during desugaring of type class declarations
105 | TypeInstanceDictionaryValue
107 -- A type instance member, generated during desugaring of type class declarations
109 | TypeInstanceMember deriving (Show, Eq, Data, Typeable)
112-- The kinds of a type
118 = DataType [String] [(ProperName, [Type])]
128 -- A local type variable
130 | LocalTypeVariable deriving (Show, Eq, Data, Typeable)
133-- Construct a ProperName in the Prim module
135primName :: String -> Qualified ProperName
136primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
139-- Construct a type in the Prim module
141primTy :: String -> Type
142primTy = TypeConstructor . primName
145-- Type constructor for functions
148tyFunction = primTy "Function"
151-- Type constructor for strings
154tyString = primTy "String"
157-- Type constructor for numbers
160tyNumber = primTy "Number"
163-- Type constructor for booleans
166tyBoolean = primTy "Boolean"
169-- Type constructor for arrays
172tyArray = primTy "Array"
175-- Smart constructor for function types
177function :: Type -> Type -> Type
178function t1 = TypeApp (TypeApp tyFunction t1)
181-- The primitive types in the external javascript environment with their associated kinds.
183primTypes :: M.Map (Qualified ProperName) (Kind, TypeKind)
184primTypes = M.fromList [ (primName "Function" , (FunKind Star (FunKind Star Star), ExternData))
185 , (primName "Array" , (FunKind Star Star, ExternData))
186 , (primName "String" , (Star, ExternData))
187 , (primName "Number" , (Star, ExternData))
188 , (primName "Boolean" , (Star, ExternData)) ]
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