Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Haskell Brain Pain: Fibonacci Numbers
Index -> Programming, General Programming -> Functional Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Sep 08, 2005 5:45 pm   Post subject: Haskell Brain Pain: Fibonacci Numbers

code:
fibonacci = 1 : 1 : zipWith (+) fibonacci (tail fibonacci)


Explain how this manages to generate all fibonacci numbers. Smile
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Thu Sep 08, 2005 6:40 pm   Post subject: (No subject)

ehm easy... it appends the zip of the sum of the nth and (n+1)th element of the list L=1:1:... to list L, through lazy evaluation.. and you get ur fibonacci sequence

that's one way of looking at it.. truth is.. it lazily evaluates the rest of the list.. nothing is appended.
Display posts from previous:   
   Index -> Programming, General Programming -> Functional Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: