Skip to content

ImplicitParams gives wrong result when used in a constraint tuple on GHC 9.8.1-alpha1

Summary

ImplicitParams returns the wrong result when the IP constraint is part of a constraint tuple. This failure appeared in GHC 9.8.1-alpha1 and does not seem to be present in earlier versions of GHC.

Steps to reproduce

The following program returns the wrong result on GHC 9.8.1-alpha1

{-# LANGUAGE ImplicitParams #-}

module Main where

type IPInt =
  ( ?ipInt :: Int
  , (Int ~ Int) -- Comment this out and main prints 7 instead of 3
  )

hasIPInt ::
  IPInt =>
  Int
hasIPInt = ?ipInt

addToIPInt
  :: forall r
   . IPInt
  => Int
  -> (IPInt => r)
  -> r
addToIPInt = \en f -> addToIPInt0 ?ipInt en f
 where
  addToIPInt0
    :: Int
    -> Int
    -> (IPInt => r)
    -> r
  addToIPInt0 gen en f =
    let ?ipInt = gen + en
     in f

main :: IO ()
main = print (let ?ipInt = 3 in addToIPInt 4 hasIPInt)

Expected behavior

The expected output is 7, but the program returns 3.

Environment

  • GHC version used: 9.8.1-alpha1

Optional:

  • Operating System: Linux (Ubuntu 22.04.2 LTS)
  • System Architecture: x86_64
Edited by Christiaan Baaij
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information