Basic number property checker I made a small program that tests numbers against some properties:


Welcome to Numbers!
Is it odd? 4
No
Is it a multiple of 18? 38
No
Is it big? 100
Yes


That's basically it :)

My code is:

import System.IO
import Text.Read

askUser :: String -&gt; IO Double
askUser str = do
  putStr str
  num &lt;- fmap readMaybe getLine

  case num of
    Nothing -&gt; putStrLn "That is not a number!" &gt;&gt; askUser str
    Just num -&gt; return num

numberCheck :: [Double] -&gt; String -&gt; IO ()
numberCheck list text = do
  num &lt;- askUser ("Is it " ++ text ++ "? ")

  if num `elem` list
    then putStrLn "Yes"
    else putStrLn "No"


main :: IO ()
main = do
  hSetBuffering stdout NoBuffering
  putStrLn "Welcome to Numbers!"
  let alot = 99999

  let oddNum = take alot [x | x &lt;- [0..], odd (round x)]
  numberCheck oddNum "odd"

  let multiples18 = take alot [x | x &lt;- [0..], round x `mod` 18 == 0]
  numberCheck multiples18 "a multiple of 18"

  let bigNumbers = take alot [99..]
  numberCheck bigNumbers "big"


Is there anything that can be improved? I was especially thinking of the alot number, as it is not a "clean" way of solving this. But if I don't, Haskell will continue checking the list infinitely.

Is there any nicer way of achieving this?

Note: I used lists instead of comparisons because that's what I just learned, and so you can ignore me using lists if you want to :)
Integer not Double

Double is not a reasonable type because checking if a number is big does not work with Doubles, you should use Integer

First class functions

Using a list is not a clean procedure, it does not work for very big numbers and it is slow for big numbers.

It is better to pass in a validation function:

numberCheck :: (Integer -&gt; Bool) -&gt; String -&gt; IO ()
numberCheck predicate text = do
  num &lt;- askUser ("Is it " ++ text ++ "? ")

  if predicate num
    then putStrLn "Yes"
    else putStrLn "No"


Usage is:

main = do
  hSetBuffering stdout NoBuffering
  putStrLn "Welcome to Numbers!"

  numberCheck odd "odd"
  numberCheck (\x -&gt; x `mod` 18 == 0) "multiple of 18"
  numberCheck (&gt; 100) "big (bigger than 100)"