[英]In what does this simple do notation desugar to?
我正在使用Aeson
和Network.HTTP
。 我能够编码 json 并将其打印在屏幕上,执行以下操作:
getCode :: String -> IO ResponseCode
getCode url = simpleHTTP req >>= getResponseCode
where req = getRequest url
main :: IO ()
main = do
x <- get "http://jsonplaceholder.typicode.com/todos/1"
let y = encode x
B.putStrLn y
但是我do
明白这个表达式脱糖是为了什么。 像这样的东西:
get "http://jsonplaceholder.typicode.com/todos/1" >>= (?)
应该是什么?
?
我只知道如何脱糖:
do { x1 <- action1
; x2 <- action2
; mk_action3 x1 x2 }
对此
action1 >>= (\ x1 -> action2 >>= (\ x2 -> mk_action3 x1 x2 ))
顺便说一句,什么是action
? https://en.m.wikibooks.org/wiki/Haskell/do_notation没有很准确地解释。
get "http://jsonplaceholder.typicode.com/todos/1" >>= (\x -> let y = encode x in B.putStrLn y)
put (x:: s)
是State s
“动作”。
put:: s -> State s ()
是一个 function 从s
类型值到State s
“动作”构造函数。
putStrLn "Hi"
是一个IO
动作。 putStrLn:: String -> IO ()
是从String
s 到IO
动作的 function 动作,一个“动作”构造函数。
IO
是一个单子。 State s
是一个单子。
“动作”是M a
类型的任何值,其中M
是 Monad。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.