News for hackers. Stuff that matters.
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @04:00AM (#37186592)
Hi, I am the lead of this project, you can try it now with our online IDE, https://try.moonbitlang.com (F5 to run)

The docs are available https://github.com/moonbitlang/moonbit-docs, the compiler would be publicly available when we reach the beta status (expected to be the end of Q2 in 2024).

Feel free to ask me any question

Re:Moonbit: The fast, compact and user friendly language for... by MarcScott on Saturday August 19, 2023 @04:05AM (#37186616)
Your docs at https://moonbitlang.com/docs/syntax/ are unreadable due to the text and background colour
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @04:39AM (#37186781)
Sorry, we are fixing that, should be better later
Re:Moonbit: The fast, compact and user friendly language for... by rapnie on Saturday August 19, 2023 @04:24AM (#37186712)
I may also point to the image on the announce page is 4.7 MB.
Re:Moonbit: The fast, compact and user friendly language for... by jwl4fun on Saturday August 19, 2023 @04:57AM (#37186861)
The image size should be smaller now, it's about 200k, thanks for your feedback :)
Re:Moonbit: The fast, compact and user friendly language for... by andrewcobby on Saturday August 19, 2023 @08:55PM (#37194926)
Each line of code on the homepage hero appears to be truncating the last character for me (W11/FF/ultrawide screen). Somewhat comically yielding `moon new hell` XD
Re:Moonbit: The fast, compact and user friendly language for... by tgv on Saturday August 19, 2023 @04:29AM (#37186737)
I think people would like to know about licenses, pricing, and control over the project. Perhaps your commercial strategy doesn't benefit from divulging that information now, but secrecy and uncertainty can kill interest.
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @04:51AM (#37186835)
It is in an very early stage, but I expect it will be free to use as normal users. To be honest, we are also thinking about how to make the project more sustainable in the long term, the project is maintained by a team of professionals who also need be paid. We will figure this out when we reach the beta (in the end of Q2/2024)
Re:Moonbit: The fast, compact and user friendly language for... by Etherlord87 on Sunday August 20, 2023 @05:38AM (#37197588)
What a great question, immediately made me realize I don't need it (killed my interest).
Re:Moonbit: The fast, compact and user friendly language for... by thangngoc89 on Saturday August 19, 2023 @04:23AM (#37186705)
Oh hey. Wasn't you the lead developer of Bucklescript/Rescript compiler? This gonna be epic.
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @04:28AM (#37186728)
Yes. Moonbit is heavily influenced by BuckleScript/ReScript. We learned a lot from our previous experience, that's why we are shipping our IDE even in the pre-alpha release. We also learned to how to make type checking fast and parallelisable.
Re:Moonbit: The fast, compact and user friendly language for... by andsoitis on Saturday August 19, 2023 @07:09AM (#37187561)
> We learned a lot from our previous experience

Does this mean you are no longer working on ReScript and you are fully focused on MoonBit?

Re:Moonbit: The fast, compact and user friendly language for... by sizediterable on Saturday August 19, 2023 @04:57AM (#37186869)
These are the usual questions I seek answers to first when seeing a new programming language:

  - What does writing asynchronous code look like
  - Will it have any novel or less mainstream features, e.g.
    - Algebraic effects [1]
    - Contexts/Capabilities [2]
    - Linear types [3]
  - Is the type system sound and does it support/need type casts
  - Does the language support interfaces/traits/protocols
  - How rich are generics, e.g.
    - Explicit variance annotations on type parameters
    - Lower or upper bound constraints on type parameters
    - Higher-kinded types
  - Is structural vs nominal subtyping more prevalent
  - Does it have algebraic data types? Generalized algebraic data types?
[1] https://v2.ocaml.org/manual/effects.html

[2] https://docs.hhvm.com/hack/contexts-and-capabilities/introdu...

[3] https://austral-lang.org/linear-types

Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @05:23AM (#37186990)
Thanks for your interest.

Note Moonbit is a language/platform for industrial usage(not an academic language), I contributed to OCaml so that I am familiar with the good/bad parts of a type system. Its aim is to build fast and run fast, and generate the tiny Wasm output.

Type system is sound, you can take it as Rust(- some features hinder fast compilation) with GC and an emphasis on data oriented programming, so we have ADT, generics, interface and ad-hoc polymorphism. We also plan to make the pattern match more expressive with first class pattern support.

The async story is constrained by the WASM runtime, we will evolve with the Wasm proposal.

Re:Moonbit: The fast, compact and user friendly language for... by wffurr on Saturday August 19, 2023 @07:16AM (#37187611)
I thought the raison d’être for Rust was not having a GC. If this is a garbage collected language, and requires a runtime for such, isn’t this more like Go or any JVM language?
Re:Moonbit: The fast, compact and user friendly language for... by blovescoffee on Saturday August 19, 2023 @07:56AM (#37187840)
They're just talking about the type system. Yes the type system in Rust serves it's GC-free goals but you could copy paste the type system and build other languages with different goals.
Re:Moonbit: The fast, compact and user friendly language for... by yawpitch on Saturday August 19, 2023 @08:13AM (#37187957)
Arguably the raison d’être for Rust is memory safe systems programming, and opt-in GC you implement as / if needed is just a consequence of that… if you’re not targeting the very small subset of systems that _cannot_ benefit from automated GC then that’s a great choice, but for everyone else it’s just complex boilerplate. This is aimed at an evolving runtime spec that already incorporates opt-in GC.

In other words if it’s Rust’s broader features but explicitly meant to write programs for a runtime that already includes opt-in GC, then it’s not doing what JVM languages or Go are doing, so there’s space for it.

Re:Moonbit: The fast, compact and user friendly language for... by spion on Saturday August 19, 2023 @09:23AM (#37188516)
For situations where you can afford a GC, Rust but with GC would be an excellent language, due to the ways macros are done, traits work, how errors are handled, tools like cargo, docs.rs, testing and doctests, self-contained binaries with additional ability to compile extra assets into them, high quality language server (rust-analyzer), and the quality of the ecosystem.

As it is now, though, regrettably Rust imposes on you the penalty of dealing with borrowing and ownership even when there is no reason to pay for that. Its not too bad in most cases but one can't help but imagine a Rust-but-with-GC world :)

Re:Moonbit: The fast, compact and user friendly language for... by wffurr on Saturday August 19, 2023 @10:45AM (#37189323)
For that world there is also Rhai (https://github.com/rhaiscript/rhai), TypeScript, Scheme, etc.

Though Moonbit does look nice too.

Re:Moonbit: The fast, compact and user friendly language for... by afavour on Saturday August 19, 2023 @10:50AM (#37189374)
> one can't help but imagine a Rust-but-with-GC world

Rust with reference counting gets you a long way there. I’ve leaned in Rc<> a ton in some projects and had a pretty great experience.

Re:Moonbit: The fast, compact and user friendly language for... by mmastrac on Saturday August 19, 2023 @11:12AM (#37189578)
I built https://github.com/mmastrac/keepcalm/ to specifically give "permission" to use ref-counting to make your life easier. For a webserver, references don't make any sense and really don't add anything measurable from a performance perspective.
Re:Moonbit: The fast, compact and user friendly language for... by afavour on Saturday August 19, 2023 @12:01PM (#37190087)
That’s awesome. I do think someone smarter than me needs to write a “Pragmatic Rust” book, or something. The complexities around references and lifetimes put a lot of people off but really aren’t necessary a lot of the time.
Re:Moonbit: The fast, compact and user friendly language for... by necrophcodr on Sunday August 20, 2023 @07:00AM (#37197972)
If you want some of the ergonomics and DX of Rust, but in a GC'd language, OCaml (the language also used to implement early Rust compilers) might be more the path to be taken. Great tooling, handlings errors in sensible ways, and pattern matching, allows you to move business logic faster and focus on shaping data rather than transforming the bytes of them.
Re:Moonbit: The fast, compact and user friendly language for... by curist on Saturday August 19, 2023 @06:02AM (#37187179)
Is having a dedicated fn keyword necessary? I mean, what’s the fundamental difference between a func and a fn ?
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @06:31AM (#37187331)
Not strictly necessary, we are not decided on it.

For func the annotation is required, while fn does not need any type annotation

Re:Moonbit: The fast, compact and user friendly language for... by darkest_ruby on Saturday August 19, 2023 @09:07AM (#37188385)
I would strongly recommend to only go with one syntax, and not differentiate between regular functions and lambda statement
Re:Moonbit: The fast, compact and user friendly language for... by ledauphin on Saturday August 19, 2023 @04:21PM (#37192756)
I disagree - allowing for type inference on the closures will make for a much more pleasant language, whereas requiring type annotations on top level functions makes sense for lots of reasons.
Re:Moonbit: The fast, compact and user friendly language for... by troupo on Saturday August 19, 2023 @04:39PM (#37192931)
> allowing for type inference on the closures

You can still have your type inference without forcing the unnecessary requirement that local functions be `fn` while top functions be `func`.

Re:Moonbit: The fast, compact and user friendly language for... by ledauphin on Saturday August 19, 2023 @07:31PM (#37194406)
agreed, but there's still differentiation in syntax, and I was responding to someone asking for no differentiation.
Re:Moonbit: The fast, compact and user friendly language for... by andrewcobby on Saturday August 19, 2023 @09:04PM (#37194986)
I agree with this, I'm designing a similar language and have gone with this approach. Same syntax for all functions, but top-level functions require explicit type annotations (purely for documentation/sanity more so than a technical requirement).
Re:Moonbit: The fast, compact and user friendly language for... by abusaidm on Saturday August 19, 2023 @06:07AM (#37187203)
Nice demo, I tried some of the examples and tweaked to see what happens. I noticed no mention of UTF-8 and I tried to add some arabic letters and other RTL letters and it printed garbage chars.

Are langs other than english supported?

Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @06:32AM (#37187342)
Yes, it is supposed to be supported, you are welcome to file an issue on github to add arabic letters https://github.com/moonbitlang/moonbit-docs
Re:Moonbit: The fast, compact and user friendly language for... by Lerc on Saturday August 19, 2023 @06:37AM (#37187367)
I couldn't see any reference to default parameters. Are they a thing?

I would quite like the ability to have something like

func makeBox(width: Int = 100, height: Int = width) -> BoxThing

everything else I've seen, I like the look of. One of my litmus tests for languages is to have the ability to make decent Vector types, tuples and operator overloading should perform that function nicely.

Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @06:41AM (#37187389)
`default parameters` and some local features will be elaborated later on. We make the big(non local) features first and add various nice sugars step by step.
Re:Moonbit: The fast, compact and user friendly language for... by DonHopkins on Saturday August 19, 2023 @06:48AM (#37187426)
Is there anything for binding Moonbit code to JavaScript, like Emscripten's Embind?

https://emscripten.org/docs/porting/connecting_cpp_and_javas...

What do you think of that approach?

Will things change as WebAssembly evolves?

Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @06:53AM (#37187446)
> Will things change as WebAssembly evolves?

Yes, but we also plan to support old Wasm versions, like 1.0 etc.

Note Moonbit is designed in a modular way that it should be easy to target different backends (JS, Native). Currently we are focused on make the Wasm experience optimal(including the debugger)

Re:Moonbit: The fast, compact and user friendly language for... by DonHopkins on Saturday August 19, 2023 @08:15AM (#37187968)
Thank you!

What I meant wasn't Moonbit targeting JavaScript, but integrating Moonbit compiled into WebAssembly with JavaScript, making it so they can call back and forth to each other more easily, like Embind wraps C++ classes, methods, and functions with glue so they are exposed and callable as JavaScript classes, methods, and functions.

Kind of like what SWIG or Boost.Python (which inspired Embind) does, too.

The plumbing for integrating JavaScript and WebAssembly is evolving (especially with respect to passing objects and garbage collection).

Re:Moonbit: The fast, compact and user friendly language for... by Corsome on Saturday August 19, 2023 @06:55AM (#37187456)
Will the compiler be open sourced?
Re:Moonbit: The fast, compact and user friendly language for... by hongbo_zhang on Saturday August 19, 2023 @07:05AM (#37187527)
The source code will be publicly available when we reach beta status(things are moving too fast right now).
Re:Moonbit: The fast, compact and user friendly language for... by Corsome on Saturday August 19, 2023 @12:10PM (#37190209)
This sounds like you're planning to use Business Source License (https://www.hashicorp.com/blog/hashicorp-adopts-business-sou...). Did I get that right?
Re:Moonbit: The fast, compact and user friendly language for... by andsoitis on Saturday August 19, 2023 @07:06AM (#37187538)
I loaded the IDE but don't see examples of doing graphics or UI. The docs are also silent on this topic, as far as I can tell.

Is graphics or UI programming possible in MoonBit?

Re:Moonbit: The fast, compact and user friendly language for... by troupo on Saturday August 19, 2023 @07:19AM (#37187630)
It clearly states: it targets web assembly. So, this should answer your question I think
Re:Moonbit: The fast, compact and user friendly language for... by andsoitis on Saturday August 19, 2023 @07:34AM (#37187716)
> It clearly states: it targets web assembly. So, this should answer your question I think

Not sure what you're implying.

Here's an example of doing graphics using Rust and WASM - http://cliffle.com/blog/bare-metal-wasm/#making-some-pixels

And another: https://blog.logrocket.com/implement-webassembly-webgl-viewe...

Given that MoonBit is developing their own IDE and it is hosted on the web, I would think one could provide an elegant pipeline to do graphics programming, no?

Re:Moonbit: The fast, compact and user friendly language for... by 10000truths on Saturday August 19, 2023 @08:53AM (#37188278)
A WebAssembly runtime is a pure compute+memory sandbox. It can only interact with the host environment in three ways:

1. The host calls an exported WASM function

2. The WASM runtime runs code that calls an imported function

3. The host reads/writes the WASM runtime's memory/globals

In your example, the WASM build process spits out two artifacts - a WASM module and a JS module. The JS module defines the actual JavaScript host functions that manipulate the canvas, and then exposes those functions to the WASM instance.

Re:Moonbit: The fast, compact and user friendly language for... by rapnie on Saturday August 19, 2023 @08:56AM (#37188306)
> I would contribute in this realm becase I'm a graphics and UI person and also enjoy working with new programming languages.

Maybe the case of Makepad will interest you then: https://news.ycombinator.com/item?id=36567681

https://github.com/makepad/makepad

Re:Moonbit: The fast, compact and user friendly language for... by eole666 on Saturday August 19, 2023 @07:40AM (#37187754)
Well, you can do graphics programming in c++ or using a game engine and compile it to Webassembly.. So this language could definitely have a graphics library.
Re:Moonbit: The fast, compact and user friendly language for... by WhiteNoiz3 on Saturday August 19, 2023 @12:28PM (#37190415)
That's only because the host javascript which loads the WASM is exposing functions to do webgl stuff. When you use emscripten to compile C++ is to WASM, part of that equation is the JS runtimes that allow you to call translate openGL calls to Webgl, play sounds etc. It's possible to do with moonbit, but it would require some work on your part.
Re:Moonbit: The fast, compact and user friendly language for... by kardianos on Saturday August 19, 2023 @08:51AM (#37188254)
* Is there a need to differentiate func and fn? * Part of the function signature is "->" to indicates what it returns. Is this arrow needed? * For new types, you use syntax "struct User". I think Go got it right in this case where types are created with "type User struct", which can also create function types for fn variables like "type AssignUser func(name: String, id: Int) -> Int". * Does it help the lexer/parser to have the ":"? In function signature, do you need the ":" in func(name: String)? Could it be "func(name String)"? Same with type declaration but not assignment "mut elems: List[Int]", could that not be "mut elems List[int]"?

I'm picking nits. Overall I like it.

Re:Moonbit: The fast, compact and user friendly language for... by politician on Saturday August 19, 2023 @09:32AM (#37188618)
I agree, it seems like there are a lot of decisions for the syntax to make writing the parser easier. It almost seems like the assumption is that there will be a robust autocomplete service available for inserting the extra notation.

The func/fn thing though with type inference of return values is especially annoying though because you won’t be able to hoist it to a package level function without changes to the signature. Subsequent readers have to perform their own mental return type analysis as well, and that’s just extra cognitive load. When reading code, I like when functions are extremely clear about their inputs and outputs.

I like that this exists though, and hope the project is successful.

Re:Moonbit: The fast, compact and user friendly language for... by 10000truths on Saturday August 19, 2023 @09:02AM (#37188345)
The docs don't seem to cover how you're supposed to interact with the host environment from within Moonbit. How do you define imported and exported functions?
Re:Moonbit: The fast, compact and user friendly language for... by jackcviers3 on Saturday August 19, 2023 @12:58PM (#37190750)
In the lexical closure doc example, why choose to show variable name shadowing? What is the purpose of `let x = 3` in the below?

let x = 3 func foo(x: Int) { fn inc() { x + 1 } // OK, will return x + 1 fn fail() { y + 1 } // fail: The value identifier y is unbound. }

`foo` also captures the global `x`, but shadows it with the parameter `x`.

Can `Generics` be generic - are there higher kinds? Are they all invariant, or do they have variance and if so what is the notation?

Maybe I missed it - can methods be destructured from structs? Can enums have methods?

Is there partial application for methods and functions?

Re:Moonbit: The fast, compact and user friendly language for... by ledgerdev on Saturday August 19, 2023 @01:08PM (#37190837)
Very cool, I really love to see these new wasm native languages, very exciting.

Do you have any plans for a standard library? Build one specific for the language, or will perhaps try use or create/collaborate on a cross language standard library based on wasm component model? Is this even possible or good idea?

May I ask the toolchain you're using to build Moonbit?

Re:Moonbit: The fast, compact and user friendly language for... by azdavis on Saturday August 19, 2023 @02:16PM (#37191538)
Glad to see new languages designed around having good support for IDEs. matklad (rust analyzer) and I wrote a bit about this:

- https://matklad.github.io/2023/08/01/on-modularity-of-lexica...

- https://azdavis.net/posts/pl-idea-tooling/

I think pure functions, sum/product types, and pattern matching are generally accepted as an excellent way to model and manipulate pure data. I wonder what the team’s thoughts are about handling less pure things like asynchrony and I/O, as well as more interesting control flow like exceptions/panicking, coroutines, generators, iterators, etc.

Re:Moonbit: The fast, compact and user friendly language for... by brundolf on Saturday August 19, 2023 @03:33PM (#37192270)
"Moonbit makes programming easier with its automatic memory management, setting it apart from Rust."

I'm curious how it handles allocations/deallocations (seemingly) without a GC or a borrow checker?

Re:Moonbit: The fast, compact and user friendly language for... by ice-bergg on Sunday August 20, 2023 @06:11AM (#37197727)
Why not go for global type inference? Should be possible with the relatively simple type system