相关疑难解决方法(0)

仿函数的这个属性比单子强吗?

在思考如何推广monad时,我想出了一个仿函数F的以下属性:

inject :: (a -> F b) -> F(a -> b) 
Run Code Online (Sandbox Code Playgroud)

- 这应该是a和b中的自然变换.

如果没有更好的名称,如果存在上面显示的自然变换,我将函数F称为可绑定inject.

主要问题是,这个属性是否已经知道并且有一个名称,它是如何与仿函数的其他众所周知的属性相关的(例如,应用,monadic,尖头,可遍历等)

名称"可绑定"的动机来自以下考虑:假设M是monad而F是"可绑定"仿函数.然后有一个具有以下自然态射:

fbind :: M a -> (a -> F(M b)) -> F(M b)
Run Code Online (Sandbox Code Playgroud)

这类似于monadic"bind",

bind :: M a -> (a -> M b) -> M b
Run Code Online (Sandbox Code Playgroud)

除了结果用仿函数F装饰.

背后的想法fbind是,广义的monadic操作不仅可以产生单个结果M b,而且可以产生这种结果的"函数"F.我想表达一个monadic操作产生几个"计算线"而不仅仅是一个的情况; 每个"计算链"再次成为一元计算.

注意,每个仿函数F都具有态射

eject :: F(a -> b) -> a -> F b
Run Code Online (Sandbox Code Playgroud)

这与"注入"相反.但并非每个仿函数F都有"注入".

具有"注入"的仿函数的示例:F t = (t,t,t) 或者F t = c -> (t,t)其中c是常量类型.F t = cFunctor(常量仿函数)或 …

monads haskell functional-programming functor category-theory

19
推荐指数
2
解决办法
675
查看次数

Juggling existentials without unsafeCoerce

Lately I have been playing with this type, which I understand to be an encoding of the free distributive functor (for tangential background on that, see this answer):

data Ev g a where
    Ev :: ((g x -> x) -> a) -> Ev g a

deriving instance Functor (Ev g)
Run Code Online (Sandbox Code Playgroud)

The existential constructor ensures I can only consume an Ev g by supplying a polymorphic extractor forall x. g x -> x, and that the lift and lower …

haskell existential-type higher-rank-types

10
推荐指数
1
解决办法
172
查看次数