除monads和ZipList以外的应用函子? [英] Applicative functors other than monads and ZipList?

查看:72
本文介绍了除monads和ZipList以外的应用函子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个着名的应用程序示例是monads和ziplists。还有其他的例子吗?

Two well-known examples of applicatives are monads and ziplists. Are there any other examples?

时间飞得像一个应用函数 Conor McBride:

From Time flies like an applicative functor by Conor McBride:


结构警察会注意到 De 是应用函数的另一个例子,它不是一个monad - 连接会将事情从遥远的将来带到不久的将来,而且最好的不可能。但是,通常情况下,应用仿函数只能通过遍历仿函数(容器中有许多元素), De 会遍历所有容器。所以这有点特别。

Structure cops will note that De is another example of an applicative functor which is not a monad — join would bring things from the far future to the near future, and that had better not be possible. However, where applicative functors in general only pull through traversable functors (containers with finitely many elements), De pulls through all containers. So it’s a bit special. I wonder what it is.


De functor表示一个固定的延迟,而不是一个任意的延迟。我将时间分成不连续的片段。 De x 是在下一个切片处到期的 x 的类型。因此, De(De x)是两个切片时间中 x 的类型,您不能让它快点起床!

The De functor represents a fixed delay, rather than an arbitrary one. I’m dividing time into discrete slices. De x is the type of an x due at the next slice. De (De x) is thus the type of an x due in two slices’ time, and you can’t make it turn up any sooner!

阅读整篇文章。为了回答眼前的问题,作者的结论是:

Read the whole post. To answer the immediate question, the author’s conclusion is


不要看!



<好的,这是实施。这是一个骗局。

Don’t Look!

OK, here’s the implementation. It’s a con.

newtype De x = De x deriving Show -- ssh, don't tell!

instance Functor De where
  fmap f (De x) = De (f x)

instance Applicative De where
  pure = De
  De f <*> De s = De (f s)

fix :: (De x -> x) -> x
fix f = f (De (fix f))


这篇关于除monads和ZipList以外的应用函子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆