caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Wohlwend <micha-1@fantasymail.de>
To: peng.zang@gmail.com, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] oo type question
Date: Thu, 6 Mar 2008 16:45:30 +0100	[thread overview]
Message-ID: <200803061645.30224.micha-1@fantasymail.de> (raw)
In-Reply-To: <200803060818.31857.peng.zang@gmail.com>

Am Donnerstag, 6. März 2008 14:18:29 schrieb Peng Zang:
> let s = new store ;;
> s#add (o1 :> <id:int>);;
> s#add (o2 :> <id:int>);;

> Note how I coerce o1 and o2 both to a subtype before adding.  Now the
> problem goes away because to the s#add method o1 and o2 have the same type.

yes, that's the easy way, but then I have to do casts all over the place, not 
very nice

> BUT, what I think you really want is a polymorphic method, not a
> polymorphic class.  The manual has a decent explanation under polymohrphic
> methods in the Objects section.  So I think you want this:
>   method add : 'a. <id:int; ..> as 'a -> unit =
>     fun o -> ids <- o#id :: ids

I know that version and of course it works. I only  didn't understand (and 
still do not) why it's not possible to just declare
method add (a: #someClass) ... which seems natural for me. And it works for 
normal functions that way.

If you have many classes (actually it's for adding widgets to group widgets) 
it seems just a bit too complicated and not a natural way to declare such a 
simple thing.


thanks,
 Michael


  reply	other threads:[~2008-03-06 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-06 12:52 Michael Wohlwend
2008-03-06 13:18 ` [Caml-list] " Peng Zang
2008-03-06 15:45   ` Michael Wohlwend [this message]
2008-03-06 16:58     ` Peng Zang
2008-03-10  8:20     ` Jacques Garrigue
2008-03-10  8:38       ` Michael Wohlwend

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=200803061645.30224.micha-1@fantasymail.de \
    --to=micha-1@fantasymail.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=peng.zang@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).