* Variable pattern matching tuple @ 2006-09-19 1:26 Denis Bueno 2006-09-19 1:40 ` [Caml-list] " Pietro Abate 0 siblings, 1 reply; 2+ messages in thread From: Denis Bueno @ 2006-09-19 1:26 UTC (permalink / raw) To: OCaml Mailing List The following is not intuitive to me. # 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 _ -> ();; - : unit = () # match foo with Withint d -> d;; (* expression A*) Characters 15-24: match foo with Withint d -> d;; ^^^^^^^^^ The constructor Withint expects 2 argument(s), but is here applied to 1 argument(s) # What is the reason that expression A won't compile? Can't one variable stand for a tuple in a pattern-matching clause? -Denis ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Variable pattern matching tuple 2006-09-19 1:26 Variable pattern matching tuple Denis Bueno @ 2006-09-19 1:40 ` Pietro Abate 0 siblings, 0 replies; 2+ messages in thread From: Pietro Abate @ 2006-09-19 1:40 UTC (permalink / raw) To: caml-list, OCaml Mailing List 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-09-19 1:40 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-09-19 1:26 Variable pattern matching tuple Denis Bueno 2006-09-19 1:40 ` [Caml-list] " Pietro Abate
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox