After solving a problem on Project Euler I came across the following Haskell code in the forum:
fillRow115 minLength = cache where cache = ((map fillRow115' [0 ..]) !!) fillRow115' 0 = 1 fillRow115' cells = sum (map cache [0..cells-minLength]) + cache (cells-1) I just started learning Haskell this week and can't seem to understand this code. Can somebody please explain the following 2 items:
- To me it looks like there is only one argument
minLength, but the function requires 2 arguments to run in ghci. Where does this other argument come into play? - From what I've been able to find online,
!!is the list index operator and returns the nth element when called as[list] !! n. The code above seems to call it with only one argument. What is that doing?
P.S. If anyone is thinking of copying this code to solve the Project Euler problem, it doesn't seem to give the correct answer.