Library defined literals
Hi!
I understand that the XML support in Scala is for the most part just libraries... all but one exception: XML literals have to be supported directly by the compiler.
Has there been some thoughts about letting libraries define literals, somewhat similar to implicit conversions? Not only XML literals, but numbers, strings, etc. just as well?
For JDK 7 they discuss allowing underscores within numeric literals to group them, and binary number literals, and list, set, and map literals. Scala can do the latter already... and not as literals but as library defined methods! If it was possible to define your own literals, DSLs could get even more natural: Writing 25ยบ18'25" would be very regular for nautical applications. Not to mention a lot of mathematical, physical, or chemical symbols that exist in the Unicode character set.
I'm quite sure anyone involved with writing compilers will start to shiver at the mere thought, but maybe it could turn out just as elegant and never-to-have-been-imagined-before like implicit conversions do. I think it would make the language even more regular... but maybe I'm wrong.
Just 2 ct.
Kind regards
Walter