gpt4 book ai didi

haskell - 我在哪里可以找到保留的 Haskell 关键字列表作为 [String]

转载 作者:行者123 更新时间:2023-12-01 07:38:20 24 4
gpt4 key购买 nike

我生成了一些haskell 代码(在haskell 中),我需要能够检测与haskell 关键字冲突的名称。有什么地方可以以编程方式检查 String 是否是 Haskell 关键字?

我当然可以自己编译它们的列表,但我不喜欢重新发明轮子。此外,如果引入了新关键字(通过扩展或在新规范中),我希望此列表自动更新。

最佳答案

hscolour uses such a simple list for its tokenise function .

keywords =
["case","class","data","default","deriving","do","else","forall"
,"if","import","in","infix","infixl","infixr","instance","let","module"
,"newtype","of","qualified","then","type","where","_"
,"foreign","ccall","as","safe","unsafe"]
keyglyphs =
["..","::","=","\\","|","<-","->","@","~","=>","[","]"]
layoutchars =
map (:[]) ";{}(),"
symbols =
"!#$%&*+./<=>?@\\^|-~"

你可以
import Language.Haskell.HsColour.Classify

isKeyword :: String -> Bool
isKeyword = (== [Keyword]) . map fst . tokenise

关于haskell - 我在哪里可以找到保留的 Haskell 关键字列表作为 [String],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24711863/

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