From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HA8U03006356 for ; Thu, 17 Mar 2011 11:08:31 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AksCAF56gU1KfVK2kGdsb2JhbACEPqEGCBQBAQEBCQkNBxQEIak0igI8gh6FFC+IWwEBAwWEZ3cEjF6IeTo X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="90621804" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Mar 2011 11:08:25 +0100 Received: by wyf23 with SMTP id 23so4018012wyf.27 for ; Thu, 17 Mar 2011 03:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=Crir/lzqF6TYv9QEy2SF4St/TozPLgMj/G3opmqdaoI=; b=I0D/Kbgtx+PJinPHo3P9H0P1AgB3tPAasZsXyHQ+9goYELcmRIbzEKg9wfOdYXwf05 kfbVqQJMKf6rTWURh2anjEDgQbEvUeVCRyD3tE0H5yjrXEP2SGxAVsPCtuIxNfQO6h21 swycSnBnFtlff03ZQqKfgaiM1sAsgYY+YumKo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=D/NwQAuK5HV965IUBecsPedXahLYVCnH1OCA4JN3SROhfG44M0doYITH5qYmbpn1wX PXb0cT3Ag9rhHEg3Z5K3+akUSt8K8N/WQqROKIglu4iM7Ch1VdUtDudPC0ufQIZDa2xa cnE3f+TgN9gMSdlBuLsls6Ad0j1NHoFqAqpV0= MIME-Version: 1.0 Received: by 10.216.52.78 with SMTP id d56mr1192591wec.44.1300356504514; Thu, 17 Mar 2011 03:08:24 -0700 (PDT) Received: by 10.216.74.5 with HTTP; Thu, 17 Mar 2011 03:08:24 -0700 (PDT) Date: Thu, 17 Mar 2011 11:08:24 +0100 Message-ID: From: Pierre-Alexandre Voye To: caml-list Content-Type: multipart/alternative; boundary=0016e6dbe6dc8872b7049eaad79c Subject: [Caml-list] Define class and sum type in one time --0016e6dbe6dc8872b7049eaad79c Content-Type: text/plain; charset=UTF-8 Hi everyone, i'm trying to write a generic hierarchical finite state machine, and I have a syntax problem which stop me. I want to define an object which use, somewhere a sum type. The compiler answer "Syntax Error" Here a simple example of my problem : class machin = object(self) val mutable valeur = 0 method getValeur = valeur end and truc = Machin of (int->int) | Recur of truc;; And the answer : Error: Syntax error which point on the "of" after "Machin" Is there a way to solve this problem ? In advance, thank you very much Pierre-Alexandre -- --------------------- Isaac Project - http://www.lisaac.org/ --0016e6dbe6dc8872b7049eaad79c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi everyone, i'm trying to write a generic hierarchical finite state ma= chine, and I have a syntax problem which stop me.
I want to define an ob= ject which use, somewhere a sum type.
The compiler answer "Syntax = Error"

Here a simple example of my problem :

class machin =3D object(se= lf)
=C2=A0 val mutable valeur =3D 0
=C2=A0 method getValeur =3D valeu= r
end
and
truc =3D Machin of (int->int) | Recur of truc;;
=
And the answer :
Error: Syntax error
=C2=A0which point=C2=A0 on the "of" after = "Machin"

Is there a way to solve this problem ?

In = advance, thank you very much

Pierre-Alexandre
-- ---------------------
Isaac Project - http://www.lisaac.org/
--0016e6dbe6dc8872b7049eaad79c-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HAXpmV007604 for ; Thu, 17 Mar 2011 11:33:51 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AksCAA2AgU1KfVI0kGdsb2JhbACEPqEHCBQBAQEBCQkNBxQEIak/igI8gh6FFS+IWwEBAwWEZ3cEjF6Gc4IGOg X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="78566701" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Mar 2011 11:33:45 +0100 Received: by wwj40 with SMTP id 40so3375912wwj.9 for ; Thu, 17 Mar 2011 03:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=pzr6Lt0s735ndIibSDQFHJkzJ9HNAcu5WA/LAOVxZm0=; b=GKd5GzMMiPyZEq5ORxEZIzaU6s0oXihaW0MGBXrds/hD8CrSqeogVjVLpswXVUCVh8 /ez+FgyDSiT/rTltBs19vtMR3omS8e38m52Wi+WsH+JxRU9qMgz7Z4clMyRTU8RZlYG2 wHknY+NVUmJCH6pDTolUZUzb+9yPliFamY320= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=QmLz1w/TOCCull2BlbHVSH9+vrBQYm13QldkIeKUQ0Bt3Pxm8tnTB1P6g8sOA1oQ6c f63lbIpfx/xyBCV7NJ2A90QcR3USdxRfwMoCGvkuUxdYQPlC/WpVDnQ6YkY863Bp4t/j g6sQQwVk0VEiUKUtrUmYijzaNaMy5K8deTkpc= MIME-Version: 1.0 Received: by 10.216.239.65 with SMTP id b43mr1213547wer.29.1300358024825; Thu, 17 Mar 2011 03:33:44 -0700 (PDT) Received: by 10.216.74.5 with HTTP; Thu, 17 Mar 2011 03:33:44 -0700 (PDT) In-Reply-To: References: Date: Thu, 17 Mar 2011 11:33:44 +0100 Message-ID: From: Pierre-Alexandre Voye To: caml-list Content-Type: multipart/alternative; boundary=e0cb4e43d1cd268ec0049eab3254 Subject: [Caml-list] Re: Define class and sum type in one time --e0cb4e43d1cd268ec0049eab3254 Content-Type: text/plain; charset=UTF-8 My example would be better with this : class machin = object(self) val mutable valeur = (None : truc option) method getValeur = valeur end and truc = Machin of (int->int) | Recur of truc;; The object need the type defined 2011/3/17 Pierre-Alexandre Voye > Hi everyone, i'm trying to write a generic hierarchical finite state > machine, and I have a syntax problem which stop me. > I want to define an object which use, somewhere a sum type. > The compiler answer "Syntax Error" > > Here a simple example of my problem : > > class machin = object(self) > val mutable valeur = 0 > method getValeur = valeur > end > and > truc = Machin of (int->int) | Recur of truc;; > > And the answer : > Error: Syntax error > which point on the "of" after "Machin" > > Is there a way to solve this problem ? > > In advance, thank you very much > > Pierre-Alexandre > -- > --------------------- > Isaac Project - http://www.lisaac.org/ > -- --------------------- Isaac Project - http://www.lisaac.org/ --e0cb4e43d1cd268ec0049eab3254 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable My example would be better with this :

class machin =3D object(self)=
=C2=A0 val mutable valeur =3D (None : truc option)
=C2=A0 method get= Valeur =3D valeur
end
and
truc =3D Machin of (int->int) | Recu= r of truc;;

The object need the type defined

2011= /3/17 Pierre-Alexandre Voye <ontologiae@gmail.com>
Hi everyone, i'm trying to write a generic hierarchical finite state ma= chine, and I have a syntax problem which stop me.
I want to define an ob= ject which use, somewhere a sum type.
The compiler answer "Syntax = Error"

Here a simple example of my problem :

class machin =3D object(se= lf)
=C2=A0 val mutable valeur =3D 0
=C2=A0 method getValeur =3D valeu= r
end
and
truc =3D Machin of (int->int) | Recur of truc;;
=
And the answer :
Error: Syntax error
=C2=A0which point=C2=A0 on the "of" after = "Machin"

Is there a way to solve this problem ?

In = advance, thank you very much

Pierre-Alexandre
--
---------------------
Isaac Project - http:/= /www.lisaac.org/



--
----------------= -----
Isaac Project - http://www.lisa= ac.org/
--e0cb4e43d1cd268ec0049eab3254-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HAlN8n008331 for ; Thu, 17 Mar 2011 11:47:23 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai4EAM6CgU1V2gB4h2dsb2JhbAClYQEBAQoLCR0lxE0NhVYEkEU X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="94312739" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail2-smtp-roc.national.inria.fr with SMTP; 17 Mar 2011 11:47:18 +0100 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id CF17212C8F9; Thu, 17 Mar 2011 11:47:16 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Q0Ajf-0002rE-AB; Thu, 17 Mar 2011 11:47:19 +0100 Date: Thu, 17 Mar 2011 11:47:19 +0100 From: Guillaume Yziquel To: Pierre-Alexandre Voye Cc: caml-list@inria.fr Message-ID: <20110317104719.GH22969@localhost> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p2HAlN8n008331 Subject: Re: [Caml-list] Re: Define class and sum type in one time Le Thursday 17 Mar 2011 à 11:33:44 (+0100), Pierre-Alexandre Voye a écrit : > My example would be better with this : > class machin = object(self) > Â val mutable valeur = (None : truc option) > Â method getValeur = valeur > end > and > truc = Machin of (int->int) | Recur of truc;; > The object need the type defined You cannot declare a class and a type with an 'and'. Either two classes, or two types. Simply declare truc before machin. type truc = Machin of int -> int | Recur of truc class machin = object val mutable valeur : truc option = None method getValeur = valeur end -- Guillaume Yziquel From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HAohL8008598 for ; Thu, 17 Mar 2011 11:50:43 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AksCADaEgU1KfVI0kGdsb2JhbACEPqEHCBQBAQEBCQkNBxQEIak6igI8gh6FGi+IWwEBAwWEZ3cEjF6IeTo X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="102939811" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Mar 2011 11:50:37 +0100 Received: by wwj40 with SMTP id 40so3392793wwj.9 for ; Thu, 17 Mar 2011 03:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=LJ3eiwlr3BLlCHnNhXJg2XB61eRiqscA6gTxlY8ktxw=; b=HYdNjkRhkF+VmGiW1qBciVF+A6P06D5i6FMwQ/HB5G0ZLR4G7HfOE+DKTYKk3yVQ+p 4VAPHoRBim79uH3gHJ0Ojwi7xLyTRjQZMrh7rCN3vV97gL6POHn1CDbps3VRBpGy2gyh yzbk818xZmJdp/BtGx5rcxMV/N611iCWiLwKI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=D/XxLioV21s4rAl9qUs6Ma2ICnY2vtw/g2YEsojB6BGzFoD3FRtzHlb8KBOpCOGbwr jscAUfhUN/KBeeemIffkp7+W5MFii2qgZr1X7Ubwdk/lvw+0kra4cWcTq0+wCK0dAZfJ 9Jvs81sLGH+CzAYKotbMHVA0JDdiTRvaTeUTc= MIME-Version: 1.0 Received: by 10.216.62.77 with SMTP id x55mr1213786wec.59.1300359037548; Thu, 17 Mar 2011 03:50:37 -0700 (PDT) Received: by 10.216.74.5 with HTTP; Thu, 17 Mar 2011 03:50:37 -0700 (PDT) In-Reply-To: <20110317104719.GH22969@localhost> References: <20110317104719.GH22969@localhost> Date: Thu, 17 Mar 2011 11:50:37 +0100 Message-ID: From: Pierre-Alexandre Voye To: caml-list Content-Type: multipart/alternative; boundary=000e0ce0b842837e9c049eab6ee4 Subject: Re: [Caml-list] Re: Define class and sum type in one time --000e0ce0b842837e9c049eab6ee4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable So, this is impossible ? : class maclasse =3D object(self) val mutable valeur =3D (None : truc option) method getValeur =3D valeur end and truc =3D Machin of (maclasse->int) | Recur of truc;; ? (three attempt to write a correct example of my problem.. All apologies !) 2011/3/17 Guillaume Yziquel > Le Thursday 17 Mar 2011 =C3=A0 11:33:44 (+0100), Pierre-Alexandre Voye a = =C3=A9crit : > > My example would be better with this : > > class machin =3D object(self) > > =C3=82 val mutable valeur =3D (None : truc option) > > =C3=82 method getValeur =3D valeur > > end > > and > > truc =3D Machin of (int->int) | Recur of truc;; > > The object need the type defined > > You cannot declare a class and a type with an 'and'. Either two classes, > or two types. > > Simply declare truc before machin. > > type truc =3D Machin of int -> int | Recur of truc > > class machin =3D object > > val mutable valeur : truc option =3D None > > method getValeur =3D valeur > > end > > -- > Guillaume Yziquel > --=20 --------------------- Isaac Project - http://www.lisaac.org/ --000e0ce0b842837e9c049eab6ee4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable So, this is impossible=C2=A0 ?=C2=A0=C2=A0 :

class maclasse =3D obje= ct(self)
=C2=A0 val mutable valeur =3D (None : truc option)
=C2=A0 me= thod getValeur =3D valeur
end
and
truc =3D Machin of (maclasse-&g= t;int) | Recur of truc;;

?
(three attempt to write a correct example of my problem.. All apologie= s !)

2011/3/17 Guillaume Yziquel <guillaume.y= ziquel@citycable.ch>
Le Thursday 17 Ma= r 2011 =C3=A0 11:33:44 (+0100), Pierre-Alexandre Voye a =C3=A9crit :
> =C2=A0 =C2=A0My example would be better with this :<= br> > =C2=A0 =C2=A0class machin =3D object(self)
> =C2=A0 =C2=A0=C3=82 =C2=A0val mutable valeur =3D (None : truc op= tion)
> =C2=A0 =C2=A0=C3=82 =C2=A0method getValeur =3D valeur
> =C2=A0 =C2=A0end
> =C2=A0 =C2=A0and
> =C2=A0 =C2=A0truc =3D Machin of (int->int) | Recur of truc;;
> =C2=A0 =C2=A0The object need the type defined

You cannot declare a class and a type with an 'and'. Either t= wo classes,
or two types.

Simply declare truc before machin.

type truc =3D Machin of int -> int | Recur of truc

class machin =3D object

=C2=A0 =C2=A0 =C2=A0 =C2=A0val mutable valeur : truc option =3D None

=C2=A0 =C2=A0 =C2=A0 =C2=A0method getValeur =3D valeur

end

--
=C2=A0 =C2=A0 Guillaume Yziquel



--
----------------= -----
Isaac Project - http://www.lisa= ac.org/
--000e0ce0b842837e9c049eab6ee4-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HB1Dj1009439 for ; Thu, 17 Mar 2011 12:01:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkgEAAaHgU3Cpx5ei2dsb2JhbAClTRQBAQEKCwsbJcQxhWMEkCsa X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208,217";a="78569352" Received: from sucre.univ-orleans.fr ([194.167.30.94]) by mail3-smtp-sop.national.inria.fr with ESMTP; 17 Mar 2011 12:01:07 +0100 Received: from localhost (localhost [127.0.0.1]) by sucre.univ-orleans.fr (Postfix) with ESMTP id B3EE794422; Thu, 17 Mar 2011 12:01:06 +0100 (CET) Received: from sucre.univ-orleans.fr ([127.0.0.1]) by localhost (sucre.univ-orleans.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r34oo0-bbd-U; Thu, 17 Mar 2011 12:01:06 +0100 (CET) Received: from smtps.univ-orleans.fr (smtps.univ-orleans.fr [194.167.30.152]) by sucre.univ-orleans.fr (Postfix) with ESMTP id 9781D94421; Thu, 17 Mar 2011 12:01:06 +0100 (CET) Received: from [192.168.6.18] (unknown [80.70.32.140]) by smtps.univ-orleans.fr (Postfix) with ESMTP id C5A1636E60; Thu, 17 Mar 2011 12:01:07 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: multipart/alternative; boundary=Apple-Mail-2--70081967 From: David Rajchenbach-Teller In-Reply-To: Date: Thu, 17 Mar 2011 12:01:05 +0100 Cc: caml-list Message-Id: <884CCEF4-03CB-42CA-8D90-A2B4709E8CED@univ-orleans.fr> References: <20110317104719.GH22969@localhost> To: Pierre-Alexandre Voye X-Mailer: Apple Mail (2.1082) Subject: Re: [Caml-list] Re: Define class and sum type in one time --Apple-Mail-2--70081967 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii You'll probably need something along the lines of: class maclasse = object(self) val mutable valeur = (None : truc option) method getValeur = valeur end let truc_maker('a) = Machin of 'a -> int | Recur of truc_maker('a) let truc = truc_maker(maclasse) On Mar 17, 2011, at 11:50 AM, Pierre-Alexandre Voye wrote: > So, this is impossible ? : > > class maclasse = object(self) > val mutable valeur = (None : truc option) > method getValeur = valeur > end > and > truc = Machin of (maclasse->int) | Recur of truc;; > > ? > (three attempt to write a correct example of my problem.. All apologies !) > > 2011/3/17 Guillaume Yziquel > > > > -- > --------------------- > Isaac Project - http://www.lisaac.org/ --Apple-Mail-2--70081967 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
You'll probably need something along the lines of:

class maclasse = object(self)
  val mutable valeur = (None : truc option)
  method getValeur = valeur
end
let truc_maker('a) = Machin of 'a -> int | Recur of truc_maker('a)
let truc = truc_maker(maclasse)

On Mar 17, 2011, at 11:50 AM, Pierre-Alexandre Voye wrote:

So, this is impossible  ?   :

class maclasse = object(self)
  val mutable valeur = (None : truc option)
  method getValeur = valeur
end
and
truc = Machin of (maclasse->int) | Recur of truc;;

?
(three attempt to write a correct example of my problem.. All apologies !)

2011/3/17 Guillaume Yziquel <guillaume.yziquel@citycable.ch>



--
---------------------
Isaac Project - http://www.lisaac.org/

--Apple-Mail-2--70081967-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HB3CXR009693 for ; Thu, 17 Mar 2011 12:03:12 +0100 X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="78569550" Received: from moloch.lri.fr (HELO is010237.localnet) ([129.175.4.90]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Mar 2011 12:03:06 +0100 From: Paolo Herms To: caml-list@inria.fr Date: Thu, 17 Mar 2011 12:02:58 +0100 User-Agent: KMail/1.13.6 (Linux/2.6.37-ARCH; KDE/4.6.1; x86_64; ; ) References: <20110317104719.GH22969@localhost> <350217430.1223639.1300359057593.JavaMail.root@zmbs3.inria.fr> In-Reply-To: <350217430.1223639.1300359057593.JavaMail.root@zmbs3.inria.fr> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Message-Id: <201103171202.59214.paolo.herms@inria.fr> Subject: Re: [Caml-list] Re: Define class and sum type in one time Yes, but you can still do this: type 'maclasse truc = Machin of ('maclasse->int) | Recur of 'maclasse truc class maclasse = object(self) val mutable valeur = (None : maclasse truc option) method getValeur = valeur end -- Paolo Herms PhD Student - CEA-LIST Software Safety Lab. / INRIA ProVal Project Paris, France On Thursday 17 March 2011 11:50:57 Pierre-Alexandre Voye wrote: > So, this is impossible ? : > > class maclasse = object(self) > val mutable valeur = (None : truc option) > method getValeur = valeur > end > and > truc = Machin of (maclasse->int) | Recur of truc;; From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HB7TvF010110 for ; Thu, 17 Mar 2011 12:07:29 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArUJALqHgU1V2gB5Zmdsb2JhbAClYQ0LCQgVJcQ2DYVWBJBF X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="94314830" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail2-smtp-roc.national.inria.fr with SMTP; 17 Mar 2011 12:07:24 +0100 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 2F1618345B3; Thu, 17 Mar 2011 12:07:21 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Q0B1c-0003wH-H4; Thu, 17 Mar 2011 12:05:52 +0100 Date: Thu, 17 Mar 2011 12:05:52 +0100 From: Guillaume Yziquel To: Pierre-Alexandre Voye Cc: caml-list Message-ID: <20110317110552.GP22969@localhost> References: <20110317104719.GH22969@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p2HB7TvF010110 Subject: Re: [Caml-list] Re: Define class and sum type in one time Le Thursday 17 Mar 2011 à 11:50:37 (+0100), Pierre-Alexandre Voye a écrit : > So, this is impossible ?  : > class maclasse = object(self) >  val mutable valeur = (None : truc option) >  method getValeur = valeur > end > and > truc = Machin of (maclasse->int) | Recur of truc;; > ? > (three attempt to write a correct example of my problem.. All apologies > !) No, you can. Break the recursivity with a recursive module. However, it's quite clumsy, so if you do not have a compelling reason to use object, avoid the useless complexity. module rec M : sig class maclasse : object val mutable valeur : M.truc option method getValeur : M.truc option end type truc = Machin of (maclasse -> int) | Recur of truc end = struct class maclasse = object val mutable valeur : M.truc option = None method getValeur = valeur end type truc = Machin of (maclasse -> int) | Recur of truc end include M -- Guillaume Yziquel From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HBEHbq010539 for ; Thu, 17 Mar 2011 12:14:17 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkgEAJqJgU3Cpx5ei2dsb2JhbAClTRQBAQEKCwsbJcRAhWMEkCsa X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208,217";a="90628052" Received: from sucre.univ-orleans.fr ([194.167.30.94]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 Mar 2011 12:14:11 +0100 Received: from localhost (localhost [127.0.0.1]) by sucre.univ-orleans.fr (Postfix) with ESMTP id F01949441E; Thu, 17 Mar 2011 12:14:10 +0100 (CET) Received: from sucre.univ-orleans.fr ([127.0.0.1]) by localhost (sucre.univ-orleans.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 61RFyoGk7LNN; Thu, 17 Mar 2011 12:14:10 +0100 (CET) Received: from smtps.univ-orleans.fr (smtps.univ-orleans.fr [194.167.30.152]) by sucre.univ-orleans.fr (Postfix) with ESMTP id C90629440E; Thu, 17 Mar 2011 12:14:10 +0100 (CET) Received: from [192.168.6.18] (unknown [80.70.32.140]) by smtps.univ-orleans.fr (Postfix) with ESMTP id 103EC36E60; Thu, 17 Mar 2011 12:14:12 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: multipart/alternative; boundary=Apple-Mail-3--69297210 From: David Rajchenbach-Teller In-Reply-To: <884CCEF4-03CB-42CA-8D90-A2B4709E8CED@univ-orleans.fr> Date: Thu, 17 Mar 2011 12:14:09 +0100 Cc: Pierre-Alexandre Voye , caml-list Message-Id: <9EB4D59D-DFE5-45E7-8218-9A9D419D7500@univ-orleans.fr> References: <20110317104719.GH22969@localhost> <884CCEF4-03CB-42CA-8D90-A2B4709E8CED@univ-orleans.fr> To: David Rajchenbach-Teller X-Mailer: Apple Mail (2.1082) Subject: Re: [Caml-list] Re: Define class and sum type in one time --Apple-Mail-3--69297210 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Arf, sorry, I got mixed with OPA syntax (or revised syntax). This was actually let 'a truc_maker = Machin of 'a -> int | Recur of 'a truc_maker let truc = maclasse truc_maker On Mar 17, 2011, at 12:01 PM, David Rajchenbach-Teller wrote: > You'll probably need something along the lines of: > > class maclasse = object(self) > val mutable valeur = (None : truc option) > method getValeur = valeur > end > let truc_maker('a) = Machin of 'a -> int | Recur of truc_maker('a) > let truc = truc_maker(maclasse) > > On Mar 17, 2011, at 11:50 AM, Pierre-Alexandre Voye wrote: > >> So, this is impossible ? : >> >> class maclasse = object(self) >> val mutable valeur = (None : truc option) >> method getValeur = valeur >> end >> and >> truc = Machin of (maclasse->int) | Recur of truc;; >> >> ? >> (three attempt to write a correct example of my problem.. All apologies !) >> >> 2011/3/17 Guillaume Yziquel >> >> >> >> -- >> --------------------- >> Isaac Project - http://www.lisaac.org/ > --Apple-Mail-3--69297210 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Arf, sorry, I got mix= ed with OPA syntax (or revised syntax).

This was a= ctually

let 'a truc_maker =3D Machin of 'a -> int | = Recur of 'a truc_maker
let truc =3D maclasse truc_maker

On Mar 17, 2011, at 12:01 PM, David Rajchenbach-Teller wrote:

You'll probably need something along the lines of:
<= div>
class maclasse =3D object(self)
  val mutab= le valeur =3D (None : truc option)
  method getValeur =3D vale= ur
end
let truc_maker('a) =3D Machin of 'a -> int | Rec= ur of truc_maker('a)
let truc =3D truc_maker(maclasse)

<= div>
On Mar 17, 2011, at 11:50 AM, Pierre-Alexandre Voye wrote:
So, this is= impossible  ?   :

class maclasse =3D object(self)  val mutable valeur =3D (None : truc option)
  method getVal= eur =3D valeur
end
and
truc =3D Machin of (maclasse->int) | Re= cur of truc;;

?
(three attempt to write a correct example of my problem.. All apologie= s !)

2011/3/17 Guillaume Yziquel <guillaume.y= ziquel@citycable.ch>



--
---------------------
Isaac Proje= ct - http://www.lisaac.org/


= --Apple-Mail-3--69297210-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HDiW8v026005; Thu, 17 Mar 2011 14:44:32 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0CAP+sgU3RVdg2kGdsb2JhbACeZAGGGkcIFAEBAQEJCQ0HFAQhqRyKPoIehSkviFsBAQMFhV4EjF6IeTo X-IronPort-AV: E=Sophos;i="4.63,199,1299452400"; d="scan'208";a="94325434" Received: from mail-qw0-f54.google.com ([209.85.216.54]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Mar 2011 14:44:27 +0100 Received: by qwc9 with SMTP id 9so3036785qwc.27 for ; Thu, 17 Mar 2011 06:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=fB1wJmiZRORjsonhW16Xz7zT5rbgpajDqJoubFJAvTU=; b=PZvAX2nXrHjEHRozAm3++Yy+iWozEPw+C1at1wZotf//dzrF2U/XMjd2ce5e8NSXDg RW4y16iepqFcYchxdOPO2RDuBurGMQ3YyJuBEg3AjH7JQgScmGHCyBfQ7EVS1LjcvslG o8TRy5DzpUDeTXbKfNRATg3BdPw0A6sTOlMBY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=TSzneNm3od04xx4Oig9sBCJN22fmk4xhxPOu3kGgFjRi6R4oCufjRkyo890rslaj5O i5W/Em6inweWpWKsCtA63e5yNuCkX/qQmAA217ci4N4a/AFLZW0gH3MWrILOwlm0hfqA 7ExzWNbpiCy9ESvdr8tLR4JCoe7vg/m7COJL4= Received: by 10.229.41.133 with SMTP id o5mr1033789qce.160.1300369464145; Thu, 17 Mar 2011 06:44:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.226.196 with HTTP; Thu, 17 Mar 2011 06:44:04 -0700 (PDT) In-Reply-To: <20110317110552.GP22969@localhost> References: <20110317104719.GH22969@localhost> <20110317110552.GP22969@localhost> From: Gabriel Scherer Date: Thu, 17 Mar 2011 14:44:04 +0100 Message-ID: To: Guillaume Yziquel Cc: Pierre-Alexandre Voye , caml-list , caml-webmaster@inria.fr Content-Type: multipart/alternative; boundary=001636833dacfcbc45049eaddb11 Subject: Re: [Caml-list] Re: Define class and sum type in one time --001636833dacfcbc45049eaddb11 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 17, 2011 at 12:05 PM, Guillaume Yziquel < guillaume.yziquel@citycable.ch> wrote: > No, you can. Break the recursivity with a recursive module. However, > it's quite clumsy, so if you do not have a compelling reason to use > object, avoid the useless complexity. > I have seen similar questions (how to define mutually recursive type/exception/classes...) asked many times. It is quite natural and the answer is not so obvious. Maybe it would be a good candidate for adoption in the OCaml FAQ? http://caml.inria.fr/resources/doc/faq/index.en.html PS : I remember reading about an extension to OCaml where all compilation units where implicitly recursive, so that you could write Current_module.foo and have mutual structure item recursion for free. I thought it was from Alain Frisch, but a search on Lexifi's blog didn't return anything. Has one list reader kept the reference to this article? --001636833dacfcbc45049eaddb11 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Thu, Mar 17, 2011 at 12:05 PM, Guillaume Yziq= uel <guillaume.yziquel@citycable.ch> wrote:
No, you can. Break the recursivity with a recursive module. However,
it's quite clumsy, so if you do not have a compelling reason to use
object, avoid the useless complexity.

I have seen = similar questions (how to define mutually recursive type/exception/classes.= ..) asked many times. It is quite natural and the answer is not so obvious.= Maybe it would be a good candidate for adoption in the OCaml FAQ?
=A0 http:/= /caml.inria.fr/resources/doc/faq/index.en.html

PS : I remember r= eading about an extension to OCaml where all compilation units where implic= itly recursive, so that you could write Current_module.foo and have mutual = structure item recursion for free. I thought it was from Alain Frisch, but = a search on Lexifi's blog didn't return anything. Has one list read= er kept the reference to this article?
--001636833dacfcbc45049eaddb11-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2HDsY1n026476 for ; Thu, 17 Mar 2011 14:54:34 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhsDAN+ugU3RVaE2kGdsb2JhbACEPpQejGoIFAEBAQEJCQ0HFAQhqSSKAoJahSmJCgEBAwWEZ3cEjF6DTXSEODqBGg X-IronPort-AV: E=Sophos;i="4.63,199,1299452400"; d="vcf'?scan'208";a="78580906" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Mar 2011 14:54:28 +0100 Received: by fxm11 with SMTP id 11so4208320fxm.27 for ; Thu, 17 Mar 2011 06:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:message-id:date:from:user-agent :mime-version:to:subject:references:in-reply-to:x-enigmail-version :content-type; bh=k1C4dJFJ27Ak0yHqqEOyZH1ZRdCdWoXXcFj6M7EJZkA=; b=fmc73l4RUcCEORNZaosv3Pk5Ii3CsGjAjXSkRQpkDm1Lnj1eWdsa3FBT+pVEx2DY3z j6Um8NqBTzwbFtrjbdViSpLsWd1jNJrvoYYF7pRpWnqX9Xtun42Yk0G2ezp0B61CLFXX ZjeMRk7gVBQCW2hlsgQLHE2gNauvQwws2cXoI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type; b=R+Zo2CZnEkdZPik0lt9drkGf8/CaPheWaMafWUik8nw7/pUsYTgQE13tQGP0m02MCu 8fq2KhYoBtGeL9tGlK1FJM3Ht7/qic8Yh9+OKkqZhbslq8myJio2DMAHA7n3kKtjDs3w Nm94no/WXzceDCtso6Hde57NPUQIAN21saLr0= Received: by 10.223.15.72 with SMTP id j8mr1511473faa.69.1300370068427; Thu, 17 Mar 2011 06:54:28 -0700 (PDT) Received: from [195.83.212.218] (chercheurs-218.saclay.inria.fr [195.83.212.218]) by mx.google.com with ESMTPS id c21sm674229fac.46.2011.03.17.06.54.26 (version=SSLv3 cipher=OTHER); Thu, 17 Mar 2011 06:54:27 -0700 (PDT) Sender: Fabrice Le Fessant Message-ID: <4D821290.6020307@inria.fr> Date: Thu, 17 Mar 2011 14:54:24 +0100 From: Fabrice Le Fessant User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: caml-list@inria.fr References: <20110317104719.GH22969@localhost> <20110317110552.GP22969@localhost> <1080649473.122478.1300369493351.JavaMail.root@zmbs4.inria.fr> In-Reply-To: <1080649473.122478.1300369493351.JavaMail.root@zmbs4.inria.fr> X-Enigmail-Version: 1.1.2 Content-Type: multipart/mixed; boundary="------------010009030001080308040203" Subject: Re: [Caml-list] Re: Define class and sum type in one time This is a multi-part message in MIME format. --------------010009030001080308040203 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 03/17/2011 02:44 PM, Gabriel Scherer wrote: > PS : I remember reading about an extension to OCaml where all > compilation units where implicitly recursive, so that you could write > Current_module.foo and have mutual structure item recursion for free. I > thought it was from Alain Frisch, but a search on Lexifi's blog didn't > return anything. Has one list reader kept the reference to this article? On Tue, Dec 28, 2010 at 03:59:32PM +0100, Alain Frisch wrote: ... I can also mention a local extension we use at LexiFi: a compilation unit (.ml) for which an explicit signature (.mli) exists is type-checked as a recursive module with itself. (Currently, we disallow recursive references to value-like components.) So in the example above, the definition of the module type S could be put in Bar.mli: ... --Fabrice --------------010009030001080308040203 Content-Type: text/x-vcard; charset=utf-8; name="fabrice_le_fessant.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fabrice_le_fessant.vcf" begin:vcard fn:Fabrice LE FESSANT n:LE FESSANT;Fabrice org:INRIA Saclay -- Ile-de-France;Projet OCamlPro adr;quoted-printable:;;Parc Orsay Universit=C3=A9 ;Orsay CEDEX;;91893;France email;internet:fabrice.le_fessant@inria.fr title;quoted-printable:Charg=C3=A9 de Recherche tel;work:+33 1 74 85 42 14 tel;fax:+33 1 74 85 42 49 url:http://fabrice.lefessant.net/ version:2.1 end:vcard --------------010009030001080308040203-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2IHHEQK027001 for ; Fri, 18 Mar 2011 18:17:14 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApACAGowg03U4367kWdsb2JhbACERKEqFQEBAQkLCwcUAyKITakMkGkCgSWDRXcEiCKIEA X-IronPort-AV: E=Sophos;i="4.63,206,1299452400"; d="scan'208";a="78663726" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2011 18:17:09 +0100 Received: from office1.lan.sumadev.de (dslb-094-219-213-188.pools.arcor-ip.net [94.219.213.188]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0Mfwsi-1QNmsa1eBI-00N6Hv; Fri, 18 Mar 2011 18:17:08 +0100 Received: from [192.168.1.111] (546BE640.cm-12-4d.dynamic.ziggo.nl [84.107.230.64]) by office1.lan.sumadev.de (Postfix) with ESMTPA id 993E65F702; Fri, 18 Mar 2011 18:17:02 +0100 (CET) From: Gerd Stolpmann To: Pierre-Alexandre Voye Cc: caml-list In-Reply-To: References: <20110317104719.GH22969@localhost> Content-Type: text/plain; charset="UTF-8" Date: Fri, 18 Mar 2011 18:16:59 +0100 Message-ID: <1300468619.8429.8.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 X-Provags-ID: V02:K0:YAwvJ8bwra75GbPWamSu0uekYoLE6EZa6NvmZWzOi4E HNrlEhXfikytAGe1jd56DIUOK4dmB/DeUvEkojMQZeEIIpKw6V URiqye2/0Tp0vNhOcdVXmmFqaXGwX9zRYFC/fxf7Z06OAQ6GN1 EHWPA/yy7oeUjgu2jC1MiIooDtOwtXC+J1TKckrCTbu8rvAvSd W3uCd5BQUZob026l4k2Uw== Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p2IHHEQK027001 Subject: Re: [Caml-list] Re: Define class and sum type in one time Am Donnerstag, den 17.03.2011, 11:50 +0100 schrieb Pierre-Alexandre Voye: > So, this is impossible ? : > > class maclasse = object(self) > val mutable valeur = (None : truc option) > method getValeur = valeur > end > and > truc = Machin of (maclasse->int) | Recur of truc;; > > ? > (three attempt to write a correct example of my problem.. All > apologies !) This is the closest without introducing a type variable: type maclasse_t = < getValeur : truc option > and truc = Machin of maclasse_t->int | Recur of truc Here, maclasse is just an object type (which is less than a full class type, as it has only methods but no type information about instance variables). In a second step you can define the class: class maclasse = ( object ... end : maclasse_t ) Generally, it is a good recommendation to define object or class types before doing the class implementation. Not only allows it more complicated types but it is also easier to get the typing right, because you have always maclasse_t at hand to give type hints. Gerd > > 2011/3/17 Guillaume Yziquel > Le Thursday 17 Mar 2011 à 11:33:44 (+0100), Pierre-Alexandre > Voye a écrit : > > My example would be better with this : > > class machin = object(self) > > > Â val mutable valeur = (None : truc option) > > Â method getValeur = valeur > > end > > and > > truc = Machin of (int->int) | Recur of truc;; > > The object need the type defined > > > You cannot declare a class and a type with an 'and'. Either > two classes, > or two types. > > Simply declare truc before machin. > > type truc = Machin of int -> int | Recur of truc > > class machin = object > > val mutable valeur : truc option = None > > method getValeur = valeur > > end > > -- > Guillaume Yziquel > > > > -- > --------------------- > Isaac Project - http://www.lisaac.org/ -- ------------------------------------------------------------ Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------