disco
disco copied to clipboard
Edit-distance-based suggestions for unbound variables
When an unbound identifier is encountered, see if it is close to any existing identifiers. Can we use http://hackage.haskell.org/package/edit-distance for this? How fast is it to simply compute the edit distance from the given unbound identifier to every other identifier in scope?
Another thing we could do is if the user wrote something like ab
which is not in scope, but a
and c
are, we could suggest perhaps they meant a*c
.
http://hackage.haskell.org/package/edit-distance looks like a good option. We should add extra fields to Unbound
and UnboundTyVar
to hold a list of suggestions. Then in these places where those errors are generated, we check the rest of the names in scope using the edit-distance package (restrictedDamerauLevenshteinDistance
with default costs looks like the way to go) and save any names which are within a certain distance:
https://github.com/disco-lang/disco/blob/e049d9aba27976ad9a5c89aa137cb72d30c6976e/src/Disco/Typecheck.hs#L205
https://github.com/disco-lang/disco/blob/e049d9aba27976ad9a5c89aa137cb72d30c6976e/src/Disco/Typecheck.hs#L516