Browse thread
Unexpected '_a problem
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Chris King <colanderman@g...> |
| Subject: | Unexpected '_a problem |
Given this code:
# let create_foo () = object method foo (_: 'a) = () end;;
val create_foo : unit -> < foo : 'a -> unit > = <fun>
# let a = create_foo ();;
val a : < bar : '_a -> unit > = <obj>
the compiler determines a is monomorphic, since 'a is in a
contravariant position. But why, when 'a is placed in a covariant
position:
# let create_bar () = object method bar (_: 'a) = () end;;
val create_bar : unit -> < bar : ('a -> unit) -> unit > = <fun>
# let b = create_bar ();;
val b : < bar : ('_a -> unit) -> unit > = <obj>
does the compiler restrict b to be monomorphic? If I wrap everything
up in a module and abstract the type returned by create_bar (),
create_bar () works as expected and returns a polymorphic value.
Thanks,
Chris King