Safe Haskell | None |
---|---|
Language | Haskell2010 |
Some motivating examples for the IfCxt module.
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.