javascript-MaybeT外部monad不受monad约束的应用实例

我正在用Javascript实现Maybe(aka选项)类型的monad转换器(请注意,我使用类型字典传递):

const optOfT = of => x =>
  of(optOf(x));

const optMapT = map => f => ttx =>
  map(optMap(f)) (ttx);

const optApT = chain => ttf => ttx =>
  chain(tf =>
    chain(tx =>
      optAp(tf) (tx)) (ttx)) (ttf);

const optChainT = chain => fm => mmx =>
  chain(mx =>
    optChain(fm) (mx)) (mmx);

(map〜< $&gt ;,ap〜< *,链〜=<< of = pure / return) 虽然这段代码有效,但我想知道是否可以在没有外部monad的monad约束的情况下实现optApT.我偶然发现了这个Haskell示例:

(<<**>>) :: (Applicative a,Applicative b) => a (b (s -> t)) -> a (b s) -> a (b t)
abf <<**>> abs = pure (<*>) <*> abf <*> abs

这似乎正是我想要的,但是我无法识别纯(< *)< *>的评估顺序. abf< *> abs和哪个< *>运算符属于哪个应用层:

const optApT = (ap,of) => ttf => ttx =>
  ...?

任何提示表示赞赏.

最佳答案
希望这会有所帮助…

以下是与各种类型类函数关联的类型:

abf <<**>> abs = pure (<*>) <*> abf <*> abs
                  (4)  (3)  (2)     (1)

(1),(2): the `ap` for type a
(3): the `ap` for type b
(4): the `pure` for type a

评估顺序为:

(pure (<*>)) <*> abf <*> abs

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...