[Haskell-beginners] Typing/N00b question/My first haskell.

Henk-Jan van Tuyl hjgtuyl at chello.nl
Mon Nov 21 11:54:32 CET 2011


On Mon, 21 Nov 2011 11:38:03 +0100, bryan hunt  
<sentimental.bryan at gmail.com> wrote:

> but keep
> getting type conversion errors.

> module Main where
>
> ageJudge :: (Integral a) => a -> String
> ageJudge age
>     | age >= 40 = "You're too old!"
>     | age <= 30 = "Your too young"
>     | otherwise   = "Not in the programming age range.."
>
> main = do
>   putStrLn "What is your name?"
>   name <- getLine
>   putStrLn ("Nice to meet you, " ++ name ++ "!")
>   putStrLn "What is your age?"
>   age <- getLine
>   let inpIntegral = (read age)::Double
> --  let decission = ageJudge (read inpIntegral)::Integral
>   putStrLn ("We decided!")
> --  putStrLn ("We decided:\n" ++ show(1) ++ "!")
> -- ageJudge inpIntegral

You use the type class Integral, which contains Int and Integer, for  
ageJudge; it is better to use Double, as you use this type for reading the  
age. Another option is, to use the function "round" to round the age.

Note, that you cannot use Integral as a type.

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



More information about the Beginners mailing list