
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