Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

haskell

Name: Anonymous 2008-03-04 9:26

i read SICP and thinkCS
i feel [b]ready[/]
how to i start learning haskell ?

Name: Anonymous 2008-03-04 10:34

>>5 here, i'm done

module Main
    where

import IO

main = do
  hSetBuffering stdin LineBuffering
  doLoop

doLoop = do
  putStrLn "Do you want to [read] a file, [write] a file or [quit]? "
  command <- getLine
  case command of
    "quit"  -> return ()
    "read"  -> do doRead
                  doLoop
    "write" -> do doWrite
                  doLoop
    _       -> do putStrLn ("I don't understand the command " ++ command ++ ".")
                  doLoop

doRead = do
  putStrLn "Enter a file name to read:"
  filename <- getLine
  bracket (openFile filename ReadMode) hClose
          (\h -> do contents <- hGetContents h
                    putStrLn contents)

doWrite = do
  putStrLn "Enter a file name to write:"
  filename <- getLine
  putStrLn "Enter text (dot on a line by itself to end):"
  bracket (openFile filename WriteMode) hClose
          startWriting

startWriting h = do
  line <- getLine
  case line of
    "." -> return ()
    _   -> do hPutStrLn h line
              startWriting h


REFACTOR MY CODE

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List