Haskell +计算子字符串

时间:2016-01-15 05:56:47

标签: haskell substring

我非常接近这个,但我仍然陷入困境:/

txt :: String
txt = "[1] and [2] both feature characters who will do whatever it takes to " ++
  "get to their goal, and in the end the thing they want the most ends " ++
  "up destroying them.  In case of [3] this is a whale..."
references :: String -> Int

split :: String -> [String]
split str = words str

find :: [String] -> [String]
find xs = [ x | x <- xs, x == "["++"1"++"]" ]                           
references x = length (find (split x ))

我需要找到时间段[n]出现在n为数字0的字符串中。

在上面的例子中n = 3

我似乎无法编写谓词来捕获括号"[1]""[3]"括起来的所有数字。 (我在这里的代码中硬编码1)

0 个答案:

没有答案
相关问题