* Objects and variants
@ 2009-03-06 15:57 Samuel Mimram
2009-03-06 16:10 ` [Caml-list] " Peng Zang
0 siblings, 1 reply; 2+ messages in thread
From: Samuel Mimram @ 2009-03-06 15:57 UTC (permalink / raw)
To: caml-list
Hi,
When I try to compile the following code:
class a =
object
method f (x:[>]) = ()
end
I get the following error:
Error: Some type variables are unbound in this type:
class a : object method f : [> ] -> unit end
The method f has type ([> ] as 'a) -> unit where 'a is unbound
Is the binding of [>] to 'a really necessary here? In particular it is
not mentioned in the inferred type...
Of course I can parametrize the class over 'a as
class ['a] a =
object
method f (x:[>] as 'a) = ()
end
which now has type
class ['a] a : object constraint 'a = [> ] method f : 'a -> unit end
But this seems rather cumbersome. Is there a way to handle this without
mentioning 'a?
Thanks!
Cheers,
Samuel.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Objects and variants
2009-03-06 15:57 Objects and variants Samuel Mimram
@ 2009-03-06 16:10 ` Peng Zang
0 siblings, 0 replies; 2+ messages in thread
From: Peng Zang @ 2009-03-06 16:10 UTC (permalink / raw)
To: caml-list; +Cc: Samuel Mimram
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You're looking for a polymorphic method:
class a = object
method f : 'a. ([>] as 'a) -> unit = fun _ -> ()
end
Peng
On Friday 06 March 2009 10:57:43 am Samuel Mimram wrote:
> Hi,
>
> When I try to compile the following code:
>
> class a =
> object
> method f (x:[>]) = ()
> end
>
> I get the following error:
>
> Error: Some type variables are unbound in this type:
> class a : object method f : [> ] -> unit end
> The method f has type ([> ] as 'a) -> unit where 'a is unbound
>
> Is the binding of [>] to 'a really necessary here? In particular it is
> not mentioned in the inferred type...
>
> Of course I can parametrize the class over 'a as
>
> class ['a] a =
> object
> method f (x:[>] as 'a) = ()
> end
>
> which now has type
>
> class ['a] a : object constraint 'a = [> ] method f : 'a -> unit end
>
> But this seems rather cumbersome. Is there a way to handle this without
> mentioning 'a?
>
> Thanks!
>
> Cheers,
>
> Samuel.
>
> _______________________________________________
> 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
iD8DBQFJsUrkfIRcEFL/JewRAqJ3AKC7Dl6+a97yrs1PKPLDEzL5c3vbVACcDdrJ
16BPB2/+ddTB4OHB/4zQ+LA=
=ltZH
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-06 16:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-06 15:57 Objects and variants Samuel Mimram
2009-03-06 16:10 ` [Caml-list] " Peng Zang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox