是否有像`>>`这样的标准函数,但返回第一个操作数的结果?

Ign*_*rov 4 monads haskell standard-library

例如,假设我想读一条线并敲响钟声:

? getLine >> putChar '\007'
How lang and dreary is the night when I am frae my Dearie.
-- Blip and `()`. The line is lost.
? getLine >>= (\x -> putChar '\007' >> return x
I restless lie frae e'en to morn though I were ne'er sae weary.
"I restless lie frae e'en to morn though I were ne'er sae weary."
-- A line and also a blip side effect.
Run Code Online (Sandbox Code Playgroud)

这个想法似乎有很多共同之处const,唯一的区别是给出的值是有效的,并且都被执行,即使只保留了第一个动作的值.(与之不同>>,它保留了第二个的价值.)我的意思是:

? constM a b = a >>= \x -> b >> return x
Run Code Online (Sandbox Code Playgroud)

这是一个更复杂的示例,涉及以下解析器Text.ParserCombinators.ReadP:

? readP_to_S (many1 (munch1 (not . isSpace) `constM` skipSpaces ) `constM` eof) <$> getLine
How slow ye move, ye heavy hours.
[(["How","slow","ye","move,","ye","heavy","hours."],"")]
Run Code Online (Sandbox Code Playgroud)

 

我想知道这个功能是否可用base,或者可以从其他功能中轻松构建base.