gpt4 book ai didi

haskell - 为什么数据库查询是使用 Arrow 的好地方?

转载 作者:行者123 更新时间:2023-12-02 10:12:36 34 4
gpt4 key购买 nike

我正在阅读this ,其中说道:

Well, the point is that arrow notation forbids some computations that do notation allows. In particular all “arrow actions” must be “statically” known“.

它解释了:

Statically known" means that if we have a couple of rows of arrow notation

> -- y <- action1 -< x

> -- z <- action2 -< y

then the expression action2 cannot depend on x or indeed anything bound on the left hand side of an arrow notation row.

据我了解,这种限制使得箭头变得有值(value)。

现在,我正在尝试学习 Opaleye,我注意到它使用箭头将事物组合在一起。

为什么 Opaleye 使用箭头?为什么箭头非常适合这项工作?数据库/查询的哪些方面使此限制变得有用?

最佳答案

参数化数据库查询看起来像箭头:

  • 每个都有一个输入和一个输出
  • 他们创作
  • 我们希望以不同于 Haskell 函数的方式对待它们

组成(.) (或 (<<<) )看起来像 SQL 子查询。 (&&&)看起来像 SQL 连接。

我相信“静态已知”限制与您可以合理地转换为 SQL 的内容相关。一旦您允许 fmap/lmap/rmap对于任意 Haskell 函数,这是不可行的(至少没有 SQL 语言扩展和 GHC 编译器插件)。不过我还没有弄清楚细节。

我不知道我们可以通过 Opaleye 实现手动管理多少翻译。

关于haskell - 为什么数据库查询是使用 Arrow 的好地方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50255304/

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