免費 Monads 就像固定點
Free 的定義比較一下自己的 Fix :
data Free f a = Return a
| Free (f (Free f a))
newtype Fix f = Fix { unFix::f (Fix f) }
特別是,將 Free 建構函式的型別與 Fix 建構函式的型別進行比較。Free 就像 Fix 一樣疊加了一個仿函式,除了 Free 還有一個 Return a 的情況。
Free 的定義比較一下自己的 Fix :
data Free f a = Return a
| Free (f (Free f a))
newtype Fix f = Fix { unFix::f (Fix f) }
特別是,將 Free 建構函式的型別與 Fix 建構函式的型別進行比較。Free 就像 Fix 一樣疊加了一個仿函式,除了 Free 還有一個 Return a 的情況。