ifcxt: put if statements within type constraints
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
- ifcxt-0.1.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
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 2016-08-03T21:52:43Z |
Distributions | |
Reverse Dependencies | 1 direct, 1 indirect [details] |
Downloads | 1682 total (2 in the last 30 days) |
Rating | 2.25 (votes: 2) [estimated by Bayesian average] |
Your Rating | |
Status | Docs not available [build log] All reported builds failed as of 2016-11-21 [all 2 reports] |