caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: andorxor@gmx.de
Cc: caml-list@inria.fr
Subject: Re: Unbound type constructor
Date: Mon, 05 Feb 2001 11:21:12 +0900	[thread overview]
Message-ID: <20010205112112B.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <9114178788.20010203181656@gmx.de>

> I'm learning OCaml...
> 
> The following code snippet fails due to an "unbound type constructor"
> error. How could I achieve the intended result in OCaml?
> 
> type combination = T1 of int | T2 of test | T3 of test * test
> 
> class test =
>       object
>             method virtual get : combination
>       end

Since you cannot have mutual recursion between a type definition and a
class definition, you have to use parameterization. In this case this
is very easy, but this can get heavier when you have lots of mutually
recursive types.

type 'a combination = T1 of int | T2 of 'a | T3 of 'a * 'a

class virtual test =
  object
    method virtual get : test combination
  end

> PS: Naive question, why aren't there type members in OCaml classes?

Because classes are not modules...
The technical explanation is rather complex, but you can just think
about the fact class types are just object types, and the compiler
should be able to infer object types without type annotations. In
general you cannot infer type members.

Jacques Garrigue



  parent reply	other threads:[~2001-02-05 16:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-03 17:16 Stephan Tolksdorf
2001-02-04 22:23 ` Brian Rogoff
2001-02-05  2:21 ` Jacques Garrigue [this message]
2001-02-05 17:30 ` John Max Skaller
     [not found] <Pine.BSF.4.21.0102050903120.28934-100000@shell5.ba.best.com>
2001-02-05 18:58 ` Stephan Tolksdorf
2001-02-06 16:35   ` Pierre Weis
2001-02-06 22:39     ` leary
2001-02-07 21:34       ` Pierre Weis
2001-02-08  7:36         ` Sven
2007-04-25 20:21 snowfall

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=20010205112112B.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=andorxor@gmx.de \
    --cc=caml-list@inria.fr \
    /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).