How to avoid construction of dead dictionaries
Motivation
I'm writing this at Simon's direction here:
https://mail.haskell.org/pipermail/glasgow-haskell-users/2021-August/027007.html
We're using Conal Elliott's ConCat framework to implement Deep Learning. (This is a project in production automation for finding anomalies in sensor data.)
ConCat includes this definition:
(<+) :: Con a => (Con b => r) -> (a |- b) -> r
r <+ Entail (Sub Dict) = r
The right-hand argument of <+ leads to a dictionary construction that is a proof of a certain property, but the dictionary itself ends up being dead, like so:
case $w$dOpCon_r2kGJ ...
of
{ (# ww1_s27L3 #) -> ... }
^^^^^^^^^
never used
Yet, ghc (8.10.4) never elides this code. (I'm naively assuming because of the unboxed tuple, but actually have no clue.)
You can try this out here:
https://github.com/mikesperber/concat/tree/dead-dictionaries
Do this:
stack build neural-networks-concat:lib
This generates oodles of output, where you can search for OpCon
.
Proposal
I don't have a concrete proposal. But is there any chance of convincing ghc of erasing the dictionary construction?