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...
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.