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: Early return in IO monad (Kim-Ee Yeoh)
2. Re: Pattern match(es) are overlapped ... but I do not see
that they do (Brent Yorgey)
3. Re: Pattern match(es) are overlapped ... but I do not see
that they do (Michael Orlitzky)
----------------------------------------------------------------------
Message: 1
Date: Sun, 1 Sep 2013 22:37:35 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Early return in IO monad
Message-ID:
<capy+zdql-r7n_eg5q4pbnzq11soiodsjt+pdq8o2g3febqj...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Sun, Sep 1, 2013 at 1:05 AM, Nathan H?sken <[email protected]>wrote:
> The eqivalent do in C:
>
> void doBlock() {
> if (some preCondition) {
> return;
> }
> ...
> }
>
Brent and Tony have already given the closest Haskell equivalents.
For completeness, it's worth pointing out that the above C is equivalent to
void doBlock() {
if (some preCondition) {
return;
} else {
...
}
}
So you can write it similarly in Haskell using if/then/else.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130901/21c30037/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 1 Sep 2013 16:32:37 -0400
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Pattern match(es) are overlapped ...
but I do not see that they do
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Aug 31, 2013 at 11:39:22PM -0400, Michael Orlitzky wrote:
> On 08/31/2013 11:07 PM, Edward Z. Yang wrote:
> > Well, the trouble is at the source language level there
> > is no way to tell if some_var is /actually/ a constant, or
> > some complicated expression. So you could do guards:
> >
> > case res of
> > _ | res == wxID_CANCEL -> True
> > | res == wxID_NO -> False
> > | ...
> >
> > The suggestion to use an ADT is, you write a helper fucntion
> > which does this case-split first, and then you do regular pattern
> > matching on the result. If you need to do this multiple times,
> > it saves you a bunch of typing; it also gives you one place
> > to write the error code when the integer is not one of these
> > three values.
> >
>
> In a perfect world, these constants would be defined as part of an
> enumeration type, correct? For example,
>
> data WxId = WxIdCancel | WxIdNo | WxIdYes ... deriving (Enum)
>
> in which case the original attempt would have succeeded since it would
> be matching on a constructor.
>
> However, unless there are constants defined for 0,1,... this approach
> won't work automatically -- the derived Enum instance starts at zero and
> increments by one. The library would have to define a custom Enum
> instance and it would add a good bit of code.
In this case I wouldn't recommend making a custom Enum instance
(because the Enum class makes all sorts of assumptions that would be
hard to satisfy); I would just make a pair of functions
wxIdToCode :: WxId -> Int
wxCodeToId :: Int -> Maybe WxId
-Brent
------------------------------
Message: 3
Date: Sun, 01 Sep 2013 18:22:56 -0400
From: Michael Orlitzky <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Pattern match(es) are overlapped ...
but I do not see that they do
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 09/01/2013 04:32 PM, Brent Yorgey wrote:
>>
>> In a perfect world, these constants would be defined as part of an
>> enumeration type, correct? For example,
>>
>> data WxId = WxIdCancel | WxIdNo | WxIdYes ... deriving (Enum)
>>
>> in which case the original attempt would have succeeded since it would
>> be matching on a constructor.
>>
>> However, unless there are constants defined for 0,1,... this approach
>> won't work automatically -- the derived Enum instance starts at zero and
>> increments by one. The library would have to define a custom Enum
>> instance and it would add a good bit of code.
>
> In this case I wouldn't recommend making a custom Enum instance
> (because the Enum class makes all sorts of assumptions that would be
> hard to satisfy); I would just make a pair of functions
>
> wxIdToCode :: WxId -> Int
> wxCodeToId :: Int -> Maybe WxId
>
Oh, I wasn't suggesting that the OP do this. I was wondering aloud
whether or not there was a reason why wxHaskell doesn't define these
constants as a separate data type rather than a series of Ints (maybe
there's a good reason).
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 63, Issue 3
****************************************