如何存储此返回类型:[(x,y)]?
我有一个这样的函数:
example :: [Char] -> [Char]
example myString = ...................
where
pat = "something"
returnList = myString =~ pat :: [(MatchOffset,MatchLength)]
我的问题是我不知道如何存储从调用 myString =~ pat :: [(MatchOffset,MatchLength)]
返回的值我
不能只需将其存储在单个变量名中,就像我在这里所做的那样,但我不确定如何存储它。
目前它给出了这个错误:
No instance for (RegexContext
Regex [Char] [(MatchOffset, MatchLength)])
arising from a use of `=~'
Possible fix:
add an instance declaration for
(RegexContext Regex [Char] [(MatchOffset, MatchLength)])
In the expression: myString =~ pat :: [(MatchOffset, MatchLength)]
In an equation for `returnList':
returnList = myString =~ pat :: [(MatchOffset, MatchLength)]
In an equation for `example':
example myString
= ....................
where
pat = "something"
returnList = myString =~ pat :: [(MatchOffset, MatchLength)]
I have a function like this:
example :: [Char] -> [Char]
example myString = ...................
where
pat = "something"
returnList = myString =~ pat :: [(MatchOffset,MatchLength)]
My problem is that I don't know how to store the values I get back from calling myString =~ pat :: [(MatchOffset,MatchLength)]
I can't just store it in a single variable name as I have done here, but I'm not sure how I do store it.
It currently gives this error:
No instance for (RegexContext
Regex [Char] [(MatchOffset, MatchLength)])
arising from a use of `=~'
Possible fix:
add an instance declaration for
(RegexContext Regex [Char] [(MatchOffset, MatchLength)])
In the expression: myString =~ pat :: [(MatchOffset, MatchLength)]
In an equation for `returnList':
returnList = myString =~ pat :: [(MatchOffset, MatchLength)]
In an equation for `example':
example myString
= ....................
where
pat = "something"
returnList = myString =~ pat :: [(MatchOffset, MatchLength)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 实例可用于 RegexLike 类,您想要的值可能是
AllMatches [] (MatchOffset, MatchLength)
类型,它简单地包装了元组列表(MatchOffset, MatchLength)
为新类型。然后可以使用 getAllMatches 函数访问该列表。所以你可以这样做:Looking at the instances available for class RegexLike, the value you want is probably of type
AllMatches [] (MatchOffset, MatchLength)
, which simply wraps the list of tuples(MatchOffset, MatchLength)
to a newtype. The list can then be accessed using thegetAllMatches
function. So you can do this: