gpt4 book ai didi

haskell - 如何查看 "and"的实现代码?

转载 作者:行者123 更新时间:2023-12-04 09:26:32 24 4
gpt4 key购买 nike

我在互联网上找到了 and 的定义,但我找不到 and 的实际实现。我确实在我的计算机上搜索了某种 prelude haskell 文件,但它没有返回任何可以在文本编辑器中打开的内容。

最佳答案

您可以使用Hoogle搜索 Haskell 函数,如下所示:

http://www.haskell.org/hoogle/?hoogle=and

函数链接将您带到定义函数的库模块,在本例中为 and 的链接带我们到这里:

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:and

然后点击Source链接到函数名称的右侧,它会将您带到该函数的源代码。对于 and 的情况它将我们链接到这里:

http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-List.html#and

and                     :: [Bool] -> Bool
or :: [Bool] -> Bool
#ifdef USE_REPORT_PRELUDE
and = foldr (&&) True
or = foldr (||) False
#else
and [] = True
and (x:xs) = x && and xs
or [] = False
or (x:xs) = x || or xs
#endif

你会看到 and实际上有两个定义。一种是标准前奏定义,仅在使用 USE_REPORT_PRELUDE 编译时启用。标志,另一个是 Prelude 通常编译时使用的定义,通常更优化。

关于haskell - 如何查看 "and"的实现代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12544800/

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