不确定如何使用组合器设计有用的库
我一直在阅读有关组合器的内容,并看到它们有多么有用(例如,在 Haskell 的秒差距中)。我的问题是我不太确定如何实际使用它们。
以下是问题的概述:可以生成、过滤和修改分布。可以组合分发来创建新的分发。
基本接口是(用伪 Haskell 类型术语):
generator:: parameters -> distribution
selector:: parameters -> (distribution -> distribution)
modifier:: parameters -> (distribution -> distribution)
现在,我认为我看到了三个组合器:
combine:: generator -> generator -> generator
filter:: generator -> selector -> generator
modify:: generator -> modifier -> generator
这些实际上是组合器吗?组合器有意义/我还缺少其他任何明显的组合器吗?
感谢您的任何建议。
I've been reading about combinators and seen how useful they are (for example, in Haskell's Parsec). My problem is that I'm not quite sure how to use them practically.
Here's an outline of the problem: distributions can be generated, filtered, and modified. Distributions may be combined to create new distributions.
The basic interfaces are (in pseudo-Haskell type terminology):
generator:: parameters -> distribution
selector:: parameters -> (distribution -> distribution)
modifier:: parameters -> (distribution -> distribution)
Now, I think that I see three combinators:
combine:: generator -> generator -> generator
filter:: generator -> selector -> generator
modify:: generator -> modifier -> generator
Are these actually combinators? Do the combinators make sense/are there any other obvious combinators that I'm missing?
Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
selector
和modifier
函数已经是完美的组合器了!除了generator
和combine
之外,你还可以做类似的事情(为了具体起见,我将假设统计分布,然后将事情编造出来!):位与组合运算符的优先级,以便顺利工作:)
一般来说,当我尝试为
A
类型的值设计组合器库时,我喜欢保留我的A
的“最后”,所以部分应用的组合器(您的选择器
和修饰符
)可以与.
链接在一起,而不必翻转
篮球。这是一篇不错的博客文章,可以帮助您设计组合器,它影响了我很多想法: 语义编辑器组合器。
编辑:鉴于
combine
的类型签名,我可能误读了您的问题。也许我错过了一些东西,但是分布不是你的组合器应该处理的更自然的对象吗?The
selector
andmodifier
functions are already perfectly good combinators! Along withgenerator
andcombine
you can do stuff like (I'm going to assume statistical distributions for concreteness and just make things up!):You may have to mess around a bit with the priority of the combine operator for this to work smoothly :)
In general, when I'm trying to design a combinator library for values of type
A
, I like to keep myA
's "at the end", so that the partially applied combinators (yourselector
andmodifier
) can be chained together with.
instead of having toflip
through hoops.Here's a nice blog article which can help you design combinators, it influenced a lot of my thinking: Semantic Editor Combinators.
EDIT: I may have misread your question, given the type signature of
combine
. Maybe I'm missing something, but wouldn't the distributions be the more natural objects your combinator should work on?