我嘗試使用data.maybe類型,但失敗。當我嘗試在ghci中運行它時,它告訴我:「構造函數'Ramen'應該沒有參數,但已經給出了1。」。我該如何解決它?執行ghc-modi`type`命令時出錯:
data Product = Ramen | Chips
totalPrice :: Product -> Integer -> Float
totalPrice product = case product of
Ramen x
| x >= 200 -> 1.35*x
| x <= 200 -> 1.4*x
| x <= 100 -> 1.5*x
| x <= 30 -> 1.8*x
| x <= 10 -> 2.0*x
| otherwise -> error "Something's wrong."
Chips x
| x >= 21 -> 2.35*x
| x <= 20 -> 2.5*x
| x <= 10 -> 2.7*x
| x <= 5 -> 2.95*x
| x >= 1 && x <= 2 -> 3.0*x
|otherwise -> error "Something's wrong."
很好的回答!爲我工作。感謝您的建議。 –