caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Mixed class / type
@ 2002-01-30 16:03 Warp
  2002-01-30 16:52 ` Remi VANICAT
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Warp @ 2002-01-30 16:03 UTC (permalink / raw)
  To: OCaml

Hello,

I got this problem :
- two classes called wmenu and wmenuitem, are mutaly recursive
- one wmenuitem can be constructed either with a wmenu or with a wmenuitem

so I need a type like this :

type menu =
    Mainmenu of wmenu
    | Menuitem of wmenuitem

So I tryied :

type menu = .....
and
    class wmenuitem : menu -> object ... end
and
    class wmenu : object ... end

But it doesn't work.
Any clue is welcomed.

Warp

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Mixed class / type
  2002-01-30 16:03 [Caml-list] Mixed class / type Warp
@ 2002-01-30 16:52 ` Remi VANICAT
  2002-01-30 23:31 ` Jacques Garrigue
  2002-02-01 10:33 ` Hendrik Tews
  2 siblings, 0 replies; 5+ messages in thread
From: Remi VANICAT @ 2002-01-30 16:52 UTC (permalink / raw)
  To: caml-list

"Warp" <warplayer@free.fr> writes:

> Hello,
> 
> I got this problem :
> - two classes called wmenu and wmenuitem, are mutaly recursive
> - one wmenuitem can be constructed either with a wmenu or with a wmenuitem
> 
> so I need a type like this :
> 
> type menu =
>     Mainmenu of wmenu
>     | Menuitem of wmenuitem
> 
> So I tryied :
> 
> type menu = .....
> and
>     class wmenuitem : menu -> object ... end
> and
>     class wmenu : object ... end
> 
> But it doesn't work.
> Any clue is welcomed.

This problem already have been answer. :

type ('a, 'b) menu_t =
     Mainmenu of 'a 
   | Menuitem of 'b

class wmenuitem : (wmenuitem, wmenu) menu_t -> object .... end
and wmenu : object ... end

type menu = (wmenuitem, wmenu) menu_t

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Mixed class / type
  2002-01-30 16:03 [Caml-list] Mixed class / type Warp
  2002-01-30 16:52 ` Remi VANICAT
@ 2002-01-30 23:31 ` Jacques Garrigue
  2002-02-01 10:33 ` Hendrik Tews
  2 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2002-01-30 23:31 UTC (permalink / raw)
  To: warplayer; +Cc: caml-list

> I got this problem :
> - two classes called wmenu and wmenuitem, are mutaly recursive
> - one wmenuitem can be constructed either with a wmenu or with a wmenuitem
> 
> so I need a type like this :
> 
> type menu =
>     Mainmenu of wmenu
>     | Menuitem of wmenuitem
> 
> So I tryied :
> 
> type menu = .....
> and
>     class wmenuitem : menu -> object ... end
> and
>     class wmenu : object ... end
> 
> But it doesn't work.
> Any clue is welcomed.

A light workaround would be

class wmenuitem : [ `Mainmenu of wmenu | `Menuitem of wmenuitem] -> ...
and wmenu : object ... end

Since polymorphic variants do not need to be defined, the problem does
not appear.

    Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Mixed class / type
  2002-01-30 16:03 [Caml-list] Mixed class / type Warp
  2002-01-30 16:52 ` Remi VANICAT
  2002-01-30 23:31 ` Jacques Garrigue
@ 2002-02-01 10:33 ` Hendrik Tews
  2002-02-04  2:40   ` Jacques Garrigue
  2 siblings, 1 reply; 5+ messages in thread
From: Hendrik Tews @ 2002-02-01 10:33 UTC (permalink / raw)
  To: OCaml

Warp writes:
   From: "Warp" <warplayer@free.fr>
   Date: Wed, 30 Jan 2002 17:03:44 +0100
   Subject: [Caml-list] Mixed class / type
   
   type menu = .....
   and
       class wmenuitem : menu -> object ... end
   and
       class wmenu : object ... end
   

The real solution would be to allow variant types and classes (or
at least class types) to be mutually dependent. 

Why is this forbidden in ocaml?

Bye,

Hendrik
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Mixed class / type
  2002-02-01 10:33 ` Hendrik Tews
@ 2002-02-04  2:40   ` Jacques Garrigue
  0 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2002-02-04  2:40 UTC (permalink / raw)
  To: tews; +Cc: caml-list

From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>

> The real solution would be to allow variant types and classes (or
> at least class types) to be mutually dependent. 
> 
> Why is this forbidden in ocaml?

The first reason is technical: class types and type declarations are
handled in two different modules, and integrating them would not be
easy.

But there are also more theoretical problems.
Basically, recursion between class types is monomorphic (to allow
propagation of type constraints), while it is polymorphic between type
declarations. So the meaning of a combined declaration is yet to be
defined.

Regards,

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-02-04  2:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-30 16:03 [Caml-list] Mixed class / type Warp
2002-01-30 16:52 ` Remi VANICAT
2002-01-30 23:31 ` Jacques Garrigue
2002-02-01 10:33 ` Hendrik Tews
2002-02-04  2:40   ` Jacques Garrigue

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).