1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Environment
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.TypeClassDictionaries
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 :: M.Map (Qualified Ident, Maybe ModuleName) TypeClassDictionaryInScope
56 , typeClasses :: M.Map (Qualified ProperName) ([String], [(Ident, Type)], [(Qualified ProperName, [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 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
76 | InlineJavascript deriving (Show, Eq, Data, Typeable)
83 -- A value introduced as a binding in a module
87 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
89 | TypeClassAccessorImport
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 deriving (Show, Eq, Data, Typeable)
108-- The kinds of a type
114 = DataType [String] [(ProperName, [Type])]
124 -- A local type variable
126 | LocalTypeVariable deriving (Show, Eq, Data, Typeable)
129-- Construct a ProperName in the Prim module
131primName :: String -> Qualified ProperName
132primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
135-- Construct a type in the Prim module
137primTy :: String -> Type
138primTy = TypeConstructor . primName
141-- Type constructor for functions
144tyFunction = primTy "Function"
147-- Type constructor for strings
150tyString = primTy "String"
153-- Type constructor for numbers
156tyNumber = primTy "Number"
159-- Type constructor for booleans
162tyBoolean = primTy "Boolean"
165-- Type constructor for arrays
168tyArray = primTy "Array"
171-- Type constructor for objects
174tyObject = primTy "Object"
177-- Smart constructor for function types
179function :: Type -> Type -> Type
180function t1 = TypeApp (TypeApp tyFunction t1)
183-- The primitive types in the external javascript environment with their associated kinds.
185primTypes :: M.Map (Qualified ProperName) (Kind, TypeKind)
186primTypes = M.fromList [ (primName "Function" , (FunKind Star (FunKind Star Star), ExternData))
187 , (primName "Array" , (FunKind Star Star, ExternData))
188 , (primName "Object" , (FunKind (Row Star) Star, ExternData))
189 , (primName "String" , (Star, ExternData))
190 , (primName "Number" , (Star, ExternData))
191 , (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