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. assistance please ? (Roelof Wobben)
2. Re: assistance please ?
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
3. Re: assistance please ? (Roelof Wobben)
4. Re: assistance please ?
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
5. figured out use for join! (Dennis Raddle)
----------------------------------------------------------------------
Message: 1
Date: Wed, 11 Nov 2015 13:59:23 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] assistance please ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Hello,
I have this exercise :
Define a function
fibTable :: Integer -> String
which produces a table of Fibonacci numbers. For instance, the effect of
putStr
(fibTable 6) should be
n fib n
0 0
1 1
2 1
3 2
4 3
5 5
6 8
1) Can somone give me any pointers how to calculate the fibb numbers
with list comprehension.
I know that the fib numbers are (n -1) + n
2) Can someone give me any pointers how to write the outcome of every run
Roelof
------------------------------
Message: 2
Date: Wed, 11 Nov 2015 18:41:13 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] assistance please ?
Message-ID:
<CAJbEW8ORUt=13ODohn1-xfHue_g=m4btefhjky4sdwo0q+f...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hint 1) fib n = fib (n - 1) + fib (n - 2), with proper base cases
Hint 2) use mapM_ to print a list of pairs, where the list is created by
zipping [1..] with the list of fibonacci numbers
On 11 November 2015 at 18:29, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> I have this exercise :
>
> Define a function
> fibTable :: Integer -> String
> which produces a table of Fibonacci numbers. For instance, the effect of
> putStr
> (fibTable 6) should be
> n fib n
> 0 0
> 1 1
> 2 1
> 3 2
> 4 3
> 5 5
> 6 8
>
>
>
> 1) Can somone give me any pointers how to calculate the fibb numbers with
> list comprehension.
> I know that the fib numbers are (n -1) + n
>
> 2) Can someone give me any pointers how to write the outcome of every run
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151111/c94b7358/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 11 Nov 2015 14:27:46 +0100
From: Roelof Wobben <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] assistance please ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151111/afe03f14/attachment-0001.html>
------------------------------
Message: 4
Date: Wed, 11 Nov 2015 19:03:16 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] assistance please ?
Message-ID:
<cajbew8nvkeuhdw1qmhmynkna-c6_yy5-xgohqjmnd7ewhag...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You can do something like
fibTable n = [ show x ++ "\t" ++ show y | (x,y) <- zip [1..] (fibs n) ]
where
fibs n = list containing fibonacci numbers from fib(1) to fib(n)
On 11 November 2015 at 18:57, Roelof Wobben <[email protected]> wrote:
> Op 11-11-2015 om 14:11 schreef Sumit Sahrawat, Maths & Computing, IIT
> (BHU):
>
> Hint 1) fib n = fib (n - 1) + fib (n - 2), with proper base cases
>
>
> oke, so use recursion. No problem.
>
> Hint 2) use mapM_ to print a list of pairs, where the list is created by
> zipping [1..] with the list of fibonacci numbers
>
>
> mapM_ is not explained in the first 5 chapters of Craft of functional
> programming,
>
> Can not both or one of the two be done with list comprehension because all
> former exercises uses list comprehension
>
> Roelof
>
>
> On 11 November 2015 at 18:29, Roelof Wobben <[email protected]> wrote:
>
>> Hello,
>>
>> I have this exercise :
>>
>> Define a function
>> fibTable :: Integer -> String
>> which produces a table of Fibonacci numbers. For instance, the effect of
>> putStr
>> (fibTable 6) should be
>> n fib n
>> 0 0
>> 1 1
>> 2 1
>> 3 2
>> 4 3
>> 5 5
>> 6 8
>>
>>
>>
>> 1) Can somone give me any pointers how to calculate the fibb numbers with
>> list comprehension.
>> I know that the fib numbers are (n -1) + n
>>
>> 2) Can someone give me any pointers how to write the outcome of every run
>>
>> Roelof
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> --
> Regards
>
> Sumit Sahrawat
>
>
> _______________________________________________
> Beginners mailing
> [email protected]http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 2015.0.6176 / Virusdatabase: 4460/10979 - datum van uitgifte:
> 11/11/15
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151111/b8adb8ae/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 11 Nov 2015 13:12:11 -0800
From: Dennis Raddle <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] figured out use for join!
Message-ID:
<CAKxLvooXD3cpgcmKP6PVwcUyP4KJZNx+R=rhb9l0xysqeue...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm starting to get the hang of certain aspects of typeclasses,
particularly with Maybe and list types. For instance I needed to write a
function as follows:
Ord k => k -> Map k [a] -> Maybe a
which evaluates to "Nothing" if there is no such key in the map, or Just
the first element of [a] if there is such a key, or Nothing if there is
such a key but [a] is null.
So I could write
import qualified Data.Map as M
import Control.Monad
import Data.Maybe
f k m = case M.lookup k m of
Nothing -> Nothing
Just xs -> listToMaybe xs
But the case "Nothing -> Nothing" is suspicious... seems like that's always
a clue some typeclass could simplify it. Eventually I figured out
f k = join . fmap listToMaybe . M.lookup k
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151111/bb392743/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 89, Issue 16
*****************************************