[Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Alexey Egorov
Hi, suppose that there is following data family: data family D a data instance D Int = DInt Int data instance D Bool = DBool Bool it is not possible to match on constructors from different instances: -- type error a :: D a - a a (DInt x) = x a (DBool x) = x however, following works:

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Francesco Mazzoli
At Thu, 25 Apr 2013 20:29:16 +0400, Alexey Egorov wrote: I'm curious - why data families constructors (such as DInt and DBool) doesn't imply such constraints while typechecking pattern matching? I think you are misunderstanding what data families do. ‘DInt :: DInt - D Int’ and ‘DBool :: DBool

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Francesco Mazzoli
At Thu, 25 Apr 2013 19:08:17 +0100, Francesco Mazzoli wrote: ... ‘DInt :: DInt - D Int’ and ‘DBool :: DBool - D Bool’ ... This should read ‘DInt :: Int - D Int’ and ‘DBool :: Bool - D Bool’. Francesco ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Francesco Mazzoli
At Thu, 25 Apr 2013 19:08:17 +0100, Francesco Mazzoli wrote: Would you expect this to work? newtype DInt a = DInt a newtype DBool a = DBool a type family D a type instance D Int = DInt Int type instance D Bool = DBool Bool a :: D a - a a (DInt x) = x a (DBool x) = x Or

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Alexey Egorov
Would you expect this to work? newtype DInt a = DInt a newtype DBool a = DBool a type family D a type instance D Int = DInt Int type instance D Bool = DBool Bool a :: D a - a a (DInt x) = x a (DBool x) = x Or even better: data family D a data instance D Int = DInt1 Int | DInt2

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Francesco Mazzoli
At Fri, 26 Apr 2013 00:20:36 +0400, Alexey Egorov wrote: Yes, my question is about why different instances are different types even if they have the same type constructor (D). I'm just find it confusing that using GADTs trick it is possible to match on different constructors. See it this way:

Re: [Haskell-cafe] pattern matching on data families constructors

2013-04-25 Thread Roman Cheplyaka
Let's look at it from the operational perspective. In the GADT case, the set of possibilities is fixed in advance (closed). Every GADT constructor has a corresponding tag (a small integer) which, when pattern-matching, tells us which branch to take. In the data family case, the set of

Re: [Haskell-cafe] Pattern matching with singletons

2013-03-27 Thread Paul Brauner
Very helpful, thanks! I may come back with more singleton/type families questions :) On Tue, Mar 26, 2013 at 6:41 PM, Richard Eisenberg e...@cis.upenn.eduwrote: Hello Paul, - Forwarded message from Paul Brauner polux2...@gmail.com - snip - is a ~ ('CC ('Left 'CA)) a

Re: [Haskell-cafe] Pattern matching with singletons

2013-03-26 Thread Richard Eisenberg
Hello Paul, - Forwarded message from Paul Brauner polux2...@gmail.com - snip - is a ~ ('CC ('Left 'CA)) a consequence of the definitions of SCC, SLeft, ... (in which case GHC could infer it but for some reason can't) - or are these pattern + definitions not sufficient to prove

[Haskell-cafe] Pattern matching with singletons

2013-03-25 Thread Paul Brauner
Hello, the following programs seems to hit either some limitation of GHC or maybe I'm just missing something and it behaves the intended way. {-# LANGUAGE TemplateHaskell, TypeFamilies, DataKinds, GADTs #-} module Test where import Data.Singletons data TA = CA data TB = CB data TC = CC

[Haskell-cafe] Pattern matching: multi constructors to same branch

2012-09-11 Thread Thiago Negri
Is it possible to capture more than one constructor in a single pattern matching? I mean, is it possible to generalize the following pattern matching of A and B to a single branch? g f C = [f C] g f v@(A _ n) = f v : g n g f v@(B _ n) = f v : g n For example: g f C = [f C] g f v@(A|B _ n) = f v

Re: [Haskell-cafe] Pattern matching: multi constructors to same branch

2012-09-11 Thread Michael Sloan
I've seen this asked before, and I think some languages support it (ML maybe?). One way to do this is with view patterns: g f C = [f C] g f (getVN - (v, n)) = f v : g f n getVN v@(A _ n) = (v, n) getVN v@(B _ n) = (v, n) (I changed the recursive call to g - figured you meant passing along f)

[Haskell-cafe] pattern matching vs if-then-else

2012-08-12 Thread Maarten Faddegon
Hi there, I am writing a toy compiler in Haskell to further my skills in functional programming. One of the functions I wrote is to determine the iteration count of a loop. I have a number of different test that I want to do and I find myself now testing some of these using pattern matching

Re: [Haskell-cafe] pattern matching vs if-then-else

2012-08-12 Thread Gregory Collins
On Sun, Aug 12, 2012 at 1:30 PM, Maarten Faddegon haskell-c...@maartenfaddegon.nl wrote: = if-- All stmts use the same lcv test_lcv == init_lcv test_lcv == update_lcv test_lcv == update_lcv' -- And the lcv is not updated in the body This

[Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Conal Elliott
Has anyone implemented pattern-matching substitution for haskell-src-exts? - Conal ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Gwern Branwen
On Wed, Jan 18, 2012 at 3:05 PM, Conal Elliott co...@conal.net wrote: Has anyone implemented pattern-matching substitution for haskell-src-exts?  - Conal I don't know what exactly you are looking for, but I remember banging together a function-name search script using haskell-src-exts and

Re: [Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Joachim Breitner
Hi, Am Mittwoch, den 18.01.2012, 12:05 -0800 schrieb Conal Elliott: Has anyone implemented pattern-matching substitution for haskell-src-exts? - Conal without checking the code, I believe that hlint does exactly that; it takes rules (given as Haskell code), matches them as patterns against

Re: [Haskell-cafe] pattern matching instead of prelude.head

2011-09-16 Thread Albert Y. C. Lai
On 11-09-15 10:24 PM, Michael Litchard wrote: Someone commented on StackOverflow that pattern matching the first element of a list was preferable to head. This makes sense intuitively. Could someone articulate the reason why this is true? if null s then e0 else ...(head s)...(tail s)... is a

Re: [Haskell-cafe] pattern matching instead of prelude.head

2011-09-16 Thread Evan Laforge
On Fri, Sep 16, 2011 at 2:34 PM, Albert Y. C. Lai tre...@vex.net wrote: On 11-09-15 10:24 PM, Michael Litchard wrote: Someone commented on StackOverflow that pattern matching the first element of a list was preferable to head. This makes sense intuitively. Could someone articulate the reason

[Haskell-cafe] pattern matching instead of prelude.head

2011-09-15 Thread Michael Litchard
Someone commented on StackOverflow that pattern matching the first element of a list was preferable to head. This makes sense intuitively. Could someone articulate the reason why this is true? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] pattern matching instead of prelude.head

2011-09-15 Thread Lyndon Maydwell
Pattern matching will warn you if you neglect to consider the empty list. On Fri, Sep 16, 2011 at 10:24 AM, Michael Litchard mich...@schmong.org wrote: Someone commented on StackOverflow that pattern matching the first element of a list was preferable to head. This makes sense intuitively.

Re: [Haskell-cafe] pattern matching instead of prelude.head

2011-09-15 Thread wren ng thornton
On 9/15/11 10:24 PM, Michael Litchard wrote: Someone commented on StackOverflow that pattern matching the first element of a list was preferable to head. This makes sense intuitively. Could someone articulate the reason why this is true? (1) If you call (head xs) you are assuming that xs is

[Haskell-cafe] Pattern matching on lazy bytestrings: how does it work?

2011-04-23 Thread Tom Brow
I noticed today that I can pattern match against lazy bytestrings when using the OverloadedStrings extension: import Data.ByteString.Char8 () import Data.ByteString.Lazy.Char8 f :: ByteString - Bool f abc = True f _ = False main = do print $ f $ fromChunks [abc] print $ f $

Re: [Haskell-cafe] Pattern matching on lazy bytestrings: how does it work?

2011-04-23 Thread Stephen Tetley
Surely `fromChunks` is making the both lines in the code snippet the same? Also, in your last sentence I think you've miscalculated the shape of the initial input. Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Pattern matching on lazy bytestrings: how does it work?

2011-04-23 Thread Helgi Kristvin Sigurbjarnarson
On Fri, Apr 22, 2011 at 11:52:32PM -0700, Tom Brow wrote: I noticed today that I can pattern match against lazy bytestrings when using the OverloadedStrings extension: [..] Given that pattern matching is based on data constructors, how is it possible that (Chunk abc Empty) and (Chunk a (Chunk

Re: [Haskell-cafe] Pattern matching, and bugs

2009-12-19 Thread wren ng thornton
Ketil Malde wrote: András Mocsáry amo...@gmail.com writes: Now we have a problem, which is most generally fixed in these ways: C-like: switch ( x ) { Case 0: Unchecked Case 1: Checked Case 2: Unknown Default: Nothing } This is not a fix, this is a workaround for a design bug, namely

[Haskell-cafe] Pattern matching, and bugs

2009-12-18 Thread András Mocsáry
Hello, I was advised respectfully to post my query here. Please, read the whole letter before you do anything, because I tried to construct the problem step by step. Also keep in mind, that the problem I query here is more general, and similar cases occur elsewhere, not just in this particular

Re: [Haskell-cafe] Pattern matching, and bugs

2009-12-18 Thread Jochem Berndsen
András Mocsáry wrote: *My concern* is about predictable failure of sw written in Haskell. To illustrate it let's see a Haskell pattern matching example: And in Haskell pattern matching: switch 1 = Unchecked switch 2 = Checked switch 3 = Unknown Let's say, these are clearly

Re: [Haskell-cafe] Pattern matching, and bugs

2009-12-18 Thread Serguey Zefirov
I would like to have a way for Haskell, not to crash, when my coders write pattern matching without the above mentioned general case. Like having the compiler auto-include those general cases for us, but when those cases got hit, then instead of crashing, it should report some error on stdout 

Re: [Haskell-cafe] Pattern matching, and bugs

2009-12-18 Thread Ketil Malde
András Mocsáry amo...@gmail.com writes: Now we have a problem, which is most generally fixed in these ways: C-like: switch ( x ) { Case 0: Unchecked Case 1: Checked Case 2: Unknown Default: Nothing } This is not a fix, this is a workaround for a design bug, namely

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Andrew Coppin
Casey Hawthorne wrote: Why in a pattern match like score (1 3) = 7 can I not have sizeMax = 3 score (1 sizeMax) = 7 If I had a dollar for every time I've written something like case msg of eVENT_QUIT - ... eVENT_POST - ... eVENT_RESIZE - ... and spent an hour trying to

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Colin Paul Adams
Andrew == Andrew Coppin andrewcop...@btinternet.com writes: Andrew Casey Hawthorne wrote: Why in a pattern match like score (1 3) = 7 can I not have sizeMax = 3 score (1 sizeMax) = 7 If I had a dollar for every time I've written

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Andrew Coppin
Colin Paul Adams wrote: If I had a dollar for every time I've written something like Andrew case msg of eVENT_QUIT - ... eVENT_POST - ... Andrew eVENT_RESIZE - ... Andrew and spent an hour trying to figure out why the messages Andrew aren't being processed right... ;-) So

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Malcolm Wallace
(And, entertainingly, because the incorrect version is perfectly valid source code, no compiler errors or warnings...) If you actually turn on compiler warnings (-Wall), I think you will see something like andrew.hs:10:10: Warning: This binding for `eVENT_QUIT' shadows the existing

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Daniel Fischer
Am Freitag 13 November 2009 11:05:15 schrieb Andrew Coppin: Colin Paul Adams wrote: If I had a dollar for every time I've written something like Andrew case msg of eVENT_QUIT - ... eVENT_POST - ... Andrew eVENT_RESIZE - ... Andrew and spent an hour trying to figure out

Re: [Haskell-cafe] Pattern Matching

2009-11-13 Thread Casey Hawthorne
Thank you to all who replied, very instructive. -- Regards, Casey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] Pattern Matching

2009-11-12 Thread Casey Hawthorne
Why in a pattern match like score (1 3) = 7 can I not have sizeMax = 3 score (1 sizeMax) = 7 -- Regards, Casey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Pattern Matching

2009-11-12 Thread Brandon S. Allbery KF8NH
On Nov 12, 2009, at 21:15 , Casey Hawthorne wrote: Why in a pattern match like score (1 3) = 7 can I not have sizeMax = 3 score (1 sizeMax) = 7 Because it's a pattern, and when you introduce a symbol you are inviting the pattern match to bind what it matched to that name for use

Re: [Haskell-cafe] Pattern Matching

2009-11-12 Thread John Dorsey
Casey, Why in a pattern match like score (1 3) = 7 You probably mean score 1 3 = 7 which applies the function 'score' to two arguments. With the parentheses, it looks like an application of '1' to the argument '3'. But to answer your actual question... can I not have sizeMax = 3

Re: [Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-26 Thread Christopher Done
Well, as I said previously, in reply to Wolfgang, forget the (==) and/or Eq instance; just use the constructors. You don't need an Eq instance for them. You have the expression: foo (a,b) and the definition: foo (X,X) = .. Let's say the predicate for checking that the value of `a' matches X

Re: [Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-23 Thread wren ng thornton
Richard O'Keefe wrote: On Jul 18, 2009, at 6:35 AM, Christopher Done wrote: [non-linear patterns] This kind of matching is provided in Prolog and Erlang. Neither of them lets the user define equality. We find the same issue with n+k patterns(e.g., n+1 as a pattern) l++r

[Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-17 Thread Christopher Done
Wouldn't it be great if pattern variables could be used more than once in a pattern? Like so: foo [x,x,_,x] = The values are the same! foo _ = They're not the same! where this could be rewritten to: foo [x,y,_,z] | x == y x == z = The values are the same! foo _ =

Re: [Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-17 Thread Stefan Holdermans
Christopher, Wouldn't it be great if pattern variables could be used more than once in a pattern? Like so: foo [x,x,_,x] = The values are the same! foo _ = They're not the same! These are called nonlinear patterns. I think Miranda (a precursor of Haskell, sort of) used to have

Re: [Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-17 Thread Wolfgang Jeltsch
Am Freitag, 17. Juli 2009 20:38 schrieb Stefan Holdermans: Christopher, Wouldn't it be great if pattern variables could be used more than once in a pattern? Like so: foo [x,x,_,x] = The values are the same! foo _ = They're not the same! These are called nonlinear

Re: [Haskell-cafe] Pattern matching with where free variables can be used more than once

2009-07-17 Thread Richard O'Keefe
On Jul 18, 2009, at 6:35 AM, Christopher Done wrote: [non-linear patterns] This kind of matching is provided in Prolog and Erlang. Neither of them lets the user define equality. We find the same issue with n+k patterns (e.g., n+1 as a pattern) l++r patterns

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-16 Thread Sebastian Fischer
On Jul 15, 2009, at 2:30 PM, Hans Aberg wrote: If ++ could be pattern matched, what should have been the result of let (x++y)=[1,2,3] in (x,y)? It will branch. In terms of unification, you get a list of substitutions. f :: [a] - ([a],[a]) f (x ++ y) = (x,y) For an argument s, any pair

[Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Magicloud Magiclouds
Hi, I do not notice this before. fun ([0, 1] ++ xs) = .. in my code could not be compiled, parse error. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread minh thu
2009/7/15 Magicloud Magiclouds magicloud.magiclo...@gmail.com: Hi, I do not notice this before. fun ([0, 1] ++ xs) = .. in my code could not be compiled, parse error. ++ is a function; you can't pattern-match on that. Cheers, Thu ___ Haskell-Cafe

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread minh thu
2009/7/15 minh thu not...@gmail.com: 2009/7/15 Magicloud Magiclouds magicloud.magiclo...@gmail.com: Hi, I do not notice this before. fun ([0, 1] ++ xs) = .. in my code could not be compiled, parse error. ++ is a function; you can't pattern-match on that. But here you can match against

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Eugene Kirpichov
Technically, the reason is not that (++) is a function, but that it is not a constructor of the [] type. And, not only is it not a constructor, but it also *can't* be one, because the main characteristic of pattern matching in Haskell is that it is (contrary to Prolog's unification) unambiguous

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Hans Aberg
On 15 Jul 2009, at 12:25, Eugene Kirpichov wrote: If ++ could be pattern matched, what should have been the result of let (x++y)=[1,2,3] in (x,y)? It will branch. In terms of unification, you get a list of substitutions. Hans ___

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Luke Palmer
On Wed, Jul 15, 2009 at 3:08 AM, Hans Aberg hab...@math.su.se wrote: On 15 Jul 2009, at 12:25, Eugene Kirpichov wrote: If ++ could be pattern matched, what should have been the result of let (x++y)=[1,2,3] in (x,y)? It will branch. In terms of unification, you get a list of substitutions.

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Andrew Wagner
Err, technically, aren't functions and constructors mutually exclusive? So if something is a function, it's, by definition, not a constructor? On Wed, Jul 15, 2009 at 6:25 AM, Eugene Kirpichov ekirpic...@gmail.comwrote: Technically, the reason is not that (++) is a function, but that it is not

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Miguel Mitrofanov
No. Most constructors are functions, e.g. Just :: a - Maybe a - a function. On the other hand, Nothing :: Maybe a is a constructor, but not a function. Andrew Wagner wrote: Err, technically, aren't functions and constructors mutually exclusive? So if something is a function, it's, by

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Hans Aberg
On 15 Jul 2009, at 13:22, Luke Palmer wrote: If ++ could be pattern matched, what should have been the result of let (x++y)=[1,2,3] in (x,y)? It will branch. In terms of unification, you get a list of substitutions. f :: [a] - ([a],[a]) f (x ++ y) = (x,y) For an argument s, any pair (x,

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Felipe Lessa
On Wed, Jul 15, 2009 at 08:09:37AM -0400, Andrew Wagner wrote: Err, technically, aren't functions and constructors mutually exclusive? So if something is a function, it's, by definition, not a constructor? I guess what Eugene Kirpichov meant was that not being a function (and being a

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Richard O'Keefe
On Jul 15, 2009, at 9:59 PM, minh thu wrote: 2009/7/15 Magicloud Magiclouds magicloud.magiclo...@gmail.com: Hi, I do not notice this before. fun ([0, 1] ++ xs) = .. in my code could not be compiled, parse error. ++ is a function; you can't pattern-match on that. Doesn't matter, it's not

Re: [Haskell-cafe] Pattern matching does not work like this?

2009-07-15 Thread Richard O'Keefe
On Jul 15, 2009, at 9:57 PM, Magicloud Magiclouds wrote: Hi, I do not notice this before. fun ([0, 1] ++ xs) = .. in my code could not be compiled, parse error. I apologise to everyone for my previous message in this thread. There was a Haskell message in amongst some Erlang messages, and

[Haskell-cafe] pattern matching on date type

2009-01-01 Thread Max.cs
thanks! suppose we have data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving Show and how I could define a function foo :: a - Tree a that foo a = Leaf a where a is not a type of Tree foo b = b where b is one of the type of Tree (Leaf or Branch) ? The following

Re: [Haskell-cafe] pattern matching on date type

2009-01-01 Thread Bulat Ziganshin
Hello Max.cs, Thursday, January 1, 2009, 11:36:24 AM, you wrote: seems that you come from dynamic languages :) Haskell has static typing meaning that your function can accept either Tree or a as arguments. so you should convert a to Tree explicitly, using Leaf thanks!  

RE: [Haskell-cafe] Pattern matching on numbers?

2008-11-19 Thread Tobias Bexelius
Cafe Subject: Re: [Haskell-cafe] Pattern matching on numbers? On Tue, Nov 18, 2008 at 6:56 PM, Henning Thielemann [EMAIL PROTECTED] wrote: On Tue, 18 Nov 2008, Ryan Ingram wrote: How does this work? fac n = case n of 0 - 1 _ - n * fac (n-1) ghci :t fac fac :: (Num t) = t - t

[Haskell-cafe] Pattern matching on numbers?

2008-11-18 Thread Ryan Ingram
How does this work? fac n = case n of 0 - 1 _ - n * fac (n-1) ghci :t fac fac :: (Num t) = t - t The first line of fac pattern matches on 0. So how does this work over any value of the Num typeclass? I know that the 1 on the rhs of fac are replaced with (fromInteger 1), but what

Re: [Haskell-cafe] Pattern matching on numbers?

2008-11-18 Thread Henning Thielemann
On Tue, 18 Nov 2008, Ryan Ingram wrote: How does this work? fac n = case n of 0 - 1 _ - n * fac (n-1) ghci :t fac fac :: (Num t) = t - t The first line of fac pattern matches on 0. So how does this work over any value of the Num typeclass? I know that the 1 on the rhs of fac are

Re: [Haskell-cafe] Pattern matching on numbers?

2008-11-18 Thread David Menendez
On Tue, Nov 18, 2008 at 6:56 PM, Henning Thielemann [EMAIL PROTECTED] wrote: On Tue, 18 Nov 2008, Ryan Ingram wrote: How does this work? fac n = case n of 0 - 1 _ - n * fac (n-1) ghci :t fac fac :: (Num t) = t - t The first line of fac pattern matches on 0. So how does this work

[Haskell-cafe] Pattern matching error

2007-12-06 Thread georg86
Hello! I need to write a function which should is supposed to merge multiple entries with the same key (out of a sorted key-value-list) into one single entry. However, I keep getting a pattern matching error. (For example, for input [('b',[5]),('b',[4]),('b',[1]),('b',[6])]: Program error:

Re: [Haskell-cafe] Pattern matching error

2007-12-06 Thread Brent Yorgey
kmerge ((x,[y]):[]) = [(x,[y])] Matching on [y] like this will only match lists with a single element (and bind y to that element). You probably just want to say kmerge ((x,y):[]) = [(x,y)] etc., which will bind y to the entire list. -Brent ___

Re: [Haskell-cafe] Pattern matching error

2007-12-06 Thread Philip Weaver
If you add a third pattern, you can see exactly what it's failing to match: kmerge x = error (show x) In order to do this, you just need to add Show constraints for a and b in the type of kmerge: kmerge :: (Show a, Show b, Eq a) = [(a,[b])]-[(a,[b])] You'll find that the pattern that

Re: [Haskell-cafe] Pattern matching error

2007-12-06 Thread Ketil Malde
Philip Weaver [EMAIL PROTECTED] writes: You'll find that the pattern that it's failing to match is: [('b',[5,4]),('b',[1]),('b',[6])] You could also use ghc with -Wall, which will tell you exactly which cases you've omitted. -k -- If I haven't seen further, it is by standing in the

[Haskell-cafe] Pattern matching articles/explanations

2007-08-16 Thread Ian Duncan
So what I noticed that A Gentle Introduction to Haskell mentioned that wild-cards are useful in constructors. For example: head (x:_) = x So, does that offer any performance benefits over: head (x:xs) = x Or is it primarily to indicate to the coder that xs is useless? I get the impression

Re: [Haskell-cafe] Pattern matching articles/explanations

2007-08-16 Thread Neil Mitchell
Hi So what I noticed that A Gentle Introduction to Haskell mentioned that wild-cards are useful in constructors. For example: head (x:_) = x So, does that offer any performance benefits over: head (x:xs) = x No. They are exactly the same. _ simply means a new unique name. Or is it

[Haskell-cafe] Pattern matching articles/explanations

2007-08-15 Thread Ian Duncan
Hello everyone, I've been working on improving my Haskell knowledge, and in doing so, I have read a little about as-patterns as well as some form of pattern that uses ~ that I don't really understand. I suspect there are even more lesser-known pattern matching expressions than just these,

[Haskell-cafe] Pattern matching

2007-01-15 Thread Stefan Aeschbacher
Hi I sometimes have a function definition similar to this: myFunction x@(Constructor1 _ _ _ _ _ _) = ... myFunction x@(Constructor2 _ _ _ _ _ _ _ _) = ... which in my eyes is not very elegant and easy to type. Is there an easier way to switch on the different constructors of a type

Re: [Haskell-cafe] Pattern matching

2007-01-15 Thread Stefan O'Rear
On Mon, Jan 15, 2007 at 10:09:10AM +0100, Stefan Aeschbacher wrote: Hi I sometimes have a function definition similar to this: myFunction x@(Constructor1 _ _ _ _ _ _) = ... myFunction x@(Constructor2 _ _ _ _ _ _ _ _) = ... myFunction [EMAIL PROTECTED] = ... myFunction [EMAIL PROTECTED] =

Re: [Haskell-cafe] Pattern matching

2007-01-15 Thread Neil Mitchell
Hi Stefan, myFunction x@(Constructor1 _*) = ... myFunction x@(Constructor2 _*) = ... myFunction x@(Constructor1 {}) = myFunction x@(Constructor2 {}) = myFunction2 (Constructor1 _* a _*) = ... could be possible as long as the pattern is non-ambiguous (in this case, only one variable with

Re: [Haskell-cafe] Pattern matching

2007-01-15 Thread Stefan Aeschbacher
2007/1/15, Stefan O'Rear [EMAIL PROTECTED]: On Mon, Jan 15, 2007 at 10:09:10AM +0100, Stefan Aeschbacher wrote: Hi I sometimes have a function definition similar to this: myFunction x@(Constructor1 _ _ _ _ _ _) = ... myFunction x@(Constructor2 _ _ _ _ _ _ _ _) = ... myFunction [EMAIL

[Haskell-cafe] Pattern matching problems

2005-09-23 Thread Marcin Tustin
In case I confused anyone, this is a separate issue. Thanks for your attention and help. On Sat, Sep 24, 2005 at 01:20:22AM +0100, Marcin Tustin wrote: For some reason the following code is producing an error message from ghci that the the patterns are non-exhaustive. Does anyone have