gpt4 book ai didi

regex - Haskell:我应该费心编译正则表达式吗?

转载 作者:行者123 更新时间:2023-12-03 14:27:31 24 4
gpt4 key购买 nike

我的冲动是说是的,特别是如果我在多个代码位置使用相同的正则表达式,但是 this article表示该库将为我缓存编译(我什至不确定它会如何做):

There’s normally no need to compile regular expression patterns. A pattern will be compiled the first time it’s used, and your Haskell runtime should memoise the compiled representation for you.

最佳答案

如果您重用正则表达式,那么值得使用 RegexMaker类型类来定义“编译”的正则表达式。它有能力在你选择的 Monad 中采用额外的选项和报告编译失败的能力。

要使用“编译”形式,您可以使用来自 RegexLike 的“match”或“matchM”。这为您提供了等效于 =~ 或 ==~ 运算符。

关于regex - Haskell:我应该费心编译正则表达式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9652351/

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