Skip to content

GHC should keep unfoldings for recursive functions which are suitable for specialization.

Motivation

Specialization is important to get good performance for many uses cases.

But currently even something simple as

elem _ []       = False
elem x (y:ys)   = x==y || elem x ys

Won't get an unfolding since it's recursive.

This is preventing specialization on the used Eq dictionary at use sites.

I've seen this cause needless regression in my code, in base and GHC's code base. And so far most people I talked to where surprised about the behaviour.

Proposal

GHC should be less eager to strip unfoldings of recursive functions if they have class constraints.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information