Turbo fish style

Is there a specific reason why the developers decided that the turbofish (::<>) syntax be used only while using a function and not while defining it?

// example definition
fn fx<T>() -> T {
// corresponding example usage
let x = fx::<T>();

Why not the same rule in both the contexts?

Prior question on URLO

Perhaps more importantly, this example, which is actually a test that must always pass:

fn main() {
    let (oh, woe, is, me) = ("the", "Turbofish", "remains", "undefeated");
    let _: (bool, bool) = (oh<woe, is>(me));

And why not require :: before <…> everywhere? That would be possible, but it would add quite a lot of visual noise in cases where it doesn’t solve any ambiguity.

Perhaps we should have an alternative syntax that doesn't require further disambiguation. We have Unicode identifiers, why not Unicode punctuation? Here are some brackets that are visually similar, but unlikely to be confused with < and >:

fn fx‹T›  // chevrons
fn fx〈T〉  // angle brackets (Miscellaneous Technical)
fn fx〈T〉 // angle brackets (CJK Symbols and Punctuation)
fn fx❬T❭   // medium angle brackets (Dingbats)
fn fx⟨T⟩  // mathematical angle brackets
fn fx«T»  // guillemets
fn fx《T》 // double angle brackets
fn fx「T」 // corner brackets

IDE support could make it even better. When you open up code that uses < and > as type parameter list delimiters, it could automatically render them as (for instance) and instead. And with a little context-sensitive partial parsing, the IDE could also render them correctly as you type, and if you ever type ::< immediately know that it should be replaced with .

This idea is mostly a joke, unless other people also like it, in which case it's not a joke and how dare you make fun of my genius idea.


哈哈 Actually, I frequently use paired brackets that are uncommon in English (e.g., « ») yet easy to keyboard (on a Mac) just to avoid grep mismatches.

Haskell and Agda have unicode syntax support. :wink:

Personally I'm against unicode brackets purely because my keyboard doesn't support them well. But to be fair, the Raku(perl6) has all sort of unicode operator support including this atomic integer operations.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.