123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148(*
* Copyright (c) 2014 Leo White <lpw25@cl.cam.ac.uk>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openLangopenNamesletpredefined_location=letpoint={Location_.line=1;column=0}in{Location_.file="predefined";start=point;end_=point}letempty_doc=[]letmk_equationparams=letopenTypeDecl.Equationin{params;private_=false;manifest=None;constraints=[]}letnullary_equation=mk_equation[]letcovariant_equation=mk_equation[{desc=Var"'a";variance=SomePos;injectivity=true}]letinvariant_equation=mk_equation[{desc=Var"'a";variance=None;injectivity=true}]letsource_loc=Noneletmk_type?(doc=empty_doc)?(eq=nullary_equation)?reprid=letcanonical=Nonein{TypeDecl.id;source_loc;doc;canonical;equation=eq;representation=repr;}letmk_constr?(args=TypeDecl.Constructor.Tuple[])id={TypeDecl.Constructor.id;doc=empty_doc;args;res=None}moduleMk=Paths.Identifier.Mkletbool_identifier=Mk.core_type"bool"letunit_identifier=Mk.core_type"unit"letexn_identifier=Mk.core_type"exn"letlist_identifier=Mk.core_type"list"letoption_identifier=Mk.core_type"option"letfalse_identifier=Mk.constructor(bool_identifier,ConstructorName.make_std"false")lettrue_identifier=Mk.constructor(bool_identifier,ConstructorName.make_std"true")letvoid_identifier=Mk.constructor(unit_identifier,ConstructorName.make_std"()")letnil_identifier=Mk.constructor(list_identifier,ConstructorName.make_std"([])")letcons_identifier=Mk.constructor(list_identifier,ConstructorName.make_std"(::)")letnone_identifier=Mk.constructor(option_identifier,ConstructorName.make_std"None")letsome_identifier=Mk.constructor(option_identifier,ConstructorName.make_std"Some")letexn_path=`Resolved(`Identifierexn_identifier)letlist_path=`Resolved(`Identifierlist_identifier)letfalse_decl=mk_constr~args:(Tuple[])false_identifierlettrue_decl=mk_constr~args:(Tuple[])true_identifierletvoid_decl=mk_constr~args:(Tuple[])void_identifierletnil_decl=mk_constr~args:(Tuple[])nil_identifierletcons_decl=lethead=TypeExpr.Var"'a"inlettail=TypeExpr.(Constr(list_path,[head]))inmk_constr~args:(Tuple[head;tail])cons_identifierletnone_decl=mk_constr~args:(Tuple[])none_identifierletsome_decl=mk_constr~args:(Tuple[TypeExpr.Var"'a"])some_identifier(** The type representation for known core types. *)lettype_repr_of_core_type=letopenTypeDecl.Representationinfunction|"bool"->Some(Variant[false_decl;true_decl])|"unit"->Some(Variant[void_decl])|"exn"->SomeExtensible|"option"->Some(Variant[none_decl;some_decl])|"list"->Some(Variant[nil_decl;cons_decl])|_->Nonelettype_eq_of_core_type=function|"lazy_t"|"extension_constructor"->Somecovariant_equation|"array"->Someinvariant_equation|_->Noneletdoc_of_core_type=leteltx=Location_.atpredefined_locationxinletwordsss=ss|>List.rev_map(funs->[elt`Space;elt(`Words)])|>List.flatten|>List.tl|>List.revinletparagraphx=elt(`Paragraphx)infunction|"floatarray"->Some[paragraph(words["This";"type";"is";"used";"to";"implement";"the"]@[elt`Space;elt(`Reference(`Module(`Root("Array",`TModule),ModuleName.make_std"Floatarray"),[]));elt`Space;]@words["module.";"It";"should";"not";"be";"used";"directly."]);]|_->Nonelettype_of_core_typename=letidentifier=Mk.core_typenameandrepr=type_repr_of_core_typenameandeq=type_eq_of_core_typenameanddoc=doc_of_core_typenameinmk_type?doc?repr?eqidentifier