gpt4 book ai didi

haskell - 使用 map 和 concat 将列表推导式转换为定义

转载 作者:行者123 更新时间:2023-12-02 14:01:15 26 4
gpt4 key购买 nike

摘自用 Haskell 进行函数式思考,第 67 页:

[...] list comprehensions are translated into equivalent definitions in
terms of map and concat. The translation rules are:

[e | True] = [e]
[e | q] = [e | q, True]
[e | b, Q] = if b then [e | Q] else []
[e | p <- xs, Q] = let ok p = [e | Q]
ok _ = []
in concat (map ok xs)

作者没有定义 e、q、Q 或 b。我认为第一个意思是“表达”,但我以前从未见过其他的。有人可以启发我吗?

最佳答案

此翻译直接来自官方Haskell Report ,其中有这样的附加句子:

where e ranges over expressions, p over patterns, l over list-valued expressions, b over boolean expressions, decls over declaration lists, q over qualifiers, and Q over sequences of qualifiers. ok is a fresh variable. The function concatMap, and boolean value True, are defined in the Prelude.

如果您想知道这些术语的含义,该报告提供了更多详细信息。

关于haskell - 使用 map 和 concat 将列表推导式转换为定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235096/

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