Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006265OCamlOCaml generalpublic2013-12-11 14:432014-07-16 14:47
Reporterjohnwhitington 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusfeedbackResolutionopen 
PlatformOSOS Version
Product Version4.01.0 
Target VersionFixed in Version 
Summary0006265: Toplevel auto-correct should know about the standard library
DescriptionCurrently:

let x = map (fun x -> x * 2) [1; 2; 3];;
Error: Unbound value map
Did you mean max?


We might like:

let x = map (fun x -> x * 2) [1; 2; 3];;
Error: Unbound value map
Did you mean List.map?


So, this is the case that the "typo" is exactly the name of a function in a known library.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010701)
gasche (developer)
2013-12-11 15:25

I think this is easy to do in a not-really-satisfying way, and too hard (or too invasive) to do right.

(1) The easy thing is to know about the modules of the standard library, and look in them for an identifier that is exactly the same as the one used (or possibly at a short edit distance but we probably don't want that), without using any kind of typing information. In your case, it would suggest both Array.map and List.map, and would also suggest Queue.map if that existed -- and not know anything about Core, even if that's what you're using.

(2) The very-hard thing to do would be to look into the set of functions that have the correct type in the current "programming environment" (the set of modules you use in your program). The current implementation will not scale to using type information (it's really harder and more invasive), and the notion of "programming environment" is not really well-defined for OCaml programs (you *probably* do not want all the .cmi in your include path to be traversed for typo suggestions, and today's compiler invocation don't have enough information to do something more refined).

I don't think it's realistic to expect (2) in a medium-term future in the compiler. I'm interested in your opinion but I think (1) would probably not improve the user experience.

It may be the case that some heuristics could substantially improve solution (1). For example we could consider only modules that are mentioned in the current compilation unit -- and their submodules. So if you used M.foo correctly the first time, and then use 'foo', it would correctly suggest M.foo.
(0010702)
johnwhitington (reporter)
2013-12-11 20:35

Thanks for the careful analysis. I think you're right. Method (2) is not a job for the top level, but for something like Merlin.

Actually, I wonder why autocorrect was included in the first place, since the toplevel has resisted various other attempts to make it less ascetic (relying on rlwrap for example, being a common whinge, not that I mind it).

So I suppose we either check all the standard library instead of just Pervasives, or leave it as is.

On another note, is there a way of doing edit distance which knows about the keyboard layout likely to be in use in the locale? My original confusion was, I suppose, that "map" and "max" are really not close together at all!
(0010703)
gasche (developer)
2013-12-11 23:55

I'm not sure whether you know this already, but the typo-correction does not only take Pervasives into account, but everything that is present (unqualified) in the current typing environment: it will understand open-ed modules. In fact it can also follow module paths, eg. List.max will get corrected into List.map.
When I said that it cannot rely on type information, I meant that it used the faulty name (and the typing environment) as its only source of information, not the type of surrounding elements in the program context (eg. it couldn't reason that it's applied to a list, so it's List.map rather than Array.map).

I suspect trying to account for keyboard layout would hit diminishing return. Something that may be interesting is to allow displacement of several letters together (to account for the distance between "mod_float" and "float_mod" being relatively small in the mind of something that doesn't remember the exact name). But I would consider waiting a bit for more user experiences before starting to tweak ad infinitum.

(If you're reading this and have strong opinions on mistake-correcting techniques that could improve the user experience, I'm interested in feedback.)

- Issue History
Date Modified Username Field Change
2013-12-11 14:43 johnwhitington New Issue
2013-12-11 15:25 gasche Note Added: 0010701
2013-12-11 20:35 johnwhitington Note Added: 0010702
2013-12-11 23:55 gasche Note Added: 0010703
2014-07-16 14:47 doligez Status new => feedback


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker