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
24import Data.Generics (mkQ, everything)
27-- A guard is just a boolean-valued expression that appears alongside a set of binders
32-- Data type for values
38 = NumericLiteral (Either Integer Double)
42 | StringLiteral String
48 -- Binary operator application. During the rebracketing phase of desugaring, this data constructor
51 | BinaryNoParens (Qualified Ident) Value Value
53 -- Explicit parentheses. During the rebracketing phase of desugaring, this data constructor
60 | ArrayLiteral [Value]
64 | ObjectLiteral [(String, Value)]
66 -- An record property accessor expression
68 | Accessor String Value
70 -- Partial record update
72 | ObjectUpdate Value [(String, Value)]
74 -- Function introduction
76 | Abs (Either Ident Binder) Value
78 -- Function application
84 | Var (Qualified Ident)
86 -- Conditional (if-then-else expression)
88 | IfThenElse Value Value Value
92 | Constructor (Qualified ProperName)
94 -- A case expression. During the case expansion phase of desugaring, top-level binders will get
95 -- desugared into case expressions, hence the need for guards and multiple binders per branch here.
97 | Case [Value] [([Binder], Maybe Guard, Value)]
99 -- A value with a type annotation
101 | TypedValue Bool Value Type
105 | Let Binder Value Value
107 -- A do-notation block
109 | Do [DoNotationElement]
111 -- A placeholder for a type class dictionary to be inserted later. At the end of type checking, these
112 -- placeholders will be replaced with actual expressions representing type classes dictionaries which
113 -- can be evaluated at runtime. The constructor arguments represent (in order): the type class name and
114 -- instance type, and the type class dictionaries in scope.
116 | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope] deriving (Show, Data, Typeable)
119-- Data representing a type class dictionary which is in scope
121data TypeClassDictionaryInScope
122 = TypeClassDictionaryInScope {
124 -- The identifier with which the dictionary can be accessed at runtime
126 tcdName :: Qualified Ident
128 -- The name of the type class to which this type class instance applies
130 , tcdClassName :: Qualified ProperName
132 -- The types to which this type class instance applies
134 , tcdInstanceTypes :: [Type]
136 -- Type class dependencies which must be satisfied to construct this dictionary
138 , tcdDependencies :: Maybe [(Qualified ProperName, [Type])]
140 -- The type of this dictionary
142 , tcdType :: TypeClassDictionaryType
143 } deriving (Show, Data, Typeable)
146-- The type of a type class dictionary
148data TypeClassDictionaryType
150 -- A regular type class dictionary
154 -- A type class dictionary which is an alias for an imported dictionary from another module
156 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
159-- A statement in a do-notation block
161data DoNotationElement
163 -- A monadic value without a binder
165 = DoNotationValue Value
167 -- A monadic value with a binder
169 | DoNotationBind Binder Value
171 -- A let statement, i.e. a pure value with a binder
173 | DoNotationLet Binder Value deriving (Show, Data, Typeable)
176-- Data type for binders
184 -- A binder which matches a boolean literal
188 -- A binder which matches a string literal
190 | StringBinder String
192 -- A binder which matches a numeric literal
194 | NumberBinder (Either Integer Double)
196 -- A binder which binds an identifier
200 -- A binder which matches a data constructor
202 | ConstructorBinder (Qualified ProperName) [Binder]
204 -- A binder which matches a record and binds its properties
206 | ObjectBinder [(String, Binder)]
208 -- A binder which matches an array and binds its elements
210 | ArrayBinder [Binder]
212 -- A binder which matches an array and binds its head and tail
214 | ConsBinder Binder Binder
216 -- A binder which binds its input to an identifier
218 | NamedBinder Ident Binder deriving (Show, Data, Typeable)
222-- Collect all names introduced in binders in an expression
224binderNames :: (Data d) => d -> [Ident]
225binderNames = everything (++) (mkQ [] go)
227 go (VarBinder ident) = [ident]
228 go (NamedBinder ident _) = [ident]
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