1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 {-# LANGUAGE Rank2Types #-}
7 {-# LANGUAGE ScopedTypeVariables #-}
8 {-# LANGUAGE TypeFamilies #-}
9 {-# LANGUAGE UndecidableInstances #-}
10 -- | Abstract Syntax Tree.
14 -- import Test.Tasty.HUnit
16 import qualified Data.List as List
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import qualified Data.Text as Text
21 import Language.Symantic.Type
22 import Language.Symantic.Expr as Expr
25 tests = testGroup "AST" $
33 -- | Custom 'Show' instance a little bit more readable
34 -- than the automatically derived one.
35 instance Show AST where
36 showsPrec p ast@(AST f args) =
37 let n = Text.unpack f in
39 AST _ [] -> showString n
41 showParen (p >= prec_arrow) $
42 showString ("("++n++") ") .
43 showsPrec prec_arrow a
45 showParen (p >= prec_arrow) $
46 showsPrec prec_arrow a .
47 showString (" "++n++" ") .
48 showsPrec prec_arrow b
52 showString (List.intercalate ", " $ show Prelude.<$> args) .
56 -- ** Parsing utilities
58 :: forall ty ast ex hs ret.
59 ( ty ~ Type_Root_of_Expr ex
60 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
61 (Error_of_Expr ast (Root_of_Expr ex))
63 -> Expr_From ast ex hs ret
64 -> Expr_From ast ex hs ret
65 from_ast0 asts k' ex ast ctx k =
68 _ -> Left $ error_expr ex $
69 Error_Expr_Wrong_number_of_arguments ast 0
72 :: forall ty ast ex hs ret.
73 ( ty ~ Type_Root_of_Expr ex
74 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
75 (Error_of_Expr ast (Root_of_Expr ex))
76 ) => [ast] -> (ast -> Expr_From ast ex hs ret)
77 -> Expr_From ast ex hs ret
78 from_ast1 asts k' ex ast ctx k =
80 [ast_0] -> k' ast_0 ex ast ctx k
81 _ -> Left $ error_expr ex $
82 Error_Expr_Wrong_number_of_arguments ast 1
85 :: forall ty ast ex hs ret.
86 ( ty ~ Type_Root_of_Expr ex
87 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
88 (Error_of_Expr ast (Root_of_Expr ex))
89 ) => [ast] -> (ast -> ast -> Expr_From ast ex hs ret)
90 -> Expr_From ast ex hs ret
91 from_ast2 asts k' ex ast ctx k =
93 [ast_0, ast_1] -> k' ast_0 ast_1 ex ast ctx k
94 _ -> Left $ error_expr ex $
95 Error_Expr_Wrong_number_of_arguments ast 2
98 :: forall ty ast ex hs ret.
99 ( ty ~ Type_Root_of_Expr ex
100 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
101 (Error_of_Expr ast (Root_of_Expr ex))
102 ) => [ast] -> (ast -> ast -> ast -> Expr_From ast ex hs ret)
103 -> Expr_From ast ex hs ret
104 from_ast3 asts k' ex ast ctx k =
106 [ast_0, ast_1, ast_2] -> k' ast_0 ast_1 ast_2 ex ast ctx k
107 _ -> Left $ error_expr ex $
108 Error_Expr_Wrong_number_of_arguments ast 3
111 :: forall root ty lit ex ast hs ret.
112 ( ty ~ Type_Root_of_Expr ex
113 , root ~ Root_of_Expr ex
116 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
117 (Error_of_Expr ast root)
118 ) => (forall repr. Sym_of_Expr ex repr => lit -> repr lit)
120 -> Expr_From ast ex hs ret
121 lit_from_AST op ty_lit asts ex ast ctx k =
123 [AST lit []] -> lit_from op ty_lit lit ex ast ctx k
124 _ -> Left $ error_expr ex $
125 Error_Expr_Wrong_number_of_arguments ast 1
128 :: forall root ty lit ex ast hs ret.
129 ( ty ~ Type_Root_of_Expr ex
130 , root ~ Root_of_Expr ex
132 , Eq_Type (Type_Root_of_Expr root)
134 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
135 (Error_of_Expr ast root)
136 , Root_of_Expr root ~ root
137 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit)
139 -> Expr_From ast ex hs ret
140 op1_from_AST op ty_lit asts ex ast ctx k =
142 [ast_x] -> op1_from op ty_lit ast_x ex ast ctx k
143 _ -> Left $ error_expr ex $
144 Error_Expr_Wrong_number_of_arguments ast 1
147 :: forall root ty lit ex ast hs ret.
148 ( ty ~ Type_Root_of_Expr ex
149 , root ~ Root_of_Expr ex
151 , Eq_Type (Type_Root_of_Expr root)
153 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
154 (Error_of_Expr ast root)
155 , Root_of_Expr root ~ root
156 ) => (forall repr. Sym_of_Expr ex repr => repr lit -> repr lit -> repr lit)
158 -> Expr_From ast ex hs ret
159 op2_from_AST op ty_lit asts ex ast ctx k =
161 [ast_x, ast_y] -> op2_from op ty_lit ast_x ast_y ex ast ctx k
162 _ -> Left $ error_expr ex $
163 Error_Expr_Wrong_number_of_arguments ast 2
165 instance -- Type_from AST Type_Var0
166 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
167 , Implicit_HBool (Is_Last_Type (Type_Var0 root) root)
168 ) => Type_from AST (Type_Var0 root) where
169 type_from ty ast _k =
170 Left $ error_type_unsupported ty ast
171 -- NOTE: no support so far.
172 instance -- Type_from AST Type_Var1
173 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
174 , Implicit_HBool (Is_Last_Type (Type_Var1 root) root)
175 ) => Type_from AST (Type_Var1 root) where
176 type_from ty ast _k =
177 Left $ error_type_unsupported ty ast
178 -- NOTE: no support so far.
179 instance -- Type_from AST Type_Unit
180 ( Lift_Type_Root Type_Unit root
181 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
182 , Implicit_HBool (Is_Last_Type (Type_Unit root) root)
183 ) => Type_from AST (Type_Unit root) where
189 _ -> Left $ lift_error_type $
190 Error_Type_Wrong_number_of_arguments ast 0
191 _ -> Left $ error_type_unsupported ty ast
192 instance -- Type_from AST Type_Bool
193 ( Lift_Type_Root Type_Bool root
194 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
195 , Implicit_HBool (Is_Last_Type (Type_Bool root) root)
196 ) => Type_from AST (Type_Bool root) where
202 _ -> Left $ lift_error_type $
203 Error_Type_Wrong_number_of_arguments ast 0
204 _ -> Left $ error_type_unsupported ty ast
205 instance -- Type_from AST Type_Int
206 ( Lift_Type_Root Type_Int root
207 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
208 , Implicit_HBool (Is_Last_Type (Type_Int root) root)
209 ) => Type_from AST (Type_Int root) where
215 _ -> Left $ lift_error_type $
216 Error_Type_Wrong_number_of_arguments ast 0
217 _ -> Left $ error_type_unsupported ty ast
218 instance -- Type_from AST Type_Ordering
219 ( Lift_Type_Root Type_Ordering root
220 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
221 , Implicit_HBool (Is_Last_Type (Type_Ordering root) root)
222 ) => Type_from AST (Type_Ordering root) where
225 AST "Ordering" asts ->
227 [] -> k type_ordering
228 _ -> Left $ lift_error_type $
229 Error_Type_Wrong_number_of_arguments ast 0
230 _ -> Left $ error_type_unsupported ty ast
231 instance -- Type_from AST Type_Fun
234 , Lift_Type_Root (Type_Fun lam) root
235 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
236 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
237 , Root_of_Type root ~ root
238 , Implicit_HBool (Is_Last_Type (Type_Fun lam root) root)
239 ) => Type_from AST (Type_Fun lam root) where
244 [ast_arg, ast_res] -> type_fun_from ty ast_arg ast_res k
245 _ -> Left $ lift_error_type $
246 Error_Type_Wrong_number_of_arguments ast 2
247 _ -> Left $ error_type_unsupported ty ast
248 instance -- Type_from AST Type_Maybe
251 , Lift_Type_Root Type_Maybe root
252 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
253 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
254 , Root_of_Type root ~ root
255 , Implicit_HBool (Is_Last_Type (Type_Maybe root) root)
256 ) => Type_from AST (Type_Maybe root) where
262 type_from (Proxy::Proxy root) ast_a $ \ty_a ->
264 _ -> Left $ lift_error_type $
265 Error_Type_Wrong_number_of_arguments ast 1
266 _ -> Left $ error_type_unsupported ty ast
267 instance -- Type_from AST Type_List
270 , Lift_Type_Root Type_List root
271 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
272 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
273 , Root_of_Type root ~ root
274 , Implicit_HBool (Is_Last_Type (Type_List root) root)
275 ) => Type_from AST (Type_List root) where
281 type_from (Proxy::Proxy root) ast_a $ \ty_a ->
283 _ -> Left $ lift_error_type $
284 Error_Type_Wrong_number_of_arguments ast 1
285 _ -> Left $ error_type_unsupported ty ast
287 instance -- Type1_from AST Type_Bool
288 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
289 , Implicit_HBool (Is_Last_Type (Type_Bool root) root)
290 ) => Type1_from AST (Type_Bool root)
291 instance -- Type1_from AST Type_Int
292 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
293 , Implicit_HBool (Is_Last_Type (Type_Int root) root)
294 ) => Type1_from AST (Type_Int root)
295 instance -- Type1_from AST Type_Unit
296 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
297 , Implicit_HBool (Is_Last_Type (Type_Unit root) root)
298 ) => Type1_from AST (Type_Unit root)
299 instance -- Type1_from AST Type_Ordering
300 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
301 , Implicit_HBool (Is_Last_Type (Type_Ordering root) root)
302 ) => Type1_from AST (Type_Ordering root)
303 instance -- Type1_from AST Type_Var0
304 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
305 , Implicit_HBool (Is_Last_Type (Type_Var0 root) root)
306 ) => Type1_from AST (Type_Var0 root)
307 instance -- Type1_from AST Type_Var1
308 ( Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
309 , Implicit_HBool (Is_Last_Type (Type_Var1 root) root)
310 ) => Type1_from AST (Type_Var1 root)
311 instance -- Type1_from AST Type_Maybe
313 , Lift_Type_Root Type_Maybe root
314 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
315 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
316 , Root_of_Type root ~ root
317 , Implicit_HBool (Is_Last_Type (Type_Maybe root) root)
318 ) => Type1_from AST (Type_Maybe root) where
319 type1_from ty ast k =
323 [] -> k (Proxy::Proxy Maybe) type_maybe
324 _ -> Left $ lift_error_type $
325 Error_Type_Wrong_number_of_arguments ast 0
326 _ -> Left $ error_type_unsupported ty ast
327 instance -- Type1_from AST Type_List
330 , Lift_Type_Root Type_List root
331 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
332 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
333 , Root_of_Type root ~ root
334 , Implicit_HBool (Is_Last_Type (Type_List root) root)
335 ) => Type1_from AST (Type_List root) where
336 type1_from ty ast k =
340 [] -> k (Proxy::Proxy []) type_list
341 _ -> Left $ lift_error_type $
342 Error_Type_Wrong_number_of_arguments ast 0
343 _ -> Left $ error_type_unsupported ty ast
344 instance -- Type1_from AST Type_Fun
347 , Lift_Type_Root (Type_Fun lam) root
348 , Lift_Error_Type (Error_Type AST) (Error_of_Type AST root)
349 , Unlift_Error_Type (Error_Type AST) (Error_of_Type AST root)
350 , Root_of_Type root ~ root
351 , Implicit_HBool (Is_Last_Type (Type_Fun lam root) root)
352 ) => Type1_from AST (Type_Fun lam root) where
353 type1_from ty ast k =
358 type_from (Proxy::Proxy root) ast_arg $ \(ty_arg::root h_arg) ->
359 k (Proxy::Proxy (Lambda lam h_arg)) $
361 _ -> Left $ lift_error_type $
362 Error_Type_Wrong_number_of_arguments ast 1
363 _ -> Left $ error_type_unsupported ty ast
365 instance -- Expr_from AST Expr_Bool
366 ( Eq_Type (Type_Root_of_Expr root)
367 , Type_from AST (Type_Root_of_Expr root)
369 , Lift_Type_Root Type_Bool (Type_Root_of_Expr root)
370 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
371 , Unlift_Type Type_Bool (Type_of_Expr root)
372 , Root_of_Expr root ~ root
373 , Implicit_HBool (Is_Last_Expr (Expr_Bool root) root)
374 ) => Expr_from AST (Expr_Bool root) where
377 AST "bool" asts -> lit_from_AST bool type_bool asts ex ast
378 AST "not" asts -> op1_from_AST Expr.not type_bool asts ex ast
379 AST "&&" asts -> op2_from_AST (Expr.&&) type_bool asts ex ast
380 AST "||" asts -> op2_from_AST (Expr.||) type_bool asts ex ast
381 AST "xor" asts -> op2_from_AST Expr.xor type_bool asts ex ast
382 _ -> \_ctx _k -> Left $ error_expr_unsupported ex ast
383 instance -- Expr_from AST Expr_If
384 ( Eq_Type (Type_Root_of_Expr root)
385 , Type_from AST (Type_Root_of_Expr root)
387 , Lift_Type_Root Type_Bool (Type_Root_of_Expr root)
388 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
389 , Root_of_Expr root ~ root
390 , Implicit_HBool (Is_Last_Expr (Expr_If root) root)
391 ) => Expr_from AST (Expr_If root) where
392 expr_from ex ast ctx k =
394 AST "if" asts -> from_ast3 asts if_from ex ast ctx k
395 _ -> Left $ error_expr_unsupported ex ast
396 instance -- Expr_from AST Expr_When
397 ( Eq_Type (Type_Root_of_Expr root)
398 , Type_from AST (Type_Root_of_Expr root)
400 , Lift_Type_Root Type_Bool (Type_Root_of_Expr root)
401 , Lift_Type_Root Type_Unit (Type_Root_of_Expr root)
402 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
403 , Root_of_Expr root ~ root
404 , Implicit_HBool (Is_Last_Expr (Expr_When root) root)
405 ) => Expr_from AST (Expr_When root) where
406 expr_from ex ast ctx k =
408 AST "when" asts -> from_ast2 asts when_from ex ast ctx k
409 _ -> Left $ error_expr_unsupported ex ast
410 instance -- Expr_from AST Expr_Int
411 ( Eq_Type (Type_Root_of_Expr root)
412 , Type_from AST (Type_Root_of_Expr root)
414 , Lift_Type_Root Type_Int (Type_Root_of_Expr root)
415 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
416 , Unlift_Type Type_Int (Type_of_Expr root)
417 , Root_of_Expr root ~ root
418 , Implicit_HBool (Is_Last_Expr (Expr_Int root) root)
419 ) => Expr_from AST (Expr_Int root) where
422 AST "int" asts -> lit_from_AST int type_int asts ex ast
423 AST "abs" asts -> op1_from_AST Expr.abs type_int asts ex ast
424 AST "negate" asts -> op1_from_AST Expr.negate type_int asts ex ast
425 AST "+" asts -> op2_from_AST (Expr.+) type_int asts ex ast
426 AST "-" asts -> op2_from_AST (Expr.-) type_int asts ex ast
427 AST "*" asts -> op2_from_AST (Expr.*) type_int asts ex ast
428 AST "mod" asts -> op2_from_AST Expr.mod type_int asts ex ast
429 _ -> \_ctx _k -> Left $ error_expr_unsupported ex ast
430 instance -- Expr_from AST Expr_Lambda
431 ( Eq_Type (Type_Root_of_Expr root)
432 , Type_from AST (Type_Root_of_Expr root)
434 , Lift_Type_Root (Type_Fun lam) (Type_Root_of_Expr root)
435 , Lift_Error_Expr (Error_Expr_Lambda AST) (Error_of_Expr AST root)
436 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
437 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
438 , Root_of_Expr root ~ root
439 , Implicit_HBool (Is_Last_Expr (Expr_Lambda lam root) root)
440 ) => Expr_from AST (Expr_Lambda lam root) where
441 expr_from ex ast ctx k =
445 [AST name []] -> var_from name ex ast ctx k
446 _ -> Left $ error_expr ex $
447 Error_Expr_Wrong_number_of_arguments ast 1
448 AST "app" asts -> from_ast2 asts app_from ex ast ctx k
449 AST "inline" asts -> go_lam asts inline
450 AST "val" asts -> go_lam asts val
451 AST "lazy" asts -> go_lam asts lazy
452 AST "let_inline" asts -> go_let asts let_inline
453 AST "let_val" asts -> go_let asts let_val
454 AST "let_lazy" asts -> go_let asts let_lazy
455 _ -> Left $ error_expr_unsupported ex ast
458 (lam::forall repr arg res. Sym_Lambda lam repr
459 => (repr arg -> repr res) -> repr (Lambda lam arg res)) =
461 [AST name [], ast_ty_arg, ast_body] ->
462 lam_from lam name ast_ty_arg ast_body ex ast ctx k
463 _ -> Left $ error_expr ex $
464 Error_Expr_Wrong_number_of_arguments ast 3
466 (let_::forall repr var res. Sym_Lambda lam repr
467 => repr var -> (repr var -> repr res) -> repr res) =
469 [AST name [], ast_var, ast_body] ->
470 let_from let_ name ast_var ast_body ex ast ctx k
471 _ -> Left $ error_expr ex $
472 Error_Expr_Wrong_number_of_arguments ast 3
473 instance -- Expr_from AST Expr_Maybe
474 ( Eq_Type (Type_Root_of_Expr root)
475 , Type_from AST (Type_Root_of_Expr root)
477 , Lift_Type (Type_Fun lam) (Type_of_Expr root)
478 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
479 , Lift_Type Type_Maybe (Type_of_Expr root)
480 , Unlift_Type Type_Maybe (Type_of_Expr root)
481 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
482 , Root_of_Expr root ~ root
483 , Implicit_HBool (Is_Last_Expr (Expr_Maybe lam root) root)
484 ) => Expr_from AST (Expr_Maybe lam root) where
485 expr_from ex ast ctx k =
487 AST "maybe" asts -> from_ast3 asts maybe_from ex ast ctx k
488 AST "nothing" asts -> from_ast1 asts nothing_from ex ast ctx k
489 AST "just" asts -> from_ast1 asts just_from ex ast ctx k
490 _ -> Left $ error_expr_unsupported ex ast
491 instance -- Expr_from AST Expr_Eq
492 ( Eq_Type (Type_Root_of_Expr root)
493 , Type_from AST (Type_Root_of_Expr root)
494 , Lift_Type Type_Bool (Type_of_Expr root)
495 , Constraint_Type Eq (Type_Root_of_Expr root)
497 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
498 , Root_of_Expr root ~ root
499 , Implicit_HBool (Is_Last_Expr (Expr_Eq root) root)
500 ) => Expr_from AST (Expr_Eq root) where
501 expr_from ex ast ctx k =
503 AST "==" asts -> from_ast2 asts eq_from ex ast ctx k
504 _ -> Left $ error_expr_unsupported ex ast
505 instance -- Expr_from AST Expr_Ord
506 ( Eq_Type (Type_Root_of_Expr root)
507 , Type_from AST (Type_Root_of_Expr root)
508 , Lift_Type Type_Ordering (Type_of_Expr root)
509 , Constraint_Type Ord (Type_Root_of_Expr root)
511 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
512 , Root_of_Expr root ~ root
513 , Implicit_HBool (Is_Last_Expr (Expr_Ord root) root)
514 ) => Expr_from AST (Expr_Ord root) where
515 expr_from ex ast ctx k =
517 AST "compare" asts -> from_ast2 asts compare_from ex ast ctx k
518 _ -> Left $ error_expr_unsupported ex ast
519 instance -- Expr_from AST Expr_List
520 ( Eq_Type (Type_Root_of_Expr root)
521 , Type_from AST (Type_Root_of_Expr root)
523 , Lift_Type (Type_Fun lam) (Type_of_Expr root)
524 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
525 , Lift_Type Type_List (Type_of_Expr root)
526 , Unlift_Type Type_List (Type_of_Expr root)
527 , Lift_Type Type_Bool (Type_of_Expr root)
528 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
529 , Root_of_Expr root ~ root
530 , Implicit_HBool (Is_Last_Expr (Expr_List lam root) root)
531 ) => Expr_from AST (Expr_List lam root) where
532 expr_from ex ast ctx k =
534 AST "[]" asts -> from_ast1 asts list_empty_from ex ast ctx k
535 AST ":" asts -> from_ast2 asts list_cons_from ex ast ctx k
536 AST "list_filter" asts -> from_ast2 asts list_filter_from ex ast ctx k
539 ast_ty_a:asts' -> list_from ast_ty_a asts' ex ast ctx k
540 _ -> Left $ error_expr ex $
541 Error_Expr_Wrong_number_of_arguments ast 1
542 _ -> Left $ error_expr_unsupported ex ast
543 instance -- Expr_from AST Expr_Map
544 ( Eq_Type (Type_Root_of_Expr root)
545 , Type_from AST (Type_Root_of_Expr root)
547 , Lift_Type (Type_Fun lam) (Type_of_Expr root)
548 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
549 , Lift_Type Type_Map (Type_of_Expr root)
550 , Unlift_Type Type_Map (Type_of_Expr root)
551 , Lift_Type Type_List (Type_of_Expr root)
552 , Unlift_Type Type_List (Type_of_Expr root)
553 , Lift_Type Type_Tuple2 (Type_of_Expr root)
554 , Unlift_Type Type_Tuple2 (Type_of_Expr root)
555 , Constraint_Type Ord (Type_Root_of_Expr root)
556 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
557 , Root_of_Expr root ~ root
558 , Implicit_HBool (Is_Last_Expr (Expr_Map lam root) root)
559 ) => Expr_from AST (Expr_Map lam root) where
560 expr_from ex ast ctx k =
562 AST "map_from_list" asts -> from_ast1 asts map_from_list_from ex ast ctx k
563 AST "map_map" asts -> from_ast2 asts map_map_from ex ast ctx k
564 _ -> Left $ error_expr_unsupported ex ast
565 instance -- Expr_from AST Expr_Functor
566 ( Eq_Type (Type_Root_of_Expr root)
567 , Type_from AST (Type_Root_of_Expr root)
569 , String_from_Type (Type_Root_of_Expr root)
570 -- , Lift_Type Type_Var1 (Type_of_Expr root)
571 , Lift_Type (Type_Fun lam) (Type_of_Expr root)
572 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
573 , Unlift_Type1 (Type_of_Expr root)
574 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
575 , Constraint_Type1 Functor_with_Lambda (Type_Root_of_Expr root)
576 , Root_of_Expr root ~ root
577 , Implicit_HBool (Is_Last_Expr (Expr_Functor lam root) root)
578 ) => Expr_from AST (Expr_Functor lam root) where
579 expr_from ex ast ctx k =
581 AST "fmap" asts -> from_ast2 asts fmap_from ex ast ctx k
582 AST "<$>" asts -> from_ast2 asts fmap_from ex ast ctx k
583 _ -> Left $ error_expr_unsupported ex ast
584 instance -- Expr_from AST Expr_Applicative
585 ( Eq_Type (Type_Root_of_Expr root)
586 , Type1_from AST (Type_Root_of_Expr root)
588 , String_from_Type (Type_Root_of_Expr root)
589 -- , Lift_Type Type_Var1 (Type_of_Expr root)
590 , Lift_Type (Type_Fun lam) (Type_of_Expr root)
591 , Unlift_Type (Type_Fun lam) (Type_of_Expr root)
592 , Eq_Type1 (Type_Root_of_Expr root)
593 , Unlift_Type1 (Type_of_Expr root)
594 , Lift_Error_Expr (Error_Expr_of_Root AST root) (Error_of_Expr AST root)
595 , Constraint_Type1 Applicative_with_Lambda (Type_Root_of_Expr root)
596 , Root_of_Expr root ~ root
597 , Implicit_HBool (Is_Last_Expr (Expr_Applicative lam root) root)
598 ) => Expr_from AST (Expr_Applicative lam root) where
599 expr_from ex ast ctx k =
601 AST "pure" asts -> from_ast2 asts pure_from ex ast ctx k
602 AST "<*>" asts -> from_ast2 asts ltstargt_from ex ast ctx k
603 _ -> Left $ error_expr_unsupported ex ast