Reputation: 1546
I'm new to Haskell and I'm having troubles understanding how the let binding works in the following example:
prefixes :: [a] -> [[a]]
prefixes xs =
let prefix n = take n xs
in map prefix (range (length xs))
'take' function returns a list, so how does this get bind to 2 variables (prefix n)? Or am I totally missing the point here...
Upvotes: 1
Views: 391
Reputation: 532268
You can think of let
as syntactic sugar for using an anonymous function.
let name = value in stuff
is equivalent to (\name -> stuff) value
. An anonymous function whose body is the expression in the in
clause is applied to the expression bound to a name in the let
clause.
Upvotes: 2