text
stringlengths
0
601k
let start_playing = ref false
let destroy ( ) = GMain . Main . quit ( )
let low_prio = Glib . int_of_priority ` LOW -> Glib . Timeout . id = " ml_g_timeout_add " val mutable period = 1 . 0 . / freq val mutable last_wall_clk = Unix . gettimeofday ( ) val mutable timer_id = None val mutable step_count = 0 method set_period v = period <- v method private clear_timer ( ) = match timer_id with None -> ( ) | Some id -> ( Glib . Timeout . remove id ; timer_id <- None ) method single_step ( ) = main_step ( ) method trigger_step ( ) = self # clear_timer ( ) ; let is_done = main_step ( ) in let delta = 1 . 0 in let wall_clk = Unix . gettimeofday ( ) in let delta ' = delta . - ( wall_clk . - last_wall_clk ) in last_wall_clk <- wall_clk ; if is_done then true else if delta ' <= 0 . 0 then main_step ( ) else ( timer_id <- Some ( timeout_add ~ prio : low_prio ~ ms ( : int_of_float ( delta ' . * period ) ) ~ callback : self # trigger_step ) ; true ) method start ( ) = last_wall_clk <- Unix . gettimeofday ( ) ; ignore ( self # trigger_step ( ) ) method stop ( ) = self # clear_timer ( ) end
let go freq main_step = let w = GWindow . window ~ title " : Simulator " ~ width : 250 ~ height : 70 ~ resizable : false ( ) in let outer_box = GPack . vbox ~ packing : w # add ( ) in let top_box = GPack . button_box ` HORIZONTAL ~ packing : outer_box # pack ~ child_width : 48 ~ child_height : 48 ~ layout ` : SPREAD ( ) in let b_play = GButton . button ~ packing : top_box # pack ~ stock ` : MEDIA_PLAY ( ) in let b_pause = GButton . button ~ packing : top_box # pack ~ stock ` : MEDIA_PAUSE ( ) in let b_single = GButton . button ~ packing : top_box # pack ~ stock ` : MEDIA_NEXT ( ) in b_pause # misc # set_sensitive false ; let stask = new step_task freq ( fun ( ) -> main_step ( ) ; false ) in let s_speed_adj = GData . adjustment ~ lower : 1 . 0 ~ upper : 100 . 0 ~ value : 10 . 0 ~ step_incr : 1 . 0 ( ) in let change_period x = stask # set_period ( 10 . . / s_speed_adj # value ) in ignore ( s_speed_adj # connect # value_changed change_period ) ; let s_speed = GRange . scale ` HORIZONTAL ~ adjustment : s_speed_adj ~ draw_value : false ~ packing : outer_box # pack ( ) in ignore ( s_speed ) ; let step_react_fun ( ) = try if Printexc . print stask # single_step ( ) then begin b_single # misc # set_sensitive false ; b_play # misc # set_sensitive false ; b_pause # misc # set_sensitive false ; ( ) end with _ -> ( destroy ( ) ) in let play_pushed ( ) = b_single # misc # set_sensitive false ; b_play # misc # set_sensitive false ; b_pause # misc # set_sensitive true ; stask # start ( ) in let pause_pushed ( ) = b_single # misc # set_sensitive true ; b_play # misc # set_sensitive true ; b_pause # misc # set_sensitive false ; stask # stop ( ) in ignore ( b_play # connect # clicked ~ callback : play_pushed ) ; ignore ( b_pause # connect # clicked ~ callback : pause_pushed ) ; ignore ( b_single # connect # clicked ~ callback : step_react_fun ) ; if ! start_playing then play_pushed ( ) else step_react_fun ( ) ; ignore ( w # connect # destroy ~ callback : destroy ) ; w # show ( ) ; GMain . Main . main ( )
type error = | Etype | Ehybrid_operator | Earray_operator | Eapplication
let error loc kind = raise ( Error ( loc , kind ) )
let message loc kind = begin match kind with | Etype -> eprintf " [ @% aTranslation to L --: This type cannot be translated . . ] " @@ output_location loc | Ehybrid_operator -> eprintf " [ @% aTranslation to L --: Hybrid operators are not treated . . ] " @@ output_location loc | Earray_operator -> eprintf " [ @% aTranslation to L --: Array operators are not treated . . ] " @@ output_location loc | Eapplication -> eprintf " [ @% aTranslation to L --: \ Application must be of the form f ( e1 , . . . , en ) . . ] " @@ output_location loc end
type return = { eqs : eq State . t ; env : tentry Env . t State . t ; assertion : exp State . t }
let empty = { eqs = State . empty ; env = State . empty ; assertion = State . empty }
let with_env ( { env = env0 } as return ) env = { return with env = State . cons env env0 }
let with_eq ( { eqs = eqs } as return ) eq = { return with eqs = State . cons eq eqs }
let par { eqs = eqs1 ; env = env1 ; assertion = as1 } { eqs = eqs2 ; env = env2 ; assertion = as2 } = { eqs = State . par eqs1 eqs2 ; env = State . par env1 env2 ; assertion = State . par as1 as2 }
let eq_make k x e ck = { eq_kind = k ; eq_ident = x ; eq_exp = e ; eq_clock = ck }
let on ck ln c = Ck_on ( ck , ln , c )
let relse res c = Res_else ( res , c )
let immediate = function | Eint ( i ) -> Lint ( i ) | Efloat ( f ) -> Lfloat ( f ) | Ebool ( b ) -> Lbool ( b ) | Echar ( c ) -> Lchar ( c ) | Estring ( s ) -> Lstring ( s ) | Evoid -> Lvoid
let constr0pat { p_desc = p_desc } = match p_desc with | Econstpat ( Ebool ( b ) ) -> Lboolpat ( b ) | Econstr0pat ( c ) -> Lconstr0pat ( c ) | _ -> assert false
let rec type_of loc { t_desc = ty } = match ty with | Deftypes . Tconstr ( q , [ ] , _ ) -> if q = Initial . int_ident then Tint else if q = Initial . int32_ident then Tint else if q = Initial . int64_ident then Tint else if q = Initial . bool_ident then Tbool else if q = Initial . zero_ident then Tbool else if q = Initial . float_ident then Tfloat else if q = Initial . char_ident then Tchar else if q = Initial . string_ident then Tstring else if q = Initial . unit_ident then Tunit else Lmm . Tconstr ( q ) | Tconstr _ -> error loc Etype | Tproduct ( ty_list ) -> Lmm . Tproduct ( List . map ( type_of loc ) ty_list ) | Tvar | Tvec _ | Tfun _ -> error loc Etype | Tlink ( ty ) -> type_of loc ty
let type_expression loc ty_e = let { typ_body = ty } = Interface . scheme_of_type ty_e in type_of loc ty
let env_of_env loc env = Env . map ( fun { Deftypes . t_typ = ty } -> { t_typ = type_of loc ty } ) env
let operator loc op e_list = match op with | Eifthenelse -> Lapp ( Lifthenelse , e_list ) | Eunarypre -> Lapp ( Lunarypre , e_list ) | Eminusgreater -> Lapp ( Lminusgreater , e_list ) | Efby -> Lapp ( Lfby , e_list ) | Eup | Einitial | Edisc | Ehorizon -> error loc Ehybrid_operator | Eaccess | Eupdate | Econcat | Eslice _ -> error loc Earray_operator | Etest | Eatomic -> assert false
let shared_variables { dv = dv } = dv
let get x name_to_exp = try Env . find x name_to_exp with | Not_found -> Llast ( x )
let rec expression ck { e_desc = desc ; e_loc = loc } = match desc with | Elocal ( id ) -> Llocal ( id ) | Eglobal { lname = lid } -> Lglobal ( lid ) | Econst ( im ) -> Lconst ( immediate im ) | Econstr0 ( lid ) -> Lconstr0 ( lid ) | Econstr1 _ -> assert false | Elast ( x ) -> Llast ( x ) | Eapp ( _ , { e_desc = Eglobal { lname = lid } } , e_list ) -> Lapp ( Lop ( lid ) , List . map ( expression ck ) e_list ) | Eapp _ -> error loc Eapplication | Eop ( op , e_list ) -> operator loc op ( map ( expression ck ) e_list ) | Erecord_access ( e , lid ) -> Lrecord_access ( expression ck e , lid ) | Erecord ( l_e_list ) -> Lrecord ( map ( fun ( l , e ) -> ( l , expression ck e ) ) l_e_list ) | Etypeconstraint ( e , _ ) -> expression ck e | Etuple ( e_list ) -> Ltuple ( List . map ( expression ck ) e_list ) | Ematch _ | Eseq _ | Elet _ | Eperiod _ | Eblock _ | Epresent _ -> assert false
let split s_set ( { eqs = eqs } as return ) = let eq_name_exp , eqs = State . partition ( fun { eq_ident = id } -> S . mem id s_set ) eqs in let name_to_exp = State . fold ( fun { eq_ident = id ; eq_exp = e } acc -> Env . add id e acc ) eq_name_exp Env . empty in name_to_exp , { return with eqs = eqs }
let rec equation ck res { eq_desc = desc ; eq_write = defnames } = match desc with | EQeq ( { p_desc = Evarpat ( x ) } , e ) -> with_eq empty ( eq_make Def x ( expression ck e ) ck ) | EQinit ( x , e ) -> let e = expression ck e in with_eq empty ( eq_make ( Init ( res ) ) x e ck ) | EQreset ( eq_list , e ) -> let e = expression ck e in equation_list ck ( relse res e ) eq_list | EQmatch ( total , e , p_h_list ) -> let e = expression ck e in let s_set = shared_variables defnames in let equations_from_handler e p b = let co = constr0pat p in let return = block ( on ck co e ) res b in let name_to_exp , return = split s_set return in co , name_to_exp , return in let constrpat_to_exp_list , return = Zmisc . map_fold ( fun return { m_pat = p ; m_body = b } -> let co , name_to_exp , return_name_to_exp = equations_from_handler e p b in let merge e x constrpat_name_to_exp_list = let p_e_list = List . map ( fun ( co , name_to_exp ) -> co , get x name_to_exp ) constrpat_name_to_exp_list in Lmerge ( e , p_e_list ) in let eq_list = S . fold ( eq_make Def x ( merge e x constrpat_to_exp_list ) ck ) :: eq_list ) s_set [ ] in List . fold_left with_eq empty eq_list | EQeq _ | EQnext _ | EQblock _ | EQemit _ | EQautomaton _ | EQpresent _ | EQder _ | EQpluseq _ | EQand _ | EQbefore _ | EQforall _ -> assert false fold_left ( fun acc eq -> par acc ( equation ck res eq ) ) empty eq_list let return = equation_list ck res body_eq_list in with_env return ( env_of_env loc n_env )
let local ck res { l_eq = eq_list ; l_env = l_env ; l_loc = loc } = let return = equation_list ck res eq_list in with_env return ( env_of_env loc l_env )
let let_expression ck res n_output ( { e_desc = desc } as e ) = match desc with | Elet ( l , e ) -> let return = local ck res l in let e = expression ck e in with_eq return ( eq_make Def n_output e ck ) | _ -> let e = expression ck e in with_eq empty ( eq_make Def n_output e ck )
let kind = function | S | AS | A | AD -> A | D -> D | C -> assert false
let typedecl loc n params td = let decl { desc = desc } = match desc with | Eabstract_type -> Labstract_type | Evariant_type _ -> assert false | Erecord_type ( n_ty_list ) -> Lrecord_type | Eabbrev _ -> assert false in match params with | [ ] -> Ltypedecl ( n , decl td ) | _ -> assert false
let implementation lmm_nodes lmm_list impl = match impl . desc with | Eopen _ -> lmm_list | Etypedecl ( n , params , td ) -> typedecl impl . loc n params td :: lmm_list | Econstdecl ( n , _ , e ) -> if Zmisc . S . mem n lmm_nodes then Lconstdecl ( n , expression Ck_base e ) :: lmm_list else lmm_list | Efundecl ( n , { f_kind = k ; f_args = p_list ; f_env = f_env ; f_body = e } ) -> if Zmisc . S . mem n lmm_nodes then let iset = List . fold_left ( Vars . fv_pat S . empty ) S . empty p_list in let i_list = S . elements iset in let n_output = Zident . fresh " out " in let { eqs = eqs ; env = env ; assertion = assertion } = let env = ( fun env acc -> Env . append env acc ) env ( env_of_env impl . loc f_env ) in let eq_list = State . list [ ] eqs in let assertion = Lfundecl ( n , { f_inputs = i_list ; else lmm_list
let implementation_list lmm_nodes impl_list = rev ( fold_left ( implementation lmm_nodes ) [ ] impl_list )
let rec repeat n a = match n with | 0 -> [ ] | n -> a :: ( repeat ( n - 1 ) a )
let rec keep l n = match ( l , n ) with | ( _ , 0 ) -> invalid_arg " keep " | ( h :: _ , 1 ) -> h | ( _ :: t , n ) -> keep t ( n - 1 ) | _ -> invalid_arg " keep "
let rec drop l n = match ( l , n ) with | ( _ , 0 ) -> invalid_arg " drop " | ( _ :: t , 1 ) -> t | ( h :: t , n ) -> h :: ( drop t ( n - 1 ) ) | _ -> invalid_arg " drop "
let rec range n m = if n > m then [ ] else n :: ( range ( n + 1 ) m )
let separate n l = let rec f acc n l = match ( n , l ) with | ( 0 , _ ) -> ( acc , l ) | ( n , h :: t ) -> f ( h :: acc ) ( n - 1 ) t | _ -> assert false in if n > List . length l then invalid_arg " separate " else let ( p , l ) = f [ ] n l in ( List . rev p , l )
type ' a pattern = | Pany | Por of ' a pattern * ' a pattern | Pconstr of ' a * ' a pattern list
module type SIG = sig type tag val compare : tag -> tag -> int val arity : tag -> int val is_complete : tag list -> bool val not_in : tag list -> tag type pattern_ast val inject : pattern_ast -> tag pattern val eject : tag pattern -> pattern_ast end
module PATTERN_CHECKER = functor ( S : SIG ) -> struct module SSet = Set . Make ( struct type t = S . tag let compare = S . compare end ) let uniq l = SSet . elements ( List . fold_right SSet . add l SSet . empty ) let is_complete sigma = S . is_complete ( uniq sigma ) let not_in sigma = S . not_in ( uniq sigma ) let rec head_constrs h = match h with | Pconstr ( c , q ) -> [ ( c , List . length q ) ] | Por ( l , r ) -> head_constrs l @ head_constrs r | Pany -> [ ] let rec matS c ar p = let vecS pv = match pv with | [ ] -> assert false | Pconstr ( c ' , r ' ) :: pv ' -> if S . compare c c ' = 0 then [ r ' @ pv ' ] else [ ] | Pany :: pv ' -> [ repeat ar Pany @ pv ' ] | Por ( t1 , t2 ) :: pv ' -> matS c ar [ t1 :: pv ' ; t2 :: pv ' ] in List . concat ( List . map vecS p ) let rec matD p = let vecD pv = match pv with | Pconstr _ :: _ -> [ ] | Pany :: pv ' -> [ pv ' ] | Por ( t1 , t2 ) :: pv ' -> matD [ t1 :: pv ' ; t2 :: pv ' ] | _ -> assert false in List . concat ( List . map vecD p ) let rec algU p q = match ( p , q ) with | ( [ ] , _ ) -> true | ( _ :: _ , [ ] ) -> false | ( h :: t , Pconstr ( c , r ) :: q ' ) -> let p ' = matS c ( List . length r ) p in algU p ' ( r @ q ' ) | ( h :: t , Por ( r1 , r2 ) :: q ' ) -> algU p ( r1 :: q ' ) || algU p ( r2 :: q ' ) | ( h :: t , Pany :: q ' ) -> let sigma = List . concat ( List . map ( fun v -> head_constrs ( List . hd v ) ) p ) in let algU_constr ( c_k , ar_k ) = let p ' = matS c_k ar_k p in algU p ' ( repeat ar_k Pany @ q ' ) in let sigma_used = List . exists algU_constr sigma in sigma_used || ( if not ( is_complete ( List . map fst sigma ) ) then algU ( matD p ) q ' else false ) type ' a trivec = { p : ' a patt_vec ; q : ' a patt_vec ; r : ' a patt_vec } and ' a trimat = ' a trivec list let rec trimatS c arity mv = let filter_line l = match l . p with | Pconstr ( c ' , t ) :: p ' -> if S . compare c c ' = 0 then [ { l with p = t @ p ' } ] else [ ] | Pany :: p ' -> [ { l with p = repeat arity Pany @ p ' } ] | Por ( t1 , t2 ) :: p ' -> trimatS c arity [ { l with p = t1 :: p ' } ; { l with p = t2 :: p ' } ] | _ -> assert false in List . concat ( List . map filter_line mv ) let shift1 l = match l . p with | p :: p ' -> { l with p = p ' ; q = p :: l . q } | _ -> assert false let shift2 l = match l . p with | p :: p ' -> { l with p = p ' ; r = p :: l . r } | _ -> assert false let simple_union e e ' = match ( e , e ' ) with | ( Some l , Some l ' ) -> Some ( l @ l ' ) | ( None , _ ) | ( _ , None ) -> None let union r1 r2 e ' e ' ' = match ( e ' , e ' ' ) with | ( Some [ ] , Some [ ] ) -> Some [ ] | ( None , None ) -> None | ( Some [ ] , None ) -> Some [ r2 ] | ( None , Some [ ] ) -> Some [ r1 ] | ( Some [ ] , Some ( _ :: _ ) ) -> e ' ' | ( Some ( _ :: _ ) , Some [ ] ) -> e ' | ( None , Some ( ( _ :: _ ) as t ) ) -> Some ( r1 :: t ) | ( Some ( ( _ :: _ ) as t ) , None ) -> Some ( r2 :: t ) | ( Some ( ( _ :: _ ) as t ' ) , Some ( ( _ :: _ ) as t ' ' ) ) -> Some ( t ' @ t ' ' ) let rec algU ' m v = match v . p with | Pconstr ( c , t ) :: p ' -> algU ' ( trimatS c ( List . length t ) m ) { v with p = t @ p ' } | Pany :: _ -> algU ' ( List . map shift1 m ) ( shift1 v ) | Por _ :: _ -> algU ' ( List . map shift2 m ) ( shift2 v ) | [ ] -> begin match v . r with | [ ] -> let qm = List . map ( fun l -> l . q ) m in if algU qm v . q then Some [ ] else None | _ :: _ -> let rec compute_Ej j = begin match List . nth v . r ( j - 1 ) with | Por ( t1 , t2 ) -> let f l = let r_j = keep l . r j and r_woj = drop l . r j in { p = [ r_j ] ; q = r_woj @ l . q ; r = [ ] } in let rv_woj = drop v . r j in let m ' = List . map f m in let m ' ' = m ' @ [ { p = [ t1 ] ; q = drop v . r j @ v . q ; r = [ ] } ] in let r1 = algU ' m ' { p = [ t1 ] ; q = rv_woj @ v . q ; r = [ ] } and r2 = algU ' m ' ' { p = [ t2 ] ; q = rv_woj @ v . q ; r = [ ] } in union t1 t2 r1 r2 | _ -> assert false end in let j_list = range 1 ( List . length ( List . hd m ) . r ) in let computed_Ej = List . map compute_Ej j_list in List . fold_left simple_union ( Some [ ] ) computed_Ej end let rec algI m n = match ( m , n ) with | ( [ ] , 0 ) -> Some [ ] | ( [ ] :: _ , 0 ) -> None | ( m , n ) -> let sigma = List . concat ( List . map ( fun v -> head_constrs ( List . hd v ) ) m ) in let sigma_c = List . map fst sigma in let default = if is_complete sigma_c then None else algI ( matD m ) ( n - 1 ) in begin match default with | Some p -> begin match sigma with | [ ] -> Some ( Pany :: p ) | _ :: _ -> let c ' = not_in sigma_c in Some ( Pconstr ( c ' , repeat ( S . arity c ' ) Pany ) :: p ) end | None -> let rec traverse_sigma sigma = match sigma with | [ ] -> None | ( c , ar ) :: sigma ' -> let res = algI ( matS c ar m ) ( ar + n - 1 ) in begin match res with | None -> traverse_sigma sigma ' | Some v -> let ( r , p ) = separate ar v in Some ( Pconstr ( c , r ) :: p ) end in traverse_sigma sigma end type result = { not_matched : S . pattern_ast option ; redundant_patterns : S . pattern_ast list ; } let check m = let m ' = List . map ( fun v -> [ S . inject v ] ) m in match m ' with | [ ] -> invalid_arg " check " | v :: _ -> { not_matched = begin let n = List . length v in match algI m ' n with | None -> None | Some [ p ] -> Some ( S . eject p ) | _ -> assert false end ; redundant_patterns = begin let make_trivec v = { p = v ; q = [ ] ; r = [ ] } in let make_trimat m = List . map make_trivec m in let check_line ( m , red ) v = let r = algU ' ( make_trimat m ) ( make_trivec v ) in ( m @ [ v ] , match r with | Some [ ] -> red | Some r -> List . map S . eject r @ red | None -> List . map S . eject v @ red ) in let ( _ , red ) = List . fold_left check_line ( [ ( List . hd m ' ) ] , [ ] ) ( List . tl m ' ) in red ; end } end
let header_in_file = let open Zconfig in " The Zelus compiler , version " ^ version ^ " " - ^ subversion ^ " \ n \ ( " ^ date ^ " ) "
module S = Set . Make ( struct type t = string let compare = compare end )
module Env = Map . Make ( struct type t = string let compare = compare end )
let default_used_modules = ref [ name_of_stdlib_module ]
let load_path = ref ( [ standard_lib ] )
let set_stdlib p = load_path := [ p ]
let locate_stdlib ( ) = Printf . printf " % s \ n " standard_lib
let show_version ( ) = let open Zconfig in Printf . printf " The Zelus compiler , version % s -% s ( % s ) \ n " version subversion date ; Printf . printf " Std lib : " ; locate_stdlib ( ) ; Printf . printf " \ n " ; ( )
let simulation_node = ref None
let set_simulation_node ( n : string ) = simulation_node := Some ( n )
let outname = ref None
let set_outname ( n : string ) = outname := Some ( n )
let node_outname = ref None
let set_node_outname ( n : string ) = node_outname := Some ( n )
let number_of_checks = ref 0
let set_check ( n : int ) = number_of_checks := n
let sampling_period = ref 0 . 0
let set_sampling_period p = sampling_period := p
let inlining_level = ref 10
let set_inlining_level l = inlining_level := l
let inline_all = ref false
let dzero = ref false
let verbose = ref false
let vverbose = ref false
let print_types = ref false
let print_causality_types = ref false
let print_initialization_types = ref false
let typeonly = ref false
let use_gtk = ref false
let no_stdlib = ref false
let no_causality = ref false
let no_initialisation = ref false
let no_opt = ref false
let no_deadcode = ref false
let no_simplify_causality_type = ref false
let no_reduce = ref false
let no_warning = ref false
let zsign = ref false
let with_copy = ref false
let use_rif = ref false
let build_deps = ref false
let lmm_nodes = ref S . empty
let set_lmm_nodes ( n : string ) = lmm_nodes := S . add n ! lmm_nodes object val mutable counter = 0 method name = counter <- counter + 1 ; counter method reset = counter <- 0 method init i = counter <- i end
let symbol = new name_generator object val mutable counter = 0 val mutable assoc_table : ( int * string ) list = [ ] method name var = try List . assq var assoc_table with not_found -> let n = f counter in counter <- counter + 1 ; assoc_table <- ( var , n ) :: assoc_table ; n method reset = counter <- 0 ; assoc_table <- [ ] end
let int_to_letter bound i = if i < 26 then String . make 1 ( Char . chr ( i + bound ) ) else String . make 1 ( Char . chr ( ( i mod 26 ) + bound ) ) ^ string_of_int ( i / 26 )
let int_to_alpha i = int_to_letter 97 i
let binding_level = ref 0
let top_binding_level ( ) = ! binding_level = 0
let push_binding_level ( ) = binding_level := ! binding_level + 1
let pop_binding_level ( ) = binding_level := ! binding_level - 1 ; assert ( ! binding_level > generic )
let reset_binding_level ( ) = binding_level := 0
let optional f acc = function | None -> acc | Some x -> f acc x
let optional_unit f acc = function | None -> ( ) | Some x -> f acc x
let optional_map f = function | None -> None | Some ( x ) -> Some ( f x )
let optional_with_map f acc = function | None -> None , acc | Some ( x ) -> let x , acc = f acc x in Some ( x ) , acc
let optional_get = function | Some x -> x | None -> assert false
let rec iter f = function | [ ] -> [ ] | x :: l -> let y = f x in y :: iter f l
let fold f l = List . rev ( List . fold_left f [ ] l )
let from i = let rec fromrec acc i = match i with | 0 -> acc | _ -> fromrec ( i :: acc ) ( i - 1 ) in fromrec [ ] i
let map_fold f acc l = let rec maprec acc = function | [ ] -> [ ] , acc | x :: l -> let y , acc = f acc x in let l , acc = maprec acc l in y :: l , acc in maprec acc l