again another question generated by my attempts at the Project Euler questions (follow on from a previous question). I'm having trouble understanding the following line:
print (maximum (map (product . take 13) (tails number)))
Specifically
map (product . take 13) (tails number)
The type signature for the first argument of map from ghci is [c] -> c:
ghci> :t (product . take 13)
(product . take 13) :: Num c => [c] -> c
The type signature for map (product . take 13) from ghci is [[b]] -> [b]:
ghci> :t map (product . take 13)
map (product . take 13) :: Num b => [[b]] -> [b]
Am I right in saying that as the first argument of map should be a function, [[b]] is not referring to a list of lists, but rather to a list of (partially applied) functions generated by (product . take 13), with the second argument for the partial functions coming from (tails number)?
product . take 13is already a function (here from a list of somec(wherecis an instance ofNumbecause we want to multiplycs) toc) you should read it from right-to-left: first you take all final-segments list of numbers (seetails), then you multiply the numbers (but only the first 13) in there for each of these segments (map (product . take 13)), then you take the maximum of these products (remember one for each segment) and finally you print it - Random DevPrelude Data.List> map (take 4) (tails [1..5])==>[[1,2,3,4],[2,3,4,5],[3,4,5],[4,5],[5],[]]. This is faulty (only 2 subsequences, of length 4, should be considered here); check out my recent answer to your previous question. - Will Ness