Version française
Home     About     Download     Resources     Contact us    

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

Browse thread
Variable pattern matching tuple
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-09-19 (01:40)
From: Pietro Abate <Pietro.Abate@a...>
Subject: Re: [Caml-list] Variable pattern matching tuple
On Mon, Sep 18, 2006 at 09:26:15PM -0400, Denis Bueno wrote:
> What is the reason that expression A won't compile? Can't one variable
> stand for a tuple in a pattern-matching clause?

somebody was discussing a similar issue on the beginners 
mailing list this week:

type 'a withint = Withint of ('a * int);;
type 'a withint = Withint of ('a * int)
let foo = Withint ("hi there", 4);;
val foo : string withint = Withint ("hi there", 4)
 match foo with Withint d -> d;; ;;
- : string * int = ("hi there", 4)

if you want to pattern match the tuple you need to add parenthesis 
in the type declaration.

have a look here for a detailed explanation:


++ Blog:
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.