源代码的定义`==`对于haskell中的列表

发布于 2025-02-04 14:41:58 字数 119 浏览 2 评论 0原文

有谁知道 ==是如何定义为Haskell中的列表定义的吗?我已经尝试将其调整为hoog,但似乎找不到实例eq [a]的定义位置。

Does anyone know how exactly == is defined for lists in Haskell? I've tried Hoogling it but can't seem to find where the instance Eq [a] is defined.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2025-02-11 14:41:58

eq的GHC实现和其他内置实例是用 ghc.classes 。具体来说,您正在寻找 eq [a]

 实例(eq a)=> eq [a]哪里
    { - #专业实例eq [[char]# - }
    { - #专业实例eq [char]# - }
    { - #专业实例eq [int]# - }
    [] == [] = true
    (x:xs)==(y:ys)= x == y&& xs == ys
    _xs == _ys = false
 

没有什么超级令人兴奋的。两个空列表相等,如果头部和尾巴相等,则两个非空列表相等。最后,两个任意列表是非平等的。唯一有趣的部分是专业指令,该指令应在整数列表,字符串和字符串列表上进行单态化。

The GHC implementation of Eq and other built-in instances is written in GHC.Classes. Specifically, you're looking for Eq [a]

instance (Eq a) => Eq [a] where
    {-# SPECIALISE instance Eq [[Char]] #-}
    {-# SPECIALISE instance Eq [Char] #-}
    {-# SPECIALISE instance Eq [Int] #-}
    []     == []     = True
    (x:xs) == (y:ys) = x == y && xs == ys
    _xs    == _ys    = False

Nothing super exciting. Two empty lists are equal, and two nonempty lists are equal if the heads and tails are equal. Finally, two arbitrary lists are non-equal. The only interesting part is the specialization directives, which should monomorphize equality checks on integer lists, strings, and lists of strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文