* Monomorphism restriction in classes
@ 2006-02-17 21:09 Christian Stork
2006-02-17 21:53 ` [Caml-list] " Gerd Stolpmann
0 siblings, 1 reply; 2+ messages in thread
From: Christian Stork @ 2006-02-17 21:09 UTC (permalink / raw)
To: caml-list
So, what's the best work-around for this problem?
class c (len : 'a list -> int) =
object
method str_len (l: string list) = len l
method int_len (l: int list) = len l
end
$ ocamlc monoRestForClasses.ml
File "monoRestForClasses.ml", line 7, characters 40-41:
This expression has type int list but is here used with type string list
Thanks,
Chris
--
Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Monomorphism restriction in classes
2006-02-17 21:09 Monomorphism restriction in classes Christian Stork
@ 2006-02-17 21:53 ` Gerd Stolpmann
0 siblings, 0 replies; 2+ messages in thread
From: Gerd Stolpmann @ 2006-02-17 21:53 UTC (permalink / raw)
To: Christian Stork; +Cc: caml-list
Am Freitag, den 17.02.2006, 13:09 -0800 schrieb Christian Stork:
> So, what's the best work-around for this problem?
>
> class c (len : 'a list -> int) =
> object
> method str_len (l: string list) = len l
> method int_len (l: int list) = len l
> end
>
type len_t = { len : 'a . 'a list -> int}
class c (len :len_t) =
object
method str_len (l:string list) = len.len l
method int_len (l: int list) = len.len l
end
I don't know why the 'a.t syntax is only allowed for records and
methods, and why one cannot say
class c (len : 'a . 'a list -> int) = ...
Gerd
> $ ocamlc monoRestForClasses.ml
> File "monoRestForClasses.ml", line 7, characters 40-41:
> This expression has type int list but is here used with type string list
>
> Thanks,
> Chris
>
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-02-17 21:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-17 21:09 Monomorphism restriction in classes Christian Stork
2006-02-17 21:53 ` [Caml-list] " Gerd Stolpmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox