From: Philippe Strauss <philou@philou.ch>
To: caml-list@yquem.inria.fr
Cc: Raphael Proust <raphlalou@gmail.com>
Subject: Re: [Caml-list] Recursive Parametric class type Typing
Date: Sat, 19 Mar 2011 21:02:28 +0100 [thread overview]
Message-ID: <F5EEC3D9-9995-4773-9B7B-8312201230BE@philou.ch> (raw)
In-Reply-To: <201103191648.40345.raphlalou@gmail.com>
Jacques answered me about a parametrized class prob. I had some time ago, about an important restriction:
"Object types are allowed to be recursive, but they are restricted to _regular_ types,
where recursive occurences have identical type parameters.
In particular, this means that in the above line, ('a,'b) node_virt_t and ('b,'c) node_virt_t
must have the same parameters, i.e. that 'a = 'b and 'b = 'c, i.e. all your types
end up being identical."
(maybe an FAQ is somewhat missing on the main, inria, ocaml website about that kind of infos.?)
Le 19 mars 2011 à 16:48, Raphael Proust a écrit :
> Hi list,
>
> Trying to bind a javascript library for js_of_ocaml, I encountered the following
> pattern (here drastically simplified):
>
> class type ['t] c =
> object
> method plus: 't -> unit
> method minus: unit -> 't
> method container: unit -> container
> end
> and container =
> object
> method int: unit -> int c
> method string: unit -> string c
> end
>
> The following error is raised at compile time:
> Error: This type string should be an instance of type int
>
> In the use case:
> - instead of [int] and [string] there are six different [class type]s;
> - [classe type]s have more methods; and
> - there are additional recursive [class type]s
>
>
> Why is there such a limitation on the types? Is there a work around that
> wouldn't induce (too much) code duplication?
>
> Thanks,
> --
> ______________
> Raphaël Proust
>
>
> --
> 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
>
prev parent reply other threads:[~2011-03-19 20:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-19 15:48 Raphael Proust
2011-03-19 17:48 ` Guillaume Yziquel
2011-03-19 19:20 ` Raphael Proust
2011-03-19 19:45 ` Guillaume Yziquel
2011-03-19 20:36 ` Raphael Proust
2011-03-19 20:02 ` Philippe Strauss [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=F5EEC3D9-9995-4773-9B7B-8312201230BE@philou.ch \
--to=philou@philou.ch \
--cc=caml-list@yquem.inria.fr \
--cc=raphlalou@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