Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Problem with recursive class and non-class types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Goswin von Brederlow  
View profile  
 More options May 20 2010, 1:12 am
Newsgroups: fa.caml
From: Goswin von Brederlow <goswin-...@web.de>
Date: Thu, 20 May 2010 05:12:02 UTC
Local: Thurs, May 20 2010 1:12 am
Subject: [Caml-list] Problem with recursive class and non-class types
Hi,

I want to define the two types below:

type foo = { bar : bar; }
class bar = object val mutable foo : foo list = [] end

Is there another way of doing this other than:

# type 'a foo = { bar : 'a; }
  class bar = object val mutable foo : #bar foo list = [] end;;
type 'a foo = { bar : 'a; }
class bar : object val mutable foo : #bar foo list end

I don't want any 'a foo other than 'a = #bar. It is too easy to create a
baz foo and then much later get a type error when trying to use it as
bar foo. I want the error where the foo gets created.

MfG
        Goswin

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacques Garrigue  
View profile  
 More options May 20 2010, 3:39 am
Newsgroups: fa.caml
From: Jacques Garrigue <garri...@math.nagoya-u.ac.jp>
Date: Thu, 20 May 2010 07:39:48 UTC
Local: Thurs, May 20 2010 3:39 am
Subject: Re: [Caml-list] Problem with recursive class and non-class types
From: Goswin von Brederlow <goswin-...@web.de>

> I want to define the two types below:

> type foo = { bar : bar; }
> class bar = object val mutable foo : foo list = [] end

> Is there another way of doing this other than:

> # type 'a foo = { bar : 'a; }
>   class bar = object val mutable foo : #bar foo list = [] end;;
> type 'a foo = { bar : 'a; }
> class bar : object val mutable foo : #bar foo list end

The alternative is to use a recursive module, but this is actually
more verbose.

module rec M : sig
  type foo = { bar : M.bar; }
  class bar : object val mutable foo : foo list end
end = struct
  type foo = { bar : M.bar; }
  class bar =  object val mutable foo : foo list = [] end
end

You can avoid a bit of the verboseness by splitting types and values,
since recursive modules built only from types require no duplication.

module rec M : sig
  type foo = { bar : M.bar; }
  class type bar = object val mutable foo : foo list end
end = M

class bar : M.bar = object val mutable foo : M.foo list = [] end

You still need to provide an explicit interface for bar.

Hope this helps,

     Jacques Garrigue

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Goswin von Brederlow  
View profile  
 More options May 21 2010, 2:01 pm
Newsgroups: fa.caml
From: Goswin von Brederlow <goswin-...@web.de>
Date: Fri, 21 May 2010 18:01:24 UTC
Local: Fri, May 21 2010 2:01 pm
Subject: Re: [Caml-list] Problem with recursive class and non-class types

Thanks, it does. It isn't nice but it does solve the problem. Now I have
to decide what I live with. 'a foo uglyness or module rec uglyness.

It is too bad a simple

type foo = ...
and class bar = ...

doesn't work.

MfG
        Goswin

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »