Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Case statements shorter ([email protected])
   2.  Re: How to Install Gtk2Hs on Windows? (John Smith)
   3. Re:  Case statements shorter (Roel van Dijk)


----------------------------------------------------------------------

Message: 1
Date: Mon, 1 Nov 2010 18:23:14 +0000
From: "[email protected]" <[email protected]>
Subject: Re: [Haskell-beginners] Case statements shorter
To: Angel Alonso <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes


> Hi,
>
> I have the following piece of code:
>
> n = 3
> case n of
>    3 -> "Something"
>    4 -> "Something"
>   _ -> "Other"
>
> Is it possible to shorten the case statement into something like  
> this?:
>
> n = 3
> case n of
>    3 or 4 -> "Something"
>    _ -> "Other"

Is the following what you are looking for?

   case n of
     _ | n == 3 || n == 4 -> "something"
     _ -> "other"

Some reminders:
* Guards are allowed in case expressions
* _ is not a special keyword in haskell. It's a regular variable so  
will always match. It's usually used when you don't use it's value in  
the right hand side or when it adds no information. In this case its  
value will be n so there is no reason to introduce another name.

Also if you just have one special case you could use if then else:

   if n == 3 || n ==4
     then "something"
     else "other"

Another solution is to take the common expression out. This is useful  
if you are matching more complex structures in your case expression:

let st = "something"
in case n of
    Left x | x == 3 || x == 4 -> st
    Right _ -> st
    _ -> "other"

Best regards. 


------------------------------

Message: 2
Date: Mon, 01 Nov 2010 21:08:25 +0200
From: John Smith <[email protected]>
Subject: [Haskell-beginners] Re: How to Install Gtk2Hs on Windows?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Seems that the Gtk+ installed with Glade wasn't good enough. I did a fresh 
installation of the all-in-one bundele, and 
it works now.

On 01/11/2010 13:28, John Smith wrote:
> I tried following the directions on 
> http://jystic.com/2010/10/20/installing-gtk2hs-on-windows/, but when I run 
> cabal
> install gtk, I get
>
> * Missing C libraries: z, cairo
> * Missing C libraries: gobject-2.0, glib-2.0, intl
>
> I seem to have everything asked for in the PATH. pkg-config reports that Gtk+ 
> 2.16.2 is installed.



------------------------------

Message: 3
Date: Tue, 2 Nov 2010 10:11:54 +0100
From: Roel van Dijk <[email protected]>
Subject: Re: [Haskell-beginners] Case statements shorter
To: "[email protected]" <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 1, 2010 at 7:23 PM, [email protected] <[email protected]> wrote:
> * _ is not a special keyword in haskell. It's a regular variable so will
> always match. It's usually used when you don't use it's value in the right
> hand side or when it adds no information. In this case its value will be n
> so there is no reason to introduce another name.

This is incorrect. _ is a pattern not a variable.

I can write

  f (_:_) = "bla"

but not

  f (x:x) = "bla"
  Conflicting definitions for `x' In the definition of `f'

So _ is a pattern that always matches but is never bound to a value.

Regards,
Roel


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 29, Issue 2
****************************************

Reply via email to