Tuesday, May 27, 2008

NumberCheck in haskell


import System.Environment
import Data.Char

main = do
arg:_ <- getArgs
putStrLn (arg ++ " is " ++ (result arg))
where result arg = if check arg then "correct" else "incorrect"
check arg = dotOrDigit `all` arg && oneOrZeroDots arg
dotOrDigit = (`elem` ['0'..'9'] ++ ['.'])
oneOrZeroDots = (<=1) . length . (filter ('.'==))

No comments: