From WG 2.11
Jump to: navigation, search

Programming languages often include specialized notation for common datatypes (e.g. lists) and some also build in support for specific specialized datatypes (e.g. regular expressions), but user-defined types must use general-purpose notations. Frustration with this causes developers to use strings, rather than structured representations, with alarming frequency, leading to correctness, performance, security and usability issues. Allowing developers to modularly extend a language with new notations could help address these issues. Unfortunately, prior mechanisms either limit expressiveness or are not safely composable: individually-unambiguous extensions can cause ambiguities when used together. We introduce type-specific languages (TSLs): logic associated with a type that determines how generic literal forms, able to contain arbitrary syntax, are parsed and expanded, hygienically, into general-purpose syntax. The TSL for a type is invoked only when a literal appears where a term of that type is expected, guaranteeing non-interference. We give evidence supporting the applicability of this approach and specify it with a bidirectional type system for an emerging language, Wyvern.