Re: ghc should be able to deduce correct use of partial functions and not give a warning in such cases

Viktor Dukhovni <[email protected]>
Newsgroups gmane.comp.lang.haskell.cafe
Message-ID <[email protected]>
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.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.