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: Pattern guard inside function (Daniel Trstenjak)
2. Re: cascade of if statements (Kim-Ee Yeoh)
3. Re: cascade of if statements (Brandon Allbery)
----------------------------------------------------------------------
Message: 1
Date: Thu, 1 Nov 2012 12:06:18 +0100
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] Pattern guard inside function
To: [email protected]
Message-ID: <20121101110618.GA2157@machine>
Content-Type: text/plain; charset=iso-8859-1
Hi Nathan,
On Wed, Oct 31, 2012 at 03:02:45PM +0100, Nathan H?sken wrote:
> collInfo' :: Maybe Rect -> Maybe Rect -> Maybe CollInfo
> collInfo' mr1 mr2 =
> r1 <- mr1
> r2 <- mr2
> collInfo r1 r2
that doesn't seem to be that nice, because you could call it with
any two Rects and get a CollInfo, even if they don't collide:
collInfo' (Just $ Rect 0 0 1 1) (Just $ Rect 5 5 1 1)
Having Maybes as arguments just doesn't feel that right.
You could separate the collision test:
colliding :: Rect -> Rect -> Bool
colliding (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) =
not $ x1 + w1 < x2
|| x1 > x2 + w2
|| y1 + h1 < y2
|| y1 > y2 + h2
collInfo :: Rect -> Rect -> Maybe (Rect, Rect)
collInfo r1 r2
| colliding r1 r2 = Just (r1, r2)
| otherwise = Nothing
Greetings,
Daniel
------------------------------
Message: 2
Date: Thu, 1 Nov 2012 22:58:58 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] cascade of if statements
To: Emmanuel Touzery <[email protected]>
Cc: [email protected]
Message-ID:
<capy+zdsys8xitakpdqy+rvfhpv3wfx30dbsmamgcbqr6k9c...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Thu, Nov 1, 2012 at 5:03 AM, Emmanuel Touzery <[email protected]> wrote:
> Thank you that is very interesting... this is really impressive with
> haskell that it's so "easy" to add such operators, that they don't need to
> be builtin.
>
This can't be emphasized enough to people starting out. Haskell doesn't
have operators in the same sense as other languages. All those punctuation
symbols are ordinary functions and can be user- or library-defined to mean
anything.
There are also primitive functions and functions defined via the FFI but
those aren't baked into the language either.
<tangential rant> There is a reason why the prelude is called as such and
not "the standard library", which is a term I don't think you can find in
the language specs. That said, people looking for "the standard library"
are usually directed to the Haskell Platform, again not because there _is_
such a thing, but because their needs are best met there.
-- Kim-Ee
On Thu, Nov 1, 2012 at 5:03 AM, Emmanuel Touzery <[email protected]> wrote:
> Thank you that is very interesting... this is really impressive with
> haskell that it's so "easy" to add such operators, that they don't need to
> be builtin.
>
> Thanks for your time, it was not wasted!
>
>
> On Wed, Oct 31, 2012 at 6:26 PM, Daniel Trstenjak <
> [email protected]> wrote:
>
>>
>> On Wed, Oct 31, 2012 at 06:14:52PM +0100, Daniel Trstenjak wrote:
>> > (<&&>) :: Monad m => m Bool -> m Bool -> m Bool
>> > (<&&>) m1 m2 = do
>> > r1 <- m1
>> > if r1 then m2 else return False
>> >
>> >
>> > (<||>) :: Monad m => m Bool -> m Bool -> m Bool
>> > (<||>) m1 m2 = do
>> > r1 <- m1
>> > if r1 then return True else m2
>>
>> That the operators behave like the boolean ones we should have the same
>> fixity declarations:
>>
>> infixr 3 (<&&>)
>> infixr 2 (<||>)
>>
>>
>> Greetings,
>> Daniel
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121101/437d11f5/attachment-0001.htm>
------------------------------
Message: 3
Date: Thu, 1 Nov 2012 12:47:00 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] cascade of if statements
To: Kim-Ee Yeoh <[email protected]>
Cc: [email protected]
Message-ID:
<cakfcl4ueho46fxajka7j7r809nnyh0yq0y4zrkqf8sbm8d-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Thu, Nov 1, 2012 at 11:58 AM, Kim-Ee Yeoh <[email protected]> wrote:
> <tangential rant> There is a reason why the prelude is called as such and
> not "the standard library", which is a term I don't think you can find in
> the language specs.
The word "standard" does not appear as such, but it can be inferred...
http://www.haskell.org/onlinereport/haskell2010/haskellpa2.html#x20-192000II
Haskell 2010 Language Report: The Haskell 2010 Libraries
Note however that the language of the Report's preface applies: this is
not intended to be a standard library in the sense usually meant by
newcomers, but a conservative minimum required by all conformant
implementations. (It's also not limited to the Prelude; neither was
Haskell98's version.)
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix/linux, openafs, kerberos, infrastructure http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121101/2694d554/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 53, Issue 2
****************************************