[Haskell-cafe] Why does (++ "!") "bla" return "bla!" and not "!bla"?

Peter Gammie peteg42 at gmail.com
Fri Jun 22 07:04:42 CEST 2012


On 22/06/2012, at 2:54 PM, Hilco Wijbenga wrote:

> I'm going through the excellent http://learnyouahaskell.com tutorial.
> So far it's been pretty easy to follow but now I ran into something
> that (when I later started reading about maps) do not seem to fully
> grasp.
> I think I'm close to understanding why (++ "!") "bla" returns "bla!
> instead of "!bla" but I seem to be missing the last step. :-) I
> noticed that ((++) "!") "bla" does indeed return "!bla". So it seems
> to be related to the infix property of ++? The types of (++) "!",
> ((++) "!"), and (++ "!") are all the same so that doesn't tell me
> much.

This stuff is in a beginner's tutorial? (!?)

This is purely a syntactic issue. These things are called "sections".

It might be more obvious if we put in some lambda abstractions, which I hope your tutorial has already introduced:

(++ "!") = (\x. x ++ "!")
("!" ++) = (\y. "!" ++ y)

Yes, it is related to the infix property of ++. You can get similar things going with arbitrary binary (two argument) functions like so:

app = (++) -- or whatever

(`app` "!") = (\x. x `app` "!") = (\x. app x "!")
(and the other way around)



More information about the Haskell-Cafe mailing list