ifcxt: put if statements within type constraints

[ bsd3, control, library ] [ Propose Tags ]

This package introduces the ifCxt function, which lets your write if statements that depend on a polymorphic variable's class instances. For example, we can make a version of show that can be called on any type:

cxtShow :: forall a. IfCxt (Show a) => a -> String
cxtShow a = ifCxt (Proxy::Proxy (Show a))
    (show a)
    "<<unshowable>>"

Running this function in ghci, we get:

>>> cxtShow (1 :: Int)
"1"
>>> cxtShow (id :: a -> a)
"<<unshowable>>"

See the project webpage http://github.com/mikeizbicki/ifcxt for more details.

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1
Dependencies base (>=4.8 && <4.9), template-haskell (>=2.10 && <2.11) [details]
License BSD-3-Clause
Author Mike Izbicki
Maintainer mike@izbicki.me
Category Control
Home page http://github.com/mikeizbicki/ifcxt
Source repo head: git clone http://github.com/mikeizbicki/ifcxt
Uploaded by MikeIzbicki at 2015-09-02T22:47:01Z
Distributions
Reverse Dependencies 1 direct, 1 indirect [details]
Downloads 1636 total (7 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-09-29 [all 3 reports]