Version française
Home     About     Download     Resources     Contact us    
Browse thread
Union of polymorphic variants...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques GARRIGUE <garrigue@m...>
Subject: Re: [Caml-list] Union of polymorphic variants...
From: Stephane Glondu <steph@glondu.net>

> However, one can do:
> 
> let f = function
>    | `A (`B _) -> ...
>    | `A (`C _) -> ..
> 
> Would it be difficult to extend the system so that #b and #c expand to 
> the constructions above?

Nothing is "difficult". But not everything is well-defined...
The question is where do we start, where do we stop.

type a = [`S of a | `Z]

should #a be (`S _ | `Z) or (`S (`S _ | `Z) | `Z) or ...?

type b = [`A of [`B] option]

should #b be (`A (None | Some `B)) ?

Generally, when such questions start to pop up, it is better to
forget about it. It could still be a good idea, but we need more
examples to see that.

Note that you can still build the types by hand

type 'a t = [`A of 'a]
type b = [`B of bool]
type c = [`C of char]
type a = [b|c] t

let f = function
    `A #b as x -> fb x
  | `A #c as x -> fc x

Jacques Garrigue