This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Re: [Caml-list] variant with tuple arg in pattern match?
• reig@d...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2001-04-10 (11:47) From: reig@d... Subject: Re: [Caml-list] variant with tuple arg in pattern match?
```Michel Mauny wrote:

> Sure. With CamlP4's revised syntax, you would write this as
>
>    type t 'a =3D
>      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 :)
> >=20
> >    type 'a t =3D
> >      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.

Like in haskell, if it *looks* curried, it *is* curried.

data T a = Curried (T a) (T a)
| Function (T a -> T a)

Main> :i T
-- type constructor
data T a

-- constructors:
Curried :: T a -> T a -> T a
Function :: (T a -> T a) -> T a

Even in ocaml's current syntax, you need parens for functions in datatypes:

# type t = F of int -> int;;
Syntax error
# type t = F of (int -> int);;
type t = F of (int -> int)

Maybe other syntax of disambiguating this case are better, I'm
proposing the one I know, which seems quite regular.

Fermin Reig

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

```