caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Rajchenbach-Teller <David.Teller@ens-lyon.org>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] function that works on different record types, assuming they have a given field
Date: Mon, 28 Mar 2011 20:34:10 +0200	[thread overview]
Message-ID: <FEF49C8B-5952-4414-A65E-DA2B5DC87C31@ens-lyon.org> (raw)
In-Reply-To: <74205EDF-69A3-479A-9214-52D2AB849558@gmail.com>

Nope, in OCaml, a field name unambiguously identifies the type of the record. On the other hand, you can obtain the same behavior by using objects instead of records:


 # let f x = x#foo;;
val f : < foo : 'a; .. > -> 'a = <fun>

Hope this helps,
 David

On Mar 28, 2011, at 8:16 PM, Joel Reymont wrote:

> Is it possible to write a function that works on different record types that have, say, a field x of type int?
> 
> The records would be in different modules but the field name and type will always be the same. 
> 
> 	Thanks, Joel
> 
> --------------------------------------------------------------------------
> - for hire: mac osx device driver ninja, kernel extensions and usb drivers
> ---------------------+------------+---------------------------------------
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> ---------------------+------------+---------------------------------------
> 
> 
> 
> 
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 



  reply	other threads:[~2011-03-28 18:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28 18:16 Joel Reymont
2011-03-28 18:34 ` David Rajchenbach-Teller [this message]
2011-03-28 18:35   ` Joel Reymont
2011-03-30 12:38     ` [Caml-list] " Dawid Toton
2011-03-30 14:15       ` Gabriel Scherer

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=FEF49C8B-5952-4414-A65E-DA2B5DC87C31@ens-lyon.org \
    --to=david.teller@ens-lyon.org \
    --cc=caml-list@inria.fr \
    --cc=joelr1@gmail.com \
    /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).