post(typoclassopedia): MonadFix

This commit is contained in:
Mahdi Dibaiee 2017-10-14 15:09:48 +03:30
parent 8b2934f53b
commit a986e5c6df

View File

@ -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)
```