HigherOrderCO / Bend

A massively parallel, high-level programming language
https://higherorderco.com
Apache License 2.0
17.19k stars 424 forks source link

Why not a statically-typed language? #374

Open cl3t0 opened 3 months ago

cl3t0 commented 3 months ago

Hi everyone!

I'm just wondering why Bend is not statically-typed. Here's an example similar to this one.

object V2 { x, y }

def distance(a, b):
  open V2: a
  open V2: b
  dx = b.x - a.x
  dy = b.y - a.y
  return (dx * dx + dy * dy) ** 0.5

def main():
  a = V2 { x: 10.0, y: 10.0 }
  b = V2 { x: 20.0, y: 22.0 }
  return distance(a, b)

The first thing that I thought was about setting a and b as we do in Rust, for example. This would remove the need to open the variables. We can annotate function output and object fields as well.

object V2 { x: f24, y: f24 }

def distance(a: V2, b: V2) -> f24:
  dx = b.x - a.x
  dy = b.y - a.y
  return (dx * dx + dy * dy) ** 0.5

def main():
  a = V2 { x: 10.0, y: 10.0 }
  b = V2 { x: 20.0, y: 22.0 }
  return distance(a, b)

It looks cleaner to me. Also, currently if I try to pass the incorrect type to the distance function it does not throws an error about opening a as V2. It returns a non-sense value as if it had run correctly. Here's an example.

object V2 { x, y }

def distance(a, b):
  open V2: a
  open V2: b
  dx = b.x - a.x
  dy = b.y - a.y
  return (dx * dx + dy * dy) ** 0.5

def main():
  a = 2.3
  b = V2 { x: 20.0, y: 22.0 }
  return distance(a, b)

Code output:

bend run hello.bend
Result: 2.300

I don't think every language should be statically-typed as it's a design decision. However, such a non-sense output sounds like a bug to me. What do you guys are planning about it?

partylikeits1983 commented 3 months ago

I agree. imho it would be nice as a statically typed language. Since it is written in rust, I think it would be cool if the language had the same syntax as Rust. An example of a DSL with rust syntax is Noir, which is also written in Rust.

But nevertheless Bend is super cool, I think the choice for picking a pythonic syntax was to appeal to as many people as possible.

developedby commented 3 months ago

We plan on adding a type system on top of Bend with Kind. It's important to have an untyped version that you can use because Bend has features which escape known type systems like unscoped variables.

KarlLivesey commented 3 months ago

for me the major pain point is I still find it really hard to parse functions without brackets mentally I would love bend but less like python

developedby commented 3 months ago

for me the major pain point is I still find it really hard to parse functions without brackets mentally I would love bend but less like python

You can use our functional syntax then! It's similar to haskell, but whitespaces are irrelevant and blocks are marked by brackets. https://github.com/HigherOrderCO/Bend/blob/main/docs/syntax.md#fun-syntax

Zafnok commented 3 months ago

We plan on adding a type system on top of Bend with Kind. It's important to have an untyped version that you can use because Bend has features which escape known type systems like unscoped variables.

Isn't Kind only functional syntax though? I like the friendliness of imperative to jump into, functional is scary

developedby commented 3 months ago

We plan on adding a type system on top of Bend with Kind. It's important to have an untyped version that you can use because Bend has features which escape known type systems like unscoped variables.

Isn't Kind only functional syntax though? I like the friendliness of imperative to jump into, functional is scary

Kind (not Formality or Kind1/Kind-Classic) is currently just a prototype. You can expect it to change in the future

cl3t0 commented 3 months ago

We plan on adding a type system on top of Bend with Kind.

What does this means? Bend will have a type system or not? I think Kind is super cool but it looks very sophisticated, calls itself a "proof language", and don't look receptive. I don't know what is the community feeling about it, but for me Bend is the easier alternative to Kind. I'm not suggesting dependent types as in Lean or a complicated type system as in TS, just a simple type system. I think it will allow much more people to adopt the language for production.

I know it's a design decision and my opinion probably won't change anything, but I'd like to at least understand the reasoning behind the decision to make Bend without a type system.

VictorTaelin commented 3 months ago

@cl3t0 Kind looking scary has nothing to do with what it actually implements. The type checker currently being implemented in Kind will also be used as the underlying type checker for Bend. This will be completely transparent to the user. The fact it is expressive enough (to, say, prove full theorems) doesn't impact someone not interested in these features!

developedby commented 2 months ago

I'm currently adding gradual typing to Bend, tracking it in https://github.com/HigherOrderCO/Bend/issues/615