English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 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