I played around a bit Text.Regex.Posixand I found this strange design choice.
This was my GHCi session:
Ξ»> "Needle, Haystack, foo, and bar." =~ "[^ ]+" :: String
"Needle,"
Ξ»> "Needle, Haystack, foo, and bar." =~ "[^ ]+" :: [[String]]
[["Needle,"],["Haystack,"],["foo,"],["and"],["bar."]]
Ξ»> "Needle, Haystack, foo, and bar." =~ "[^ ]+" :: [String]
<interactive>:27:35:
No instance for (RegexContext Regex [Char] [String])
arising from a use of β=~β
In the expression:
"Needle, Haystack, foo, and bar." =~ "[^ ]+" :: [String]
In an equation for βitβ:
it = "Needle, Haystack, foo, and bar." =~ "[^ ]+" :: [String]
I was surprised to find that in RegexContextinstances RegexLike a b => RegexContext a b [b]there was no instance , but only RegexLike a b => RegexContext a b [[b]].
I do not understand why this design was used. Why is there no instance for [String], as described above, and why is it instead only [[String]]?
source
share