haskell - Can't understand result of Monad >> application -
operation >> description following:
sequentially compose 2 actions, discarding value produced first, sequencing operators (such semicolon) in imperative languages.
here example confuses me:
> ([1] ++ [2]) >> ([2] ++ [3]) [2,3,2,3]
i'm expecting list [2,3] result of right part of expression. how can result of [2,3,2,3] explained?
(>>)
default defined as
a >> b = >>= (\_ -> b)
so value being ignored a
in given monadic value m a
. type of >>=
specialised list is:
(>>=) :: [a] -> (a -> [b]) -> [b]
l >>= f
invokes f
each element of list l
product list of lists concatenated.
e.g.
[1,2] >>= (\i -> [i, -i]) > [1,-1,2,-2]
ignoring each input element , returning value [2,3]
result in n copies of list [2,3]
input list of length n
e.g.
[1] >>= (\_ -> [2,3]) > [2,3] [1,2] >>= (\_ -> [2,3]) > [2,3,2,3]
this second example equivalent ([1] ++ [2]) >> ([2] ++ [3])
in question.
Comments
Post a Comment