我有以下简单的代码:
data Shape = Circle Float Float Float | Rectangle Float Float Float Float deriving (Show)
surface :: Shape -> Float
surface (Circle _ _ r) = pi * r ^ 2
main = putStrLn $ surface $ Circle 10 20 30
它抱怨:
Couldn't match expected type `String' with actual type `Float'
In the second argument of `($)', namely `surface $ Circle 10 20 30'
如何摆脱错误?我还想“添加”show
方法Shape
并覆盖它,以便我可以Shape
在屏幕上(打印)表示我想要的任何内容。