gpt4 book ai didi

haskell - 为什么 haskell 同时保留 isAlpha 和 isLetter?

转载 作者:行者123 更新时间:2023-12-02 17:04:53 24 4
gpt4 key购买 nike

learn you a haskell这本书中,我发现isAlphaisLetter都检查一个字符是否是字母。

我找到了一个问题和答案 here ,这说明这两个函数没有区别。

现在,我想知道为什么 haskell 保留它们?由于历史原因?

我找到了解释here ,它说保留两个都是为了向后兼容性,但我不确定这是否正是原因。

有谁知道更多吗?

最佳答案

注意:以下内容仅针对 ghc

git log of ghc's sourcearchive of Haskell Cafe 周围走动,我找到了一些信息来回答你的问题。虽然这不是一个直接的答案,并且充满了垃圾信息,但希望这会有所帮助。

isAlpha 排在第一位

isAlpha 已于 1996 年包含在 initial revision 中。

2005 年初:增强 ghc 中的 unicode 支持

2005 年初,Dimitry Golubovsky 发布了 this question 关于 ghc 对 unicode 的支持有多好。他是 one of the developer of the unicode patch of hugs 。也许他想增强ghc的unicode支持。

后来他离开了this post

Before (i. e. up to and including 6.4), Unicode stuff was handled through wc* locale based functions for wide chars conversion. Since not every installation of Unix (or some other OS) has this set up properly (mine was not: personal itch), this code was proposed for GHC and finally made it there.

2005 年 3 月 14 日:添加了 isLetter

为了增强对 unicode 的支持,在 this commit 中添加了一些函数,例如 isLetterisMarkisNumber 等。提交的评论说:

Add Dimitry Golubovsky 's Unicode character class implementation. This will remove the dependency on libc's locale code and give us much more consistent support for Unicode across platforms.

Unicode.hs

These are copied from Hugs Unicode.hs

2005 年 3 月 16 日:添加了“两者等效”的注释

两天后,this commit添加了这两条评论。

-- This function is equivalent to 'Data.Char.isAlpha'.
isLetter :: Char -> Bool
-- This function is equivalent to 'Data.Char.isLetter'.
isAlpha :: Char -> Bool

我找不到添加此注释的原因,但我的假设是 - 由于 isAlpha 似乎已经支持 unicode,因此两个函数被认为是等效的。

结论

isAlpha 是最古老的,isLetter 是后来与其他一些来自 Hugs 的 unicode 函数一起添加的,所以也许没有理由只删除 isLetter 来自函数集。我没有足够的时间进一步调查,但我写下了我研究的所有信息。

关于haskell - 为什么 haskell 同时保留 isAlpha 和 isLetter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24073968/

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