-
Notifications
You must be signed in to change notification settings - Fork 28
Concrete syntax for handler types #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,8 +168,19 @@ ty_expr_simple | |
| | UNDERSCORE { make TWildcard } | ||
| | SBR_OPN effct SBR_CLS { make ($2).data } | ||
| | CBR_OPN ty_field_list CBR_CLS { make (TRecord $2) } | ||
| | KW_HANDLER effct_bind ty_expr KW_IN ty_expr ARROW2 ty_expr | ||
| { make (THandler ($2, $3, $5, $7)) } | ||
| | KW_HANDLER effct_bind ty_expr ARROW2 ty_expr | ||
| { make (THandler ($2, $3, $5, $5)) } | ||
| ; | ||
|
|
||
| effct_bind | ||
| : CBR_OPN UID CBR_CLS { Some $2 } | ||
| | CBR_OPN UNDERSCORE CBR_CLS { None } | ||
| | /* empty */ { None } | ||
|
Comment on lines
175
to
+180
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Proposed change should remove shift-reduce conflicts, or at least reduce their number. |
||
| ; | ||
|
|
||
|
|
||
| /* ------------------------------------------------------------------------- */ | ||
|
|
||
| type_annot | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -354,25 +354,38 @@ let rec print_type env (tp : type_tree) prec = | |||||||||||||||
|
|
||||||||||||||||
| | PP_THandler h -> | ||||||||||||||||
| paren env prec 0 (fun () -> | ||||||||||||||||
| let name = gen_tvar_name (fun n -> fresh_for_type env n tp) "E" in | ||||||||||||||||
| let name = | ||||||||||||||||
| match Env.lookup_tvar env h.eff_var with | ||||||||||||||||
| | Found name -> name | ||||||||||||||||
| | Anon(name, _) -> name | ||||||||||||||||
| | Unbound _ -> gen_tvar_name (fun n -> fresh_for_type env n tp) "E" | ||||||||||||||||
| in | ||||||||||||||||
|
Comment on lines
+357
to
+362
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no point in looking up the environment here, as the variable is not bound in this scope (it would be bound in the next line). I know, that asking the environment for a name that is meaningful for the programmer is tempting, but the binding structure doesn't work that way. Such an programmer-friendly name could be stored in a variable metadata, but we could do this a separate issue.
Suggested change
|
||||||||||||||||
| let env1 = Env.add_tvar env name h.eff_var in | ||||||||||||||||
| Env.print_string env "handler "; | ||||||||||||||||
| Env.print_string env "{"; | ||||||||||||||||
| Env.print_string env name; | ||||||||||||||||
| Env.print_string env " of "; | ||||||||||||||||
| Env.print_string env "} "; | ||||||||||||||||
| print_type env1 h.cap_tp 1; | ||||||||||||||||
| Env.print_string env " with ["; | ||||||||||||||||
| print_effect_body env1 h.in_eff; | ||||||||||||||||
| Env.print_string env "] "; | ||||||||||||||||
| print_type env1 h.in_tp 1; | ||||||||||||||||
| begin match h.out_eff with | ||||||||||||||||
| | [ PP_EffWildcard ] -> | ||||||||||||||||
| Env.print_string env " ->> " | ||||||||||||||||
| | effs -> | ||||||||||||||||
| Env.print_string env " ->["; | ||||||||||||||||
| print_effect_body env effs; | ||||||||||||||||
| Env.print_string env "] " | ||||||||||||||||
| end; | ||||||||||||||||
| print_type env h.out_tp 1) | ||||||||||||||||
| let print_comp env eff tp = | ||||||||||||||||
| begin match eff with | ||||||||||||||||
| | [ PP_EffWildcard ] -> () | ||||||||||||||||
| | _ -> | ||||||||||||||||
| Env.print_string env " ["; | ||||||||||||||||
| print_effect_body env eff; | ||||||||||||||||
| Env.print_string env "]" | ||||||||||||||||
| end; | ||||||||||||||||
| Env.print_string env " "; | ||||||||||||||||
| print_type env tp 1 | ||||||||||||||||
| in | ||||||||||||||||
| if h.in_eff = h.out_eff && h.in_tp = h.out_tp then ( | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be fully correct, we should also check, that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, structural equality is bad (for many reasons). Maybe a custom function that checks α-equivalence modulo permutations of effects, and understands, that the scope of compared types/effects are different would solve all the problems. |
||||||||||||||||
| Env.print_string env " =>"; | ||||||||||||||||
| print_comp env h.out_eff h.out_tp | ||||||||||||||||
| ) else ( | ||||||||||||||||
| Env.print_string env " in"; | ||||||||||||||||
| print_comp env1 h.in_eff h.in_tp; | ||||||||||||||||
| Env.print_string env " =>"; | ||||||||||||||||
| print_comp env h.out_eff h.out_tp | ||||||||||||||||
| )) | ||||||||||||||||
|
|
||||||||||||||||
| | PP_TEffect eff -> print_effect env eff prec | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It would be nice to have some tests for the new feature.