Browse thread
When is a function polymorphic?
[
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: | Eric Cooper <ecc@c...> |
| Subject: | Re: [Caml-list] When is a function polymorphic? |
On Wed, Mar 30, 2005 at 07:51:04PM -0500, Yaron Minsky wrote:
> Consider some complicated union type with a single parameter:
>
> type 'a foo = A of 'a | B of int | C of string * string | ... | ZZ of float
>
> I want a function that converts an 'a foo to a unit foo. I tried to
> write it this way:
>
> function A _ -> A () | x -> x
>
> But this ends up having type: unit foo -> unit foo, which isn't what I
> want at all. Any idea of how to achieve this cleanly?
If you can accept another level of constructors, this will work:
type 'a foo = A of 'a | NotA of bar
and bar = B of int | C of string | D of bool | ...
function A _ -> A () | NotA x -> NotA x
--
Eric Cooper e c c @ c m u . e d u