Skip to content

GADTs not specialized properly

This has probably been raised before, but I can't find a ticket. If I write

data Silly a where
  Silly :: Ord a => a -> Silly a

isItSilly :: a -> Silly a -> Bool
isItSilly a (Silly x) = a < x

isItSillyInt :: Int -> Silly Int -> Bool
isItSillyInt = isItSilly

then I get

isItSilly
isItSilly =
  \ @ a_aBq eta_B2 eta1_B1 ->
    case eta1_B1 of _ { Silly $dOrd_aBs x_aAy ->
    < $dOrd_aBs eta_B2 x_aAy
    }

isItSillyInt
isItSillyInt = isItSilly

Although GHC knows that eta_B2 and x_aAy are Int, it looks up the < method in the eta1_B1 dictionary instead of just using ltInt. Note: it does not help to INLINE isItSilly.

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