简体   繁体   English

功能响应式编程语言规范

[英]Specification for a Functional Reactive Programming language

I am looking at messing around with creating a functional reactive framework at some point.我正在考虑在某个时候创建一个功能性反应框架。 I have read quite a lot about it and seen a few examples but I wanted to get a clear idea of what this framework would HAVE to do to be considered an FRP extension/dsl.我已经阅读了很多关于它的内容并看到了一些示例,但我想清楚地了解这个框架必须做什么才能被视为 FRP 扩展/dsl。 I'm not really concerned with implementation problems or specifics etc but more as to what would be desired in a perfect world situation.我并不真正关心实施问题或细节等,而是更关心在完美世界情况下需要什么。

What would be the key operations and qualities of an ideal functional reactive programming language?理想的函数式反应式编程语言的关键操作和品质是什么?

I'm glad you're starting by asking about a specification rather than implementation first.我很高兴您首先询问规范而不是实施。 There are a lot of ideas floating around about what FRP is.关于 FRP 是什么,有很多想法。 For me it's always been two things: (a) denotative and (b) temporally continuous.对我来说,这一直是两件事:(a)外延和(b)时间连续。 Many folks drop both of these properties and identify FRP with various implementation notions, all of which are beside the point in my perspective.许多人放弃了这两个属性,并用各种实现概念来识别 FRP,在我看来,所有这些都是无关紧要的。 To reduce confusion, I would like to see the term "functional reactive programming" replaced by the more accurate & descriptive "denotative, continuous-time programming" (DCTP), as suggested by Jake McArthur in a conversation last year .为了减少混淆,我希望看到术语“函数式反应式编程”被更准确和描述性的“指示性、连续时间编程”(DCTP)取代,正如 Jake McArthur 在去年的一次谈话中所建议的那样。

By "denotative", I mean founded on a precise, simple, implementation-independent, compositional semantics that exactly specifies the meaning of each type and building block.通过“外延”,我的意思是建立在精确、简单、独立于实现的组合语义之上,该语义准确地指定了每种类型和构建块的含义。 The compositional nature of the semantics then determines the meaning of all type-correct combinations of the building blocks.然后,语义的组合性质决定了构建块的所有类型正确组合的含义。 For me, denotative is the heart & essence of functional programming, and is what enables precise & tractable reasoning and thus a foundation for correctness, derivation, and optimization.对我来说,外延是函数式编程的核心和本质,是实现精确和易于推理的原因,因此是正确性、推导和优化的基础。 Peter Landin recommended "denotative" as a substantive replacement to the fuzzier term "functional" and a way to distinguish deeply/genuinely functional programming from merely functional-looking notations. Peter Landin 建议将“外延”作为模糊术语“函数式”的实质性替代,以及一种将深度/真正函数式编程与仅仅具有函数式外观的符号区分开来的方法。 See this comment for some Landin quotes and a paper reference.有关 Landin 的一些引述和论文参考,请参阅此评论

About continuous time, see the post Why program with continuous time?关于连续时间,请参阅帖子为什么要使用连续时间进行编程? and my quote in AshleyF's answer on this page.以及我在此页面上 AshleyF 的回答中的引述。 I'm surprised over & over by hearing the claim that the idea of continuous time is somehow unnatural or impossible to implement, considering the discrete nature of computers.考虑到计算机的离散性,听到连续时间的想法在某种程度上不自然或不可能实现的说法,我一次又一次地感到惊讶。 This line of thinking strikes me as bizarre, especially when coming from Haskellers, for a few reasons:这种思路让我觉得很奇怪,尤其是来自 Haskellers 时,原因如下:

  • Using lazy functional languages, we casually program with infinite data on finite machines.使用惰性函数式语言,我们随意地在有限机器上用无限数据进行编程。 We get lovely modularity as a result, as illustrated in John Hughes's classic paper Why Functional Programming Matters .结果,我们得到了可爱的模块化,正如 John Hughes 的经典论文Why Functional Programming Matters中所说明的那样。
  • There are many examples of programming in continuous space, for instance, vector graphics, but also things like Pan .在连续空间中编程的例子有很多,例如矢量图形,还有Pan之类的东西。
  • I like my programs to reflect how I think about the problem space rather than the machine that executes the programs, and I tend to expect other high-level language programmers to share that preference.我喜欢我的程序反映我对问题空间的看法,而不是对执行程序的机器的看法,我倾向于期望其他高级语言程序员也能分享这种偏好。 ("A programming language is low level when its programs require attention to the irrelevant." - Alan Perlis) (“当程序需要关注不相关的内容时,编程语言是低级的。” - Alan Perlis)

I've been making libraries for programming with continuous time since TBAG and ActiveVRML (the first DCTP/FRP system) and later Fran .TBAGActiveVRML (第一个 DCTP/FRP 系统)和后来的Fran以来,我一直在制作用于连续时间编程的库。 It's easy to implement correctly.很容易正确实施。 A few different approaches are described in the paper Functional Implementations of Continuous Modeled Animation .连续建模 Animation 的功能实现一文中描述了几种不同的方法。 Implementing continuous time efficiently (and still correctly,) is another matter.有效地(并且仍然正确地)实施连续时间是另一回事。 especially avoidance of recomputing unchanging values.特别是避免重新计算不变的值。 (See the paper Push-pull functional reactive programming .) (请参阅论文推拉功能反应式编程。)

For related remarks, please see my answer to The difference between Reactive and Functional-Reactive programming and to What is (functional) reactive programming?有关相关说明,请参阅我对响应式编程和功能响应式编程之间的区别什么是(功能)响应式编程? Update: For more on why continuous time matters, see these notes .更新:有关连续时间为何重要的更多信息,请参阅这些说明 Update: See also, my 2015 talk The essence and origins of FRP (and the related talks linked there).更新:另见,我的 2015 年演讲FRP 的本质和起源(以及链接在那里的相关演讲)。

Good luck with your exploration, and please let me know if you have any questions.祝您探索顺利,如果您有任何问题,请告诉我。 My contact info is on my home page .我的联系信息在我的主页上

I assume you've probably seen Matthias Felleisen's talk on Functional I/O and read his paper .我假设您可能已经看过Matthias Felleisen 关于函数式 I/O 的演讲并阅读了他的论文 I think his is a very pragmatic and beautiful approach.我认为他是一个非常务实和美丽的方法。 Hopefully you've also stumbled onto some of Conal Elliott 's excellent work.希望您也偶然发现了Conal Elliott的一些出色作品。

My personal requirements would be that the system is completely pure.我个人的要求是系统是完全纯净的。 That is, all behavior is defined by pure world->world functions and all realization or visualization is defined by world->visual functions;也就是说,所有的行为都是由纯world->world函数定义的,所有的实现或可视化都是由world->visual函数定义的; where visual is some static description of the output from the system.其中visual是来自系统的output的一些 static 描述。

My other primary feature would be a historical debugger.我的另一个主要功能是历史调试器。 It should be relatively trivial to maintain a history of world states and be able to replay from any point in time.维护world状态的历史并能够从任何时间点重播应该是相对微不足道的。

One area of extremely interesting research (I believe an unsolved problem) would be to use continuous time rather than iterating the world->world functions upon some discrete clock ticks .一个非常有趣的研究领域(我相信一个未解决的问题)是使用连续时间,而不是在一些离散的时钟滴答上迭代world->world函数。 I once did a few blog posts on FRP and Conal Elliott left the following thought provoking comment:我曾经在 FRP 上发表过几篇博文, Conal Elliott留下了以下发人深省的评论:

I like denotative/functional approaches, for composability & semantic clarity.我喜欢指称/功能方法,以实现可组合性和语义清晰。 For the same reasons, I prefer continuous time & space over discrete time & space.出于同样的原因,我更喜欢连续的时间和空间而不是离散的时间和空间。 In all of these cases, the less machine-like formulation nicely separates the what from the how of its machine-based presentation.在所有这些情况下,不太像机器的公式很好地将其基于机器的演示的内容与方式分开。

Solve that and you'll be a hero!解决这个问题,您将成为英雄!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM