[Haskell-cafe] ghc should be able to deduce correct use of partial functions and not give a warning in such cases
Richard O'Keefe
raoknz at gmail.com
Fri Apr 19 03:33:38 UTC 2024
I do see a problem with the use of Safe.tailErr in this example
and that is that it turns something that could be simple and obvious
into something quite obscure.
On Fri, 19 Apr 2024 at 10:24, George Colpitts <george.colpitts at gmail.com> wrote:
>
> It seems that I can replace
>
> if null ys then [] else [(xs,tail ys)])
>
> with
>
> if null ys then [] else [(xs, Safe.tailErr ys)])
>
>
> and not get any warnings so I think I am going to do that. I'm surprised that the warning doesn't mention that option to fix the issue. Do you see any issues with this fix?
>
> Thanks,
> George
>
>
> On Tue, Apr 16, 2024 at 11:57 AM George Colpitts <george.colpitts at gmail.com> wrote:
>>
>> Hi Henning,
>>
>> Thanks for the quick response!
>> Yes, that's basically how I fixed it but I really don't want to have to do that since the code is correct. Not a big deal but may be irritating to beginners or large projects that want to eliminate warnings. Do you think an ER would be rejected ? If I remember correctly there is already detection of incomplete pattern matching that is ok and in such cases warnings are omitted. This would be similar to that.
>>
>> Cheers,
>> George
>>
>>
>> On Tue, Apr 16, 2024 at 11:46 AM Henning Thielemann <lemming at henning-thielemann.de> wrote:
>>>
>>>
>>> On Tue, 16 Apr 2024, George Colpitts 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?
>>>
>>>
>>> I would just use good old pattern matching:
>>>
>>> case ys of
>>> [] -> []
>>> _:zs -> [(xs,zs)]
>
> _______________________________________________
> 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.
More information about the Haskell-Cafe
mailing list