Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file types.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204openOpen(** {6 Encoder } *)moduleEncoder=structtype('host,'target)t='host->'targetend(** {6 Decoder } *)moduleDecoder=structtype('host,'target)t=?trace:'targetError.trace->'target->('host,'targetError.t)Result.t(** Error is reported via Result.t *)type('host,'target)t_exn=?trace:'targetError.trace->'target->'host(** Error is reported via a target specific exception *)end(** {6 Conv module type } *)moduletypeMin=sigtypetargetvalformat:Format.formatter->target->unit(** The target must be printable. *)(* CR jfuruse: Is it called [print] instead? *)moduleConstr:sigvaltuple:targetlist->targetvalvariant:string->string->targetlist->targetvalpoly_variant:string->string->targetlist->targetvalrecord:string->(string*target)list->targetvalobject_:string->(string*target)list->targetendmoduleDeconstr:sig(** Primitive ADT decoders. They may raise exceptions. *)valtuple:target->targetlistvalvariant:string->target->string*targetlistvalpoly_variant:string->target->string*targetlistvalrecord:string->target->(string*target)listvalobject_:string->target->(string*target)listendend(** [Internal.Make(A : Min)] returns a module with this signature *)moduletypeS=sigincludeMin(** Exception for decoding error. We must declare here and not
in a more general place, since the error contains [target],
and we cannot have polymorphic exceptions in OCaml. *)exceptionExceptionoftargetError.ttype'aencoder=('a,target)Encoder.ttype'adecoder=('a,target)Decoder.ttype'adecoder_exn=('a,target)Decoder.t_exn(** Auto generated decoders from Deconstr *)moduleDeconstrDecoder:sigvaltuple:targetlistdecodervalvariant:string->(string*targetlist)decodervalpoly_variant:string->(string*targetlist)decodervalrecord:string->((string*target)list)decodervalobject_:string->((string*target)list)decodervaltuple_exn:targetlistdecoder_exnvalvariant_exn:string->(string*targetlist)decoder_exnvalpoly_variant_exn:string->(string*targetlist)decoder_exnvalrecord_exn:string->((string*target)list)decoder_exnvalobject_exn:string->((string*target)list)decoder_exnendvalexn:'adecoder->'adecoder_exn(** Result monad decoder to decoder with runtime exception [Exception]. *)valresult:'adecoder_exn->'adecoder(** Any exception (including [Exception]) reported from [decoder_exn]
is reported as [Error] *)valthrow:targetError.t->'exn(** raises [Exception] *)valcatch:('a->'b)->'a->('b,targetError.t)Result.tvalfrom_Ok:('a,targetError.t)Result.t->'a(** If the argument is [Error e], raises [Exception e]. *)openFormatvalformat_error:formatter->targetError.t->unit(** Format the error, without its trace *)valformat_full_error:formatter->targetError.t->unit(** Format the error, with its full trace *)valformat_with:('host->target)->formatter->'host->unit(** Format host data using its encoder *)moduleHelper:sig(** {6 Useful tool functions for writing encoders+decoders of primitive types } *)valinteger_of_float:float(*+ min value for 'int in float *)->float(*+ max value for 'int in float *)->(float->'int)(*+ conversion *)->float(*+ to convert *)->('int,string)Result.t(** float to integer conversion with error checks.
This is not target type dependent, but it is here for easier access.
*)vallist_of:(target->targetlistoption)->'adecoder->'alistdecoder(** typical list_of_<targe_type>. It takes a function to get a list from a target value *)valarray_of:(target->targetlistoption)->'adecoder->'aarraydecoder(** typical array_of_<targe_type>. It takes a function to get a list from a target value *)valoption_of:(target->targetoptionoption)->'adecoder->'aoptiondecoder(** typical option_of_<targe_type>.
It takes predicate to check the arg is a Some, None or something else.
Some (Some v) : Some for a target value v
Some None : None
None : : Error. Target value cannot have the option type
*)valref_of:(target->targetoption)->'adecoder->'arefdecoder(** typical ref_of_<targe_type>.
It takes predicate to check the arg is a reference or something else.
Some v : Found a record { contents = <v> }
None : Error. Target value cannot have the option type
*)vallazy_t_of:(targetError.t->'a)(*+ error handler *)->'adecoder->'alazy_tdecoder(** typical lazy_t_of_<targe_type>.
The decoding is done lazily.
Error at the deferred decoding is handled by the error handler,
normally it should raises <Target_conv>.Exception exception.
*)valof_mc_lazy_t:'aencoder->('a,target)mc_lazy_tencoder(** typical <targe_type>_of_mc_lazy_t *)valmc_lazy_t_of:'adecoder->('a,target)mc_lazy_tdecoder(** typical mc_lazy_t_of_<targe_type>
The decoding is done lazily.
Error at the lazy decoding is reported by the result monad.
*)valmc_fields_of:(target->(string*target)listoption)->'adecoder->(string*'a)listdecoder(** typical mc_fields_of_<targe_type> *)valof_deconstr:(target->'a)->'adecoder(** Convert a simple raw deconstr of type [target -> 'a] to ['a decoder].
Error must be reported as [Failure s]. The other exceptions simply escape.
*)valof_hashtbl:(targetencoder->targetlistencoder)(*+ target_of_list *)->'aencoder(*+ key encoder *)->'bencoder(*+ value encoder *)->('a,'b)Hashtbl.tencodervalhashtbl_of:(('a*'b)decoder->('a*'b)listdecoder)(*+ list_of_target *)->'adecoder(*+ key encoder *)->'bdecoder(*+ value encoder *)->('a,'b)Hashtbl.tdecodervalof_result:(target->target)(* ok embedder *)->(target->target)(* error embedder *)->'aencoder(* ok encoder *)->'bencoder(* error encoder *)->('a,'b)resultencodervalresult_of:(target,target)resultdecoder(* result extractor *)->'adecoder(* ok deoder *)->'bdecoder(* error decoder *)->('a,'b)resultdecoderendend