monads - Haskell: 'do [1,2,3]; ["hello"]' behavior clarification -


so i'm trying understand how haskell do notation works. understand used monads , expands (since it's syntactic sugar) anonymous functions connected either bind (>>=) or (>>) shown here https://en.wikibooks.org/wiki/haskell/syntactic_sugar#do_notation.

however my question is why following command

prelude> [1, 2, 3]; "hello" 

returns

"hellohellohello" 

i know arrays monads (and strings arrays of chars) fail see how results in behavior above.

do [1, 2, 3]; "hello" 

desugars to

[1, 2, 3] >> "hello" 

which same

[1, 2, 3] >>= (\_ -> "hello") 

which same as

concatmap (\_ -> "hello") [1, 2, 3] 

which same as

concat (map (\_ -> "hello") [1, 2, 3]) 

which same as

concat [(\_ -> "hello") 1, (\_ -> "hello") 2, (\_ -> "hello") 3]) 

which same as

concat ["hello","hello","hello"] 

which same as

"hellohellohello" 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -