caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] a class as method parameter...
@ 2004-05-28  9:25 Michael
  2004-05-28 14:33 ` skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Michael @ 2004-05-28  9:25 UTC (permalink / raw)
  To: caml-list

Hi,

I don't understand why this doesn't work:

class one = object
  val name = "test"
  method name = name
end;;
class two = object
  method take_one o -> o#name
end;;

that gives:
Some type variables are unbound in this type:
  class two : object method take_one : < name : 'a; .. > -> 'a end
The method take_one has type (< name : 'b; .. > as 'a) -> 'b where 'a
is unbound

I have to declare:
class two = object
  method take_one : 'a. (#one as 'a) -> string = fun o ->  o#name
end;;

.. to get it work (from chapter 3.10 )

why has it to be declared this way? 
( and not:
class two = object
  method take_one ( o : #one ) =  o#name
end;;

which also does not work:
The method take_one has type (#one as 'a) -> string where 'a is unbound ) ??

thanks,
 Michael
 



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] a class as method parameter...
  2004-05-28  9:25 [Caml-list] a class as method parameter Michael
@ 2004-05-28 14:33 ` skaller
  2004-05-28 14:49   ` Michael
  2004-05-28 14:52   ` Remi Vanicat
  0 siblings, 2 replies; 5+ messages in thread
From: skaller @ 2004-05-28 14:33 UTC (permalink / raw)
  To: micha-1; +Cc: caml-list

On Fri, 2004-05-28 at 19:25, Michael wrote:
> Hi,
> 
> I don't understand why this doesn't work:
> 
> class one = object
>   val name = "test"
>   method name = name
> end;;

What kind of weirdness is this? A val called name
and also a method called name??

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] a class as method parameter...
  2004-05-28 14:33 ` skaller
@ 2004-05-28 14:49   ` Michael
  2004-05-28 16:43     ` skaller
  2004-05-28 14:52   ` Remi Vanicat
  1 sibling, 1 reply; 5+ messages in thread
From: Michael @ 2004-05-28 14:49 UTC (permalink / raw)
  To: caml-list

On Freitag, 28. Mai 2004 16:33, skaller wrote:
> On Fri, 2004-05-28 at 19:25, Michael wrote:
> > Hi,
> >
> > I don't understand why this doesn't work:
> >
> > class one = object
> >   val name = "test"
> >   method name = name
> > end;;
>
> What kind of weirdness is this? A val called name
> and also a method called name??

oke, use:
class one method name = "one" end

it is just an access method to get the val back, rename it as you like :-). 
pretty useless, of course as standalone program, the whole thing, but short 
enough for my previous question:
why does this not work:

  method take_one ( o : #one ) =  o#name

(in class two...)

 Michael

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] a class as method parameter...
  2004-05-28 14:33 ` skaller
  2004-05-28 14:49   ` Michael
@ 2004-05-28 14:52   ` Remi Vanicat
  1 sibling, 0 replies; 5+ messages in thread
From: Remi Vanicat @ 2004-05-28 14:52 UTC (permalink / raw)
  To: caml-list

skaller <skaller@users.sourceforge.net> writes:

> On Fri, 2004-05-28 at 19:25, Michael wrote:
>> Hi,
>> 
>> I don't understand why this doesn't work:
>> 
>> class one = object
>>   val name = "test"
>>   method name = name
>> end;;
>
> What kind of weirdness is this? A val called name
> and also a method called name??

method and val don't live in the same domain name. There is no
problem in the point of vue of ocaml (and semantically, they are the
same here, so it is not too much a problem for code's users).
-- 
Rémi Vanicat

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] a class as method parameter...
  2004-05-28 14:49   ` Michael
@ 2004-05-28 16:43     ` skaller
  0 siblings, 0 replies; 5+ messages in thread
From: skaller @ 2004-05-28 16:43 UTC (permalink / raw)
  To: micha-1; +Cc: caml-list

On Sat, 2004-05-29 at 00:49, Michael wrote:
> On Freitag, 28. Mai 2004 16:33, skaller wrote:

> it is just an access method to get the val back, rename it as you like :-). 

Ya, but it makes it much harder to see the typing
issue if you have to keep thinking about which name
is being refered to .. fact is i'd never do this,
and so I had no idea how Ocaml resolved it ..

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2004-05-28 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-28  9:25 [Caml-list] a class as method parameter Michael
2004-05-28 14:33 ` skaller
2004-05-28 14:49   ` Michael
2004-05-28 16:43     ` skaller
2004-05-28 14:52   ` Remi Vanicat

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