Safe Haskell | None |
---|---|
Language | Haskell2010 |
Documentation
This class lets a polymorphic function behave differently depending on the constraints of the polymorphic variable. For example, we can use it to write the following improved version of the "show" function:
ifShow :: forall a. IfCxt (Show a) => a -> String ifShow = ifCxt (Proxy::Proxy (Show a)) show (const "<<unshowable>>")
In ghci, we can run:
>>>
ifShow (1 :: Int)
"1">>>
ifShow (id :: a -> a)
"<<unshowable>>"
The IfCxt.Examples module contains more examples.