Browse thread
Simple(?) subtyping 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: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Simple(?) subtyping problem... |
On Tuesday 24 October 2006 21:45, Till Varoquaux wrote:
> I'm currently trying to split functions matching against given variant
> type and I'm running across this pb:
>
> let a= function
>
> | `A -> ()
> | `B -> ()
>
> doesn't split into
>
> let c=function
>
> | `B -> ()
>
> let b =function
>
> | `A -> ()
> | x -> c x
>
> since it messes up the type rules. I really want to avoid having to
> write down precise type informations (The point here is to have an
> extensible system)...
How about:
# type c = [`B];;
type c = [ `B ]
# let c = function
| #c -> ();;
val c : [< c ] -> unit = <fun>
# let b k = function
| `A -> ()
| #c as x -> c x
| x -> k x;;
val b : (([> `A | `B ] as 'a) -> unit) -> 'a -> unit = <fun>
> I am sure this question has been asked loads of times (but I couldn't
> find the right thread in the archives) and I apologize for asking it
> yet again.
I don't think it comes up very often.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists