List Info

Thread: "ocaml_beginners"::[] quick question on mutually recursive types




"ocaml_beginners"::[] quick question on mutually recursive types
country flaguser name
United States
2007-03-05 02:22:16

how do i make a class obj containing a Set of obj? it's like the
chicken and egg problem - if i first instantiate the module, obj is
undefined, but if i first define the class, i haven't instantiated
the Set yet. thanks in advance for any help.

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] quick question on mutually recursive types
country flaguser name
United Kingdom
2007-03-05 06:36:44

On Mon, Mar 05, 2007 at 08:22:16AM -0000, overbored wrote:
> how do i make a class obj containing a Set of obj? it's like the
> chicken and egg problem - if i first instantiate the module, obj is
> undefined, but if i first define the class, i haven't instantiated
> the Set yet. thanks in advance for any help.

Do you need to use objects? A much more natural way to express this
in functional languages is:

type 'a thing = Thing of 'a | List of 'a thing list

Example usage:

# let w1 = Thing 1;;
val w1 : int thing = Thing 1
# let w2 = Thing 2;;
val w2 : int thing = Thing 2
# let things = List [w1; w2];;
val things : int thing = List [Thing 1; Thing 2]

If you really want a set (ie. no duplicates) then it's a little bit
more complicated.

Rich.

--
Richard Jones
Red Hat UK Limited

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] quick question on mutually recursive types
country flaguser name
United Kingdom
2007-03-05 07:08:21

On Monday 05 March 2007 08:22, overbored wrote:
> how do i make a class obj containing a Set of obj? it's like the
> chicken and egg problem - if i first instantiate the module, obj is
> undefined, but if i first define the class, i haven't instantiated
> the Set yet. thanks in advance for any help.

You must use mutually recursive modules:

# module rec A : sig
type t = <get: ASet.t>
val compare : t -> t -> int
end = struct
type t = <get: ASet.t>
let compare = compare
end
and ASet : Set.S = Set.Make(A);;
module rec A : sig type t = < get : ASet.t > val compare : t -> t -> int end
and ASet : Set.S

However, as Richard has said you are probably using the wrong tool for the
job. Try posting problems rather than proposed solutions without the problem
and you'll probably get more helpful advice.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] ocamldefun
country flaguser name
United States
2007-03-08 13:18:26

I'd really like to play around ocamldefun, but it seems to only work
with ocaml 3.06. Has anyone had luck setting this up in more recent
versions of ocaml?

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] ocamldefun
country flaguser name
United Kingdom
2007-03-08 13:30:38

On Thursday 08 March 2007 19:18, Sasha Rush wrote:
&gt; I'd really like to play around ocamldefun, but it seems to only work
>; with ocaml 3.06. Has anyone had luck setting this up in more recent
&gt; versions of ocaml?

Isn't it just a preprocessor for OCaml code, so you can feed any OCaml code
through it independent of the compiler?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] ocamldefun
country flaguser name
United States
2007-03-08 14:02:46


On Mar 8, 2007, at 2:30 PM, Jon Harrop wrote:

> On Thursday 08 March 2007 19:18, Sasha Rush wrote:
&gt;> I'd really like to play around ocamldefun, but it seems to only work
>;> with ocaml 3.06. Has anyone had luck setting this up in more recent
&gt;> versions of ocaml?
&gt;
> Isn't it just a preprocessor for OCaml code, so you can feed any
> OCaml code
>; through it independent of the compiler?
>

I'm having trouble just compiling it. It requires claims it requires
3.06.

> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
>; OCaml for Scientists
> http://www.ffconsultancy.com/products/ocaml_for_scientists
>
>;
> ------------------------ Yahoo! Groups Sponsor --------------------
> ~-->
> Check out the new improvements in Yahoo! Groups email.
&gt; http://us.click.yahoo.com/4It09A/fOaOAA/yQLSAA/saFolB/TM
&gt; ----------------------------------------------------------
> ~->
&gt;
> Archives up to November 11, 2006 are also downloadable at http://
> www.connettivo.net/cntprojects/ocaml_beginners/
&gt; The archives of the very official ocaml list (the seniors' one) can
> be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames
> etc.
>; Yahoo! Groups Links
&gt;
>
>
>;

__._,_.___
.

__,_._,___
[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )