spl / dlist

Difference lists in Haskell
https://hackage.haskell.org/package/dlist
BSD 3-Clause "New" or "Revised" License
65 stars 15 forks source link

Tests have compilation warnings about partial functions with GHC 9.8 #108

Closed andreasabel closed 8 months ago

andreasabel commented 1 year ago
tests/DListProperties.hs:70:31: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
70 | prop_head = eqOn (not . null) List.head (head . fromList)
   |                               ^^^^^^^^^

tests/DListProperties.hs:73:31: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
73 | prop_tail = eqOn (not . null) List.tail (tail . fromList)
   |                               ^^^^^^^^^

It seems that the use of head and tail here is intended, so maybe just switch off the warning.

spl commented 1 year ago

Thanks! I couldn't find any documentation on -Wx-partial. How do I turn it off?

spl commented 1 year ago

Ah, I think I just found it: -Wno-x-partial

spl commented 1 year ago

If I understand the proposal correctly, it seems like -Wno-x-partial is not backwards-compatible, so it would need to be done for GHC >= 9.8 in DListProperties.hs. Is that correct?

andreasabel commented 1 year ago

Indeed, yes.