[JsLIGO] Update syntax for generic functions
Motivation and Context
The syntax for defining generic functions was bit misleading,
Before, the type variables were bound in the annotation, not function expression.
const concat : <T>(xs : list<T>, ys : list<T>) => list<T> = (xs : list<T>, ys : list<T>) : list<T> => {
let f = ([x, ys] : [T, list<T>]) : list<T> => list([x, ...ys]);
return List.fold_right(f, xs, ys)
}
This is one of the things planned in the issue #1597
Description
This MR creates a way for binding type variables in function expressions.
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
In JsLIGO, the syntax for defining generic functions was misleading.
This MR fixes this issue by adding the syntatic contruct to bind type variables in function expressions.
Before
const concat : <T>(xs : list<T>, ys : list<T>) => list<T> = (xs : list<T>, ys : list<T>) : list<T> => {
let f = ([x, ys] : [T, list<T>]) : list<T> => list([x, ...ys]);
return List.fold_right(f, xs, ys)
}
Before the type variables were bound in the LHS type annotation in the type expression.
After
const concat = <T>(xs : list<T>, ys : list<T>) : list<T> => {
let f = ([x, ys] : [T, list<T>]) : list<T> => list([x, ...ys]);
return List.fold_right(f, xs, ys)
}
After this change type variables can be bound in function expression like above.
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha