[Haskell-beginners] question on types

Jake Penton djp at arqux.com
Fri Jul 29 13:27:28 CEST 2011


On 2011-07-29, at 6:54 AM, Gary Klindt wrote:

> So, why is it possible to work with the map :: (a -> b) -> [a] -> [b] function? One can use it with list of number and functions on numbers, can't one.
> 

Yeah. Your question is pretty much an example of what what troubling me in my original post. And frankly, I doubt that my reasoning on this will get straightened out until I have studied the type system more thoroughly.

Naively, the difference I see between your example using map and my original post is that I was *defining*  f:

f::a
f = 1

which, I suppose, is quite a bit different than *calling* map. To parallel my example, one would (mistakenly) write something like this:

map::(a -> b)  -> [a] ->  [b]
map f lst = ['a','b','c']

The above gives the same message I got. It is tempting to think that " ['a','b','c'] is a list of b's, so it should work", but that is clearly wrong.

- j -


More information about the Beginners mailing list