2

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

?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Gergely
  • 6,879
  • 6
  • 25
  • 35

1 Answers1

6

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 Monads (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:

Yuri Kovalenko
  • 1,325
  • 9
  • 19