ndmitchell / ndmitchell/hlint

Incorrect eta-reduction suggestion in the presence of RankNTypes

Open
#514 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
1.6k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

hlint warns about the following code:

{-# LANGUAGE RankNTypes #-}
module Foo where

type A = forall a. a -> a

f :: A -> ()
f x = undefined x
$ hlint Foo.hs 
Foo.hs:7:1: Warning: Eta reduce
Found:
  f x = undefined x
Perhaps:
  f = undefined

1 hint

This suggestion is incorrect, however, since using f = undefined will cause the code to no longer typecheck:

$ /opt/ghc/8.4.3/bin/ghc Foo.hs 
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:7:5: error:
    • Cannot instantiate unification variable ‘a0’
      with a type involving foralls: A -> ()
        GHC doesn't yet support impredicative polymorphism
    • In the expression: undefined
      In an equation for ‘f’: f = undefined
  |
7 | f = undefined
  |     ^^^^^^^^^

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in Foo.hs with hlint and GHC, focusing on the eta-reduction hint for f x = undefined x under RankNTypes. Done means hlint no longer suggests the invalid f = undefined transformation, while valid eta-reduction suggestions remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.