caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Mykola Stryebkov'" <nick@mykola.org>, <caml-list@inria.fr>
Subject: RE: [Caml-list] Same name fields
Date: Sat, 21 Nov 2009 15:55:32 -0000	[thread overview]
Message-ID: <000001ca6ac3$13a30c20$3ae92460$@allsopp@metastack.com> (raw)
In-Reply-To: <A9B74EBD-2FDD-4705-BE61-90C75E813529@mykola.org>

Mykola Stryebkov wrote:
> I'm trying to declare to record types with fields having the same name
> but different types.

This is not possible with record types (at the same module scope) - when you
declare the second type you obscure the previous type.

<snip>

> If I declare type ta second - everything works fine.
> Is it a bug?

No :o)

> If not, what is an appropriate workaround here?

Either put types ta and tb in separate modules (then you can use qualified
field names) or use different field names. The Unix module in the Standard
Library is a good example of how to do all this in practice - the record
types there all have standard prefixes on the field names.

The other alternative is to use objects but this is heavier in terms of
memory and field access and the type errors messages are more confusing than
with records (but neither of these reasons are necessarily bars to using
them!!).


David


PS Not that it I think it generally offends people on this list, but this
question would have been more appropriate for the Beginners' List -
http://groups.yahoo.com/group/ocaml_beginners


      parent reply	other threads:[~2009-11-21 15:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-21 15:32 Mykola Stryebkov
2009-11-21 15:51 ` [Caml-list] " Goswin von Brederlow
2009-11-21 15:55 ` David Allsopp [this message]

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='000001ca6ac3$13a30c20$3ae92460$@allsopp@metastack.com' \
    --to=dra-news@metastack.com \
    --cc=caml-list@inria.fr \
    --cc=nick@mykola.org \
    /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;
as well as URLs for NNTP newsgroup(s).