[Haskell-beginners] Why WinGHCi does not complain with no import?

Angus Comber anguscomber at gmail.com
Tue Jan 7 13:58:37 UTC 2014


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140107/000fdb37/attachment.html>


More information about the Beginners mailing list