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:
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
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
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
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
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:
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
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
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
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
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
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)
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
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
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
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
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
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
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
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
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.
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
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 $
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
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
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
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
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
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
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
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
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
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
(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
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
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
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
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
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
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
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
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 _ =
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
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
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
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
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
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
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
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
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
___
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.
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
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
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,
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
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
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
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
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!
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
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
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
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
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:
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
___
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
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
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
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
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,
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
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] =
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
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
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
76 matches
Mail list logo