idiomatic: Deriving Applicative for sum types.. Idiomatically.
Idiomatically
is used with DerivingVia
to derive Applicative
for types with multiple constructors.
The name comes from the original paper on Applicative
s: Idioms: applicative programming with effects.
It features an extensible domain-specific language of sums with
Applicative
instances. Idiomatically
is then passed a type-level
list of applicative sums that specify how deriving should take
place.
{-# Language DataKinds #-} {-# Language DeriveGeneric #-} {-# Language DerivingStrategies #-} {-# Language DerivingVia #-} import Generic.Applicative data Zip a = No | a ::: Zip a deriving stock (Show, Generic1) deriving (Functor, Applicative) via Idiomatically Zip '[RightBias Terminal]
This derives the standard behaviour of ZipList
but this same
"RightBias Terminal" behaviour describes the Maybe
and
Validation
applicative as well.
pure @Zip a = a ::: a ::: a ::: ... liftA2 (+) No No = No liftA2 (+) No (⊥:::⊥) = No liftA2 (+) (⊥:::⊥) No = No liftA2 (+) (2:::No) (10:::No) = 12:::No
Idiomatically
shares an intimate relationship with Generically1
:
it is defined in terms of Generically1
and they are
interchangeable when there is an empty list of sums:
type Generically1 :: (k -> Type) -> (k -> Type) type Generically1 f = Idiomatically f '[]
Based on Abstracting with Applicatives.
[Skip to Readme]
Modules
[Index] [Quick Jump]
Flags
Manual Flags
Name | Description | Default |
---|---|---|
examples | Enable examples | Disabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- idiomatic-0.1.1.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
Versions [RSS] | 0.1.0.0, 0.1.1.0 |
---|---|
Change log | ChangeLog.md |
Dependencies | base (>=4 && <5), idiomatic [details] |
License | BSD-3-Clause |
Author | Baldur Blöndal |
Maintainer | Baldur Blöndal |
Category | Generics |
Home page | https://github.com/Icelandjack/idiomatic |
Source repo | head: git clone https://github.com/Icelandjack/idiomatic |
Uploaded | by BaldurBlondal at 2022-04-16T18:41:21Z |
Distributions | NixOS:0.1.1.0 |
Executables | ZipList-example |
Downloads | 175 total (0 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs available [build log] Last success reported on 2022-04-16 [all 1 reports] |