gpt4 book ai didi

haskell - 警告: Pattern match is redundant?是什么原因

转载 作者:行者123 更新时间:2023-12-05 01:23:34 26 4
gpt4 key购买 nike

我正在尝试解决将华氏温度转换为摄氏温度的练习​​,反之亦然,但我收到此警告:

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

我是 Haskell 的新手,需要帮助来理解警告的原因。

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

最佳答案

您需要删除行 tempToC temp = error "Implement this function."tempToF temp = error "Implement this function."。由于 temp 只是命名一个新变量,它将匹配任何内容,因此这些行将阻止它们下面的行运行。

关于haskell - 警告: Pattern match is redundant?是什么原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72282848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com