[Haskell-cafe] How does one use Text.Regex.Base.RegexLike?

Jeremy Shaw jeremy at n-heptane.com
Tue Dec 23 14:29:20 EST 2008


Hello,

Does this help? 

http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/

j.

At Tue, 23 Dec 2008 11:21:41 -0800,
Lyle Kopnicky wrote:
> 
> [1  <multipart/alternative (7bit)>]
> [1.1  <text/plain; ISO-8859-1 (7bit)>]
> I'm trying to migrate code from using the old Text.Regex to the new
> Text.Regex.Base. But, I'm getting type errors. I can't even create a regex.
> Looking at the docs, it seems like this should print "bcd":
> 
> import Data.Array
> import Text.Regex.Base
> import Text.Regex.Posix
> 
> rx = makeRegex "a(.*)A"
> 
> Just (_, mt, _) = matchOnceText rx "abcdA"
> 
> main = putStrLn (fst (mt ! 0))
> 
> 
> But I get an error:
> 
> src\regex.hs:5:5:
>     No instance for (RegexMaker regex compOpt execOpt [Char])
>       arising from a use of `makeRegex' at src\regex.hs:5:5-22
>     Possible fix:
>       add an instance declaration for
>       (RegexMaker regex compOpt execOpt [Char])
>     In the expression: makeRegex "a(.*)A"
>     In the definition of `rx': rx = makeRegex "a(.*)A"
> 
> src\regex.hs:7:18:
>     No instance for (RegexLike regex [Char])
>       arising from a use of `matchOnceText' at src\regex.hs:7:18-41
>     Possible fix:
>       add an instance declaration for (RegexLike regex [Char])
>     In the expression: matchOnceText rx "abcdA"
>     In a pattern binding: Just (_, mt, _) = matchOnceText rx "abcdA"
> 
> Why does it say there is no instance? Isn't the instance imported by
> Text.Regex.Posix?
> 
> Why in the world is it so complicated just to get a matched substring out of
> the text? Is there an easier way?
> 
> Thanks,
> Lyle
> [1.2  <text/html; ISO-8859-1 (7bit)>]
> 
> [2  <text/plain; us-ascii (7bit)>]
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list