Git Product home page Git Product logo

Comments (2)

baszalmstra avatar baszalmstra commented on August 21, 2024

Having a symbol at all is for consistency. We want a symbol to associate a type to a construct. We use : to ascribe a binding (let x:int: x is of type int) and -> to denote a return type (fn f(int) -> int applying f to an int results in an int).

The -> is used to distinguish the return type from the rest of the signature. We used to have : but we choose to revert to the same as Rust (partly because it was confusing for users coming from Rust).

There are a lot of languages that use -> (Mathematics, Rust, Swift, C++, Python) and there are a lot of languages using : (Typescript, Scala, Perl), there is no silver bullet. Here is a more formal explanation, which I think is also the reason Rust is using the return arrow. There are basically two cases where the return arrow makes an appearance:

  1. Function item declaration: fn foo(x: int) -> int {}
  2. Assignment of a function to a variable with explicit type: let x : fn(int) -> int = foo (not implemented yet)

One might say the arrow is clearer in the case where a function type is specified. To me let x : fn(T) -> U; is easier to understand than let x : fn(T) : U; but you may disagree.

All in all, I think its a matter of preference, we choose to use the return arrow.

from mun.

 avatar commented on August 21, 2024

@baszalmstra i am not asking to use : . i am proposing not having a symbol at all. like Go or Zig.

from mun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.