Skip to content

Incorrect transpilation of polymorphic where clauses #362

@HeinrichApfelmus

Description

@HeinrichApfelmus

Consider the following program

test : {{_ : Ord a}}  a  a  a  a
test x1 x2 x3 = min x1 y
  where
    y = max x2 x3

Agda2hs 1.2 transpiles this into

test :: Ord a => a -> a -> a -> a
test x1 x2 x3 = min x1 y
  where
    y :: a
    y = max x2 x3

However, this is not valid Haskell: The type signature y :: a is understood as a polymorphic value y : ∀ a. a, but what we really want is that the a is the same as the one in the type signature of test. However, this requires the use of the ScopedTypeVariables extension and an explicit introduction test :: forall a. Ord a => a -> a -> a -> a.

For reference, here is the error message when compiling the generated Haskell code:

 error: [GHC-25897]
    • Couldn't match expected type ‘a1’ with actual type ‘a’
      ‘a1’ is a rigid type variable bound by
        the type signature for:
          y :: forall a1. a1
        at haskell/Cardano/Wallet/Deposit/Pure/RollbackWindow.hs:75:5-10
      ‘a’ is a rigid type variable bound by
        the type signature for:
          test :: forall a. Ord a => a -> a -> a -> a
        at haskell/Cardano/Wallet/Deposit/Pure/RollbackWindow.hs:72:1-33
    • In the first argument of ‘max’, namely ‘x2’
      In the expression: max x2 x3
      In an equation for ‘y’: y = max x2 x3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions