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
91 | Constructor (Qualified ProperName)
93 -- A case expression. During the case expansion phase of desugaring, top-level binders will get
94 -- desugared into case expressions, hence the need for guards and multiple binders per branch here.
96 | Case [Value] [([Binder], Maybe Guard, Value)]
98 -- A value with a type annotation
100 | TypedValue Bool Value Type
102 -- A do-notation block
104 | Do [DoNotationElement]
106 -- A placeholder for a type class dictionary to be inserted later. At the end of type checking, these
107 -- placeholders will be replaced with actual expressions representing type classes dictionaries which
108 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
109 -- instance type, and the type class dictionaries in scope.
111 | TypeClassDictionary (Qualified ProperName, Type) [TypeClassDictionaryInScope] deriving (Show, Data, Typeable)
114-- The type of a type class dictionary
116data TypeClassDictionaryType
118 -- A regular type class dictionary
122 -- A type class dictionary which is an alias for an imported dictionary from another module
124 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
127-- Data representing a type class dictionary which is in scope
129data TypeClassDictionaryInScope
130 = TypeClassDictionaryInScope {
132 -- The identifier with which the dictionary can be accessed at runtime
134 tcdName :: Qualified Ident
136 -- The name of the type class to which this type class instance applies
138 , tcdClassName :: Qualified ProperName
140 -- The type to which this type class instance applies
142 , tcdInstanceType :: Type
144 -- Type class dependencies which must be satisfied to construct this dictionary
146 , tcdDependencies :: Maybe [(Qualified ProperName, Type)]
148 -- The type of this dictionary
150 , tcdType :: TypeClassDictionaryType
151 } deriving (Show, Data, Typeable)
154-- A statement in a do-notation block
156data DoNotationElement
158 -- A monadic value without a binder
160 = DoNotationValue Value
162 -- A monadic value with a binder
164 | DoNotationBind Binder Value
166 -- A let statement, i.e. a pure value with a binder
168 | DoNotationLet Binder Value deriving (Show, Data, Typeable)
171-- Data type for binders
179 -- A binder which matches a boolean literal
183 -- A binder which matches a string literal
185 | StringBinder String
187 -- A binder which matches a numeric literal
189 | NumberBinder (Either Integer Double)
191 -- A binder which binds an identifier
195 -- A binder which matches a data constructor
197 | ConstructorBinder (Qualified ProperName) [Binder]
199 -- A binder which matches a record and binds its properties
201 | ObjectBinder [(String, Binder)]
203 -- A binder which matches an array and binds its elements
205 | ArrayBinder [Binder]
207 -- A binder which matches an array and binds its head and tail
209 | ConsBinder Binder Binder
211 -- A binder which binds its input to an identifier
213 | 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