Following is some notes that are intended for potential project contributors, to understand the architecture and design motives of the language and the compiler.
Fun is a functional programming language, but why is it compiled to Golang, and embracing the Golang ecosystem?
If Fun is a toy language, it could target at any runtimes, and there are lots of options. But Fun is ambitious to be a real industrial language, then multiple factors need to be considered. Popular options are listed below.
Option | Pros | Cons | Example |
Mainstream virtual machine like JVM or .Net |
|
Heavy dependency on the VM | Scala, F# |
Create the language's own runtime | Tailored environment is flexible |
|
Haskell, Ocaml |
Fun wants to have the benefits of VM without writing a VM, so we are experimenting a new way: compiling to Golang. Note that transpiling to another language is not new, the GHC compiler also compiles to C.
Compared to C, Golang has all the tooling and features of a modern programming language, eg.
- Build system and module manager
- Garbage collector
- Green thread (go routine)
That's why we chose Golang as the target platform.
- Abstract syntax tree
- Type system
- Lexing
- Parsing
- Alpha transformation
- Type inference
- Code generation
- Golang compatibility
- Investigate type reconstruction with structural subtyping
- Retreat to local type inference
- Extend it with modern features
- Default parameter of function
- For comprehension
- Extension method
- Elegant exception/error handling
- Should we implement break/continue/return statements via escape continuation?
- If so, maybe we can add a variant of
let in end
expression, and borrow thelet/ec
syntax from Racket. - In addition, if escape continuation is supported, then all these statements plus exception handling can be built on it. Refer to this doc.
- If so, maybe we can add a variant of