为什么我应该在函数式编程中使用应用函子? [英] Why should I use applicative functors in functional programming?
问题描述
我是Haskell的新手,我正在阅读函数和应用函子。好吧,我理解函子以及如何使用它们,但我不明白为什么 applicative 函数是有用的,我如何在Haskell中使用它们。你可以用一个简单的例子向我解释为什么我需要应用函数吗?
解决方案应用仿函数是一种构造,它提供仿函数和 monads ,因此比单子更普遍,但比仿函数更有用。通常情况下,你可以通过函数映射一个函数。应用仿函数允许您采用正常函数(使用非函数参数)来使用它来操作仿函数上下文中的多个值。作为一个推论,这给了你有效的编程,没有monad。
一个很好的自包含的解释充满了例子可以找到 here 。你也可以阅读一个实用的解析示例,由Bryan O'Sullivan开发,不需要预先知识。
I'm new to Haskell, and I'm reading about functors and applicative functors. Ok, I understand functors and how I can use them, but I don't understand why applicative functors are useful and how I can use them in Haskell. Can you explain to me with a simple example why I need applicative functors?
Applicative functors are a construction that provides the midpoint between functors and monads, and are therefore more widespread than monads, while more useful than functors. Normally you can just map a function over a functor. Applicative functors allow you to take a "normal" function (taking non-functorial arguments) use it to operate on several values that are in functor contexts. As a corollary, this gives you effectful programming without monads.
A nice, self-contained explanation fraught with examples can be found here. You can also read a practical parsing example developed by Bryan O'Sullivan, which requires no prior knowledge.
这篇关于为什么我应该在函数式编程中使用应用函子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!