I’m doing some simple regexp work in Haskell using this excellent tutorial as a basis, and I’m following the author’s advice of using explicit type signatures to get the =~ regexp operator to return a String. My problem is that I want to then manipulate this further (basically toUpper the result) and I can’t quite see how to do this.
I’ve tried each of the below and with each I get a Couldn't match expected type 'String' against inferred type 'Char' error or similar:
getSKU :: FilePath -> String
getSKU path =
toUpper $ path =~ "^sku[0-9]{5}" :: String
-- or...
getSKU path =
let key = (path =~ "^sku[0-9]{5}")
in toUpper key
-- or ...
getSKU =
toUpper . sub
where
sub p = (p =~ "^sku[0-9]{5}") :: String
I’m stumped – how do I express a type signature part way through an expression without resorting to a whole separate function?
The function
toUpperhas the signatureChar -> Char. Usemapto maptoUpperover all chars in aString: