[Haskell-cafe] Typeclasses vs simple functions?

John Dorsey haskell at colquitt.org
Tue Sep 15 10:20:00 EDT 2009

> 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.


More information about the Haskell-Cafe mailing list