Hi. I've been trying to get this simple function in Haskell to let me call it for many hours and come to a problem I can't find an answer for. The function is of type
Float -> Float -> [Int]
so I need to pass it two Float values. I've fed the result of getLine (d :: IO String, I believe) to the "det" function, where it's passed through a "show " and then a "read" function. I think this should yield a value of type Float and the compiler seems to agree, as it compiles fine. Then, at runtime I get a "Prelude.read: no parse" exception. The code is below. Can anyone explain what I'm doing wrong here?
module Main where
decimal_binary :: Float -> Float -> [Int]
decimal_binary d_num factor = if d_num < 0 || d_num > 255
then [0]
else if (d_num - factor) < 0
then 0 : decimal_binary d_num (factor / 2)
else if (d_num - factor) == 0
then [1]
else 1 : decimal_binary (d_num - factor) (factor / 2)
det a = read(show a)::Float
main = do putStrLn "Enter an integer in the range 0 - 255: "
d <- getLine
putStrLn "The binary form of your input is: "
print (decimal_binary (det d) 128)
Steven