"enable_if" in Haskell

Viewed 227

How do I write something like the following in Haskell:

showSquare :: (Show a, Num a) => a -> String
showSquare x = "The square of " ++ (show x) ++ " is " ++ (show (x * x))

showSquare :: (Show a, not Num a) => a -> String
showSquare x = "I don't know how to square " ++ (show x)

Basically, something like boost::enable_if in C++.

GHC extensions are ok.

4 Answers
Related