Understanding Text.Regex.Posix Design Choices

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]]?

+4
source share
1 answer

Text.Regex.Base.Context regex-base-0.83 ( 5 2007 .), regex-base-0.90 ( 13 2007 .). ( XXX THIS HADDOCK DOCUMENTATION IS OUT OF DATE XXX, .)

, , , String [Char], String [b] - , , , , OverloadedStrings ( , ).

+1

All Articles