unison icon indicating copy to clipboard operation
unison copied to clipboard

ability variable inference error when inlining certain functions

Open aryairani opened this issue 4 months ago • 3 comments

Describe and demonstrate the bug Transcript follows:

Sorry I wasn't able to minimize this much:

> lib.install @unison/base

  I installed @unison/base/releases/4.8.0 into
  lib.unison_base_4_8_0
type Branch = Branch Text
type GithubEvent = BranchCreate Branch | BranchUpdate Branch | BranchDelete Branch
type GithubEvent' = BranchCreate' | BranchUpdate' | BranchDelete'
type Summary = Summary (Map Branch GithubEvent')
> add

UCM accepts this version:

{{ Takes a subsequence of events from the middle or end of the stream, and summarizes them. }}
summarizeEvents : [GithubEvent] -> Summary
summarizeEvents =
  _ = {{ not sure why when I inline more than one of these three functions, I got an ability inference error }}
  handleCreate branch = Map.alter_ branch cases
      None -> Some (BranchCreate')
      Some (BranchCreate') -> bug "Got two successive Creates."
      Some (BranchUpdate') -> bug "Got a Create after an Update."
      Some (BranchDelete') -> Some (BranchUpdate')
  handleDelete branch = Map.alter_ branch cases
      None -> Some (BranchDelete')
      Some (BranchCreate') -> None
      Some (BranchUpdate') -> Some (BranchDelete')
      Some (BranchDelete') -> bug "Got two successive Deletes."
  handleUpdate branch = Map.alter_ branch cases
      None -> Some (BranchCreate')
      Some (BranchCreate') -> Some (BranchCreate')
      Some (BranchUpdate') -> Some (BranchUpdate')
      Some (BranchDelete') -> bug "Got an Update after a Delete."

  Summary << List.foldLeft_ Map.empty (flip cases
    BranchCreate branch -> handleCreate branch
    BranchDelete branch -> handleDelete branch
    BranchUpdate branch -> handleUpdate branch)
  Loading changes detected in scratch.u.

  + summarizeEvents     : [GithubEvent] -> Summary
  + summarizeEvents.doc : Doc

  Run `update` to apply these changes to your codebase.

but errors if I inline the three local functions:

summarizeEvents : [GithubEvent] -> Summary
summarizeEvents =
  Summary << List.foldLeft_ Map.empty (flip cases
    BranchCreate branch -> Map.alter_ branch cases
      None -> Some (BranchCreate')
      Some (BranchCreate') -> bug "Got two successive Creates."
      Some (BranchUpdate') -> bug "Got a Create after an Update."
      Some (BranchDelete') -> Some (BranchUpdate')
    BranchDelete branch -> Map.alter_ branch cases
      None -> Some (BranchDelete')
      Some (BranchCreate') -> None
      Some (BranchUpdate') -> Some (BranchDelete')
      Some (BranchDelete') -> bug "Got two successive Deletes."

    BranchUpdate branch -> Map.alter_ branch cases
      None -> Some (BranchCreate')
      Some (BranchCreate') -> Some (BranchCreate')
      Some (BranchUpdate') -> Some (BranchUpdate')
      Some (BranchDelete') -> bug "Got an Update after a Delete.")
  Loading changes detected in scratch.u.

  The expression in red needs the {e81} ability, but this location only has access to these abilities: {𝕖74, e75}

     10 |     BranchDelete branch -> Map.alter_ branch cases
     11 |       None -> Some (BranchDelete')
     12 |       Some (BranchCreate') -> None
     13 |       Some (BranchUpdate') -> Some (BranchDelete')
     14 |       Some (BranchDelete') -> bug "Got two successive Deletes."

Environment (please complete the following information):

  • 0.5.45

Additional context Add any other context about the problem here.

aryairani avatar Aug 19 '25 20:08 aryairani

@dolio Any ideas on this one? The workaround is easy enough if one thinks of it, though.

aryairani avatar Aug 19 '25 20:08 aryairani

Oh I guess having them factored out lets typechecking proceed in stages.

aryairani avatar Aug 19 '25 20:08 aryairani

Does not using << and flip help? I think sometimes those result in type checking situations that are more likely to bump into these multiple slack variable problems.

dolio avatar Aug 19 '25 20:08 dolio