Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumieval/moldable
Poor man's extensible records
https://github.com/fumieval/moldable
Last synced: 23 days ago
JSON representation
Poor man's extensible records
- Host: GitHub
- URL: https://github.com/fumieval/moldable
- Owner: fumieval
- License: bsd-3-clause
- Created: 2018-04-10T01:10:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-29T06:56:15.000Z (over 5 years ago)
- Last Synced: 2024-10-15T06:50:54.549Z (2 months ago)
- Language: Haskell
- Homepage:
- Size: 365 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![logo](https://github.com/fumieval/moldable/blob/master/artwork/logo-256px.png?raw=true)
```haskell
declareMold [d|
data Foo = Foo
{ foo :: Int
, bar :: Bool
}|]
```The declaration above instead creates a following datatype:
```haskell
data Foo s = Foo
{ foo :: Shroud s "foo" Int
, bar :: Shroud s "bar" Bool
}
````Shroud` is a type family that wraps a type depending on the switch type.
`Foo Raw` is equivalent to the original declaration and `Foo (Ann f)` wraps each
field by `f`.```haskell
type family Shroud switch name a where
Shroud Raw _ a = a
Shroud (Ann f) name a = f name a
```The datatype is an instance of the `Moldable` class:
```haskell
class Moldable m where
annotateMold :: m Raw -> m (Ann Tagged)
unannotateMold :: m (Ann Tagged) -> m Raw
traverseMold :: Applicative f => (forall k x. KnownSymbol k => g k x -> f (h k x)) -> m (Ann g) -> f (m (Ann h))
traverseMold_ :: Applicative f => (forall k x. KnownSymbol k => g k x -> f r) -> m (Ann g) -> f ()
zipMold :: (forall k x. KnownSymbol k => f k x -> g k x -> h k x) -> m (Ann f) -> m (Ann g) -> m (Ann h)
zipMoldA :: Applicative t => (forall k x. KnownSymbol k => f k x -> g k x -> t (h k x)) -> m (Ann f) -> m (Ann g) -> t (m (Ann h))
zipMoldA_ :: Applicative t => (forall k x. KnownSymbol k => f k x -> g k x -> t r) -> m (Ann f) -> m (Ann g) -> t ()
````Wrap` allows you to use `Type -> Type` wrappers.
```haskell
data Wrap h name a = Wrap { unWrap :: h a }rewrap :: (forall x. f x -> g x) -> Wrap f k a -> Wrap g k a
rewrapF :: Functor t => (forall x. f x -> t (g x)) -> Wrap f k a -> t (Wrap g k a)
```