据我了解,每个 van Laarhoven 光学类型都可以通过类型构造函数的约束来定义:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
-- etc.
Run Code Online (Sandbox Code Playgroud)
如果我们选择Monad
作为约束,它是否以有意义的方式形成某种“光学”?
type Something s t a b = forall f. Monad f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
我的直觉是,Monad
约束可能过于严格,无法从这样的结构中获取任何值:由于Const
函子不是 a Monad
,我们无法通过专门化 …