post(typoclassopedia): MonadFix
This commit is contained in:
parent
8b2934f53b
commit
a986e5c6df
@ -731,3 +731,26 @@ class MonadTrans t where
|
|||||||
c = distrib b :: M (N (N a))
|
c = distrib b :: M (N (N a))
|
||||||
in c >>= join :: M (N a)
|
in c >>= join :: M (N a)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
MonadFix
|
||||||
|
========
|
||||||
|
|
||||||
|
## Examples and intuition
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
maybeFix :: (a -> Maybe a) -> Maybe a
|
||||||
|
maybeFix f = ma
|
||||||
|
where ma = f (fromJust ma)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exercises
|
||||||
|
|
||||||
|
1. Implement a MonadFix instance for [].
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
listFix :: (a -> [a]) -> [a]
|
||||||
|
listFix f = la
|
||||||
|
where la = f (head la)
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user