What is the cause of the warning : Pattern match is redundant?

Viewed 81

I am trying to solve an exercises that Convert Fahrenheit to Celsius and vice versa but I'm getting this warning:

Pattern match is redundant
In an equation for ‘tempToC’: tempToC temp = ...compile(-Woverlapping-patterns)

I am new to Haskell and need help understanding the cause of the warning.

module Temperature (tempToC, tempToF) where

{- Implement the function `tempToC` to convert
`  Fahrenheit to Celsius                    -}

tempToC :: Integer -> Float
tempToC temp = error "Implement this function."
tempToC temp = fromIntegral (temp - 32 ) / 1.8 --line of the warning

{- Implement the function `tempToF` to convert
   Celsius to Fahrenheit                    -}

tempToF :: Float -> Integer
tempToF temp = error "Implement this function."
tempToF temp = ceiling  (temp * 1.8 + 32) --line of the warning
1 Answers

You need to remove the lines tempToC temp = error "Implement this function." and tempToF temp = error "Implement this function.". Since temp just names a new variable, it will match anything, so those lines will prevent the lines below them from ever running.

Related