From: nadji@noos.fr
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic methods
Date: Mon, 15 Jul 2002 18:24:22 +0200 [thread overview]
Message-ID: <3D32F736.E0A88673@noos.fr> (raw)
In-Reply-To: <20020715100504O.garrigue@kurims.kyoto-u.ac.jp>
Jacques Garrigue wrote:
> > # let f = (new c)#m ();;
> > val f : '_a -> '_a = <fun>
>
> Unsound. RTFM (polymorphism restricted to values)
> Try "let f x = (new c)#m () x"
>
Oups, sorry. I did'nt recognize this classical problem ...
In fact this example was an attempt to simplify my
next question, but I can see now that they are not related.
> But I don't see why you need ().
>
You're right. It was there for historical reasons and I had
not realized I did'nt need an argument anymore.
> > Can someone give me some hints why I can't coerce subd ?
>
> Sorry, but there is no handling of instanciation via subtyping.
> Currently subtyping and instanciation are orthogonal concepts: you
> cannot subtype in an .mli, and you cannot instanciate an
> explicitly polymorphic type when subtyping.
That's a shame because if one tries to use objects for manipulating
lists :
# exception Emptylist
class type ['a] olist = object
method hd : 'a
method tl : 'a olist
end
class nil = object
method ~hd: 'a . 'a = raise Emptylist
method ~tl: 'a . 'a olist = raise Emptylist
end
let objnil = (new nil :> 'a olist);;
Characters 14-21:
let objnil = (new nil :> 'a olist);;
^^^^^^^
This expression cannot be coerced to type
'a olist = < hd : 'a; tl : 'a olist >;
it has type nil = < hd : 'b. 'b; tl : 'c. 'c olist >
but is here used with type < hd : 'a; tl : 'a #olist >.
This simple coercion was not fully general. Consider using a double coercion.
Too bad. Also this is the first time I get this error message. Does it mean that
I have to try something like (a : b :> c) ? If not, what is a double coercion,
and
can you give a case where is it needed ?
>
> I believe it's correct, but you won't make me write the code without a
> proof :-)
This is why I like Ocaml :)
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-07-15 16:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-14 23:16 nadji
2002-07-15 1:05 ` Jacques Garrigue
2002-07-15 2:08 ` Brian Smith
2002-07-15 16:24 ` nadji [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-12-18 9:18 Christoph Höger
2015-12-18 10:07 ` Leo White
2003-03-12 23:07 Damien
2003-03-13 0:56 ` brogoff
2003-03-13 1:56 ` Jacques Garrigue
2003-03-13 9:04 ` Damien
2003-03-13 9:27 ` Jacques Garrigue
2003-03-13 14:49 ` Damien
2003-03-13 9:41 ` Olivier Andrieu
2002-08-23 15:46 [Caml-list] Polymorphic methods Frederic Tronel
2002-08-23 17:32 ` Fred Smith
2002-08-23 18:21 ` Remi VANICAT
2001-11-19 15:29 Alain Frisch
2001-11-20 0:29 ` Jacques Garrigue
2001-11-20 9:33 ` Alain Frisch
2001-11-20 20:55 ` Xavier Leroy
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=3D32F736.E0A88673@noos.fr \
--to=nadji@noos.fr \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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