1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Values
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- Data types for values, statements, binders and do notation
14-----------------------------------------------------------------------------
16{-# LANGUAGE DeriveDataTypeable #-}
18module Language.PureScript.Values where
20import Language.PureScript.Types
21import Language.PureScript.Names
26-- A guard is just a boolean-valued expression that appears alongside a set of binders
31-- Data type for values
37 = NumericLiteral (Either Integer Double)
41 | StringLiteral String
47 -- Binary operator application. During the rebracketing phase of desugaring, this data constructor
50 | BinaryNoParens (Qualified Ident) Value Value
52 -- Explicit parentheses. During the rebracketing phase of desugaring, this data constructor
59 | ArrayLiteral [Value]
63 | ObjectLiteral [(String, Value)]
65 -- An record property accessor expression
67 | Accessor String Value
69 -- Partial record update
71 | ObjectUpdate Value [(String, Value)]
73 -- Function introduction
77 -- Function application
83 | Var (Qualified Ident)
85 -- Conditional (if-then-else expression)
87 | IfThenElse Value Value Value
89 -- A \"Block\" i.e. a collection of statements which evaluate to a value
95 | Constructor (Qualified ProperName)
97 -- A case expression. During the case expansion phase of desugaring, top-level binders will get
98 -- desugared into case expressions, hence the need for guards and multiple binders per branch here.
100 | Case [Value] [([Binder], Maybe Guard, Value)]
102 -- A value with a type annotation
104 | TypedValue Bool Value Type
106 -- A do-notation block
108 | Do [DoNotationElement]
110 -- A placeholder for a type class dictionary to be inserted later. At the end of type checking, these
111 -- placeholders will be replaced with actual expressions representing type classes dictionaries which
112 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
113 -- instance type, and the type class dictionaries in scope.
115 | TypeClassDictionary (Qualified ProperName, Type) [TypeClassDictionaryInScope] deriving (Show, Data, Typeable)
118-- The type of a type class dictionary
120data TypeClassDictionaryType
122 -- A regular type class dictionary
126 -- A type class dictionary which is an alias for an imported dictionary from another module
128 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
131-- Data representing a type class dictionary which is in scope
133data TypeClassDictionaryInScope
134 = TypeClassDictionaryInScope {
136 -- The identifier with which the dictionary can be accessed at runtime
138 tcdName :: Qualified Ident
140 -- The name of the type class to which this type class instance applies
142 , tcdClassName :: Qualified ProperName
144 -- The type to which this type class instance applies
146 , tcdInstanceType :: Type
148 -- Type class dependencies which must be satisfied to construct this dictionary
150 , tcdDependencies :: Maybe [(Qualified ProperName, Type)]
152 -- The type of this dictionary
154 , tcdType :: TypeClassDictionaryType
155 } deriving (Show, Data, Typeable)
158-- A statement in a do-notation block
160data DoNotationElement
162 -- A monadic value without a binder
164 = DoNotationValue Value
166 -- A monadic value with a binder
168 | DoNotationBind Binder Value
170 -- A let statement, i.e. a pure value with a binder
172 | DoNotationLet Binder Value deriving (Show, Data, Typeable)
175-- Data type for statements which can appear inside a @Block@ expression
179 -- A variable introduction and initial assignment
181 = VariableIntroduction Ident Value
183 -- A variable reassignment
185 | Assignment Ident Value
189 | While Value [Statement]
193 | For Ident Value Value [Statement]
195 -- An if-then-else statement
199 -- A return statement
201 | Return Value deriving (Show, Data, Typeable)
204-- Data type for if-statements
208 -- An if statement. Arguments are (in order): boolean condition, true branch, optional else branch.
210 = IfStatement Value [Statement] (Maybe ElseStatement) deriving (Show, Data, Typeable)
213-- Data type for the else branch in an if-statement
223 | ElseIf IfStatement deriving (Show, Data, Typeable)
226-- Data type for binders
234 -- A binder which matches a boolean literal
238 -- A binder which matches a string literal
240 | StringBinder String
242 -- A binder which matches a numeric literal
244 | NumberBinder (Either Integer Double)
246 -- A binder which binds an identifier
250 -- A binder which matches a data constructor
252 | ConstructorBinder (Qualified ProperName) [Binder]
254 -- A binder which matches a record and binds its properties
256 | ObjectBinder [(String, Binder)]
258 -- A binder which matches an array and binds its elements
260 | ArrayBinder [Binder]
262 -- A binder which matches an array and binds its head and tail
264 | ConsBinder Binder Binder
266 -- A binder which binds its input to an identifier
268 | NamedBinder Ident Binder deriving (Show, Data, Typeable)
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