* restricting and hiding record fields for functors
@ 2008-01-04 8:24 Jeff Shaw
2008-01-04 10:09 ` [Caml-list] " Keiko Nakata
0 siblings, 1 reply; 2+ messages in thread
From: Jeff Shaw @ 2008-01-04 8:24 UTC (permalink / raw)
To: caml-list
Hello. I searched through the Google archives of this list, so I
apologize if I missed something relevant.
I'm working on a project that uses record types, perhaps
module type Cordinate = sig
type ordinate
type point2d = {x : ordinate; y : ordinate;}
val distance : point2d -> float
end
Now I have a functor over modules that match the signature Coordinate,
but I want to allow the modules given to the functor to have things in
the record "point2d" besides just x and y. It seems the types in this
case are really clear and there shouldn't be any ambiguity (but I'm no
expert).
As it is now, to use such records I have to entirely hide their contents
so that the type checker doesn't complain when "point2d" contains extra
fields. In addition, any fields I need access to in the functor will
have an associated function for setting and getting the values. For
instance,
module type Cordinate1 = sig
type ordinate
type point2d
val setx : ordinal -> point2d -> point2d
val sety : ordinal -> point2d -> point2d
val makepoint : ordinal -> ordinal -> point2d
val getx : point2d -> ordinate
val gety : point2d -> ordinate
val getpoint : point2d -> ordinate * ordinate
val distance : point2d -> float
end
This is really quite ugly. I would rather be able to have x and y in the
signature and get rid of get/set functions. But then you can't have
extra fields. You can't, for instance, hide them via a signature.
Or perhaps I'm missing some simple technique? Please let me know.
Thanks,
Jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-01-04 10:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-04 8:24 restricting and hiding record fields for functors Jeff Shaw
2008-01-04 10:09 ` [Caml-list] " Keiko Nakata
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox