caseof: Combinators for casing on constructors

[ bsd3, development, library ] [ Propose Tags ]
Versions 0.0.0, 0.0.1
Dependencies base (>=4.7 && <5), template‑haskell [details]
License BSD-3-Clause
Copyright 2018 Chris Done
Author Chris Done
Category Development
Home page
Source repo head: git clone
Uploaded by ChrisDone at Wed Mar 7 22:43:14 UTC 2018
Distributions NixOS:0.0.1
Downloads 46 total (46 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-07 [all 1 reports]
Hackage Matrix CI

Template-Haskell-based combinators that let you select on constructors.

[Skip to Readme]




Maintainer's Corner

For package maintainers and hackage trustees

Readme for caseof-0.0.1

[back to package description]


A simple way to query constructors, like cases but slightly more concise.

Prisms from the lens package can also manage this, but this is a bit simpler.

Aimed at sum types with many constructors:

data Wiggle = Woo Int Char | Wibble Int deriving Show

There is a case predicate:

> $(isCaseOf 'Woo) (Woo 5 'a')

There is a Maybe-based matcher:

> $(maybeCaseOf 'Woo) (Woo 1 'a')
Just (1,'a')

There is a "map" over a constructor:

> $(mapCaseOf 'Left) succ (Left 3)
Left 4

There is a combinator which calls your function with n arguments, or passes the whole value to an "else" clause.

> $(caseOf 'Woo) (\x y -> show x ++ show y) (const "") (Wibble 5)

Use in your project

In your stack.yaml, put:

- git:
  commit: 9a7f6bb