I would like to write a Haskell function that's behavior is dependent upon regex pattern matching one of the arguments. In a language like C/Python/Perl, I would definitely just use a large if/else construct, but I don't really have that option. What is the most idiomatic Haskell way to handle this?
I've considered guards, but they don't work: No instance for (Data.String.IsString source0):
function arg
| arg =~ "pattern1" = dothis arg
| arg =~ "pattern2" = dothat arg
| otherwise = failwith arg
The pattern matching used in case constructs would be perfect, if it handled Regex.
function arg = case arg of
(pattern1 match) -> dothis match
(pattern2 match) -> dothat match
_ -> failwith arg
function :: String -> ReturnType