ifcxt-0.1.0.0: put if statements within type constraints

Safe HaskellNone
LanguageHaskell2010

IfCxt.Examples

Description

Some motivating examples for the IfCxt module.

Synopsis

Documentation

cxtShow :: forall a. IfCxt (Show a) => a -> String Source

A version of "show" that can be called on any type. If the type is not an instance of Show, then gets displayed.

cxtShowTypeable :: forall a. (IfCxt (Show a), IfCxt (Typeable a)) => a -> String Source

Like "cxtShow" above, but if a is not an instance of Show then we print out the type.

cxtNub :: forall a. (Eq a, IfCxt (Ord a)) => [a] -> [a] Source

A version of "nub" that is maximally efficient for the given type. If we only have an Eq constraint, then "cxtNub" takes time O(n^2), but if we also have an Ord constraint, then "cxtNub" only takes time O(n*log n). If the type a does have an Ord constraint, then the order of the elements may change.

magic :: Int Source

This function behaves differently depending on whether there exists a Magic instance or not.