git.iko.soy/rowtype-yoga/purescript-native
on eb2ce65 help sign in
217 lines 5.3 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Values
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12-- Data types for values, statements, binders and do notation
13--
14-----------------------------------------------------------------------------
16{-# LANGUAGE DeriveDataTypeable #-}
18module Language.PureScript.Values where
20import Language.PureScript.Types
21import Language.PureScript.Names
23import Data.Data
25-- |
26-- A guard is just a boolean-valued expression that appears alongside a set of binders
27--
28type Guard = Value
30-- |
31-- Data type for values
32--
33data Value
34 -- |
35 -- A numeric literal
36 --
37 = NumericLiteral (Either Integer Double)
38 -- |
39 -- A string literal
40 --
41 | StringLiteral String
42 -- |
43 -- A boolean literal
44 --
45 | BooleanLiteral Bool
46 -- |
47 -- Binary operator application. During the rebracketing phase of desugaring, this data constructor
48 -- will be removed.
49 --
50 | BinaryNoParens (Qualified Ident) Value Value
51 -- |
52 -- Explicit parentheses. During the rebracketing phase of desugaring, this data constructor
53 -- will be removed.
54 --
55 | Parens Value
56 -- |
57 -- An array literal
58 --
59 | ArrayLiteral [Value]
60 -- |
61 -- An object literal
62 --
63 | ObjectLiteral [(String, Value)]
64 -- |
65 -- An record property accessor expression
66 --
67 | Accessor String Value
68 -- |
69 -- Partial record update
70 --
71 | ObjectUpdate Value [(String, Value)]
72 -- |
73 -- Function introduction
74 --
75 | Abs (Either Ident Binder) Value
76 -- |
77 -- Function application
78 --
79 | App Value Value
80 -- |
81 -- Variable
82 --
83 | Var (Qualified Ident)
84 -- |
85 -- Conditional (if-then-else expression)
86 --
87 | IfThenElse Value Value Value
88 -- |
89 -- A data constructor
90 --
91 | Constructor (Qualified ProperName)
92 -- |
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.
95 --
96 | Case [Value] [([Binder], Maybe Guard, Value)]
97 -- |
98 -- A value with a type annotation
99 --
100 | TypedValue Bool Value Type
101 -- |
102 -- A let binding
103 --
104 | Let Binder Value Value
105 -- |
106 -- A do-notation block
107 --
108 | Do [DoNotationElement]
109 -- |
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.
114 --
115 | TypeClassDictionary (Qualified ProperName, [Type]) [TypeClassDictionaryInScope] deriving (Show, Data, Typeable)
117-- |
118-- The type of a type class dictionary
119--
120data TypeClassDictionaryType
121 -- |
122 -- A regular type class dictionary
123 --
124 = TCDRegular
125 -- |
126 -- A type class dictionary which is an alias for an imported dictionary from another module
127 --
128 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
130-- |
131-- Data representing a type class dictionary which is in scope
132--
133data TypeClassDictionaryInScope
134 = TypeClassDictionaryInScope {
135 -- |
136 -- The identifier with which the dictionary can be accessed at runtime
137 --
138 tcdName :: Qualified Ident
139 -- |
140 -- The name of the type class to which this type class instance applies
141 --
142 , tcdClassName :: Qualified ProperName
143 -- |
144 -- The types to which this type class instance applies
145 --
146 , tcdInstanceTypes :: [Type]
147 -- |
148 -- Type class dependencies which must be satisfied to construct this dictionary
149 --
150 , tcdDependencies :: Maybe [(Qualified ProperName, [Type])]
151 -- |
152 -- The type of this dictionary
153 --
154 , tcdType :: TypeClassDictionaryType
155 } deriving (Show, Data, Typeable)
157-- |
158-- A statement in a do-notation block
159--
160data DoNotationElement
161 -- |
162 -- A monadic value without a binder
163 --
164 = DoNotationValue Value
165 -- |
166 -- A monadic value with a binder
167 --
168 | DoNotationBind Binder Value
169 -- |
170 -- A let statement, i.e. a pure value with a binder
171 --
172 | DoNotationLet Binder Value deriving (Show, Data, Typeable)
174-- |
175-- Data type for binders
176--
177data Binder
178 -- |
179 -- Wildcard binder
180 --
181 = NullBinder
182 -- |
183 -- A binder which matches a boolean literal
184 --
185 | BooleanBinder Bool
186 -- |
187 -- A binder which matches a string literal
188 --
189 | StringBinder String
190 -- |
191 -- A binder which matches a numeric literal
192 --
193 | NumberBinder (Either Integer Double)
194 -- |
195 -- A binder which binds an identifier
196 --
197 | VarBinder Ident
198 -- |
199 -- A binder which matches a data constructor
200 --
201 | ConstructorBinder (Qualified ProperName) [Binder]
202 -- |
203 -- A binder which matches a record and binds its properties
204 --
205 | ObjectBinder [(String, Binder)]
206 -- |
207 -- A binder which matches an array and binds its elements
208 --
209 | ArrayBinder [Binder]
210 -- |
211 -- A binder which matches an array and binds its head and tail
212 --
213 | ConsBinder Binder Binder
214 -- |
215 -- A binder which binds its input to an identifier
216 --
217 | NamedBinder Ident Binder deriving (Show, Data, Typeable)