I created my own version of getLine like this:
getLine' :: IO String
getLine' = do x <- getChar
if x == '\n' then
return []
else
do
xs <- getLine'
return (x:xs)
Basically I created a new file called test.hs and copied above code into it. I opened WinGHCi afresh and :load test.hs
I can run getLine' in WinGHCi with no problem. But how does WinGHCi know about getChar and IO?
I assumed I would have to import like this:
import System.IO
Is it because WinGHCi does this import for me?
If I write this program and invoke using runghci:
getLine' :: IO String
getLine' = do x <- getChar
if x == '\n' then
return []
else
do
xs <- getLine'
return (x:xs)
main = do
getLine'
It also works without complaining.
Is there a list of built-in libraries? Is that platform dependent?