gpt4 book ai didi

immutability - ClojureScript、Elm、PureScript、GHCJS 等不可变语言如何编译为可变 javascript?

转载 作者:行者123 更新时间:2023-12-03 23:36:48 24 4
gpt4 key购买 nike

我认为埋头于所列语言的源代码对我来说太过分了。但是有没有人能够简单地解释一下事情是如何发生的?

我的意思是,最终不可变数据仍将是 javascript 的数据。或者编译后的代码是否包含非标准数据结构,例如'a,b,c' 不可变数组的字符串

最佳答案

我会回答有关 PureScript 的问题,因为我对这种语言比较熟悉。

来自 PureScript By Example [2.7]关于 PureScript 到 JavaScript 的生成:

  • Every module gets turned into an object, created by a wrapper function, which contains the module’s exported members.
  • PureScript tries to preserve the names of variables wherever possible.
  • Function applications in PureScript get turned into function applications in JavaScript.
  • The main method is run after all modules have been defined, and is generated as a simple method call with no arguments.
  • PureScript code does not rely on any runtime libraries. All of the code that is generated by the compiler originated in a PureScript module somewhere which your code depended on.

These points are important, since they mean that PureScript generates simple, understandable code. In fact, the code generation process in general is quite a shallow transformation. It takes relatively little understanding of the language to predict what JavaScript code will be generated for a particular input.

因此,是的,正如您所写:“最终,不可变数据仍将是 javascript 的数据”。编译后,PureScript 模块的包装函数在更高级别保证了不变性。

关于immutability - ClojureScript、Elm、PureScript、GHCJS 等不可变语言如何编译为可变 javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52087693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com