Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic Effect Inference Inconsistency for Function Values Across Multiple Call Sites #401

Open
chtenb opened this issue Dec 26, 2023 · 1 comment

Comments

@chtenb
Copy link
Contributor

chtenb commented Dec 26, 2023

Take the following code

pub fun take-div(i : () -> div int) ()
pub fun take-total(i : () -> <> int) ()
pub fun get() : e int 42

Now this will compile

pub fun main()
  take-div(get)
  take-total(get)

But this will not

pub fun main()
  val f = get
  take-div(f)
  take-total(f)

with the error message being

repro.kk(4,14): error: effects do not match
context : take-total(f)
term : f
inferred effect: <div|_e>
expected effect: (<>)

Superficially the problem seems to be that the effect is inferred for the value f once, rather than for each call site individually.

@chtenb chtenb changed the title Issue with Polymorphic Effect Inference for Function Values in Koka: Inconsistent Effect Inference Across Multiple Call Sites Polymorphic Effect Inference Inconsistency for Function Values Across Multiple Call Sites Dec 26, 2023
@anfelor
Copy link
Collaborator

anfelor commented Jan 16, 2024

As already pointed out by Tim in issue #402 this is due to the missing let-generalization of effects. In particular, the example can be checked if the type signature of f is provided:

pub fun main()
  val f : forall <e> () -> e int = get 
  take-div(f)
  take-total(f)

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

No branches or pull requests

3 participants