问题标签 [transducer]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
clojure - 什么是状态转换器?
clojure - core.async 是否可以在序列方面实现其功能?
Rich Hickey 的 Strange Loop 转换器演示文稿告诉我们 Clojure 1.6 中有两种实现map
,一种用于序列输入clojure.core
,一种用于通道输入core.async
。
现在我们知道,在 1.7 中我们有转换器,对于这些转换器,foldr
( reduce
) 函数是从高阶函数返回的,例如map
,filter
当给定一个函数而不是一个集合时。
我试图表达和失败的是为什么core.async
函数不能返回一个序列,或者是Seq
-like。我有一种“接口”(协议)不同的感觉,但我不知道如何。
当然,如果您要从频道中删除第一项,那么您可以将其表示为从序列中删除第一项?
我的问题是:可以core.async
在序列方面实现它的功能吗?
haskell - 换能器与部分应用函数有何不同?
在阅读了关于 Clojure ( http://blog.podsnap.com/ducers2.html ) 介绍传感器的这篇文章后,我对传感器是什么感到困惑。是否部分应用于map
Haskell,例如map (+1)
传感器?起初我认为这是使用部分应用程序的 Clojure 方式,但随后文章继续在 Haskell 中使用显式类型实现它。它在 Haskell 中有什么用?
transducer - What are transducers good for other than optimization and helping language/API designers?
After watching Rich Hickey's talk on transducers, my understanding is that they can
- greatly optimize performance of compositions of reducers (by removing the need for intermediate sequence representations)
- assist a language/API designer in getting reducers 'for free' over all of their sequences/iterables/streams/etc as long as they are implemented once as a transducer.
Beyond these advantages (which may not be relevant for many) are there any other benefits to coding with transducers?
lazy-evaluation - 用 sml 表示一个传感器系统
我需要帮助编写这样的代码:
给定两个函数,比如 f1 和 f2 以及 f1 的初始输入 i1,我会将 i1 提供给 f1,无论它返回什么输出,我都会提供给 f2,而无论 f2 返回什么,我都会提供给 f1,依此类推......
因此它看起来像这样: fun pair(m1, m2, i1) = ...
这里的 m1 和 m2 实际上代表有限状态传感器,使得 m1 = (state, f1)。这里的状态是我们拥有的初始状态 i1。f1 接收 (state, input) 并返回一个输出 (next state, oput),然后将 oput 馈送到 m1 等等..
为澄清起见,这代表一个传感器系统。这意味着两个具有互补输入和输出的 FST 可以并行运行,每个 FST 的输出作为另一个的输入。
这应该返回生成的输出列表。
为了提供帮助,我已经编写了一个函数 run,它接受 fst m 和输入列表,给出通过在输入上运行 m 获得的输出列表。
然而,当我尝试编写这个函数时,我的头晕了,因为我进入了一个无限循环,而且我的代码长得令人难以置信,而这可以使用我的辅助函数 run 轻松完成。
有任何想法吗?
scala - Scala Transducers 和 Clojure Transducers 有什么异同?
Paul Chiusano和Rúnar Óli写了一本很棒的书《Scala 函数式编程》。在其中,他们提到了 Scala 社区中一个很少被引用的概念——Transducers。
在 Clojure 社区中,Transducers得到了更多的 关注 。
我的问题是: Scala Transducers **(来自《Scala 中的函数式编程》一书)和 Clojure Transducers之间有什么异同?**
假设:
我知道
haskell - Haskell 中的换能器和单态性限制
我在 Haskell 中实现了如下的转换器:
现在我想定义一个通用map
函数。因此,我将上述代码加载到 GHCi 中:
所以我无法定义map = reduce . mapping
。但是,我可以定义map f = reduce (mapping f)
.
我相信这个问题是由单态限制引起的。我真的很想写map = reduce . mapping
而不是map f = reduce (mapping f)
。因此,我有两个问题:
- 是什么导致了这个问题?确实是单态限制吗?
- 我该如何解决这个问题?
haskell - Haskell中的有限状态传感器?
我一直想知道是否有一种方法可以在 Haskell 中以惯用的方式定义和使用有限状态传感器。
您可以将 FST 作为生成器(它生成 {x1,x2} 类型的输出)或识别器(给定 {x1,x2} 类型的输入,如果它属于有理关系,它会识别它),或者作为翻译器(给定输入磁带,它将其转换为输出磁带)。表示会根据方法而改变吗?
是否也可以通过指定重写规则来对 FST 进行建模?例如,创建一个 DSL 来模拟重写规则,然后创建一个函数createFST :: [Rule] -> FST
。
我能找到的最接近的是 Kmett、Bjarnason 和 Cough 的machines
图书馆:
https ://hackage.haskell.org/package/machines
但我似乎无法意识到如何用Machine
. 我认为正确的做法类似于他们定义 Moore 和 Mealy 机器的方式:将 FST 定义为不同的实体,但提供一个Automaton
能够将其用作机器的实例。
我也找到了一些其他选项,但它们以一种直接的方式定义它(如在https://hackage.haskell.org/package/fst中)。这并没有让我很信服,因为我想知道是否有更好的方法来使用 Haskell 类型系统的优势(比如machines
库中如何定义 Moore 和 Mealy 机器)。
python - How to parse a DOT file in Python
I have a transducer saved in the form of a DOT file. I can see a graphical representation of the graphs using gvedit, but what if I want to convert the DOT file to an executable transducer, so that I can test the transducer and see what strings it accepts and what it doesn't.
In most of the tools I have seen in Openfst, Graphviz, and their Python extensions, DOT files are only used to create a graphical representation, but what if I want to parse the file to get an interactive program where I can test the strings against the transducer?
Are there any libraries out there that would do the task or should I just write it from scratch?
As I said, the DOT file is related to a transducer I have designed that simulates morphology of English. It is a huge file, but just to give you an idea of how it is like, I provide a sample. Let's say I want to create a transducer that would model the behavior of English with regards to Nouns and in terms of plurality. My lexicon consists of only three words (book, boy, girl). My transducer in this case would look something like this:
which is directly constructed from this DOT file:
Now testing this transducer against the words means that if you feed it with book+Pl
it should spit back books
and vice versa. I'd like to see how it is possible to turn the dot file into a format that would allow such analysis and testing.
clojure - 使用换能器的机会?
使用 Clojure,我从 SQLite 数据库中提取了一些数据。它将以地图列表的形式到达。这是数据外观的简短示例。
我想把它改造成这样的东西:
我知道我可以编写一个函数来处理部门和员工,然后将它们“粘合”在一起以实现我想要的形状。事实上,我在 REPL 中就是这样做的。
但我最近听说了一些关于换能器的事情,想知道这是一个使用换能器的机会。
如果是,代码会是什么样子?