From 1e1728e5dd03b303914b8a8cea64b1704c19082b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Tue, 31 Mar 2020 23:26:01 +0200 Subject: [PATCH] [WIP, does not build] Remove some polymorphism : customized visitors must be specific to their accumulator type --- src/stages/adt_generator/generator.raku | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/stages/adt_generator/generator.raku b/src/stages/adt_generator/generator.raku index 7a0dcbd9b..57c27ee8c 100644 --- a/src/stages/adt_generator/generator.raku +++ b/src/stages/adt_generator/generator.raku @@ -173,34 +173,34 @@ for $adts.kv -> $index, $t { say ""; for $adts.list -> $t { - say "type continue_fold_map__$t = \{"; - say " node__$t : 'state . $t -> 'state -> ($t * 'state) ;"; + say "type 'state continue_fold_map__$t = \{"; + say " node__$t : $t -> 'state -> ($t * 'state) ;"; for $t.list -> $c - { say " $t__$c : 'state . {$c || 'unit'} -> 'state -> ({$c || 'unit'} * 'state) ;" } + { say " $t__$c : {$c || 'unit'} -> 'state -> ({$c || 'unit'} * 'state) ;" } say ' }'; } -say "type continue_fold_map = \{"; +say "type 'state continue_fold_map = \{"; for $adts.list -> $t { - say " $t : continue_fold_map__$t ;"; + say " $t : 'state continue_fold_map__$t ;"; } say ' }'; say ""; for $adts.list -> $t -{ say "type fold_map_config__$t = \{"; - say " node__$t : 'state . $t -> 'state -> continue_fold_map -> ($t * 'state) ;"; # (*Adt_info.node_instance_info ->*) - say " node__$t__pre_state : 'state . $t -> 'state -> 'state ;"; # (*Adt_info.node_instance_info ->*) - say " node__$t__post_state : 'state . $t -> $t -> 'state -> 'state ;"; # (*Adt_info.node_instance_info ->*) +{ say "type 'state fold_map_config__$t = \{"; + say " node__$t : $t -> 'state -> 'state continue_fold_map -> ($t * 'state) ;"; # (*Adt_info.node_instance_info ->*) + say " node__$t__pre_state : $t -> 'state -> 'state ;"; # (*Adt_info.node_instance_info ->*) + say " node__$t__post_state : $t -> $t -> 'state -> 'state ;"; # (*Adt_info.node_instance_info ->*) for $t.list -> $c - { say " $t__$c : 'state . {$c || 'unit'} -> 'state -> continue_fold_map -> ({$c || 'unit'} * 'state) ;"; # (*Adt_info.ctor_or_field_instance_info ->*) + { say " $t__$c : {$c || 'unit'} -> 'state -> 'state continue_fold_map -> ({$c || 'unit'} * 'state) ;"; # (*Adt_info.ctor_or_field_instance_info ->*) } say '}' } -say "type fold_map_config ="; +say "type 'state fold_map_config ="; say ' {'; for $adts.list -> $t -{ say " $t : fold_map_config__$t;" } +{ say " $t : 'state fold_map_config__$t;" } say ' }'; say ""; @@ -352,31 +352,31 @@ for $adts.list -> $t say ""; -say 'type mk_continue_fold_map = {'; -say " fn : mk_continue_fold_map -> fold_map_config -> continue_fold_map"; +say "type 'state mk_continue_fold_map = \{"; +say " fn : 'state mk_continue_fold_map -> 'state fold_map_config -> 'state continue_fold_map"; say '}'; # fold_map functions say ""; for $adts.list -> $t -{ say "let _fold_map__$t : type qstate . mk_continue_fold_map -> fold_map_config -> $t -> qstate -> ($t * qstate) = fun mk_continue_fold_map visitor x state ->"; - say " let continue_fold_map : continue_fold_map = mk_continue_fold_map.fn mk_continue_fold_map visitor in"; +{ say "let _fold_map__$t : type qstate . qstate mk_continue_fold_map -> qstate fold_map_config -> $t -> qstate -> ($t * qstate) = fun mk_continue_fold_map visitor x state ->"; + say " let continue_fold_map : qstate continue_fold_map = mk_continue_fold_map.fn mk_continue_fold_map visitor in"; say " let state = visitor.$t.node__$t__pre_state x state in"; # (*(fun () -> whole_adt_info, info__$t)*) say " let (new_x, state) = visitor.$t.node__$t x state continue_fold_map in"; # (*(fun () -> whole_adt_info, info__$t)*) say " let state = visitor.$t.node__$t__post_state x new_x state in"; # (*(fun () -> whole_adt_info, info__$t)*) say " (new_x, state)"; say ""; for $t.list -> $c - { say "let _fold_map__$t__$c : type qstate . mk_continue_fold_map -> fold_map_config -> { $c || 'unit' } -> qstate -> ({ $c || 'unit' } * qstate) = fun mk_continue_fold_map visitor x state ->"; - say " let continue_fold_map : continue_fold_map = mk_continue_fold_map.fn mk_continue_fold_map visitor in"; + { say "let _fold_map__$t__$c : type qstate . qstate mk_continue_fold_map -> qstate fold_map_config -> { $c || 'unit' } -> qstate -> ({ $c || 'unit' } * qstate) = fun mk_continue_fold_map visitor x state ->"; + say " let continue_fold_map : qstate continue_fold_map = mk_continue_fold_map.fn mk_continue_fold_map visitor in"; say " visitor.$t.$t__$c x state continue_fold_map"; # (*(fun () -> whole_adt_info, info__$t, info__$t__$c)*) say ""; } } # make the "continue" object say ""; say '(* Curries the "visitor" argument to the folds (non-customizable traversal functions). *)'; -say "let mk_continue_fold_map : mk_continue_fold_map = \{ fn = fun self visitor ->"; +say "let mk_continue_fold_map : 'stateX . 'stateX mk_continue_fold_map = \{ fn = fun self visitor ->"; say ' {'; for $adts.list -> $t { say " $t = \{"; @@ -391,12 +391,12 @@ say ""; # fold_map functions : tying the knot say ""; for $adts.list -> $t -{ say "let fold_map__$t : type qstate . fold_map_config -> $t -> qstate -> ($t * qstate) = fun visitor x state -> _fold_map__$t mk_continue_fold_map visitor x state"; +{ say "let fold_map__$t : type qstate . qstate fold_map_config -> $t -> qstate -> ($t * qstate) = fun visitor x state -> _fold_map__$t mk_continue_fold_map visitor x state"; for $t.list -> $c - { say "let fold_map__$t__$c : type qstate . fold_map_config -> { $c || 'unit' } -> qstate -> ({ $c || 'unit' } * qstate) = fun visitor x state -> _fold_map__$t__$c mk_continue_fold_map visitor x state"; } } + { say "let fold_map__$t__$c : type qstate . qstate fold_map_config -> { $c || 'unit' } -> qstate -> ({ $c || 'unit' } * qstate) = fun visitor x state -> _fold_map__$t__$c mk_continue_fold_map visitor x state"; } } -say "let no_op : fold_map_config = \{"; +say "let no_op : 'state . 'state fold_map_config = \{"; for $adts.list -> $t { say " $t = \{"; say " node__$t = (fun v state continue ->"; # (*_info*)