From: Jeff Shaw <shawjef3@msu.edu>
To: caml-list@inria.fr
Subject: restricting and hiding record fields for functors
Date: Fri, 04 Jan 2008 03:24:33 -0500 [thread overview]
Message-ID: <477DED41.3040009@msu.edu> (raw)
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
next reply other threads:[~2008-01-04 8:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-04 8:24 Jeff Shaw [this message]
2008-01-04 10:09 ` [Caml-list] " Keiko Nakata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=477DED41.3040009@msu.edu \
--to=shawjef3@msu.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox