[Haskell-beginners] Reading input

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Aug 21 00:08:54 EDT 2008


2008/8/20 Yitzchak Gale <gale at sefer.org>:
> Here's how you could write your main function:
>
> main = do
>   putStr "Enter a list: "
>   lst <- getLine
>   print $ median $ read lst
>

Another possibility would be a space delimited number list, easier for
your users to remember :

> parseWordList :: (Read a) => String -> [a]
> parseWordList str = map read . unwords $ str
>
> main = do
>   putStrLn "Enter a list of integers : "
>   line <- getLine
>   print . median . parseWordList $ line

-- 
Jedaï


More information about the Beginners mailing list