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.  How to Install Gtk2Hs on Windows? (John Smith)
   2.  Case statements shorter (Angel Alonso)
   3. Re:  Case statements shorter (Ozgur Akgun)
   4. Re:  Case statements shorter (Daniel Fischer)
   5.  Re: Case statements shorter (Angel Alonso)


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

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

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: 2
Date: Mon, 1 Nov 2010 16:59:33 +0100
From: Angel Alonso <[email protected]>
Subject: [Haskell-beginners] Case statements shorter
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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"

Thanks.

-- Angel Alonso


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

Message: 3
Date: Mon, 1 Nov 2010 16:25:07 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Case statements shorter
To: Angel Alonso <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

No, not if you use case. But you can do better with a simple if, in this
particular case.

if n == 3 || n == 4
then "Something"
else "Other"

Or even,

if n `elem` [3,4]
them "Something"
else "Other"

HTH,

On 1 November 2010 15:59, Angel Alonso <[email protected]> wrote:

> 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"
>
> Thanks.
>
> -- Angel Alonso
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20101101/45040dfe/attachment-0001.html

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

Message: 4
Date: Mon, 1 Nov 2010 17:28:26 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Case statements shorter
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Monday 01 November 2010 16:59:33, Angel Alonso wrote:
> 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"

No, case does a pattern match. You can do

case n of
   _ | n `elem` [3,4] -> "Something"
     | otherwise -> "Other"

however, which becomes really useful if you have

case expression of
  pat1 | cond11 -> thing11
       | cond12 -> thing12
       | otherwise -> thing1Other
  pat2 | cond21 -> thing21
   ...

>
> Thanks.
>
> -- Angel Alonso



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

Message: 5
Date: Mon, 1 Nov 2010 17:38:24 +0100
From: Angel Alonso <[email protected]>
Subject: [Haskell-beginners] Re: Case statements shorter
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Thank you for all your responses. I didn't know about the elem function.


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

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


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

Reply via email to