[Haskell-beginners] function not working as expected, type issues (Gesh)

Alexej Magura sickhadas at gmail.com
Thu Apr 10 04:00:40 UTC 2014


>an arg.  My initial guess is that the *first* type specified is the one 
>returned, but I’m not sure. 
> 
I'm curious as to why you thought that. The directionality of the arrows in a type signature is quite clear, at least to me. a -> b is the type of functions *from* a *to* b. 
Well, most of the languages that I’ve used are dynamically typed, but the one language that I’m _kinda_ familiar with that _is_ statically typed is C: several of the Haskell tutorials that I’ve been reading describe that:

	A :: Int

means that *A* is _of_ type *Int*, which kind of sounds like A returns type Int

functions such as map :: (a -> b) -> [a] -> [b] (can you guess what it does and how it does it? Can you do that just by looking at the type?). 
Map appears to take a lambda function, which takes type *a* returning type *b* (both of which are purely arbitrary), a list of type *a*, and returns a list of type *b*, applying the lambda function to each element in the list of type *a*.

From your coding style, it appears that you think of && in the way Bash does - as the function: 

> p && x = if p then x else *nothing* 

Something like that.

Anyway, all of the above means that passing a non-Bool value to && is not acceptable, and since hPutStr stdout string is not a value of type Bool, GHC complains. 
Makes sense.

--  
Alexej Magura
Sent with Airmail


More information about the Beginners mailing list