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

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -