mirror of
https://github.com/Lysxia/first-class-families.git
synced 2024-10-03 22:57:15 +03:00
README: Comment about overloaded families
This commit is contained in:
parent
fc18ad42df
commit
464d78da85
20
README.md
20
README.md
@ -72,6 +72,26 @@ import Fcf -- Simple but fragile
|
||||
import Fcf.Class.Functor (FMap) -- Explicit and robust
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
### Overloaded type families
|
||||
|
||||
Value-level functions can be overloaded using type classes.
|
||||
Type families---type-level functions---are open by design,
|
||||
so overloading is as easy as just declaring them with more general types.
|
||||
|
||||
```haskell
|
||||
data Map :: (a -> Exp b) -> f a -> Exp (f b)
|
||||
|
||||
-- Instances for f = []
|
||||
type instance Eval (Map f '[]) = '[]
|
||||
type instance Eval (Map f (x ': xs)) = Eval (f x) ': Eval (Map f xs)
|
||||
|
||||
-- Instances for f = Maybe
|
||||
type instance Eval (Map f 'Nothing) = 'Nothing
|
||||
type instance Eval (Map f ('Just x)) = 'Just (Eval (f x))
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [Haskell with only one type family](http://blog.poisson.chat/posts/2018-08-06-one-type-family.html)
|
||||
|
Loading…
Reference in New Issue
Block a user