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

Unification Bug in Typechecker #321

Closed
noahyor opened this issue Mar 26, 2022 · 1 comment
Closed

Unification Bug in Typechecker #321

noahyor opened this issue Mar 26, 2022 · 1 comment
Labels
I-Expected Behavior The reported behavior is not actually a bug. Consider converting to a user experience issue. L-Type system Issues related to the Swarm language type system. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@noahyor
Copy link
Member

noahyor commented Mar 26, 2022

I was making a program called 'trash.sw' in VSCode containing this:

def rep : int -> cmd a -> cmd a = \n. \c.
  if (n == 0) {} {c; rep (n-1) c}
end

def trash : int -> string -> cmd () = \n. \i.
  trash <- build {};
  rep n (give trash i);
  reprogram trash {selfdestruct};
end;

and swarm-lsp gave the error message "Can't unify s0 and ()"

@byorgey
Copy link
Member

byorgey commented Mar 26, 2022

I think the problem is the type of rep. The type you have written claims that if you give it a command that returns a value of type a it will also yield a command that returns a value of type a, but it doesn't actually do that: when n reaches 0 it results in {} (which is shorthand for {noop}). noop does nothing and returns nothing and therefore has type cmd (), not cmd a. The most general type for rep would be rep : int -> cmd a -> cmd (). You could also figure this out by simply removing the type annotation from rep, i.e. writing def rep = \n. \c... etc. and seeing what type swarm thinks it has.

I don't think this is a bug, though the error message is definitely not very helpful. Related: #99 and #109.

@noahyor noahyor changed the title Unification Bug in Typechecker Unification ~Bug~ in Typechecker Mar 27, 2022
@noahyor noahyor changed the title Unification ~Bug~ in Typechecker Unification Bug in Typechecker Mar 27, 2022
@byorgey byorgey closed this as completed Apr 20, 2022
@byorgey byorgey added Z-User Experience This issue seeks to make the game more enjoyable to play. I-Expected Behavior The reported behavior is not actually a bug. Consider converting to a user experience issue. L-Type system Issues related to the Swarm language type system. labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-Expected Behavior The reported behavior is not actually a bug. Consider converting to a user experience issue. L-Type system Issues related to the Swarm language type system. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

No branches or pull requests

2 participants