What's the differ开发者_开发百科ence? Does seq
guarantee more flow conditions?
They aren't related at all.
seq
has the type:
seq :: a -> b -> b
It is used (as seq a b
, or a `seq` b
) to evaluate a
to head normal form, which is a fancy way of saying that it forces the lazy value a
to be evaluated a little bit. It has nothing to do with monads.
>>=
is for sequencing monads. It has the type:
(>>=) :: Monad m => m a -> (a -> m b) -> m b
It is used to get the value from a monadic value and pass it to a function that returns another monadic value. Basically something like:
getLine >>= putStrLn
which would get a string of input from the command-line and then print it out.
So, basically, no relation at all.
seq
is not specific to monads. seq
is used to force evaluation of its first argument before its second is returned.
精彩评论