Browse thread
Oddness with recursive polymorphic variants
[
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: | brogoff <brogoff@s...> |
| Subject: | Re: [Caml-list] Oddness with recursive polymorphic variants |
On Thu, 4 May 2006, Jeremy Yallop wrote:
> Thanks for the reply. That doesn't seem to be what I want, though. The
> input to k should have type 'f'. The output should have type 'g'. Your
> 'k' can be called with values that don't match type 'f':
>
> # k `C;;
> - : g = `C
>
> The following does what I want:
>
> let k (#f as x:f) = (x:g)
>
> I'd like to understand why it behaves differently from the following:
>
> let k (x:f) = (x:g)
Right, others have shown that you can do what you want with a coercion. The
problem is that you are using exact types ("[" rather than "[>" ) and there
is a mismatch of exact types. ":" is not a coercion, it just tells the type
that should be there. ":>" coerces. x is not of type g, but it can be coerced to
g.
-- Brian