Hello fellow RLUGers and Haskell novices, Brian aka fooburger mentioned needing a few I/O examples. I thumbed ahead in "Yet Another Haskell Tutorial" to the I/O chapter and kludged together an example. It's attached and hopefully this is good enough to allow a basic program to be written. We could use the file I/O for a more interesting and applicable example. It's very much like pascal from what I can tell so far. Someone tells me Sam is a Haskell guru but he's been pretty silent on the list lately. *nudge*
peace, core
This example comes from "Yet Another Haskell Tutorial". It seems to do the job
fairly well though. Hopefully this is enough to get us started. Yes, this is
very lame. ;) -- core
This module is called IO Example.. and it's written in literate Haskell
> module IOExample() where
We use the Prelude, although we don't actually need it AFAIK, and the IO module
to handle all of the string input and ouput.
> import Prelude -- Standard utility functions
> import IO -- I/O specific definitions
This is the main function:
> main = do
> hSetBuffering stdin LineBuffering
> hPutStr stdout "Please enter your name: " -- no newline
> name <- getLine
> putStr ("Hello, " ++ name ++ ", how old are you? ")
> age <- getLine
We need to convert the age into an integer. Apparently read is a pure function
that is similar to `expr' in bash scripting or `eval' in Python. At least that
is my current assumption... correct me if I'm wrong. So it reads the input age
as an Integer. There is no error checking, yet. ;-(
> if read age < 65
> then do putStrLn ("You're not old enough to join AARP") -- newline
> else do putStrLn ("How does it feel to be " ++ age ++ " years young?")
The end.
signature.asc
Description: Digital signature
_______________________________________________ RLUG mailing list [email protected] http://lists.rlug.org/mailman/listinfo/rlug
