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

Confused by type error on expression with consumption #1836

Closed
nbos opened this issue Jan 10, 2023 · 2 comments
Closed

Confused by type error on expression with consumption #1836

nbos opened this issue Jan 10, 2023 · 2 comments

Comments

@nbos
Copy link
Contributor

nbos commented Jan 10, 2023

The program

def main = map (const (iota 3 with [0] = 1)) (iota 3)

raises a type error

Cannot apply "map" to "(const (iota 3 with [0] = 1))" (invalid type).
Expected: a₈ -> x₁₀
Actual:   b₇ -> [3]i64

Type
  a₈ -> x₁₀
found to be functional.
When checking type of expression with consumption at test.fut:1:24-42

while

def main = map (\_ -> (iota 3 with [0] = 1)) (iota 3)

raises no such error. It's not clear to me why the first would raise a type error and not the second, or why the expected type can't be instantiated into the actual.

@athas
Copy link
Member

athas commented Jan 10, 2023

It's a conservative check meant to ensure that defunctionalisation can duplicate expressions when needed. This is in general not safe when the expression performs consumption (although it is in this case). It's been a very long while since this rule was instituted, so I no longer remember the actual problematic examples.

@athas
Copy link
Member

athas commented Jan 10, 2023

We can probably relax this a bit. I hope nothing important breaks.

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

2 participants