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. basic State Monad (Imants Cekusins)
2. Re: basic State Monad (Rein Henrichs)
3. Re: basic State Monad (Imants Cekusins)
4. Re: basic State Monad (MJ Williams)
5. Re: basic State Monad (Imants Cekusins)
6. Re: Haskell code optimisation (Magnus Therning)
7. Re: Doubts about functional programming paradigm
(Henk-Jan van Tuyl)
8. Re: Doubts about functional programming paradigm
(Imants Cekusins)
----------------------------------------------------------------------
Message: 1
Date: Sun, 13 Dec 2015 18:14:29 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] basic State Monad
Message-ID:
<cap1qinzsj-qmt0vghhnyba1ondma+bt2exrlf3axiz0sg9l...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
This snippet increments integer n times using state monad.
How to call:
main 10 5
module BasicState where
import Control.Monad.State.Strict
import Debug.Trace
type St a = State a a
-- caller is not aware that main uses state
-- mai is a pure function
main :: Int -> Int -> Int
main start0 repeat0 =
evalState (repeatN repeat0) start0
-- state-passing computation
repeatN :: Int -> St Int
repeatN n0 -- repeat n times
| n0 < 1 = get -- current state
| otherwise = do
withState pureStateModifier get -- update state
repeatN $ n0 - 1 -- recurse
-- state unaware modifier function
pureStateModifier :: Int -> Int
pureStateModifier = (+ 1)
------------------------------
Message: 2
Date: Sun, 13 Dec 2015 21:03:02 +0000
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic State Monad
Message-ID:
<cajp6g8wjnnqkw04hhh1bkytyglquxjgtpevyqw7dp0auhsb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I don't think that code snippets presented without motivation, explanation,
or commentary are an effective way to teach.
On Sun, Dec 13, 2015 at 9:14 AM Imants Cekusins <[email protected]> wrote:
> This snippet increments integer n times using state monad.
>
> How to call:
> main 10 5
>
>
>
>
> module BasicState where
>
> import Control.Monad.State.Strict
> import Debug.Trace
>
> type St a = State a a
>
>
> -- caller is not aware that main uses state
> -- mai is a pure function
> main :: Int -> Int -> Int
> main start0 repeat0 =
> evalState (repeatN repeat0) start0
>
>
> -- state-passing computation
> repeatN :: Int -> St Int
> repeatN n0 -- repeat n times
> | n0 < 1 = get -- current state
> | otherwise = do
> withState pureStateModifier get -- update state
> repeatN $ n0 - 1 -- recurse
>
>
> -- state unaware modifier function
> pureStateModifier :: Int -> Int
> pureStateModifier = (+ 1)
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151213/18b956a9/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 13 Dec 2015 22:10:36 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic State Monad
Message-ID:
<cap1qinzrpa9n361b1kxga-nyu2ao6gplywou6cb0sf+yqwf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> I don't think that code snippets presented without motivation,
explanation, or commentary are an effective way to teach.
I agree, they are not.
However it took me a better part of today to write this snippet.
If I saw it as it is, I could proceed with my coding task without delay.
I posted it just in case someone faces a similar problem and could benefit
from it.
This is to complement other available materials, not to replace them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151213/3c01386e/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 13 Dec 2015 21:36:45 +0000
From: MJ Williams <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic State Monad
Message-ID:
<caakj9fn6bsf710m19tgqm4uwh3g30etswxab8hmpfobmyrg...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Perhaps you would be so kind as to provide the `motivation',
`explanation' and maybe some `commentary' for good measure. *smile*
On 13/12/2015, Imants Cekusins <[email protected]> wrote:
>> I don't think that code snippets presented without motivation,
> explanation, or commentary are an effective way to teach.
>
> I agree, they are not.
>
> However it took me a better part of today to write this snippet.
>
> If I saw it as it is, I could proceed with my coding task without delay.
>
> I posted it just in case someone faces a similar problem and could benefit
> from it.
>
> This is to complement other available materials, not to replace them.
>
------------------------------
Message: 5
Date: Sun, 13 Dec 2015 22:54:36 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic State Monad
Message-ID:
<CAP1qinYHDKTCG-y475YzyA=E5=3bOUOy4pf3c=0aay99cv-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> Perhaps you would be so kind as to provide the `motivation',
`explanation' and maybe some `commentary' for good measure.
Well anyone could ask specific questions, and anyone could attempt to
answer, couldn't they? Let's try.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151213/70afda81/attachment-0001.html>
------------------------------
Message: 6
Date: Sun, 13 Dec 2015 22:58:26 +0100
From: Magnus Therning <[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] Haskell code optimisation
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Sumit Sahrawat, Maths & Computing, IIT (BHU) writes:
> Graham Hutton's paper "A tutorial on the expressiveness and universality of
> folds", provides a good introduction to folds, and implements the Ackerman
> function as an example.
> Folds were the first stumbling point for me when learning Haskell, and this
> paper helped me a lot.
To save others from a search: http://www.cs.nott.ac.uk/~pszgmh/fold.pdf
/M
--
Magnus Therning OpenPGP: 0x927912051716CE39
email: [email protected] jabber: [email protected]
twitter: magthe http://therning.org/magnus
Failure is not an option. It comes bundled with the software.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151213/b97dae81/attachment-0001.sig>
------------------------------
Message: 7
Date: Mon, 14 Dec 2015 00:51:11 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>,
"Dimitri DeFigueiredo" <[email protected]>
Subject: Re: [Haskell-beginners] Doubts about functional programming
paradigm
Message-ID: <op.x9lwjqkupz0j5l@alquantor>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
On Sat, 12 Dec 2015 01:56:48 +0100, Dimitri DeFigueiredo
<[email protected]> wrote:
:
> Couldn't match expected type ?r? with actual type ?COParseResult?
> ?r? is a rigid type variable bound by
> the type signature for
> getParseResult :: ParseResult r => String -> IO r
> ...
>
> I have a PhD in computer science, but never really liked programming
> languages back then and somehow I never learned what a "rigid type
> variable" is.
See
[Haskell-cafe] What is a rigid type variable?
https://mail.haskell.org/pipermail/haskell-cafe/2008-June/044622.html
:
> But would anyone care to explain to a
> novice in a couple paragraphs why foldl (+) 0 [1..10^9] may take 10 Gigs
> of RAM to calculate?
The foldl builds up a very long expression and evaluates it after the last
element of the list is reached (the evaluation is non-strict, or lazy). If
you use foldl' (from Data.List) instead, the calculation is done per
element (the evaluation is strict).
For more details, see
Foldr Foldl Foldl'
https://wiki.haskell.org/Foldr_Foldl_Foldl'
Lazy vs. non-strict
https://wiki.haskell.org/Lazy_vs._non-strict
Regards,
Henk-Jan van Tuyl
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 8
Date: Mon, 14 Dec 2015 01:02:24 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Doubts about functional programming
paradigm
Message-ID:
<CAP1qinb8X9vOJN7A5MNtR_eELv39tfEEtv3Bh0gJ=ke1bxx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> The foldl builds up a very long expression and evaluates it after the
last element of the list is reached (the evaluation is non-strict, or
lazy). If you use foldl' (from Data.List) instead, the calculation is done
per element (the evaluation is strict).
Is it possible to write a wrapping function (if it does not already exist)
which would analyze inputs and apply appropriate fold (foldl, foldl',
foldr, foldr') or safeguard (return Left warning) against following the
10Gb ram route - if this can be avoided?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151214/3faf04d7/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 90, Issue 25
*****************************************