caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Polymorphic methods
@ 2002-08-23 15:46 Frederic Tronel
  2002-08-23 17:32 ` Fred Smith
  2002-08-23 18:21 ` Remi VANICAT
  0 siblings, 2 replies; 20+ messages in thread
From: Frederic Tronel @ 2002-08-23 15:46 UTC (permalink / raw)
  To: caml-list

Hello list,


I've just compiled the new 3.05 version (I will change for 3.06
tomorrow),
and start playing a little bit with polymorphic methods. 
But this small piece of code does not compile:

class node =
object 
val mutable t = None
method set_t: 'a. 'a -> unit = fun nt -> t <- Some nt
end

File "essai.ml", line 4, characters 31-53:
This method has type 'a -> unit which is less general than 'b. 'b ->
unit

while this one is OK (useless).

class node =
object 
val mutable t = None
method set_t: 'a. 'a -> unit = fun nt -> ()
end
class node : object val mutable t : 'a option method set_t : 'b -> unit
end

Where am I going wrong ??

Best regards,

Frederic.
-------------------
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] 20+ messages in thread
* [Caml-list] polymorphic methods
@ 2015-12-18  9:18 Christoph Höger
  2015-12-18 10:07 ` Leo White
  0 siblings, 1 reply; 20+ messages in thread
From: Christoph Höger @ 2015-12-18  9:18 UTC (permalink / raw)
  To: caml users

Dear all,

I am attempting to store polymorphic methods in classes (i.e. keep the
type variables out of the class-type by putting them directly into the
method signatures).

However, I have some trouble when it comes to convince the compiler that
my code is typecorrect:

type ('a, 'b) f_arg = < x : 'b; .. > as 'a ;;
let f : 'a 'b . (('a,'b) f_arg) -> 'b  = fun a -> a#x ;;
class foo = object method f : 'a 'b . ('a, 'b) f_arg -> 'b = f end  ;;

yields:

Error: This expression has type
'a 'b. (< x : 'b; .. > as 'a) -> 'b
but an expression was expected of type
'c 'b. (< x : 'b; .. > as 'c) -> 'b
The type variable 'd occurs inside 'd

What is 'd? Why do these types not unify?

-- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de

^ permalink raw reply	[flat|nested] 20+ messages in thread
* [Caml-list] polymorphic methods
@ 2003-03-12 23:07 Damien
  2003-03-13  0:56 ` brogoff
  2003-03-13  1:56 ` Jacques Garrigue
  0 siblings, 2 replies; 20+ messages in thread
From: Damien @ 2003-03-12 23:07 UTC (permalink / raw)
  To: caml-list

Hello,

Does someone know why the following class type
is not accepted ?

# class type a = object method m: 'a. (#a as 'a) -> unit end;;
The abbreviation #a expands to type #a but is used with type < .. >
# 

Thanks,
Damien

-------------------
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] 20+ messages in thread
* [Caml-list] polymorphic methods
@ 2002-07-14 23:16 nadji
  2002-07-15  1:05 ` Jacques Garrigue
  0 siblings, 1 reply; 20+ messages in thread
From: nadji @ 2002-07-14 23:16 UTC (permalink / raw)
  To: caml-list

Hello,

While playing with the current cvs version of ocaml (3.04+15),
several questions came to me concerning the semantics of
polymorphic methods. For example :

# class c = object
  method ~m: 'a . unit -> 'a -> 'a = fun _ x -> x
end;;
    class c : object method m : unit -> 'a -> 'a end
# let f = (new c)#m ();;
val f : '_a -> '_a = <fun>

Shouldn't the type of f be : 'a -> 'a  ?
(Would it be sound/implementable/easy to add ?)

Second question:
# class ['a] d = object
  method m: 'a -> 'a = fun x -> x
end;;
    class ['a] d : object method m : 'a -> 'a end
# class subd = object
  method ~m: 'a. 'a -> 'a = fun x -> x
end;;
    class subd : object method m : 'a -> 'a end
# let v = (new subd :> 'a d);;
Characters 9-17:
  let v = (new subd :> 'a d);;
           ^^^^^^^^
This expression cannot be coerced to type 'a d = < m : 'a -> 'a >;
it has type subd = < m : 'b. 'b -> 'b > but is here used with type 'a d

Or even the easier :
# class d' = object
  method m x = x + 0
end;;
    class d' : object method m : int -> int end
# let v' = (new subd :> d');;
Characters 10-18:
  let v' = (new subd :> d');;
            ^^^^^^^^
This expression cannot be coerced to type d' = < m : int -> int >;
it has type subd = < m : 'a. 'a -> 'a > but is here used with type d'

But the type ('b. 'b -> 'b) is more general than ('a -> 'a)
or (int -> int), no ?
Can someone give me some hints why I can't coerce subd ?

Btw, thanks for the upcoming release, it seems _really_ excellent !
Nadji

-------------------
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] 20+ messages in thread
* [Caml-list] Polymorphic methods
@ 2001-11-19 15:29 Alain Frisch
  2001-11-20  0:29 ` Jacques Garrigue
  0 siblings, 1 reply; 20+ messages in thread
From: Alain Frisch @ 2001-11-19 15:29 UTC (permalink / raw)
  To: Caml list

Hello,

is there any plan to add polymorphic methods to OCaml ?  The more I use
objects, the more I miss this feature. There is a poly_meth branch in
the CVS, but it does not seem really active nowadays ...

Did OLabl raise some practical problems with polymorphic methods ?


-- 
  Alain

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2015-12-18 10:07 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-23 15:46 [Caml-list] Polymorphic methods Frederic Tronel
2002-08-23 17:32 ` Fred Smith
2002-08-23 18:21 ` Remi VANICAT
  -- strict thread matches above, loose matches on Subject: below --
2015-12-18  9:18 [Caml-list] polymorphic methods Christoph Höger
2015-12-18 10:07 ` Leo White
2003-03-12 23:07 Damien
2003-03-13  0:56 ` brogoff
2003-03-13  1:56 ` Jacques Garrigue
2003-03-13  9:04   ` Damien
2003-03-13  9:27     ` Jacques Garrigue
2003-03-13 14:49       ` Damien
2003-03-13  9:41     ` Olivier Andrieu
2002-07-14 23:16 nadji
2002-07-15  1:05 ` Jacques Garrigue
2002-07-15  2:08   ` Brian Smith
2002-07-15 16:24   ` nadji
2001-11-19 15:29 [Caml-list] Polymorphic methods Alain Frisch
2001-11-20  0:29 ` Jacques Garrigue
2001-11-20  9:33   ` Alain Frisch
2001-11-20 20:55   ` Xavier Leroy

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