Skip to content

Unannotated recursive local binding: Cannot unify 'Int -> Int' with 'Int -> Int' #680

Closed

Description

@i-am-the-slime

A local binding that has no type signature and refers to itself inside a lambda passed to another function is rejected by Iris with a CannotUnify error between two identical types. purs 0.15.16 accepts the same code.

Repro

module Main where

import Prelude

call :: forall f. (Unit -> f) -> f
call k = k unit

f :: Int -> Int
f = go
  where
  go = call \_ -> go

Iris 0.1.15

Error! · [CannotUnify] · src/Main.purs:11:3
  │
  • Cannot unify 'Int -> Int' with 'Int -> Int'
  │
  │     go = call \_ -> go
  │     ╰─────────────────

purs 0.15.16 (via spago) builds the same module successfully.

What changes the result

  • Adding a signature to the local binding (go :: Int -> Int) makes Iris accept it.
  • The same binding at top level, without a signature, is accepted.
  • let inside do fails the same way as where.
  • Rank-N is not required: call :: forall f. (forall x. x -> f) -> f fails identically.

Where it shows up

The playwright package (registry package set) uses this pattern in three places, so any project depending on it fails to build with Iris. For example, in Playwright/Dialog.purs:

type' :: Dialog -> Effect DialogType
type' = map convert <<< type''
  where
    type'' = effCall "type" \_ -> type''

There, Iris reports Cannot unify 'Function Dialog (Effect String)' with 'Function Dialog (Effect String)'.

Activity

  1. purefunctor commented on Nov 14, 2026

    @purefunctor
    Owner

    Fixed in aeedfce ([checking] Fix unannotated recursive local bindings).

    An unannotated local binding with no arguments, such as go = call \_ -> go, could already have its placeholder type linked to the body's type by the time the body was inferred. The let-binding checker then solved that unification variable to itself, which the occurs check rejects, so Iris reported Cannot unify 'Int -> Int' with 'Int -> Int'. It now relates the two types with unify, which accepts identical types before solving, as upstream's unifyTypes does.

    The regression fixture is tests-integration/fixtures/compiler/1794636859_unannotated_recursive_local_lambda. klntsky/purescript-playwright now builds with no errors; before the fix it failed in Playwright/Dialog.purs and Playwright.purs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions