[Haskell-cafe] pattern matches are overlapped

Brandon Allbery allbery.b at gmail.com
Thu Oct 23 18:27:26 UTC 2014


On Thu, Oct 23, 2014 at 2:23 PM, <briand at aracnet.com> wrote:

> keyboardAct a d p (SpecialKey KeyLeft) Down shiftDown = do
>   (x,y) <- get p
>   p $= (x-0.1, y)
>
> where,
>
>    shiftDown = Modifiers {shift=Down, ctrl=Up, alt=Up}
>

You can't use a definition like that directly in a pattern match; a name
starting with lowercase is a new binding, not the value of some existing
binding. You can instead use a guard or, sometimes, a pattern guard.

That is,

    keyboardAct a d p (SpecialKey KeyLeft) Down shiftDown =

is identical to

    keyboardAct a d p (SpecialKey KeyLeft) Down x =

aside from the name of the new local binding it introduces. It does *not*
use an existing binding for shiftDown or x, it always creates a new one.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141023/a766f21b/attachment.html>


More information about the Haskell-Cafe mailing list