
Thank you, but why in
map :: (a -> b) -> [a] -> [b]
are there parentheses around a -> b ? In general, what is the currying
aspect of this?
On Fri, Dec 18, 2020 at 12:43 PM David McBride
They are not parameters, they are the types of the parameters.
In this case a can really be anything, Int, Char, whatever, so long as the function takes a single argument of that type and the list that is given has elements of that same type. It is the same for b, it doesn't matter what b ends up being, so long as when you call that function the function's return value is compatible with the element type of the list that you intended to return from the entire statement.
You can mess with it yourself in ghci to see how type inference works.
:t show :show :: Show a => a -> String :t map show map show :: Show a => [a] -> [String] :t flip map [1::Int] flip map [1::Int] :: (Int -> b) -> [b]
On Fri, Dec 18, 2020 at 1:31 PM Lawrence Bottorff
wrote: I'm looking at this
ghci> :type map map :: (a -> b) -> [a] -> [b]
and wondering what the (a -> b) part is about. map takes a function and applies it to an incoming list. Good. Understood. I'm guessing that the whole Haskell type declaration idea is based on currying, and I do understand how the (a -> b) part "takes" an incoming list, [a] and produces the [b] output. Also, I don't understand a and b very well either. Typically, a is just a generic variable, then b is another generic variable not necessarily the same as a. But how are they being used in this type declaration?
LB _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners