14 ms·
Moonbit: Fast, compact and user friendly language for WebAssembly
- homarp 3y ago"The development of an entire language toolchain, previously spanning years or even a decade, has been streamlined through our accrued experience and the establishment of a dedicated talented team from Moonbit's inception. We expect Moonbit to reach beta status by the end of Q2 of 2024, indicating a phase of relative stability, minimal bugs, and a robust Foreign Function Interface (FFI) for interactions with the Wasm host. We will make the source code publicly available once we reach beta quality. Our strategic plans involve Wasm GC integration for Wasm 2.0 and our homebrewed GC for Wasm 1.0, in line with Wasm proposals." so https://github.com/moonbitlang/ https://github.com/moonbitlang/ is empty for now
- homarp 3y agoSample code at https://try.moonbitlang.com/ https://try.moonbitlang.com/
- jasonjmcghee 3y agofwiw this just says "Connecting..." with the 3x3 dots for as long as my patience lasted
- jesperwe 3y agoWith a bit more patience you would have seen that it loads up VSCode for web, which takes a while.
- jasonjmcghee 3y agoWow a full 60 seconds though? Loads in a few seconds on github.dev Loads immediately on mobile though
- quickthrower2 3y agohug of death?
- hongbo_zhang 3y agoThe docs are available here: https://github.com/moonbitlang/moonbit-docs https://github.com/moonbitlang/moonbit-docs You can also try our online IDE https://try.moonbitlang.com https://try.moonbitlang.com
- deleted 3y ago[deleted]
- xmonkee 3y agoAbsolutely nothing about memory management?
- ledauphin 3y ago"Moonbit makes programming easier with its automatic memory management" isn't absolutely nothing. they apparently have their own GC and intend to use the one that comes with WASM 2.0.
- deleted 3y ago[deleted]
- afavour 3y agoThe site compares it to Rust and Go but to me the comparison is AssemblyScript. It’s also WASM-native and new with relatively little ecosystem around it. But compared to Moonbit it’s a familiar language to anyone that’s used TypeScript. So why use Moonbit over AssemblyScript?
- csjh 3y agoI think the Rust and Go comparisons are because they’re popular languages with first class WASM support but I agree
- jedisct1 3y agoWhy didn't they include Zig and AsssemblyScript, then?
- csjh 3y agoNo clue, maybe they performed too well :p
- giovannibonetti 3y agoNot OP, but although Zig is pretty good, it is arguably a relatively low-level language for application development. Thinking about pointers, for example, is tiring and unnecessary for most apps.
- noelwelsh 3y agoBecause Moonbit is a modern language, while AssemblyScript is carrying forward the mistakes of the past. For example, Moonbit supports pattern matching and most language constructs are expressions. AS doesn't have pattern matching and consists primarily of statements. Moonbit has algebraic data types; it's not clear to me that AS does. There might be other differences at runtime, but it's difficult to tell from just the website.
- IshKebab 3y agoGo is also an old-school statement based language though.
- noelwelsh 3y agoI'm excited to see a modern GCed language that is targetting WASM. Closest comparison is probably Grain (https://grain-lang.org/ https://grain-lang.org/).
- tempodox 3y agoGrain does look interesting, thanks for the link!
- frou_dh 3y agoApparently the Grain compiler is written in ReasonML rather than plain OCaml. Isn't it a bit comedic how readily these niche things are stacked up?
- giraffe_lady 3y agoWhy? A language's implementation language doesn't affect me much. And isn't reason just a syntax layer on ocaml? The tooling can convert back and forth and the runtime semantics are the same. I can read reason code fine if I need to, but I don't.
- noelwelsh 3y agoOCaml syntax is quite annoying ... everything is backwards and it even uses double semicolons! :-)
- iFire 3y agoNo license. https://github.com/moonbitlang/moonbit-docs/ https://github.com/moonbitlang/moonbit-docs/
- HL33tibCe7 3y agohttps://github.com/moonbitlang/moonbit-docs/blob/8be949ff902b554dc04643e592f0e2d05d4e4044/parser.mly#L2 https://github.com/moonbitlang/moonbit-docs/blob/8be949ff902... > (* Copyright International Digital Economy Academy, all rights reserved *)
- gmerc 3y agoI’m wondering what the game here is. A language itself dies with lack of adoption, I’m not sure there’s a business model here. Tools maybe but then why not have a license on the language.
- pmontra 3y agoAbout Team links to a edu.cn page in Chinese. It seems a university project but I can't confirm. The Join Us page is another Chinese one. The examples on the home page seem to require JavaScript from baidu.com.
- Erlangen 3y agoDemos still work with umatrix plugin on. It requires script from unpkg and msecnd(microsoft domain), but not baidu.
- pjmlp 3y agoSo why bother with this, when compared against AssemblyScript and Grain, both more mature and existing communities?
- noelwelsh 3y agoI would say Grain is very close to Moonbit. They are both MLs for WASM. AssemblyScript is not. No pattern matching, not expression oriented, no ADTs AFAICT, etc.
- deleted 3y ago[deleted]
- IshKebab 3y agoGrain miserably fails rule 0 of programming language websites - show me the language! They expect you to go through installation, IDE setup, hello world before they tell you anything about it. The front page doesn't even tell you anything about its unique features. This Moonbit page is a million times better. I might actually try it. I'm not going to try Grain. Why would I?
- pjmlp 3y agoThey assume anyone is clever enough to find the guide on their site. https://grain-lang.org/docs/guide/hello_world https://grain-lang.org/docs/guide/hello_world
- IshKebab 3y agoThat's a guide for how to learn the language once you've already decided that you want to learn it. There's nothing to convince me that I should bother. Hello world and variable declaration syntax isn't going to make me go "ooo interesting! Tell me more!". I skimmed the guide and found none of the promised "Grain is a new language that puts academic language features to work". It seems to be a reasonably nice ML/Rust-alike presumably with GC and depending on the unstable WASM GC proposals, though that's mostly a guess - obviously they don't say that anywhere in the main page.
- 3y ago
- DoesntMatter22 3y agoThere are now more programming languages coming out than JD frameworks! Hard to keep up
- andsoitis 3y agoUnless you're deeply interesting the programming language space for its own sake, the good news is you don't really have to keep up because they're unlikely to make any dent anytime soon. Even if you are interested in the programming language space, most are not groundbreaking.
- mijoharas 3y agoI tried clicking through to find some syntax and got to this page[0] which seems to show things but the text is illegible on a dark background (something to do with picking up a dark mode setting on my device maybe?) [0] https://moonbitlang.com/docs/syntax/ https://moonbitlang.com/docs/syntax/
- deleted 3y ago[deleted]
- jwl4fun 3y agoThanks for your feedback, the back background should works now.
- mijoharas 3y agoThanks! It is indeed fixed.
- layer8 3y agoThe colored syntax highlighting is still hard to read in dark mode, too little contrast. You really need different colors for light vs. dark mode.
- mijoharas 3y agoFwiw I did also think this a little, but they were good enough to be legible so I didn't mention it. The code examples actually looked fine to me on the page before the change due to the white background to them.
- IshKebab 3y agoDo you really avoid pointers by making everything a pointer?
- deleted 3y ago[deleted]
- TuringTest 3y agoYes, if the reference is immutable. The main problem with pointers is ad-hoc memory management anyway.
- IshKebab 3y agoThe references are not immutable in this case.
- TuringTest 3y agoA reference, unlike a pointer, always points to the same memory address(*); so the reference is immutable even if the cell contents it points to are not. That's the difference between a reference and a pointer, by definition; not just the different syntax. Back in the day, that was one of the major selling points of the new language Java over the more common C and C++. Developers don't learn about it nowadays because changing pointers is practically never done outside the most esoteric parts of system programming. (*) Semantically, at least. The compiler is free to relocate the value to a different memory position in a way transparent to the programmer.
- IshKebab 3y agoAh, not the pointer problems I thought they were talking about...
- taklimakan 3y agoThat’s not how you’d implement fibonacci in Go
- tgv 3y agoThat's not how you'd implement it in rust either. It's a pretty bad benchmark. From my experience, I'd guess it's lack of tail recursion and the switch statement. That one can be slow in Go. It is however a good teaser for Moonbit.
- makapuf 3y agoYes, using WASM and Go in an contrived example and not mentioning tinyGo is not very honest.
- spion 3y agoI'm not a fan of Go, but I have to admit that benchmark doesn't make any sense. If you use tail calls in a language that doesn't support TCO, then of course you'll get bad results. I guess its easier to just throw in some numbers than compare idiomatic implementations and then discuss tradeoffs with some nuance. Even if its just a language teaser, I'd still add a note on TCO to avoid misleading people though.
- hongbo_zhang 3y agoHi, I am the lead of this project, you can try it now with our online IDE, https://try.moonbitlang.com https://try.moonbitlang.com (F5 to run) The docs are available https://github.com/moonbitlang/moonbit-docs 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
- MarcScott 3y agoYour docs at https://moonbitlang.com/docs/syntax/ https://moonbitlang.com/docs/syntax/ are unreadable due to the text and background colour
- deleted 3y ago[deleted]
- rapnie 3y agoI may also point to the image on the announce page is 4.7 MB.
- deleted 3y ago[deleted]
- jwl4fun 3y agoThe image size should be smaller now, it's about 200k, thanks for your feedback :)
- andrewcobby 3y agoEach 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
- hongbo_zhang 3y agoSorry, we are fixing that, should be better later
- thefounder 3y agoI like it a lot tbh b/c it looks a lot like Go. Unfortunately Go is unusuable as wasm target for browsers due its huge binary. The browser needs a lot of time to download and parse it. Not to mention it starts to crash if your app is large enough(i.e a complete SPA in Go only).
- aatd86 3y agoYeah, Go has to embed the whole runtime and that amkes for huge payloads. I'm interested in your experience as I've been working on wasm SPA with Go. How does it crash? Seems to me that there are examples of stable webapps (for instance using go-app). Were you using a framework or raw syscall/js call? Have you tried compiling with tinyGo?
- thefounder 3y agoI've been using my own wrapper/library around syscall/js. It crashes mostly due memory issues/allocation. My own app worked fine until a point and then it started crashing. I applied several temporary fixes by limiting the amount of memory it allocates at start-up. Then optimised various libs to use less memory such: - instead of generating the html in pure Go using x/html package and applying it to the DOM later I created my own /x/html like package using the DOM (via syscall/js) directly. This was a big optimisation. - "cleaned" up/forked some public libraries such these provided by Google. For example many of Google's libraries (and not only) use an OpenTelemetry component that's cpu/memory intensive(at least for wasm/browsers). - replaced some libraries with my own implementation(i.e aws library) reduced to only the API calls I need. Now it stopped crashing in firefox/chrome (at least on my computer) but it crashes on Safari(at least on mobile). At this point I stopped working on it because I feel the platform is just not ready and I no longer have the drive to fix it(been working for more than 2 years on it). As you can see it forces you to think about resource management and browser compatibility and you are working in the dark b/c these limitations are not published/official. Keep in mind that I didn't run intensive tasks. Just SPA stuff(web services requests, data rendering etc). I didn't try to compile it with tinyGo because I built my tooling/libraries based on Go and unfortunately I do not have the resources required to support yet another platform/compiler(tinyGo). I made extensive use of reflection and last time I checked tinygo had some issues/restrictions with that. Recently I've implemented generics as well(where it made sense). I may revisit Go with WASM if/when there is a WASM-GC integration. The good part is that perf issues aside it made UI apps development a pleasure(for me at least).
- depr 3y agoWho funds the development? Will there be paid features?
- conaclos 3y agoThis makes me think about Grain [0] - another Wasm-first programming language. This could be nice to add Grain to the comparison. [0] https://grain-lang.org/ https://grain-lang.org/
- lemper 3y agoin an era where there are too many choices for writing things, if you don't show how your language is different and/or better compared to other languages which almost definitely more popular, then you'll lost before you start. I mean, show some example and I'll decide if it's worth to try. for this language? sorry, I'm not sold in the slightest.
- loeg 3y agoHalfway down the page is some (tiny) comparisons to Go and Rust, highlighting some differences and then elaborating (in prose) as to why that's better. We're both reading the same article, right? "A taste of MoonBit."
- jacquesm 3y agoWhat is your long term plan? Do you intend to support this language indefinitely?
- hongbo_zhang 3y agoYes, it will be my last project before retirement, we have a very ambitious goal and long term vision.
- jacquesm 3y agoThank you, that really helps. Too many abandonware languages already. If you are close to retirement it might be a good idea to get a governance structure in place that survives your retirement. That way the language isn't tied to you personally.
- revskill 3y agoCan i SSR a WASM module ?
- fovc 3y agoI see from comments here that Moonbit has a GC. However, the resulting binary for Fibonacci is 253 bytes, which presumably does not include a GC. Is that using the proposed WASM-native GC, or is the build system smart enough to omit the GC since it’s not needed here?
- csjh 3y agoProbably smart enough, since code size is part of their mission statement
- andsoitis 3y agoWhen you right-click on the file and choose Compile to Wat (second last menu item), you can see the WASM text directly. This is the output of the Fibonacci example: (module (import "spectest" "print_i32" (func $printi (param $i i32))) (memory $rael.memory (export "memory") 1) (table $rael.global funcref (elem)) (func $fib.fn/2 (param $n/1 i32) (result i32) (local $x/12 i32) (local.get $n/1) (local.set $x/12) (block $join:11 (local.get $x/12) (i32.const 0) (i32.eq) (if (result i32) (then (i32.const 0)) (else (local.get $x/12) (i32.const 1) (i32.eq) (if (result i32) (then (i32.const 1)) (else (br $join:11))))) (return)) (local.get $n/1) (i32.const 1) (i32.sub) (call $fib.fn/2) (local.get $n/1) (i32.const 2) (i32.sub) (call $fib.fn/2) (i32.add)) (func $fib2.fn/1 (param $num/2 i32) (result i32) (local $n/4 i32) (local $acc1/5 i32) (local $acc2/6 i32) (local $x/16 i32) (block $join:3 (local.get $num/2) (i32.const 0) (i32.const 1) (local.set $acc2/6) (local.set $acc1/5) (local.set $n/4) (br $join:3)) (loop $join:3 (result i32) (local.get $n/4) (local.set $x/16) (block $join:15 (block $join:14 (block $join:13 (local.get $x/16) (i32.const 0) (i32.eq) (if (result i32) (then (br $join:13)) (else (local.get $x/16) (i32.const 1) (i32.eq) (if (result i32) (then (br $join:14)) (else (br $join:15))))) (return)) (local.get $acc1/5) (return)) (local.get $acc2/6) (return)) (local.get $n/4) (i32.const 1) (i32.sub) (local.get $acc2/6) (local.get $acc1/5) (local.get $acc2/6) (i32.add) (local.set $acc2/6) (local.set $acc1/5) (local.set $n/4) (br $join:3))) (func $init/3 (i32.const 3) (call $fib.fn/2) (call $printi) (i32.const 46) (call $fib2.fn/1) (call $printi)) (export "_start" (func $init/3)))
- csjh 3y agoI’ve been considering trying my hand at a C-like WASM language, with most features mapping directly to WASM instructions. Surprised no one’s done something like that yet. Very cool tech
- moron4hire 3y agoWhat about AssemblyScript? https://www.assemblyscript.org/ https://www.assemblyscript.org/
- WhiteNoiz3 3y agoThere are a few.. Zig compiles to webassembly and looks fairly C-like. You can also use Cheerp or Emscripten to compile C to WebAssembly (though they both assume you are targeting the browser). Also +1 for Assemblyscript which is fairly C-ish. It's based on Javascript / Typescript but really works more like C if you are doing anything low level (also it doesn't support Closures etc).
- pxeger1 3y agoInteresting how this is written like a corporate press release.
- simon_void 3y agohow do you intend to handle nulls? allow nulls, nullable types or Option/Maybe type?
- bbkane 3y agoLooks quite nice, but you should add a banner to the load screen for https://try.moonbitlang.com https://try.moonbitlang.com that it will take quite a while to load and the page is not broken.
- lolinder 3y agoI'd assume that's not normal and is just due to being on the front page of HN.
- phosphorco 3y agoWell. I am very excited by this. We've built our front end in F# with Fable and our backend/engine is in Rust which compiles to WASM. The WASM story came second, and it'd be really cool to eventually lean into something like this, particularly given the much faster compilation time. Have followed your work on Rescript, and excited to see that this is where you've taken things.
- keithalewis 3y agoLooking forward to a "container-free Cloud IDE with offline capabilities, accessible from any location with a browser".
- mmastrac 3y agoThe module-level init seems like a great idea. I have been pondering how to get something like this right.
- garganzol 3y agoHaving `func` keyword for a top function definition, but `fn` keyword for a nested function definition is evil. It should be either `func` or `fn` independently of a particular context.
- Touche 3y agoReally, "evil"?
- politician 3y agoExcess energy wasted = Unnecessary cognitive load * number of affected (readers + writers) * lifetime of Moonbit code * Calories per thought Tongue in cheek, yes, but I’m sure that if we can make this about contributing to climate change via energy consumption then there will be a sufficient group of folks ready to label it evil.
- troupo 3y agoIt also makes refactoring a pain in the ass. Wanna convert your local function to top level? Do unnecessary monkey job of using a different keyword.
- brundolf 3y agoIt might be because nested functions are closures, which are optionally-named, optionally-typed, and can capture values, unlike top-level declarations. It's not unusual for languages to have a special closure/lambda syntax (whether that's really necessary or good is another question, but there's a lot of precedent)
- garganzol 3y agoAny function is a closure. Top-level function declarations can capture static variables and type members. Nested functions can capture static variables, type members, and local variables of a declaring function. Difference is negligible.
- MikeTheRocker 3y agoIs this project associated with Meta? The creator Hongbo Zhang worked at Meta on some of their open source programming language projects (ReasonML and Flow). According to LinkedIn, he's still employed there.
- neoneye2 3y agoSuggestion. Rename from `func` to `fn` so it's more aligned with Rust.
- tritipsocial 3y agoThe `fn` keyword is already used for local functions, which allow a more compact function definition than `func`.