aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/extraction/ocaml.ml
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/extraction/ocaml.ml')
-rw-r--r--plugins/extraction/ocaml.ml12
1 files changed, 8 insertions, 4 deletions
diff --git a/plugins/extraction/ocaml.ml b/plugins/extraction/ocaml.ml
index ce88ea6d2..85f18a093 100644
--- a/plugins/extraction/ocaml.ml
+++ b/plugins/extraction/ocaml.ml
@@ -634,10 +634,12 @@ and pp_module_type params = function
str "functor (" ++ name ++ str ":" ++ typ ++ str ") ->" ++ fnl () ++ def
| MTsig (mp, sign) ->
push_visible mp params;
- let try_pp_specif x l =
+ let try_pp_specif l x =
try pp_specif x :: l with Failure "empty phrase" -> l
in
- let l = List.fold_right try_pp_specif sign [] in
+ (* We cannot use fold_right here due to side effects in pp_specif *)
+ let l = List.fold_left try_pp_specif [] sign in
+ let l = List.rev l in
pop_visible ();
str "sig " ++ fnl () ++
v 1 (str " " ++ prlist_with_sep fnl2 identity l) ++
@@ -710,10 +712,12 @@ and pp_module_expr params = function
str "functor (" ++ name ++ str ":" ++ typ ++ str ") ->" ++ fnl () ++ def
| MEstruct (mp, sel) ->
push_visible mp params;
- let try_pp_structure_elem x l =
+ let try_pp_structure_elem l x =
try pp_structure_elem x :: l with Failure "empty phrase" -> l
in
- let l = List.fold_right try_pp_structure_elem sel [] in
+ (* We cannot use fold_right here due to side effects in pp_structure_elem *)
+ let l = List.fold_left try_pp_structure_elem [] sel in
+ let l = List.rev l in
pop_visible ();
str "struct " ++ fnl () ++
v 1 (str " " ++ prlist_with_sep fnl2 identity l) ++