Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] tpyping question
[ 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@k...>
Subject: Re: [Caml-list] tpyping question
From: skaller <skaller@ozemail.com.au>

> type x = [`A | `B of int | `V of float];;
> let g (a:x) = a;;
> let f a = match a with
> | `A -> g a
> (* | `B _ *) | _ -> g a;;
> 
> Compiles fine, but gives an error if the comments are
> removed.

Indeed, there seems to be a bug here, since the non-commented version
should be equivalent to

# let f a = match a with
  | `A ->  g a
  | `B _ -> g a
  | _ -> g a;;
val f : x -> x = <fun>

I will investigate this.
On the other hand, this code is meaningless, as _ is more general
than `B _, and the order of or-patterns is not significant.

If the code you really intended was

  let f a = match a with
    | `A ->  g a
    | `B _ -> g a

then the answer is in the manual:

  let f = function `A | `B _ as a -> g a

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners