KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I think I do understand the list monad but then I found I am not. Here is the story. Given list m and function k > let m = [1..10] > :t m m :: [Integer] > let k = replicate 2 > :t k k :: a -> [a] Playing with bind >>= give what I expect > :t (>>=) (>>=) :: Monad m => m a -> (a -> m b) -> m b > :t m >>= k m >>= k :: [Integer] > m >>= k [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10] but for >> Expected (from experiencing with IO monad, everything on left side would be discarded) m >> m [1,2,3,4,5,6,7,8,9,10] Got > :t (>>) (>>) :: Monad m => m a -> m b -> m b :t m >> m m >> m :: [Integer] > m >> m [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5 ... 9,10] -- truncated, real output is 100 elements Please explain why >> is not behave like I expected (of course I must have misunderstanding) and what is the correct way to interpret >> ?
Tags (comma-separated)
Save Edits
Cancel