Comments (3)
@chengluyu being a bit busy this week, maybe someone else wants to take this one up. Cc @Meowcolm024.
(Though we need to wait for #53 to be merged.)
from mlscript.
Ah and also: in the future the semantics of recursive definitions will be changed, so that all the rec def
s in a block can see each other, as in:
rec def foo() = bar()
rec def baz() = 1
rec def bar() = baz()
So it would be good to preemptively account for that future semantics in the code-gen.
Finally, we don't yet have a check that recursive defs are "compilable", but eventually we'll need one. For instance:
rec def foo = { bar: () => foo } // this is fine
rec def foo = { bar: foo } // this is NOT fine
It's fine for the JS code to either loop forever, stack-overflow, or return undefined
in the latter case.
from mlscript.
It seems #81 solves this for top-level defs but not for recursive let bindings. Cc @chengluyu:
:js
rec def pow0 n x =
if n > 0 then pow0 (n - 1) x * x
else 1
//│ // Prelude
//│ let res;
//│ // Query 1
//│ globalThis.pow0 = function pow0(n) {
//│ return (x) => n > 0 ? pow0(n - 1)(x) * x : 1;
//│ };
//│ res = pow0;
//│ // End of generated code
//│ pow0: int -> int -> int
//│ = [Function: pow0]
pow0 3 4
//│ res: int
//│ = 64
:js
def pow1 x =
let rec go n =
if n > 0 then go (n - 1) * x
else 1
in go
//│ // Query 1
//│ globalThis.pow1 = function pow1(x) {
//│ return ((function (go) {
//│ return go;
//│ })((n) => n > 0 ? go(n - 1) * x : 1));
//│ };
//│ res = pow1;
//│ // End of generated code
//│ pow1: int -> int -> int
//│ = [Function: pow1]
// FIXME support recursive let bindings
pow1 3 4
//│ res: int
//│ Runtime error:
//│ ReferenceError: go is not defined
from mlscript.
Related Issues (20)
- Simplify the `with` construct semantics
- Implement new MLscript syntax
- Traits should be implemented as proper mixins
- The next step of code generation
- TypeScript Libraries Support HOT 18
- Add comprehensive contribution guide
- Add documentation to the MLscript code base
- Type errors in class definitions are swallowed in the web demo
- Add support for class type difference HOT 1
- UCS tracking issue HOT 7
- Add enumerated types (not ADTs)
- Iron out semantics of new object definition parameters and fields HOT 3
- Implement virtuality and constructor restrictions HOT 1
- User-defined operators can lead to insufficient fuel and constraint leakage HOT 3
- Potential infinite loop in type checking HOT 3
- Constructors can be called with invalid parameters HOT 1
- Wrong mixin typing
- Some generic object types are not lattice homomorphisms and those which are should not be forall-distributivity targets
- Infinite loop in expanding abstract class with self type HOT 4
- Quasiquote syntax support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlscript.