Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: let , equations, and monads (Chadda? Fouch?)
2. Partition a list recursively (Alexandre Delano?)
3. Re: Partition a list recursively (Francesco Ariis)
----------------------------------------------------------------------
Message: 1
Date: Tue, 03 Nov 2015 06:56:59 +0000
From: Chadda? Fouch? <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] let , equations, and monads
Message-ID:
<canfjzrbzxxmp6yvzkmku-kbp3zwvlmbve8rosac-qhpwmk8...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello,
Le mer. 28 oct. 2015 ? 15:59, PATRICK BROWNE <[email protected]> a
?crit :
> {- From Learn Haskell Fast and Hard : 4.3.1. Maybe is a monad
> http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/#maybe-monad
>
> Concerning the code below I have the following questions:
> 1) Are eligibleLet and eligibleEquational operationally equivalent (i.e.
> perform the same operations) and/or semantically equivalent(i.e.
> Church-Rosser)?
>
A priori, they're only semantically equivalent since in eligibleEquational
intermediary computation are repeated whereas in eligibleLet they're only
effectued once.
> 2) Apart from the return type of Maybe instead of Bool how does
> eligibleMonad differ from eligibleLet?
>
eligibleMonad is nice and readable while eligibleLet is a tiresome mess to
write and maintain...
Basically in eligibleMonad the logic that checks whether an operation is
possible is rolled into the monadic operations themselves whereas in
eligibleLet you have to check every operation validity yourself (so you can
forget one or do it incorrectly).
Note that with more familiarity with monads, you would probably rewrite
eligibleMonad to avoid naming the intermediary account (and thus avoid any
confusion between versions) :
eligibleMonad account = depositM 100 account
>>= withdrawM 200
>>= depositM 100
>>= withdrawM 300
>>= depositM 1000
>> Just True
This would make it very easy to add or remove operations.
--
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151103/d67bd0e9/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 3 Nov 2015 11:12:31 +0100
From: Alexandre Delano? <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Partition a list recursively
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Hello,
I am looking for such function:
function :: Ord a => [a] -> [a] -> [[a]]
function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]]
Question: does it exist already ? If no, continue:
Let:
partIt :: Ord a => a -> [a] -> [[a]]
partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs]
example:
partIt 1 [0..5] == [[0,1],[2,3,4,5]]
Question: How to define recursively partIt
1) with a list as parameter ?
2) recursively on the second part of the list ?
Thanks for help,
--
Alexandre Delano?
------------------------------
Message: 3
Date: Tue, 3 Nov 2015 12:46:29 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Partition a list recursively
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On Tue, Nov 03, 2015 at 11:12:31AM +0100, Alexandre Delano? wrote:
> Hello,
> I am looking for such function:
>
> function :: Ord a => [a] -> [a] -> [[a]]
> function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]]
>
> Question: does it exist already ?
``Data.List.Split`` (from package ``split``) may have what you are
looking for.
>
> Let:
>
> partIt :: Ord a => a -> [a] -> [[a]]
> partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs]
> example:
> partIt 1 [0..5] == [[0,1],[2,3,4,5]]
>
> Question: How to define recursively partIt
> 1) with a list as parameter ?
> 2) recursively on the second part of the list ?
With pattern matching:
partIt :: Ord a => a -> [a] -> [[a]]
partIt [] xs = xs
partIt (m:ms) xs = let (a, b) = span (<= m) xs in (a : partIt ms b)
?> partIt [1,3,6] [0..6]
[[0,1],[2,3],[4,5,6],[]] -- expected: splits on 6 too
Learn You a Haskell has nice section on pattern matching.
Did this answer the question?
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 89, Issue 3
****************************************