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
75 | Abs (Either Ident Binder) Value
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
104 | Let Binder Value Value
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 types to which this type class instance applies
146 , tcdInstanceTypes :: [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 binders
183 -- A binder which matches a boolean literal
187 -- A binder which matches a string literal
189 | StringBinder String
191 -- A binder which matches a numeric literal
193 | NumberBinder (Either Integer Double)
195 -- A binder which binds an identifier
199 -- A binder which matches a data constructor
201 | ConstructorBinder (Qualified ProperName) [Binder]
203 -- A binder which matches a record and binds its properties
205 | ObjectBinder [(String, Binder)]
207 -- A binder which matches an array and binds its elements
209 | ArrayBinder [Binder]
211 -- A binder which matches an array and binds its head and tail
213 | ConsBinder Binder Binder
215 -- A binder which binds its input to an identifier
217 | 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