[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jeff Shaw <shawjef3@m...> |
| Subject: | restricting and hiding record fields for functors |
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