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

"Richard O'Keefe" <[email protected]>
Newsgroups gmane.comp.lang.haskell.cafe
Message-ID <CABcYAdJPXM0Lrb=Z=WdjDqU+DLTabwfYQc2pTiEXPAU6KrzNRA@mail.gmail.com>
The clearest way that I know to write that code fragment is
  case break (== ch) str of
    (_,[]) -> []
    (xs,(_:ys)) -> [(xs,ys)]

It's one line longer, but there are no warnings and NO SURPRISES for the reader.
The version that matches on (_:_) before testing whether that's
possible surprised
me mightly.  Confused me, even.

On Sun, 21 Apr 2024 at 00:29, George Colpitts <[email protected]> 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 <[email protected]> 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.
_______________________________________________
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.