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: Doubts about functional programming paradigm
(Imants Cekusins)
2. Re: Doubts about functional programming paradigm (MJ Williams)
3. Re: foldr, Foldable and right-side folding (Kim-Ee Yeoh)
4. Re: Haskell code optimisation (Abhishek Kumar)
5. Re: Haskell code optimisation (Kim-Ee Yeoh)
----------------------------------------------------------------------
Message: 1
Date: Sat, 12 Dec 2015 02:03:43 +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:
<cap1qinanj1czg844c4asvcc1qcjxaxmo+ojmsqwgkl0820y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> What is a `race condition'?
Multiple threads accessing and modifying shared resource (value) in
uncontrolled order, which may differ each time code runs.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151212/c447c0ce/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 12 Dec 2015 01:07:49 +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] Doubts about functional programming
paradigm
Message-ID:
<caakj9fpdho8i+hpxkjafpwe4mhdusm1r0l7ewdxrbnxvap-...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Just out of interest, what was your PHD in?
On 12/12/2015, Imants Cekusins <[email protected]> wrote:
>> What is a `race condition'?
>
> Multiple threads accessing and modifying shared resource (value) in
> uncontrolled order, which may differ each time code runs.
>
------------------------------
Message: 3
Date: Sat, 12 Dec 2015 11:10:45 +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] foldr, Foldable and right-side
folding
Message-ID:
<capy+zdtfxfo-gzsitemtmoz4vt4phyrc0xr1gwqbg_zaan0...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Sun, Dec 6, 2015 at 10:24 AM, Daniel Bergey <[email protected]> wrote:
> data Li a = Nil | Cons a (Li a)
> > deriving (Show)
> >
> > instance Foldable Li where
> > foldr f b Nil = b
> > foldr f b (Cons a y) = foldr f (f a b) y
> >
> > So I'm trying out foldr for my type:
> >> foldr Cons Nil (Cons 1 (Cons 2 Nil))
> > Cons 2 (Cons 1 Nil)
> >
> > This shows my foldr implementation i'm not folding from right side,
> > but how can I possibly do that - the data could have been an infinite
> > stream.
>
> A right fold on an infinite stream can terminate if the function f
> sometimes discards it's second argument. For example, takeWhile can be
> implemented this way.
>
> You are right that `foldr Cons Nil` or `foldr (:) []` will not terminate
> on an infinite list.
It's slightly misleading to say: `foldr (:) []` -- call it the foo fold --
will not terminate on an infinite list.
It suggests that folds normally terminate on an infinite list whereas this
one doesn't, with the implied meaning that the foo fold is "defective" in
some sense.
Fact is, the foo fold is perfectly cromulent. It's equivalent to the
identity function on both finite and infinite lists. So the foo fold
doesn't terminate on an infinite list because -- well, duh -- the infinite
list doesn't terminate.
Also not all folds are designed to terminate. E.g. a list map makes sense
even for infinite lists. A list map can be written as a fold. Such a fold
wouldn't terminate either.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151212/fb78e49f/attachment-0001.html>
------------------------------
Message: 4
Date: Sat, 12 Dec 2015 14:49:58 +0530
From: Abhishek Kumar <[email protected]>
To: 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:
<CAEAgXqWoULZc4+Z1TMbRxxGV+Zf=oze8kccn73dyw90wkx9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks Kim for your answer but as far as I understand strict evaluation
should save in space as expression is not expanded in terms of thunks,but I
can't understand time savings.Can you pls explain strict evaluation?
On Friday, December 11, 2015, Kim-Ee <[email protected]> wrote:
> Have you tried BangPatterns? Compiled with optimization, I get 22 secs.
> Here's the full program:
>
> {-# LANGUAGE BangPatterns #-}
>
> f :: Int -> Int -> Int
> f !m !n
> | m==0 = n+1
> | n==0 = f (m-1) 1
> | otherwise = f (m-1) (f m (n-1))
>
> main = putStrLn (show (f 4 1))
>
>
> -- Kim-Ee
>
> On Fri, Dec 11, 2015 at 9:47 PM, Abhishek Kumar <[email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote:
>
>> I was trying to write below program for ackerman function but it fails
>> (waits too long) for ack(4,1) whereas a recursive C program gives result in
>> 37secs.Can someone pls explain this behaviour and recomend some
>> optimisation.
>>
>> ------haskell code
>> f m n | m==0 =n+1
>> | n==0 = f (m-1) 1
>> | otherwise = f (m-1) (f m (n-1))
>>
>> Thanks
>> Abhishek Kumar
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> <javascript:_e(%7B%7D,'cvml','[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/20151212/123fc655/attachment-0001.html>
------------------------------
Message: 5
Date: Sat, 12 Dec 2015 18:41:19 +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] Haskell code optimisation
Message-ID:
<CAPY+ZdQCw0AAxhBRoCiQDH2-m6zr3bB-=sue89lrm4_rudy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Sat, Dec 12, 2015 at 4:19 PM, Abhishek Kumar <[email protected]>
wrote:
> Thanks Kim for your answer but as far as I understand strict evaluation
> should save in space as expression is not expanded in terms of thunks,but I
> can't understand time savings.Can you pls explain strict evaluation?
For this particular problem, start here:
https://en.wikipedia.org/wiki/Memory_hierarchy
What happens to original program that has a sprawling mass of thunks all
over RAM? The CPU spends most of its time waiting on the memory bus. And
that's not even going into things like disk-backed virtual mem.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151212/c2ea12e0/attachment-0001.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 22
*****************************************