3 ms·
Yes. Here's a function that has type `IO ()` but doesn't obviously use `IO`'s monadic interface. foo = print "hello" `print` may use `IO`'s monadic inter
by wyager 12y ago
Yes.
Here's a function that has type `IO ()` but doesn't obviously use `IO`'s monadic interface.
foo = print "hello"
`print` may use `IO`'s monadic interface under the hood, I don't know.
Here's some code that has type `IO ()` and does use `IO`'s monadic interface.
foo = do
str <- getLine
print str
which is de-sugared to
foo = getLine >>= \str -> print str
which you can, if you like concise code, feel free to shorten to
foo = getLine >>= print
The important part is `>>=` (pronounced "bind"), which is defined in the monad typeclass. (A typeclass is like a Java interface, by the way.)
- JoshTriplett 12y agoOr: foo = print =<< getLine which often reads better when trying to build something that looks more like a nested function call and less like a pipeline.