caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] module alias inside class
@ 2013-07-02 15:09 ygrek
  2013-07-03  5:09 ` Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: ygrek @ 2013-07-02 15:09 UTC (permalink / raw)
  To: caml-list

Dear list,

 Just a short question tonight, why is the following code rejected?
 
 class z = let module A = String in object end;;

 Is there some deep reason or it was simply overlooked?

-- 

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

* Re: [Caml-list] module alias inside class
  2013-07-02 15:09 [Caml-list] module alias inside class ygrek
@ 2013-07-03  5:09 ` Jacques Garrigue
  2013-07-03 10:56   ` AW: " Gerd Stolpmann
  0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2013-07-03  5:09 UTC (permalink / raw)
  To: ygrek; +Cc: caml-list

On 2013/07/03, at 0:09, ygrek <ygrekheretix@gmail.com> wrote:

> Dear list,
> 
> Just a short question tonight, why is the following code rejected?
> 
> class z = let module A = String in object end;;
> 
> Is there some deep reason or it was simply overlooked?


This would be very nice to able to do that.
Unfortunately, the typing of classes is a rather complex process,
which seems difficult to integrate with local module definitions,
except maybe in a very restrictive way.
There are also deep questions, such as what to do in presence
of inheritance.

On the other hand, "let open" would be much easier to add.

	Jacques Garrigue

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

* AW: [Caml-list] module alias inside class
  2013-07-03  5:09 ` Jacques Garrigue
@ 2013-07-03 10:56   ` Gerd Stolpmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Stolpmann @ 2013-07-03 10:56 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: ygrek, caml-list

Am 03.07.2013 07:09:49 schrieb(en) Jacques Garrigue:
> On 2013/07/03, at 0:09, ygrek <ygrekheretix@gmail.com> wrote:
> 
> > Dear list,
> >
> > Just a short question tonight, why is the following code rejected?
> >
> > class z = let module A = String in object end;;
> >
> > Is there some deep reason or it was simply overlooked?
> 
> 
> This would be very nice to able to do that.
> Unfortunately, the typing of classes is a rather complex process,
> which seems difficult to integrate with local module definitions,
> except maybe in a very restrictive way.
> There are also deep questions, such as what to do in presence
> of inheritance.

I guess the main problem is that types from A wouldn't be allowed to  
appear in class types (type escapes definition scope) - unless the  
notion of class types were extended so that such modules are bound  
(e.g. class type z = object method foo : A.t end with module A :  
TYPE_OF_A). But that mixes classes with modules conceptually (well, not  
that we have that already).

Just trying:

# class x =
     let s = (module String : Set.OrderedType) in
     object
       method compare = let module S = (val s) in S.compare
     end;;
Error: This expression has type S.t -> S.t -> int
        but an expression was expected of type S.t -> S.t -> int
        The type constructor S.t would escape its scope

Gerd


> 
> On the other hand, "let open" would be much easier to add.
> 	Jacques Garrigue
> 
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
> 



-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

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

end of thread, other threads:[~2013-07-03 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-02 15:09 [Caml-list] module alias inside class ygrek
2013-07-03  5:09 ` Jacques Garrigue
2013-07-03 10:56   ` AW: " Gerd Stolpmann

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