
21 Apr
2024
21 Apr
'24
4:14 p.m.
On Sun, Apr 21, 2024 at 01:17:26PM +1200, Richard O'Keefe wrote:
The clearest way that I know to write that code fragment is case break (== ch) str of (_,[]) -> [] (xs,(_:ys)) -> [(xs,ys)]
I'd also consider changing the return type from `[([a], [a])]` to `Maybe ([a], [a])`, as in: maybeSplit :: Eq a => a -> [a] -> Maybe ([a], [a]) maybeSplit sep xs = case break (== sep) xs of (ys, (_:zs)) -> Just (ys, zs) _ -> Nothing A list of at most one element begs to be a `Maybe` instead. -- Viktor.