Some day I have to document the huge range of things Felix can do ..
| BEXPR_coerce ((srcx,srct) as srce,dstt) ->
let coerce_variant () =
let vts =
match dstt with
| BTYP_variant ls -> ls
| _ -> syserr sr "Coerce non-variant"
in
begin match srcx with
| BEXPR_variant (s,argt) ->
print_endline "Coerce known variant!";
ge' (bexpr_variant t (s,argt))
| _ ->
let i =
begin try
Hashtbl.find syms.variant_map (srct,dstt)
with Not_found ->
let i = fresh_bid syms.counter in
Hashtbl.add syms.variant_map (srct,dstt) i;
i
end
in
ce_atom ("::flx::rtl::_uctor_(vmap_" ^ cid_of_bid i ^ "," ^ ge srce ^
")")
end
in
begin match dstt with
| BTYP_variant _ -> coerce_variant ()
| _ -> ce_atom ("reinterpret<"^tn dstt^","^tn srct^">("^ge srce^")")
end
I have to fix this to make some tests pass... what is this? I see the
variant_map
there .. I didn't know what that was for .. lol .. now I do.
What this code does is support *subtyping* of "variant kind" variants,
these are the equivalent of records: anonymous types with named constructors.
[Heck, I don't even have a name for these things]
A variant V with constructors A, B, C only, can safely be passed to a function
handling any super-set of these constructors, eg W=X Y A B C Q, that is,
V is a subtype of W.
As usual, this isn't automatic, you have to use an explicit coercion.
The variant_map "remaps" the indicies of V to those of W.
So that's what it's for .. :)
--
john skaller
[email protected]
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language