Misleading strictness annotations in Data.List.NonEmpty

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Fri Jan 8 17:11:07 UTC 2021


On Fri, Jan 08, 2021 at 04:52:33PM +0000, Keith wrote:
> Currently:
> 
>    head ~(a :| _) = a
>    tail ~(_ :| as) = as
> 
> But head and tail are both strict. At best the '~'s have no effect.
> 
> Should I open a PR to change it to
> 
>    head (a :| _) = a
>    tail (_ :| as) = as

I would support that.  It would be nice if GHC warned about misleading
lazy patterns.

> or maybe even more clearly
> 
>    head !(a :l _) = a
>    tail !(_ :| as) = as

Why do you say "more clearly"?  Every pattern match is strict, more or
less by definition[1] so I don't see how a bang pattern adds anything.
If this is more clear then shouldn't we make the case to do it to
*every* pattern match everywhere?

Tom



[1] with the exception of weird edge cases around pattern synonyms:

pattern Pat :: p
pattern Pat <- _

pattern LPat :: a -> Maybe a
pattern LPat a <- ~(Just a)

f :: a -> Int
f Pat = 1
f _ = 2

f' :: a -> Int
f' !Pat = 1
f' _ = 2

g :: Maybe a -> Int
g (LPat _) = 1
g _ = 2

g' :: Maybe a -> Int
g' (LPat _) = 1
g' _ = 2


More information about the Libraries mailing list