
15 Sep
2009
15 Sep
'09
2:20 p.m.
perimeter :: Geometry -> Double perimeter (Sphere _ r) = 0.0 perimeter (Circle _ r) = 2.0 * pi * r
The latter is even simpler because there is no need in extraction of Double value from Maybe.
I'd strongly advise against this last one on style grounds. (0 :: Double) isn't nearly as suitable as a distinguished value indicating an invalid result as Nothing. It can be made to work, in the same way that you can write complex code in asm; instead, use a solution that gives you type-level help in getting it right. I'd use Maybe. Regards, John