disco icon indicating copy to clipboard operation
disco copied to clipboard

Edit-distance-based suggestions for unbound variables

Open byorgey opened this issue 4 years ago • 2 comments

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?

byorgey avatar Oct 02 '19 15:10 byorgey

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.

byorgey avatar Jun 24 '20 16:06 byorgey

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

byorgey avatar Mar 05 '22 03:03 byorgey