[Haskell-cafe] A beginners question
agl at imperialviolet.org
Sat Feb 23 11:36:29 EST 2008
On Sat, Feb 23, 2008 at 8:00 AM, Harri Kiiskinen <harkiisk at utu.fi> wrote:
> then why does
> let i = fmap (^4) [1,2,3] in shows i " "
> "[1,16,81] "
I'll probably mess this up somewhere, but if I do, reset assured that
someone else here will correct me ;)
fmap (^4) [1,2,3] == [1,16,81] so shows " " of that == "[1,16,81] "
(note the trailing space), obvious I hope.
However, [1,16,81] >>= \i -> shows i " " operates in the list monad. I
can't find the actual instance of Monad  right now, but it will
apply 'shows i " "' to each element in the first list and concat the
results. Since strings are just [Char], concating them is string
concatenation. And so you have "1 16 81 " (again, note the trailing
Adam Langley agl at imperialviolet.org http://www.imperialviolet.org
More information about the Haskell-Cafe