Make better use of known dictionaries
Example:
{-# LANGUAGE GADTs #-}
module T5835 where
data T a where
T :: Eq a => a -> T a
foo :: a -> T a -> Bool
{-# INLINE foo #-}
foo x = \(T y) -> x == y
appl :: (a -> b) -> a -> b
{-# NOINLINE appl #-}
appl f x = f x
bar :: T Int -> Bool
bar t = appl (foo 42) t
GHC generates this for bar
:
bar2 :: Int
bar2 = I# 42
bar1 :: T Int -> Bool
bar1 =
\ (ds_dhk :: T Int) ->
case ds_dhk of _ { T $dEq_agz y_aa4 ->
== @ Int $dEq_agz bar2 y_aa4
}
bar :: T Int -> Bool
bar = \ (t_aga :: T Int) -> appl @ (T Int) @ Bool bar1 t_aga
Note how it want to get the Eq
dictionary for Int
from T
. But we know the Eq Int
instance without inspecting T
and bar
could be significantly simplified if we used that.