我正在尝试将我的 java 程序翻译成 Haskell。我的目标是将我的字符串分成几个字符串并将它们放在一个列表中。
这是我目前的代码
import Char
import IO
import Text.Regex
translate :: String -> Int
translate input =
testcode(splitRegex (mkRegex "\\s") input)
testcode 会根据第一个值进行一些测试,例如(在飞行中做这个还没有到这一步)
testcode :: [String] -> Int -> Int
testcode [] 0
testcode (x:xs) n
|(x=="test") = 1
|otherwise = testcode xs
我不断收到的编译错误如下:
Could not find module `Text.Regex'
Perhaps you meant Text.Read (from base)
如何导入 Text.Regex?
最佳答案
Text.Regex
位于 regex-compat
包中。你安装了吗?
Cabal 是 haskell 的包管理器:http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package
要安装 regex 包,请输入以下 a shell:
cabal install regex-compat
关于正则表达式导入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13233019/