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)]
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 thegetAllMatchesfunction. So you can do this: