Functor for applying a fold over any ADT node (e.g. generate all print

functions in one go)
This commit is contained in:
Suzanne Dupéron 2020-04-27 13:16:33 +01:00
parent 94b9404d1b
commit 9b1e66622a
2 changed files with 11 additions and 3 deletions

View File

@ -106,6 +106,8 @@ let op ppf = {
let print : (unit fold_config -> unit -> 'a -> unit) -> formatter -> 'a -> unit = fun fold ppf v ->
fold (op ppf) () v
let program = print fold__program
let type_expression = print fold__type_expression
let full_environment = print fold__full_environment
include Fold.Folds(struct
type state = unit ;;
type 'a t = formatter -> 'a -> unit ;;
let f = print ;;
end)

View File

@ -465,3 +465,9 @@ for $adts.list -> $t
say "let with__$t<name>__post_state : _ -> _ fold_map_config__$moduleName -> _ fold_map_config__$moduleName = (fun node__$t<name>__post_state op -> \{ op with $t<name> = \{ op.$t<name> with node__$t<name>__post_state \} \});;";
for $t<ctorsOrFields>.list -> $c
{ say "let with__$t<name>__$c<name> : _ -> _ fold_map_config__$moduleName -> _ fold_map_config__$moduleName = (fun $t<name>__$c<name> op -> \{ op with $t<name> = \{ op.$t<name> with $t<name>__$c<name> \} \});;"; } }
say "";
say "module Folds (M : sig type state type 'a t val f : (state fold_config -> state -> 'a -> state) -> 'a t end) = struct";
for $adts.list -> $t
{ say "let $t<name> = M.f fold__$t<name>;;"; }
say "end";