是所有可区分类型Monads [英] Are all differentiable types Monads
问题描述
Comonad
data Zipper ta = Zipper {diff :: D ta,here :: a}
导出实例Diff t => Functor(Zipper t)
class(Functor t,Functor(D t))=> Diff t其中
type D t :: * - > *
up ::拉链t a - > t a
down:t a - >我们可以写出类似于
的签名的函数吗?我们可以写一些类似于>的签名的函数吗?
return ::(Diff t)=> a - > t a
(>> =)::(Diff t)=> t a - > (a - > t b) - > tb
服从 Monad laws 。
链接的问题,有两种成功的方法来解决为 Zipper
派生 Comonad
实例的类似问题。第一种方法是展开 Diff
类以包含>> =
并使用偏分化。第二种方法是要求该类型是两次或无限可区分。
没有。 void functor data V a
是可区分的,但是 return
无法实现。
Given a differentiable type, we know that its Zipper
is a Comonad
. In response to this, Dan Burton asked, "If derivation makes a comonad, does that mean that integration makes a monad? Or is that nonsense?". I'd like to give this question a specific meaning. If a type is differentiable, is it necessarily a monad? One formulation of the question would be to ask, given the following definitions
data Zipper t a = Zipper { diff :: D t a, here :: a }
deriving instance Diff t => Functor (Zipper t)
class (Functor t, Functor (D t)) => Diff t where
type D t :: * -> *
up :: Zipper t a -> t a
down :: t a -> t (Zipper t a)
can we write functions with signatures similar to
return :: (Diff t) => a -> t a
(>>=) :: (Diff t) => t a -> (a -> t b) -> t b
obeying the Monad laws.
In the answers to the linked questions, there were two successful approaches to a similar problem of deriving Comonad
instances for the Zipper
. The first approach was to expand the Diff
class to include the dual of >>=
and use partial differentiation. The second approach was to require that the type be twice or infinitely differentiable.
No. The void functor data V a
is differentiable, but return
cannot be implemented for it.
这篇关于是所有可区分类型Monads的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!