IO

LA home
Computing
 Algorithms
 Bioinformatics
 FP,  λ
 Logic,  π
 MML
 Prog.Langs

FP
 Haskell
  Haskell98
   IO
    Monad
s.7.1 p.98 RR, I/O
Output Functions ...
putChar  :: Char -> IO ()
putStr   :: String -> IO ()
putStrLn :: String -> IO ()   -- adds a newline
print    :: Show a => a -> IO ()

Recall that (IO τ) is a Monad (s.7.2 pp.99 RR), so that >>, etc. are applicable to it. The " main program", main, must be of type (IO τ) for some type τ.

main = putStr "Hello " >> putStr "World."
       ---------------    ---------------
           IO ()              IO ()
       ----------------------------------
                     IO ()
Input Functions ...
getChar     :: IO Char     -- exception on EOF
getLine     :: IO String   -- ditto
getContents :: IO String
interact    :: (String -> String) -> IO ()
readIO      :: Read a => String -> IO a
readLn      :: Read a => IO a

In input step passes a value on to the next step after >>=

... getChar  >>=  putChar  ...
    -------       -------
    IO Char      Char->IO()
    -----------------------
              IO ()

IO type, s.8.1. prelude, p.111, RR
 
data IO a = ...abstract
 
instance Functor IO where
  fmap f x = x >>= (return . f)
 
instance Monad IO where
  (>>=) = ...
  return = ...
  fail s = ioError (userError s)

RR = revised report, CUP, 2003.


7/2002, 11/2005
window on the wide world:

Computer Science Education Week

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite,
ver 3.4+

The GIMP
~ free photoshop
Firefox
web browser
FlashBlock
like it says!

Haskell:
(:) cons
[x1,...] list
[ ]list
(++) append
\ λ :-)
:: has type
Compared

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 25-Jul-2014 06:02:07 EST.