I have a working program
main = do
inpStr <- getLine
putStrLn ( "Hello " ++ inpStr )
where
putStrLn :: String -> IO ()
and
getLine :: IO String
From this can I conclude that the type of <-
is
IO a -> a
?
Unfortunately, it is not a regular function, but a language construct. You can use it only in do
blocks to "extract" value from some context, such as IO
.
do
blocks and <-
is just a syntax sugar for such things called Monad
s (and IO
is one of them).
There are some other examples of such contexts, which you can use with do
and <-
, such as lists, optional, or nullable, values (such as Maybe Int
), stateful computations and so on.
Some links: