
11 Jun
2007
11 Jun
'07
3:26 p.m.
Hi all, I'm trying to write a untab function that would split a string on tabs and return a list. Code is here. import Data.List (break, unfoldr) import Data.Char (String) untab :: String -> [String] untab s = unfoldr untab' s untab' :: String -> Maybe (String, String) untab' s | s == "" = Nothing | otherwise = Just (h, ts) where (h, t:ts) = break (== '\t') s This code raises an exception when handling the last portion of the string. Break returns a ("something", "") and t:ts cannot match on "". I was wondering if there way a clean way of handling this last case without adding tons of code. Some kind of "idiomatic expression" ;-) Thanks, Olivier.