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-- Built-in unary operators
47 -- Numeric unary \'plus\'
49 | Positive deriving (Show, Eq, Data, Typeable)
52-- Built-in binary operators
60 -- Numeric subtraction
64 -- Numeric multiplication
76 -- Generic equality test
80 -- Generic inequality test
88 -- Numeric less-than-or-equal
92 -- Numeric greater-than
96 -- Numeric greater-than-or-equal
98 | GreaterThanOrEqualTo
120 -- Bitwise left shift
124 -- Bitwise right shift
128 -- Bitwise right shift with zero-fill
132 -- String concatenation
134 | Concat deriving (Show, Eq, Data, Typeable)
137-- Data type for values
143 = NumericLiteral (Either Integer Double)
147 | StringLiteral String
151 | BooleanLiteral Bool
153 -- Unary operator application
155 | Unary UnaryOperator Value
157 -- Binary operator application
159 | Binary BinaryOperator Value Value
161 -- Binary operator application. During the rebracketing phase of desugaring, this data constructor
164 | BinaryNoParens (Qualified Ident) Value Value
166 -- Explicit parentheses. During the rebracketing phase of desugaring, this data constructor
173 | ArrayLiteral [Value]
175 -- An array indexing expression
177 | Indexer Value Value
181 | ObjectLiteral [(String, Value)]
183 -- An record property accessor expression
185 | Accessor String Value
187 -- Partial record update
189 | ObjectUpdate Value [(String, Value)]
191 -- Function introduction
195 -- Function application
201 | Var (Qualified Ident)
203 -- Conditional (if-then-else expression)
205 | IfThenElse Value Value Value
207 -- A \"Block\" i.e. a collection of statements which evaluate to a value
211 -- A data constructor
213 | Constructor (Qualified ProperName)
215 -- A case expression. During the case expansion phase of desugaring, top-level binders will get
216 -- desugared into case expressions, hence the need for guards and multiple binders per branch here.
218 | Case [Value] [([Binder], Maybe Guard, Value)]
220 -- A value with a type annotation
222 | TypedValue Bool Value Type
224 -- A do-notation block
226 | Do [DoNotationElement]
228 -- A placeholder for a type class dictionary to be inserted later. At the end of type checking, these
229 -- placeholders will be replaced with actual expressions representing type classes dictionaries which
230 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
231 -- instance type, and the type class dictionaries in scope.
233 | TypeClassDictionary (Qualified ProperName, Type) [TypeClassDictionaryInScope] deriving (Show, Data, Typeable)
236-- The type of a type class dictionary
238data TypeClassDictionaryType
240 -- A regular type class dictionary
244 -- A type class dictionary which is an alias for an imported dictionary from another module
246 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
249-- Data representing a type class dictionary which is in scope
251data TypeClassDictionaryInScope
252 = TypeClassDictionaryInScope {
254 -- The identifier with which the dictionary can be accessed at runtime
256 tcdName :: Qualified Ident
258 -- The name of the type class to which this type class instance applies
260 , tcdClassName :: Qualified ProperName
262 -- The type to which this type class instance applies
264 , tcdInstanceType :: Type
266 -- Type class dependencies which must be satisfied to construct this dictionary
268 , tcdDependencies :: Maybe [(Qualified ProperName, Type)]
270 -- The type of this dictionary
272 , tcdType :: TypeClassDictionaryType
273 } deriving (Show, Data, Typeable)
276-- A statement in a do-notation block
278data DoNotationElement
280 -- A monadic value without a binder
282 = DoNotationValue Value
284 -- A monadic value with a binder
286 | DoNotationBind Binder Value
288 -- A let statement, i.e. a pure value with a binder
290 | DoNotationLet Binder Value deriving (Show, Data, Typeable)
293-- Data type for statements which can appear inside a @Block@ expression
297 -- A variable introduction and initial assignment
299 = VariableIntroduction Ident Value
301 -- A variable reassignment
303 | Assignment Ident Value
307 | While Value [Statement]
311 | For Ident Value Value [Statement]
313 -- An if-then-else statement
317 -- A return statement
319 | Return Value deriving (Show, Data, Typeable)
322-- Data type for if-statements
326 -- An if statement. Arguments are (in order): boolean condition, true branch, optional else branch.
328 = IfStatement Value [Statement] (Maybe ElseStatement) deriving (Show, Data, Typeable)
331-- Data type for the else branch in an if-statement
341 | ElseIf IfStatement deriving (Show, Data, Typeable)
344-- Data type for binders
352 -- A binder which matches a boolean literal
356 -- A binder which matches a string literal
358 | StringBinder String
360 -- A binder which matches a numeric literal
362 | NumberBinder (Either Integer Double)
364 -- A binder which binds an identifier
368 -- A binder which matches a data constructor with no argument
370 | NullaryBinder (Qualified ProperName)
372 -- A binder which matches a data constructor with one argument
374 | UnaryBinder (Qualified ProperName) Binder
376 -- A binder which matches a record and binds its properties
378 | ObjectBinder [(String, Binder)]
380 -- A binder which matches an array and binds its elements
382 | ArrayBinder [Binder]
384 -- A binder which matches an array and binds its head and tail
386 | ConsBinder Binder Binder
388 -- A binder which binds its input to an identifier
390 | 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