text
stringlengths
0
601k
let sp_xpost ( loc , q_pat_t_option_list ) = let loc = T . location loc in let pat_term ( q , t ) = ( T . pattern q , T . term true t ) in let qualid_pat_term_opt ( q , pt_opt ) = ( T . qualid q , Opt . map pat_term pt_opt ) in ( loc , List . map qualid_pat_term_opt q_pat_t_option_list )
let empty_spec = { sp_pre = [ ] ; sp_post = [ ] ; sp_xpost = [ ] ; sp_reads = [ ] ; sp_writes = [ ] ; sp_alias = [ ] ; sp_variant = [ ] ; sp_checkrw = false ; sp_diverge = false ; sp_partial = false ; }
let vspec spec = let sp_writes = List . map ( T . term false ) spec . Uast . sp_writes in let sp_checkrw = match sp_writes with [ ] -> false | _ -> true in let sp_post = match spec . Uast . sp_header with | None -> List . map sp_post_no_ret spec . sp_post | Some hd -> List . map ( sp_post hd . sp_hd_ret ) spec . sp_post in { sp_pre = List . map ( T . term false ) spec . Uast . sp_pre ; sp_post ; sp_xpost = List . map sp_xpost spec . sp_xpost ; sp_reads = [ ] ; sp_writes ; sp_alias = [ ] ; sp_variant = List . map ( fun t -> ( T . term false t , None ) ) spec . sp_variant ; sp_checkrw ; sp_diverge = spec . sp_diverge ; sp_partial = false ; }
let fun_spec spec = { sp_pre = List . map ( T . term false ) spec . Uast . fun_req ; sp_post = List . map sp_post_no_ret spec . fun_ens ; sp_xpost = [ ] ; sp_reads = [ ] ; sp_writes = [ ] ; sp_alias = [ ] ; sp_variant = List . map ( fun t -> ( T . term false t , None ) ) spec . fun_variant ; sp_checkrw = false ; sp_diverge = false ; sp_partial = false ; }
let spec_union s1 s2 = { sp_pre = s1 . sp_pre @ s2 . sp_pre ; sp_post = s1 . sp_post @ s2 . sp_post ; sp_xpost = s1 . sp_xpost @ s2 . sp_xpost ; sp_reads = s1 . sp_reads @ s2 . sp_reads ; sp_writes = s1 . sp_writes @ s2 . sp_writes ; sp_alias = s1 . sp_alias @ s2 . sp_alias ; sp_variant = s1 . sp_variant @ s2 . sp_variant ; sp_checkrw = s1 . sp_checkrw || s2 . sp_checkrw ; sp_diverge = s1 . sp_diverge || s2 . sp_diverge ; sp_partial = s1 . sp_partial || s2 . sp_partial ; }
let add_word ? custom name dict = let open L in { dict with words = Dict . add name ? custom dict . words }
let add role ? custom name dict = let open L in { dict with words = Dict . add name ? custom dict . words ; roles = R . add ( String . lowercase_ascii name ) role dict . roles ; }
let add_ext x exts = S . add ( String . lowercase_ascii x ) exts
let vendor_tag ( dict , out ) ( x : Structured_spec . short_tag ) = ( add Extension x . name dict , add_ext x . name out )
let empty = let open L in { words = Dict . empty ; roles = R . empty ; context = { mu with prefix = [ " vk " ] } }
let add_post x dict = L . { dict with roles = R . add x Postfix dict . roles }
let add_pre x dict = L . { dict with roles = R . add x Prefix dict . roles }
let make spec = let dict , exts = List . fold_left vendor_tag ( empty , S . empty ) spec . Structured_spec . tags in dict |> add Main " RandR " |> add Main " RR " |> add Main " DirectFB " |> add Main " FB " |> add Main " D3D12 " |> add Main " MacOS " |> add Main " LOD " |> add Main " ID " |> add Extension " EXT " |> add Extension " KHX " |> add Main " IOS " |> add Main " 1D " |> add Main " 2D " |> add Main " 3D " |> add Main " 1d " |> add Main " 2d " |> add Main " 3d " |> add Main " 16Bit " |> add Main " 8Bit " |> add Main " UUID " |> add_word " AABB " |> add_word " CAMetalLayer " |> add_word " SM " |> add_word ~ custom [ " : vulkan " ; " 1 " ; " 1 " ] " Vulkan11 " |> add_word ~ custom [ " : vulkan " ; " 1 " ; " 2 " ] " Vulkan12 " |> add Main " ASTC " |> add Main " HDR " |> add_word " PCI " |> add_word " Win32 " |> add_post " flags " |> add_post " flag " |> add_post " bits " |> add_post " bit " |> add_pre " vk " , exts |> add_ext " KHX " |> add_ext " EXT "
object method msg : Js . js_string Js . t Js . readonly_prop method indicator : Js . js_string Js . t Js . readonly_prop method file : Js . js_string Js . t Js . readonly_prop method line : int Js . readonly_prop method col : int Js . readonly_prop end object method code : Js . js_string Js . t Js . optdef_prop method file : Js . js_string Js . t Js . optdef_prop end object method version : bool Js . optdef_prop method dparse : bool Js . optdef_prop method deps : bool Js . optdef_prop method check : bool Js . optdef_prop method eval : bool Js . optdef_prop method code : Js . js_string Js . t Js . optdef_prop method output : Js . js_string Js . t Js . optdef_prop method real : Js . js_string Js . t Js . optdef_prop method template : Js . js_string Js . t Js . optdef_prop method includes : Js . js_string Js . t Js . js_array Js . t Js . optdef_prop method files : js_file_code Js . t Js . js_array Js . t Js . optdef_prop end object method output : Js . js_string Js . t Js . optdef_prop method real : Js . js_string Js . t Js . optdef_prop method template : Js . js_string Js . t Js . optdef_prop method includes : Js . js_string Js . t Js . js_array Js . t Js . optdef_prop end
let new_object ( ) = Js . Unsafe . coerce ( object % js end )
let convertOutputErrors errors = let makeErrorObject error : error Js . t = let msg , indicator , file , line , col = Error . reportErrorStringNoLoc error in object % js val msg = Js . string msg val indicator = Js . string indicator val file = Js . string file val line = line val col = col end in List . map makeErrorObject errors |> Array . of_list |> Js . array
let convertInputFile ( i : js_file_code Js . t ) : input list = match Js . Optdef . to_option i . ## file , Js . Optdef . to_option i . ## code with | Some file , Some code -> [ Code ( Js . to_string file , Js . to_string code ) ] | Some file , None -> [ File ( Js . to_string file ) ] | None , Some code -> [ Code ( " live . vult " , Js . to_string code ) ] | None , None -> [ ]
let convertInputFiles ( files : js_file_code Js . t Js . js_array Js . t ) : input list = Js . to_array files |> Array . map convertInputFile |> Array . to_list |> List . flatten
let getFile ( args : args ) ( ext : FileKind . t ) : string = match ext with | FileKind . ExtOnly e -> args . output ^ " . " ^ e | FileKind . FullName n -> Filename . concat ( Filename . dirname args . output ) n
let convertOutputFile ( file : string ) ( code : string ) : js_file_code Js . t = let obj = new_object ( ) in obj . ## file := Js . string file ; obj . ## code := Js . string code ; obj
let convertOutputFiles args files = List . map ( fun ( text , file ) -> convertOutputFile ( getFile args file ) ( Pla . print text ) ) files |> Array . of_list |> Js . array
let set value fset = if Js . Optdef . test value then Js . Optdef . iter value ( fun a -> fset a )
let convertCodeName code = match code with | " c " -> CCode | " js " -> JSCode | " lua " -> LuaCode | _ -> failwith ( Printf . sprintf " unknow code generator ' % s ' " code )
let getArguments ( obj : js_args Js . t ) = let args = { default_arguments with files = [ ] } in set obj . ## dparse ( fun v -> args . dparse <- v ) ; set obj . ## deps ( fun v -> args . deps <- v ) ; set obj . ## check ( fun v -> args . check <- v ) ; set obj . ## eval ( fun v -> args . eval <- v ) ; set obj . ## version ( fun v -> args . show_version <- v ) ; set obj . ## code ( fun v -> args . code <- convertCodeName ( Js . to_string v ) ) ; set obj . ## output ( fun v -> args . output <- Js . to_string v ) ; set obj . ## real ( fun v -> args . real <- Js . to_string v ) ; set obj . ## template ( fun v -> args . template <- Js . to_string v ) ; set obj . ## includes ( fun v -> args . includes <- Js . to_array v |> Array . map Js . to_string |> Array . to_list ) ; set obj . ## files ( fun v -> args . files <- convertInputFiles v ) ; args
let applyOptions ( options : options Js . t ) ( args : args ) = set options . ## output ( fun v -> args . output <- Js . to_string v ) ; set options . ## real ( fun v -> args . real <- Js . to_string v ) ; set options . ## template ( fun v -> args . template <- Js . to_string v ) ; set options . ## includes ( fun v -> args . includes <- Js . to_array v |> Array . map Js . to_string |> Array . to_list )
let showResult ( args : args ) ( output : output ) : ' a Js . t = match output with | Version v -> let obj = new_object ( ) in obj . ## version := Js . string v ; obj | Message v -> let obj = new_object ( ) in obj . ## message := Js . string v ; obj | Dependencies deps -> let obj = new_object ( ) in obj . ## dependencies := Js . array ( List . map Js . string deps |> Array . of_list ) ; obj | ParsedCode v -> let obj = new_object ( ) in obj . ## parsedCode := Js . string v ; obj | GeneratedCode files -> let obj = new_object ( ) in obj . ## generatedCode := convertOutputFiles args files ; obj | Interpret v -> let obj = new_object ( ) in obj . ## interpret := Js . string v ; obj | CheckOk -> let obj = new_object ( ) in obj . ## check := Js . bool true ; obj | Errors errors -> let obj = new_object ( ) in obj . ## errors := convertOutputErrors errors ; obj
let showResults ( args : args ) ( results : output list ) = results |> List . map ( showResult args ) |> Array . of_list |> Js . array
let main ( input : js_args Js . t ) = let args = getArguments input in Driver . main args |> showResults args
let version = let args = { default_arguments with show_version = true } in match Driver . main args with | [ Version v ] -> Js . string v | _ -> failwith " unknown error "
let codeGeneration args results = match results with | GeneratedCode files :: _ -> convertOutputFiles args files |> Js . Unsafe . coerce | Errors errors :: _ -> convertOutputErrors errors |> Js . Unsafe . coerce | _ -> failwith " unknown error "
let generateJs ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = JSCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let generateC ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = CCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let generateLua ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = LuaCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let _ = Js . export_all ( object % js method main = main method version = version method generateJs = generateJs method generateC = generateC method generateLua = generateLua end )
let generateJSCode s = let args = { default_arguments with code = JSCode ; real = " js " ; template = " browser " ; files = [ Code ( " live . vult " , Js . to_string s ) ] } in match Driver . main args with | [ GeneratedCode [ ( code , _ ) ] ] -> Js . string ( Pla . print code ) | [ Errors errors ] -> let error_strings = List . map ( fun error -> let msg , indicator , _ , _ , _ = Error . reportErrorStringNoLoc error in msg ^ " \ n " ^ indicator ) errors |> String . concat " \ n " in Js . string ( " Errors in the program :\ n " ^ error_strings ) | _ -> Js . string " unknown error "
let makeAceError ( e : Error . t ) = let msg , indicator , _ , line , col = Error . reportErrorStringNoLoc e in Js . Unsafe . obj [ | " text " , Js . Unsafe . inject ( Js . string ( msg ^ " \ n " ^ indicator ) ) ; " row " , Js . Unsafe . inject ( Js . string ( string_of_int ( line - 1 ) ) ) ; " column " , Js . Unsafe . inject ( Js . string ( string_of_int ( col - 1 ) ) ) ; " type " , Js . Unsafe . inject ( Js . string " error " ) ; " raw " , Js . Unsafe . inject ( Js . string msg ) ] |
let checkCode s = let args = { default_arguments with check = true ; files = [ Code ( " live . vult " , Js . to_string s ) ] } in match Driver . main args with | [ Errors errors ] -> let error_objects = List . map makeAceError errors in error_objects |> Array . of_list |> Js . array | _ -> Js . array [ ] ||
let _ = Js . export " vult " ( object % js method main = Vultlib . main method version = Vultlib . version method generateJs = Vultlib . generateJs method generateC = Vultlib . generateC method generateLua = Vultlib . generateLua method checkCode = checkCode method generateJSCode = generateJSCode end )
type t = unit Pp . t
let quoted s = i ( sprintf " % S " s )
let surround delim a = let start , finish = match delim with | ` Paren -> ( i " ( " , i " ) " ) | ` Curly -> ( i " { " , i " } " ) | ` Square -> ( i " [ " , i " ] " ) in Pp . concat [ start ; a ; finish ]
module Name = struct let to_json t = sprintf " yojson_of_ % s " t let of_json t = sprintf " % s_of_yojson " t end
module Json = struct let invalid_pat name = ( ident " json " , Pp . textf " Json . error " \ invalid % s " \ json " name ) let typ = " Json . t " module Literal = struct let str n = sprintf " ` String % S " n let int i = sprintf " ` Int ( % d ) " i let null = " ` Null " let bool b = sprintf " ` Bool % b " b end let str = sprintf " ` String % s " let int = sprintf " ` Int % s " let bool = sprintf " ` Bool % s " end
module Gen = struct let record ~ delim fields = let sep = Pp . concat [ Pp . verbatim " ; " ; Pp . newline ] in Pp . text " { " ++ Pp . concat_map ~ sep fields ~ f ( : fun ( name , f ) -> Pp . concat [ Pp . textf " % s % s " name delim ; f ] ) ++ Pp . verbatim " } " let clause ~ delim l r = Pp . concat [ l ; Pp . verbatim ( sprintf " % s " delim ) ; r ] end
module Attr = struct type t = { name : string ; payload : w list } let make name payload = { name ; payload } let pp kind { name ; payload } = let kind = match kind with | ` Field -> " " @ | ` Type -> " " @@ in Pp . concat [ i kind ; i name ; Pp . space ; Pp . concat ~ sep : Pp . space payload ] |> surround ` Square end
module Type = struct let string = i " string " let int = i " int " let name = i let bool = i " bool " let gen_decl kw name body = Pp . concat [ Pp . textf " % s % s " = kw name ; Pp . newline ; body ] let and_ name body = gen_decl " and " name body let decl name body = gen_decl " type " name body let record fields = Gen . record ~ delim " " :: fields let field_attrs ~ field ~ attrs = match attrs with | [ ] -> field | attrs -> let attrs = Pp . concat_map attrs ~ sep : Pp . space ~ f ( : Attr . pp ` Field ) in Pp . concat [ field ; Pp . space ; attrs ] let var typ = Pp . textf " ' % s " typ let app typ = function | [ ] -> assert false | [ x ] -> Pp . concat [ x ; Pp . space ; typ ] | xs -> let args = let sep = Pp . verbatim " , " in Pp . concat [ Pp . verbatim " ( " ; Pp . concat ~ sep xs ; Pp . verbatim " ) " ] in Pp . concat [ args ; Pp . space ; typ ] let tuple fields = let sep = i " " * in i " ( " ++ Pp . concat ~ sep fields ++ i " ) " let rec_decls xs = match xs with | [ ] -> Pp . concat [ ] | ( name , body ) :: xs -> decl name body ++ newline ++ Pp . concat_map xs ~ sep : Pp . newline ~ f ( : fun ( name , body ) -> and_ name body ) let deriving td ~ record = let fields = if record then space ++ i " [ @@ yojson . allow_extra_fields ] " else space in Pp . concat [ td ; Pp . newline ; Pp . text " [ @@ deriving_inline yojson ] " ; fields ; space ; Pp . text " [ @@@ end ] " ] let opt_attr = ident " option [ @ yojson . option ] " let opt_field f = Pp . seq f opt_attr let default f def = Pp . concat [ f ; ident " [ @ default " ; ident def ; ident " ] " ] let key name = concat [ ident " [ @ key " ; quoted name ; ident " ] " ] let gen_variant ~ poly constrs = let sep = Pp . concat [ Pp . newline ; i " | " ] in Pp . concat_map constrs ~ sep ~ f ( : fun ( name , arg ) -> let name = let name = String . capitalize_ascii name in if poly then " ` " ^ name else name in match arg with | [ ] -> i name | xs -> let xs = match xs with | [ x ] -> x | xs -> tuple xs in Gen . clause ~ delim " : of " ( ident name ) xs ) let poly constrs = concat [ i " [ " ; gen_variant ~ poly : true constrs ; i " ] " ] let variant constrs = gen_variant ~ poly : false constrs end
let gen_module kw name body = Pp . concat [ Pp . textf " module % s % s " name kw ; Pp . newline ; body ; newline ; verbatim " end " ; newline ]
module Sig = struct let module_ name body = gen_module " : sig " name body let val_ name b = let sep = Pp . concat [ space ; i " " ; -> space ] in let b = Pp . concat ~ sep b in Pp . concat [ textf " val % s : " name ; b ; Pp . newline ] let assoc k v = Pp . concat [ Type . tuple [ k ; v ] ; Pp . space ; i " list " ] module Json = struct let arr typ = [ i typ ; i Json . typ ] let to_json typ = val_ ( Name . to_json typ ) ( arr typ ) let of_json typ = val_ ( Name . of_json typ ) ( List . rev ( arr typ ) ) end end
let warnings codes = seq ( textf " [ @@@ warning % S ] " codes ) newline
let opens names = Pp . concat_map names ~ f ( : fun name -> Pp . concat [ textf " open ! % s " name ; newline ] )
let module_ name body = gen_module " = struct " name body
let record fields = Gen . record ~ delim " " := fields
let match_ e clauses = let clauses = let sep = Pp . concat [ Pp . newline ; i " | " ] in Pp . concat_map ~ sep clauses ~ f ( : fun ( l , r ) -> Gen . clause ~ delim " " :-> l r ) in Pp . concat [ Pp . textf " match % s with " e ; Pp . newline ; clauses ]
let to_json t body = Pp . concat [ Pp . textf " let % s ( json : Json . t ) : t " = ( Name . to_json t ) ; Pp . newline ; Pp . hovbox ~ indent : 2 body ]
let of_json t body = Pp . concat [ Pp . textf " let % s ( t : t ) : Json . t " = ( Name . of_json t ) ; Pp . newline ; Pp . hovbox ~ indent : 2 body ]
let foo = ( ) ; ; *
let f x y = x ; ;
let 1 = 1 ; ; ; ;
type phone_number = int * int * int * int ; ;
type contact = { name : string ; phone_number : phone_number } ; ;
let nobody = { name = " " ; phone_number = ( 0 , 0 , 0 , 0 ) } ; ;
type database = { number_of_contacts : int ; contacts : contact array ; } ; ;
let make max_number_of_contacts = { number_of_contacts = 0 ; contacts = Array . make max_number_of_contacts nobody } ; ;
type query = { code : int ; contact : contact } ; ;
let insert db contact = if db . number_of_contacts >= Array . length db . contacts then ( false , db , nobody ) else let ( status , db , _ ) = search db contact in if status then ( false , db , contact ) else let cells i = in let db ' = { number_of_contacts = db . number_of_contacts + 1 ; contacts = Array . init ( Array . length db . contacts ) cells } in ( true , db ' , contact ) ; ;
let proof_of_bug = [ | { code = 0 ; contact = { name = " uno " ; phone_number = ( 1 , 1 , 1 , 1 ) } } ; { code = 0 ; contact = { name = " dos " ; phone_number = ( 2 , 2 , 2 , 2 ) } } ; { code = 1 ; contact = { name = " uno " ; phone_number = ( 0 , 0 , 0 , 0 ) } } ; { code = 0 ; contact = { name = " tres " ; phone_number = ( 3 , 3 , 3 , 3 ) } } ; { code = 2 ; contact = { name = " dos " ; phone_number = ( 0 , 0 , 0 , 0 ) } } ] | ; ;
let delete db contact = let ( status , db , contact ) = search db contact in if not status then ( false , db , contact ) else let cells i = if i = db . number_of_contacts - 1 then nobody else if db . contacts . ( i ) . name = contact . name then db . contacts . ( db . number_of_contacts - 1 ) else db . contacts . ( i ) in let db ' = { number_of_contacts = db . number_of_contacts - 1 ; contacts = Array . init ( Array . length db . contacts ) cells } in ( true , db ' , contact )
let update db contact = let ( status , _ , _ ) = engine db { code = 2 ; contact } in if status then let cells i = if db . contacts . ( i ) . name = contact . name then contact else db . contacts . ( i ) in let db ' = { number_of_contacts = db . number_of_contacts ; contacts = Array . init ( Array . length db . contacts ) cells } in ( true , db ' , contact ) else engine db { code = 0 ; contact }
let engine db { code ; contact } = if code = 0 then insert db contact else if code = 1 then delete db contact else if code = 2 then search db contact else if code = 3 then update db contact else ( false , db , nobody ) ; ;
let g x = x
let h x = x
let k x = x
let o x = x
module M = struct [ @@@ warning " - 32 " ] let f x = x let [ @ warning " + 32 " ] g x = x let [ @ warning " + 32 " ] h x = x and i x = x let j x = x and [ @ warning " + 32 " ] k x = x end
module F ( X : sig val x : int end ) = struct end
module G ( X : sig val x : int end ) = X
module H ( X : sig val x : int end ) = X
type story = { context : context ; perturbation : event ; adventure : event list ; conclusion : context ; } ; ;
let compatible_actions_for_character character context = match character with | { location = Restaurant } -> [ Eat ] | { location = Appartment } -> [ GoToRestaurant ] ; ;
let apply_action character = function | Eat -> { state = Happy ; location = character . location ; name = character . name } | GoToRestaurant -> { location = Restaurant ; state = character . state ; name = character . name } | Sleep -> { location = character . location ; state = Hungry ; name = character . name } ; ;
let compatible_actions context = let rec aux = function | [ ] -> [ ] | character :: cs -> let can_do = compatible_actions_for_character character context in let rec aux ' = function | [ ] -> [ ] | a :: actions -> Action ( character , a ) :: aux ' actions in aux ' can_do in aux context . characters ; ;
let possible_changes_for_character character = match character with | { state = Happy } -> [ Hungry ] | { state = Hungry } -> [ ] | { state = Tired } -> [ ] ; ;
let apply_change character state = { name = character . name ; state = state ; location = character . location } ; ;
let possible_changes context = let rec aux = function | [ ] -> [ ] | character :: cs -> let possible_changes = possible_changes_for_character character in let rec aux ' = function | [ ] -> [ ] | c :: changes -> Change ( character , c ) :: aux ' changes in aux ' possible_changes in aux context . characters ; ;
let character_of_event = function | Action ( character , _ ) -> character | Change ( character , _ ) -> character ; ;
let apply event context = let rec aux = function | [ ] -> assert false | character :: cs -> if character = character_of_event event then match event with | Action ( _ , action ) -> apply_action character action :: cs | Change ( _ , change ) -> apply_change character change :: cs else character :: aux cs in { characters = aux context . characters } ; ;
let rec is_one_of state states = match states with | [ ] -> false | state ' :: ss -> state = state ' || is_one_of state ss ; ;
let rec all_characters_are states = function | [ ] -> true | character :: cs -> is_one_of character . state states && all_characters_are states cs ; ;
let random_pick xs = List . nth xs ( Random . int ( List . length xs ) ) ; ;
let something_happens context = let what_can_happen = compatible_actions context @ possible_changes context in let event = random_pick what_can_happen in event , apply event context ; ;
let happy context = all_characters_are [ Happy ] context . characters ; ;
let rec end_story events context = if happy context then context , List . rev events else let event , context = something_happens context in end_story ( event :: events ) context ; ;
let make_story initial_context = let perturbation , context = something_happens initial_context in let conclusion , adventure = end_story [ ] context in { context = initial_context ; perturbation = perturbation ; adventure = adventure ; conclusion = conclusion } ; ;
let describe_location = function | Appartment -> " at home " | Restaurant -> " at the restaurant " ; ;
let describe_state = function | Happy -> " happy " | Hungry -> " hungry " | Tired -> " tired " ; ;
let describe character = character . name ^ " was " ^ describe_location character . location ^ " and was " ^ describe_state character . state ^ " . " ; ;
let tell_context context = let rec aux = function | [ ] -> " " | character :: characters -> describe character ^ aux characters in aux context . characters ; ;
let tell_action = function | Eat -> " ate " | GoToRestaurant -> " went to the restaurant " | Sleep -> " took a nap " ; ;
let tell_event = function | Action ( character , action ) -> character . name ^ " " ^ tell_action action ^ " . " | Change ( character , state ) -> character . name ^ " was made " ^ describe_state state ^ " . " ; ;
let rec tell_adventure = function | [ ] -> " " | event :: adventure -> tell_event event ^ tell_adventure adventure ; ;