Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumieval/covalent
heterogenous traversal
https://github.com/fumieval/covalent
Last synced: 23 days ago
JSON representation
heterogenous traversal
- Host: GitHub
- URL: https://github.com/fumieval/covalent
- Owner: fumieval
- Created: 2022-01-21T09:05:48.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T09:14:08.000Z (almost 3 years ago)
- Last Synced: 2024-10-15T06:50:58.951Z (2 months ago)
- Language: Haskell
- Size: 1.95 KB
- Stars: 3
- Watchers: 4
- 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 Genericinstance 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)
```