Module Types.Record
Record normalization.
val or_absent : t -> tor_absent tadds the absent component to the type. This is an alias forcup t Absent.anyorAbsent.update t true.
val any_or_absent : tThe top type with the absent component set.
val has_absent : t -> boolhas_absent ttests the value of the absent component. Equivalent tonon_empty (cap t Absent.any), but slightly more efficient.
val has_record : t -> boolhas_record treturnstrueif and only if the record component oftis not empty. This is an alias fornon_empty (cap Rec.any t).
val split : t -> Cduce_types.Ident.label -> Product.tsplit t lreturns a list of pair of types. For each pair, the first component is the type of the labellintand the second component is the type of the remaining labels int, given as a record type.
val split_normal : t -> Cduce_types.Ident.label -> Product.normalsplit_normal t lreturns the same list assplit t lwhere the first components, that is, the types associated withlare pairwise disjoint.
val project : t -> Cduce_types.Ident.label -> tproject t lreturns the type associted with the labellin the record component of typet. It is equivalent to :- computing
n = split t l - computing
s, the union of the first components of the listn - checking whether the absent type is present in
s
- raises Not_found
if the resulting type may is absent (meaning that
lis not necessarily present int).
- computing
val project_opt : t -> Cduce_types.Ident.label -> tproject_opt t lis similar toproject t lbut returns the type and erase the absent component if it is present. In other words, this function returns the the union of all the types associated tolfor the records where it is present.
val has_empty_record : t -> boolhas_empty_record treturnstrueif and only if the record component oftcontains a record with no label explicitely present for sure (that is there is a recordrintwhich has no explicit label (open or closed), or for which all explicit labels are associated with an absent type).{ },{ ..},{ a=?Int b=?Any ..}are examples of such record types.
val first_label : t -> Cduce_types.Ident.labelfirst_label treturns the first label (in the total ordering of label names) to appear explicitely in any of the records present int. The function returnsLabel.dummyif no such label exists.
val empty_cases : t -> bool * boolhas_empty_cases tmust only be called on types whose record component have no explicit labels. It returns a pair of boolean(some, none), where:someistrueif and only if the record component is opennoneistrueif and only if the type is non empty.
In otherwords :
true, trueindicates that the record component oftcontains{ ..}false, trueindicates that the record component oftcontains only{}false, falseindicates that the record component oftis empty.true, falseis not possible.
val merge : t -> t -> tmerge t1 t2discards the non record component oft1andt2and returns the type of the+operators on records, that is, returns a record typetwhere the type of labellis the one oft2if it is present int2and the type oft1otherwise.
val remove_field : t -> Cduce_types.Ident.label -> tremove_field t lreturns the type of typetwhere the labellis marked as explicitely absent fromt. There are two ways to do that:- for closed record types, the label
lis simply removed, if present - for open record types, the type is intersected with
{l=?Empty}meaning that either the labellis absent, or if present it is associated to the empty type, that is, if it is present, the whole record is empty.
- for closed record types, the label
val get : t -> ((bool * t) Cduce_types.Ident.label_map * bool * bool) listget treturns a list whose union is the record component oft. Each element of the list is a triple(map, op, none)wheremapis a map from labels to pairs of a boolean indicating whether the label is optional or not and t the associated (non absent) type. The booleanopindicates whether the record is open. The booleannoneis alwaystrueand is here for compatibility reasons with other parts of the ℂDuce compiler which return a similar type wherenonecan befalse, indicating an empty component. Such components are not returned byget.
val focus : descr -> Cduce_types.Ident.label -> tfocus d lprepares a normal form where the types associated tolhave been isolated.
val get_this : t -> descrget_this treturns the type associated with labell. Doingget_this (focus t l)is equivalent toproject_opt t l.
val need_others : t -> boolneed_others treturnstrueif and only if the focused label yields two distinct types. For instance, focusingt= {x = Int; y = Int } | {x = Bool; y = Int }onx,get_this tyieldsInt | Bool, andneed_other tyieldsfalse, since the projection can be represented as a single pair :[ (Int|Bool, { y = Int }) ].On the other hand, focusing
t= {x = Char; y = Bool } | {x = Bool; y = Int}onx,get_this tyieldsChar | Bool, andneed_other tyieldstrue, since the projection cannot be represented as a single pair :[(Char, { y = Bool }); (Bool, { y= Int }) ].