我有兴趣尽可能接近以下语法。TH对我来说很好。
bootapplication :: IO ()
bootapplication = do
clientA <- newChan :: IO (Chan AMsg)
clientB <- newChan :: IO (Chan BMsg)
...
magicHappens
doSomething :: SomeSortaMonadTOnIO ()
doSomething = do
writeChan clientA aMsg
writeChan clientB bMsg
我想以下是可以接受的
main = do
clientA <- newChan :: IO (Chan [Char])
clientB <- newChan :: IO (Chan Whatever)
let a = putStrLn . (++) "a"
let moof = do
-- b "hello"
a "hi"
-- d "meh"
readChan clientA
return ()
let b = putStrLn . (++) "b"
let d = putStrLn . (++) "c"
return ()
但是注释行是不可接受的,因为 let 绑定只能继续进行。我如何锤击和胶带 ghc 让我这样做?
编辑:
这是我确定的语法
main = do
clientA <- newChan :: IO (Chan [Char])
clientB <- newChan :: IO (Chan Whatever)
let {
a :: [Char] -> IO ()
;a = putStrLn . (++) "a"
;moof :: IO ()
;moof = do
a "a"
b "b"
;b :: [Char] -> IO ()
;b = putStrLn . (++) "b"
;d :: [Char] -> IO ()
;d = putStrLn . (++) "c"
}
moof
return ()