Haskell pattern matching is often head strict, for example,f (x:xs) = ...
requires input list to be evaluated to (thunk : thunk). But sometimes such evaluation is not needed and function can afford to be non-strict on some arguments, for example f (x:xs) = 3
.
Ideally, in such situations we could avoid evaluating arguments to get the behaviour of const 3
, which could be done with irrefutable pattern: f ~(x:xs) = 3
. This gives us performance benefits and greater error tolerance.
My question is: Does GHC already implement such transformations via some kind of strictness analysis? Appreciate it if you could also point me to some readings on it.
seq x y
toy
, which would defeat the purpose ofseq
. A strict pattern, in principle, could be used as a special case ofseq
. – Gunmaker