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.
Versions [faq] | 0.1.0.0, 0.1.1 |
---|---|
Dependencies | base (==4.8.*), template-haskell (==2.10.*) [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 | NixOS:0.1.1 |
Downloads | 1371 total (5 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] |
Modules
- IfCxt
- IfCxt.Examples
Downloads
- ifcxt-0.1.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)