[Haskell-cafe] ghc should be able to deduce correct use of partial functions and not give a warning in such cases

Viktor Dukhovni ietf-dane at dukhovni.org
Sun Apr 21 16:14:18 UTC 2024


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.


More information about the Haskell-Cafe mailing list