https://github.com/fumieval/covalent
heterogenous traversal
https://github.com/fumieval/covalent
Last synced: 8 months ago
JSON representation
heterogenous traversal
- Host: GitHub
- URL: https://github.com/fumieval/covalent
- Owner: fumieval
- Created: 2022-01-21T09:05:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T09:14:08.000Z (over 4 years ago)
- Last Synced: 2025-03-26T06:44:10.990Z (about 1 year ago)
- Language: Haskell
- Size: 1.95 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
Covalent: heterogenous traversal
----
`Covalent` is an analogue of `Traversal` where its targets may be any type satisfying the specified constraint.
```haskell
class Covalent c a where
traverseCommon :: Applicative f => (forall x. c x => x -> f x) -> a -> f a
```
An instance of `Covalent` can be generically derived as long as _all_ the fields satisfy the constraint:
```haskell
data Numeral = NumInt Int | NumDouble Double | NumPair Double Int deriving Generic
instance Covalent Show Numeral
instance Covalent Num Numeral
```
Using the `Covalen Num Numeral` instance, you can write a function that adds 1 regardless of the constructor.
```haskell
add1 :: Numeral -> Numeral
add1 = overCommon @Num (+1)
```