Comment #0 by bearophile_hugs — 2013-02-21T19:10:22Z
In the standard library of Haskell and D there is a function named "group" that has similar use. If in both languages you write such function name wrongly, adding a trailing "s" you get:
The D program:
import std.algorithm, std.stdio;
void main() {
writeln(groups([1, 1, 1, 3, 3]));
}
DMD 2.063alpha gives the error:
temp.d(3): Error: undefined identifier groups, did you mean template group(alias pred = "a == b", Range)(Range r)?
The Haskell program:
import Data.List
main = do
print $ groups [1, 1, 1, 3, 3]
The GHC compiler V.7.6.1 gives the error:
temp.hs:3:13:
Not in scope: `groups'
Perhaps you meant one of these:
`group' (imported from Data.List),
`groupBy' (imported from Data.List)
Likewise I'd like the error message of the D compiler to give the module name where group() comes from. This is useful:
- to understand better the offered suggestion, because it gives more context;
- It allows a coding trick useful when you're working with unfamiliar code: >Change an identifier from foo to fooX. The compiler will helpfully inform you "Not in scope: fooX. Perhaps you meant foo (imported from Data.Foo)?"<
So a possible error message becomes:
temp.d(3): Error: undefined identifier groups, did you mean template std.algorithm.group(alias pred = "a == b", Range)(Range r)?
------------------------
A second differnt but related possible enhancement for the D compiler (but for me with a lower priority) is to offer more than one suggestion when there is more than very similar identifier, like in the Haskell error message that suggests both "group" and "groupBy".
Comment #1 by robert.schadek — 2024-12-13T18:04:12Z