Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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:
http://www.archivesat.com/Ocaml_Beginners/thread1620469.htm

:)
p

-- 
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++ 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html