Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language tour feedback #7

Open
FaberVitale opened this issue Feb 18, 2024 · 2 comments
Open

Language tour feedback #7

FaberVitale opened this issue Feb 18, 2024 · 2 comments

Comments

@FaberVitale
Copy link
Collaborator

Lang tour

Math ops

For UX reasons, it would be better to not duplicate the math operators.

There are 2 possible better alternatives.

1. Overload operators (Rust, Elm)

  • operator is overloaded and can be used for Int + Int and Float + Float.

Attempting to sum an Int with a Float is a compile time error.

    let a = 1.0 + 2; // error[E0277]: cannot add an integer to a float ❌

An explicit cast is required to sum integers

    let a = 1.0 + 2 as f32; // compiles ✅

2. Numeric promotion (Java approach)

In Java 1.0 + 2 Returns 3.0.
Numbers are automatically promoted, when necessary, in binary ops.

See 5.1.3 Narrowing Primitive Conversion

String concat operator

In SQL <> is the not equal operator.
It's confusing to use it for string concatenation.

Either +, ++ or :: are better alternatives.

@ascandone
Copy link
Owner

ascandone commented Feb 18, 2024

About the nums:
for the language to work without types it's crucial not to have polymorphic overloading. In other words, + has to have type Fn(Int, Int) -> Int and +. has to have type Fn(Float, Float) -> Float.
In order to be able to calculate 1 + 1.2 it's enough to expose a function int_to_float : Fn(Int) -> Float so that we don't need extra concepts in the language (e.g. as). This is actually already implemented in the kestrel_core library - currently private

About the strings:
Didn't think about it! <> is the str concat in elixir so I just went with this
But maybe ++ might be more natural 🤔

@ascandone
Copy link
Owner

Update 1: <> was changed into ++
Update 2: A simplified version of Haskell's type classes was introduced in #25. So far only the trait Show, Eq and Ord are included, but a Num type classes might be defined too, in order to solve the +, *, etc overloading problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants