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

George Colpitts george.colpitts at gmail.com
Sat Apr 20 16:24:11 UTC 2024


I've decided to stick with case and pattern matching as Henning suggested
in his original reply.

Thanks


On Sat, Apr 20, 2024 at 12:30 PM Andrew Lelechenko <
andrew.lelechenko at gmail.com> wrote:

> Hi George,
>
> If you do not want to pattern match on `ys`, the simplest solution is to
> do what the GHC warning suggests you to do and use `drop 1` instead of
> `tail`. Another alternative is `Data.List.uncons` followed by
> `Data.Maybe.maybe`.
>
> Best regards,
> Andrew
>
> On 20 Apr 2024, at 13:28, George Colpitts <george.colpitts at gmail.com>
> wrote:
>
> Thanks for everybody's replies
>
> To give more context the original code from Ch. 12 of Bird's *Thinking
> Functionally with Haskell* was:
>
>
> let (xs, ys) = break (== ch) str in
>
>          if null ys then [] else [(xs, tail ys)])
>
> I replaced it with
>
> let (xs, ys@(_ : t)) = break (== ch) str in
>
>          if null ys then [] else [(xs, t)])
>
> On Tue, Apr 16, 2024 at 10:51 AM George Colpitts <
> george.colpitts at gmail.com> wrote:
>
>> ghc should be able to deduce correct use of partial functions and not
>> give a warning in such cases, e.g. in 9.8.2
>>
>>      if null ys then [] else [(xs,tail ys)])
>>
>> gets a warning
>>
>>       warning: [GHC-63394] [-Wx-partial]
>>
>> but it is clear that this use of tail will never be a problem so IMHO
>> that line of code should not get a warning.
>>
>> Does anybody know if there is a plan or enhancement request to eliminate
>> such warnings?
>>
>> Cheers
>> George
>>
>>
>>
>>
>> _______________________________________________
> 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.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20240420/af016345/attachment.html>


More information about the Haskell-Cafe mailing list