Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] variant with tuple arg in pattern match?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michel Mauny <Michel.Mauny@i...>
Subject: Re: [Caml-list] variant with tuple arg in pattern match?
reig@dcs.gla.ac.uk wrote/écrivait (Apr 10 2001, 11:44AM +0100):

> This is how you do it in haskell:
> 
> data T a = I Int
> 	 | B Bool
> 	 | N (T a) (T a) 
> 	 | Uncurried (Int,Int)

Sure. With CamlP4's revised syntax, you would write this as

   type t 'a =
     I of int
   | B of bool
   | N of (t 'a) and (t 'a)      (* parens probably unnecessary *)
   | Uncurried of int * int

> Moreover, the last part (-> 'a t) is the same for all constructors and
> can be omitted like you do in haskell (so that Xavier is happier :)
> 
>    type 'a t =
>      Int : int
>    | Bool : bool
>    | Node : 'a t -> 'a t
>    | Uncurried : int * int

I'm afraid the Node case is ambiguous, here.

Is the type of Node   'a t -> 'a t  -> 'a t
or is it             ('a t -> 'a t) -> 'a t ?

In other words, you can't know wether Node carries functions, or is
curried.

-- Michel
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr