]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Expr/From.hs
fix Num requiring Integer
[haskell/symantic.git] / Language / Symantic / Expr / From.hs
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE DataKinds #-}
3 {-# LANGUAGE DefaultSignatures #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE FlexibleInstances #-}
6 {-# LANGUAGE GADTs #-}
7 {-# LANGUAGE KindSignatures #-}
8 {-# LANGUAGE MultiParamTypeClasses #-}
9 {-# LANGUAGE OverloadedStrings #-}
10 {-# LANGUAGE Rank2Types #-}
11 {-# LANGUAGE ScopedTypeVariables #-}
12 {-# LANGUAGE TypeFamilies #-}
13 {-# LANGUAGE TypeOperators #-}
14 {-# LANGUAGE UndecidableInstances #-}
15 module Language.Symantic.Expr.From where
16
17 import Data.Maybe (fromMaybe)
18 import Data.Monoid
19 import Data.Proxy (Proxy(..))
20 import Data.Text (Text)
21 import qualified Data.Text as Text
22 import Data.Type.Equality ((:~:)(Refl))
23 import GHC.Prim (Constraint)
24
25 import Language.Symantic.Type
26 import Language.Symantic.Expr.Root
27 import Language.Symantic.Expr.Alt
28 import Language.Symantic.Expr.Error
29 import Language.Symantic.Trans.Common
30 import Language.Symantic.Repr
31
32 -- * Class 'Expr_From'
33 -- | Parse given @ast@ into
34 -- a 'Type_Root_of_Expr' and
35 -- a 'Forall_Repr_with_Context',
36 -- or return an 'Error_of_Expr'.
37 class Expr_From ast (ex:: *) where
38 expr_from :: ExprFrom ast ex hs ret
39 instance -- Expr_From
40 ( Expr_From ast (ex (Expr_Root ex))
41 , Root_of_Expr (ex (Expr_Root ex)) ~ Expr_Root ex
42 ) => Expr_From ast (Expr_Root ex) where
43 expr_from _ex ctx ast k =
44 expr_from (Proxy::Proxy (ex (Expr_Root ex)))
45 ctx ast $ \ty (Forall_Repr_with_Context repr) ->
46 k ty (Forall_Repr_with_Context repr)
47 instance -- Expr_From
48 ( Expr_From ast (curr root)
49 , Expr_From ast (next root)
50 , Root_of_Expr (curr root) ~ root
51 , Root_of_Expr (next root) ~ root
52 , Error_Expr_Unlift (Error_Expr (Error_of_Type ast (Type_Root_of_Expr root))
53 (Type_Root_of_Expr root) ast)
54 (Error_of_Expr ast root)
55 ) => Expr_From ast (Expr_Alt curr next root) where
56 expr_from _ex ctx ast k =
57 case expr_from (Proxy::Proxy (curr root)) ctx ast $
58 \ty (Forall_Repr_with_Context repr) ->
59 Right $ k ty (Forall_Repr_with_Context repr) of
60 Right ret -> ret
61 Left err ->
62 case error_expr_unlift err of
63 Just (Error_Expr_Unsupported_here _
64 :: Error_Expr (Error_of_Type ast (Type_Root_of_Expr root))
65 (Type_Root_of_Expr root) ast) ->
66 expr_from (Proxy::Proxy (next root)) ctx ast $
67 \ty (Forall_Repr_with_Context repr) ->
68 k ty (Forall_Repr_with_Context repr)
69 _ -> Left err
70
71 -- ** Type 'ExprFrom'
72 -- | Convenient type synonym defining a parser.
73 type ExprFrom ast ex hs ret
74 = Proxy ex
75 -- ^ Select the 'Expr_From' instance.
76 -> ast
77 -- ^ The input data to parse.
78 -> Lambda_Context (Lambda_Var (Type_Root_of_Expr ex)) hs
79 -- ^ The bound variables in scope and their types:
80 -- held in the heterogeneous list @hs@,
81 -- from the closest including lambda abstraction to the farest.
82 -> ( forall h
83 . Type_Root_of_Expr ex h
84 -> Forall_Repr_with_Context ex hs h
85 -> Either (Error_of_Expr ast (Root_of_Expr ex)) ret )
86 -- ^ The accumulating continuation.
87 -> Either (Error_of_Expr ast (Root_of_Expr ex)) ret
88
89 -- ** Type 'Lambda_Context'
90 -- | GADT for a typing context,
91 -- accumulating an @item@ at each lambda;
92 -- used to accumulate object-types (in 'Expr_From')
93 -- or host-terms (in 'Repr_Host')
94 -- associated with the 'Lambda_Var's in scope.
95 data Lambda_Context :: (* -> *) -> [*] -> * where
96 Lambda_Context_Empty :: Lambda_Context item '[]
97 Lambda_Context_Next :: item h
98 -> Lambda_Context item hs
99 -> Lambda_Context item (h ': hs)
100 infixr 5 `Lambda_Context_Next`
101
102 -- ** Type 'Lambda_Var'
103 -- | Join a name and a type.
104 --
105 -- This data type is used to handle lambda variables by name
106 -- (instead of DeBruijn indices for instance).
107 data Lambda_Var ty h
108 = Lambda_Var Lambda_Var_Name (ty h)
109 type Lambda_Var_Name = Text
110
111 -- ** Type 'Forall_Repr_with_Context'
112 -- | A data type embedding a universal quantification
113 -- over an interpreter @repr@
114 -- and qualified by the symantics of an expression.
115 --
116 -- Moreover the expression is abstracted by a 'Lambda_Context'
117 -- built at parsing time to build a /Higher-Order Abstract Syntax/ (HOAS)
118 -- for lambda abstractions.
119 --
120 -- This data type is used to keep a parsed expression polymorphic enough
121 -- to stay interpretable by different interpreters.
122 --
123 -- NOTE: 'Sym_of_Expr'@ ex repr@
124 -- is needed to be able to use symantic methods of the parsed expression
125 -- into a 'Forall_Repr_with_Context'@ ex@.
126 --
127 -- NOTE: 'Sym_of_Expr'@ (@'Root_of_Expr'@ ex) repr@
128 -- is needed to be able to use an expression
129 -- out of a 'Forall_Repr_with_Context'@ (@'Root_of_Expr'@ ex)@
130 -- into a 'Forall_Repr_with_Context'@ ex@,
131 -- which happens when a symantic method includes a polymorphic type
132 -- and thus calls: 'expr_from'@ (Proxy::Proxy (@'Root_of_Expr'@ ex))@.
133 --
134 -- NOTE: 'Sym_Lambda_Lam repr@
135 -- is needed to be able to parse partially applied functions
136 -- (when their type is knowable).
137 data Forall_Repr_with_Context ex hs h
138 = Forall_Repr_with_Context
139 ( forall repr. ( Sym_of_Expr ex repr
140 , Sym_of_Expr (Root_of_Expr ex) repr
141 , Sym_Lambda_Lam repr
142 ) => Lambda_Context repr hs -> repr h )
143
144 -- ** Type 'Forall_Repr'
145 -- | 'Forall_Repr_with_Context' applied on a 'Lambda_Context'.
146 data Forall_Repr ex h
147 = Forall_Repr
148 { unForall_Repr :: forall repr
149 . ( Sym_of_Expr ex repr
150 , Sym_of_Expr (Root_of_Expr ex) repr
151 , Sym_Lambda_Lam repr )
152 => repr h }
153
154 -- * Class 'Sym_Lambda_Lam'
155 class Sym_Lambda_Lam repr where
156 -- | /Lambda abstraction/.
157 lam :: (repr arg -> repr res) -> repr ((->) arg res)
158 default lam :: Trans t repr
159 => (t repr arg -> t repr res) -> t repr ((->) arg res)
160 lam f = trans_lift $ lam $ trans_apply . f . trans_lift
161 instance Sym_Lambda_Lam Repr_Host where
162 lam f = Repr_Host (unRepr_Host . f . Repr_Host)
163 instance Sym_Lambda_Lam Repr_Text where
164 lam f =
165 Repr_Text $ \p v ->
166 let p' = Precedence 1 in
167 let x = "x" <> Text.pack (show v) in
168 paren p p' $ "\\" <> x <> " -> "
169 <> unRepr_Text (f (Repr_Text $ \_p _v -> x)) p' (succ v)
170 instance (Sym_Lambda_Lam r1, Sym_Lambda_Lam r2) => Sym_Lambda_Lam (Repr_Dup r1 r2) where
171 lam f = repr_dup_1 (lam f) `Repr_Dup` repr_dup_2 (lam f)
172
173 -- ** Type family 'Sym_of_Expr'
174 -- | The symantic of an expression.
175 type family Sym_of_Expr (ex:: *) (repr:: * -> *) :: Constraint
176 type instance Sym_of_Expr (Expr_Root ex) repr
177 = Sym_of_Expr (ex (Expr_Root ex)) repr
178 type instance Sym_of_Expr (Expr_Alt curr next root) repr
179 = ( Sym_of_Expr (curr root) repr
180 , Sym_of_Expr (next root) repr
181 )
182
183 -- * Checks
184
185 -- | Parsing utility to check that the type resulting
186 -- from the application of a given type family to a given type
187 -- is within the type stack,
188 -- or raise 'Error_Expr_Type_mismatch'.
189 check_type0_family
190 :: forall ast ex tf root ty h ret.
191 ( root ~ Root_of_Expr ex
192 , ty ~ Type_Root_of_Expr ex
193 , Type0_Family tf ty
194 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
195 (Error_of_Expr ast root)
196 ) => Proxy tf -> Proxy ex -> ast -> ty h
197 -> (ty (Host_of_Type0_Family tf h) -> Either (Error_of_Expr ast root) ret)
198 -> Either (Error_of_Expr ast root) ret
199 check_type0_family tf ex ast ty k =
200 case type0_family tf ty of
201 Just t -> k t
202 Nothing -> Left $ error_expr ex $
203 Error_Expr_Type (error_type_lift $ Error_Type_No_Type_Family ast) ast
204
205 -- | Parsing utility to check that two types are equal,
206 -- or raise 'Error_Expr_Type_mismatch'.
207 check_type0_eq
208 :: forall ast ex root ty x y ret.
209 ( root ~ Root_of_Expr ex
210 , ty ~ Type_Root_of_Expr ex
211 , Type0_Eq ty
212 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
213 (Error_of_Expr ast root)
214 ) => Proxy ex -> ast -> ty x -> ty y
215 -> (x :~: y -> Either (Error_of_Expr ast root) ret)
216 -> Either (Error_of_Expr ast root) ret
217 check_type0_eq ex ast x y k =
218 case x `type0_eq` y of
219 Just Refl -> k Refl
220 Nothing -> Left $ error_expr ex $
221 Error_Expr_Type_mismatch ast
222 (Exists_Type0 x)
223 (Exists_Type0 y)
224
225 -- | Parsing utility to check that two 'Type1' are equal,
226 -- or raise 'Error_Expr_Type_mismatch'.
227 check_type1_eq
228 :: forall ast ex root ty h1 h2 a1 a2 ret.
229 ( root ~ Root_of_Expr ex
230 , ty ~ Type_Root_of_Expr ex
231 , Type1_Eq ty
232 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
233 (Error_of_Expr ast root)
234 )
235 => Proxy ex -> ast -> ty (h1 a1) -> ty (h2 a2)
236 -> (h1 :~: h2 -> Either (Error_of_Expr ast root) ret)
237 -> Either (Error_of_Expr ast root) ret
238 check_type1_eq ex ast h1 h2 k =
239 case h1 `type1_eq` h2 of
240 Just Refl -> k Refl
241 Nothing -> Left $ error_expr ex $
242 Error_Expr_Type_mismatch ast
243 (Exists_Type0 h1)
244 (Exists_Type0 h2)
245
246 -- | Parsing utility to check that a 'Type0' or higher
247 -- is an instance of a given 'Constraint',
248 -- or raise 'Error_Expr_Constraint_missing'.
249 check_type0_constraint
250 :: forall ast ex c root ty h ret.
251 ( root ~ Root_of_Expr ex
252 , ty ~ Type_Root_of_Expr ex
253 , Type0_Constraint c ty
254 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
255 (Error_of_Expr ast root)
256 )
257 => Proxy ex -> Proxy c -> ast -> ty h
258 -> (Dict (c h) -> Either (Error_of_Expr ast root) ret)
259 -> Either (Error_of_Expr ast root) ret
260 check_type0_constraint ex c ast ty k =
261 case type0_constraint c ty of
262 Just Dict -> k Dict
263 Nothing -> Left $ error_expr ex $
264 Error_Expr_Constraint_missing ast
265 {-(Exists_Dict c)-}
266 -- FIXME: not easy to report the constraint
267 -- and still support 'Eq' and 'Show' deriving.
268 (Exists_Type0 ty)
269
270 -- | Parsing utility to check that a 'Type1' or higher
271 -- is an instance of a given 'Constraint',
272 -- or raise 'Error_Expr_Constraint_missing'.
273 check_type1_constraint
274 :: forall ast ex c root ty h a ret.
275 ( root ~ Root_of_Expr ex
276 , ty ~ Type_Root_of_Expr ex
277 , Type1_Constraint c ty
278 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
279 (Error_of_Expr ast root)
280 ) => Proxy ex -> Proxy c -> ast -> ty (h a)
281 -> (Dict (c h) -> Either (Error_of_Expr ast root) ret)
282 -> Either (Error_of_Expr ast root) ret
283 check_type1_constraint ex c ast ty k =
284 case type1_constraint c ty of
285 Just Dict -> k Dict
286 Nothing -> Left $ error_expr ex $
287 Error_Expr_Constraint_missing ast
288 (Exists_Type0 ty)
289
290 -- | Parsing utility to check that the given type is at least a 'Type1'
291 -- or raise 'Error_Expr_Type_mismatch'.
292 check_type1
293 :: forall ast ex root ty h ret.
294 ( root ~ Root_of_Expr ex
295 , ty ~ Type_Root_of_Expr ex
296 , Type1_Unlift (Type_of_Expr root)
297 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
298 (Error_of_Expr ast root)
299 ) => Proxy ex -> ast -> ty h
300 -> (forall (t1:: *).
301 ( Type1 t1 ty h
302 , Type1_Lift t1 ty (Type_Var0 :|: Type_Var1 :|: Type_of_Expr root)
303 ) -> Either (Error_of_Expr ast root) ret)
304 -> Either (Error_of_Expr ast root) ret
305 check_type1 ex ast ty k =
306 (`fromMaybe` type1_unlift (unType_Root ty) (Just . k)) $
307 Left $
308 error_expr ex $
309 Error_Expr_Type_mismatch ast
310 (Exists_Type0 (type_var1 SZero (type_var0 SZero)
311 :: ty (Var1 Var0)))
312 (Exists_Type0 ty)
313
314 -- * Parsers
315
316 -- | Like 'expr_from' but for a root expression.
317 root_expr_from
318 :: forall ast root.
319 ( Expr_From ast root
320 , Root_of_Expr root ~ root
321 ) => Proxy root -> ast
322 -> Either (Error_of_Expr ast root)
323 (Exists_Type0_and_Repr (Type_Root_of_Expr root)
324 (Forall_Repr root))
325 root_expr_from _ex ast =
326 expr_from (Proxy::Proxy root) ast
327 Lambda_Context_Empty $ \ty (Forall_Repr_with_Context repr) ->
328 Right $ Exists_Type0_and_Repr ty $
329 Forall_Repr $ repr Lambda_Context_Empty
330
331 -- | Parse a literal.
332 lit_from
333 :: forall ty lit ex ast hs ret.
334 ( ty ~ Type_Root_of_Expr ex
335 , Read lit
336 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
337 (Error_of_Expr ast (Root_of_Expr ex))
338 ) => (forall repr. Sym_of_Expr ex repr => lit -> repr lit)
339 -> ty lit -> Text
340 -> ExprFrom ast ex hs ret
341 lit_from lit ty_lit toread ex ast _ctx k =
342 case read_safe toread of
343 Left err -> Left $ error_expr ex $ Error_Expr_Read err ast
344 Right (i::lit) -> k ty_lit $ Forall_Repr_with_Context $ const $ lit i
345
346 -- | Parse a unary class operator.
347 class_op1_from
348 :: forall root ty cl ex ast hs ret.
349 ( ty ~ Type_Root_of_Expr ex
350 , root ~ Root_of_Expr ex
351 , Type0_Eq ty
352 , Expr_From ast root
353 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
354 (Error_of_Expr ast root)
355 , Root_of_Expr root ~ root
356 , Type0_Constraint cl ty
357 ) => (forall lit repr. (cl lit, Sym_of_Expr ex repr) => repr lit -> repr lit)
358 -> Proxy cl -> ast
359 -> ExprFrom ast ex hs ret
360 class_op1_from op cl ast_x ex _ast ctx k =
361 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
362 check_type0_constraint ex cl ast_x ty_x $ \Dict ->
363 k ty_x $ Forall_Repr_with_Context (op . x)
364
365 -- | Parse a binary class operator.
366 class_op2_from
367 :: forall root ty cl ex ast hs ret.
368 ( ty ~ Type_Root_of_Expr ex
369 , root ~ Root_of_Expr ex
370 , Type0_Eq ty
371 , Expr_From ast root
372 , Type0_Constraint cl ty
373 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
374 (Error_of_Expr ast root)
375 , Root_of_Expr root ~ root
376 ) => (forall lit repr. (cl lit, Sym_of_Expr ex repr) => repr lit -> repr lit -> repr lit)
377 -> Proxy cl -> ast -> ast
378 -> ExprFrom ast ex hs ret
379 class_op2_from op cl ast_x ast_y ex ast ctx k =
380 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
381 expr_from (Proxy::Proxy root) ast_y ctx $ \ty_y (Forall_Repr_with_Context y) ->
382 check_type0_constraint ex cl ast_x ty_x $ \Dict ->
383 check_type0_constraint ex cl ast_y ty_y $ \Dict ->
384 check_type0_eq ex ast ty_x ty_y $ \Refl ->
385 k ty_x $ Forall_Repr_with_Context $
386 \c -> x c `op` y c
387
388 -- | Parse a binary class operator, partially applied.
389 class_op2_from1
390 :: forall root ty cl ex ast hs ret.
391 ( ty ~ Type_Root_of_Expr ex
392 , root ~ Root_of_Expr ex
393 , Type0_Eq ty
394 , Type0_Constraint cl ty
395 , Type0_Lift Type_Fun (Type_of_Expr root)
396 , Expr_From ast root
397 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
398 (Error_of_Expr ast root)
399 , Root_of_Expr root ~ root
400 ) => (forall lit repr. (cl lit, Sym_of_Expr ex repr) => repr lit -> repr lit -> repr lit)
401 -> Proxy cl -> ast
402 -> ExprFrom ast ex hs ret
403 class_op2_from1 op cl ast_x ex _ast ctx k =
404 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
405 check_type0_constraint ex cl ast_x ty_x $ \Dict ->
406 k (type_fun ty_x ty_x) $ Forall_Repr_with_Context $
407 \c -> lam $ \y -> x c `op` y
408
409 -- | Parse a unary operator.
410 op1_from
411 :: forall root ty lit ex ast hs ret.
412 ( ty ~ Type_Root_of_Expr ex
413 , root ~ Root_of_Expr ex
414 , Type0_Eq ty
415 , Expr_From ast root
416 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
417 (Error_of_Expr ast root)
418 , Root_of_Expr root ~ root
419 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit)
420 -> ty lit -> ast
421 -> ExprFrom ast ex hs ret
422 op1_from op ty_lit ast_x ex ast ctx k =
423 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
424 check_type0_eq ex ast ty_lit ty_x $ \Refl ->
425 k ty_x $ Forall_Repr_with_Context (op . x)
426
427 -- | Parse a unary operator, partially applied.
428 op1_from0
429 :: forall root ty lit ex ast hs ret.
430 ( ty ~ Type_Root_of_Expr ex
431 , root ~ Root_of_Expr ex
432 , Type0_Eq ty
433 , Type0_Lift Type_Fun (Type_of_Expr root)
434 , Expr_From ast root
435 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
436 (Error_of_Expr ast root)
437 , Root_of_Expr root ~ root
438 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit)
439 -> ty lit
440 -> ExprFrom ast ex hs ret
441 op1_from0 op ty_lit _ex _ast _ctx k =
442 k (type_fun ty_lit ty_lit) $ Forall_Repr_with_Context $
443 \_c -> lam op
444
445 -- | Parse a binary operator.
446 op2_from
447 :: forall root ty lit ex ast hs ret.
448 ( ty ~ Type_Root_of_Expr ex
449 , root ~ Root_of_Expr ex
450 , Type0_Eq ty
451 , Expr_From ast root
452 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
453 (Error_of_Expr ast root)
454 , Root_of_Expr root ~ root
455 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit -> repr lit)
456 -> ty lit -> ast -> ast
457 -> ExprFrom ast ex hs ret
458 op2_from op ty_lit ast_x ast_y ex ast ctx k =
459 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
460 expr_from (Proxy::Proxy root) ast_y ctx $ \ty_y (Forall_Repr_with_Context y) ->
461 check_type0_eq ex ast ty_lit ty_x $ \Refl ->
462 check_type0_eq ex ast ty_lit ty_y $ \Refl ->
463 k ty_x $ Forall_Repr_with_Context $
464 \c -> x c `op` y c
465
466 -- | Parse a binary operator, partially applied.
467 op2_from1
468 :: forall root ty lit ex ast hs ret.
469 ( ty ~ Type_Root_of_Expr ex
470 , root ~ Root_of_Expr ex
471 , Type0_Eq ty
472 , Type0_Lift Type_Fun (Type_of_Expr root)
473 , Expr_From ast root
474 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
475 (Error_of_Expr ast root)
476 , Root_of_Expr root ~ root
477 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit -> repr lit)
478 -> ty lit -> ast
479 -> ExprFrom ast ex hs ret
480 op2_from1 op ty_lit ast_x ex ast ctx k =
481 expr_from (Proxy::Proxy root) ast_x ctx $ \ty_x (Forall_Repr_with_Context x) ->
482 check_type0_eq ex ast ty_lit ty_x $ \Refl ->
483 k (type_fun ty_x ty_x) $ Forall_Repr_with_Context $
484 \c -> lam $ \y -> x c `op` y
485
486 -- | Parse a binary operator, partially applied.
487 op2_from0
488 :: forall root ty lit ex ast hs ret.
489 ( ty ~ Type_Root_of_Expr ex
490 , root ~ Root_of_Expr ex
491 , Type0_Eq ty
492 , Type0_Lift Type_Fun (Type_of_Expr root)
493 , Expr_From ast root
494 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
495 (Error_of_Expr ast root)
496 , Root_of_Expr root ~ root
497 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit -> repr lit)
498 -> ty lit
499 -> ExprFrom ast ex hs ret
500 op2_from0 op ty_lit _ex _ast _ctx k =
501 k (type_fun ty_lit $ type_fun ty_lit ty_lit) $ Forall_Repr_with_Context $
502 \_c -> lam $ \x -> lam $ \y -> x `op` y