caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Width subtyping
@ 2009-05-29 14:10 Dario Teixeira
  2009-05-29 14:21 ` [Caml-list] " Jacques Carette
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dario Teixeira @ 2009-05-29 14:10 UTC (permalink / raw)
  To: caml-list


Hi,

Though it is probably been-there-done-that material for the veterans in this list,
for the sake of the not-so-veterans I have to ask: how do you guys typically model
width subtyping in Ocaml?   Consider for example three record types that share some
of their fields:

type t1 = {a: int; b: int; c: int;        }
type t2 = {a: int; b: int; c: int; d: int;}
type t3 = {        b: int; c: int; d: int;}

In some circumstances, the object system can be put to good use for this kind of problem.
Not always though, so I'm curious about other approaches people use.  One approach
I've considered is to create a superset record where each field is an optional type,
and then creating constructors/getters for each valid subset.  Unfortunately this
solution feels a bit kludgy, even if it reduces code duplication.  For safety reasons
I'm therefore currently just declaring each record type independently (concerns about
duplication be damned).

In other words, polymorphic variants provide a very elegant solution for subtyping
with sum types.  Is there some brilliant idea that could do the same for product types?

Best regards,
Dario Teixeira







^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-29 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-29 14:10 Width subtyping Dario Teixeira
2009-05-29 14:21 ` [Caml-list] " Jacques Carette
2009-05-29 14:43 ` David Allsopp
2009-05-29 15:33 ` Richard Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).