diff --git a/packages/squiggle-lang/.prettierignore b/packages/squiggle-lang/.prettierignore
new file mode 100644
index 00000000..07e4ebf8
--- /dev/null
+++ b/packages/squiggle-lang/.prettierignore
@@ -0,0 +1,3 @@
+*.bs.js
+*.gen.tsx
+dist
diff --git a/packages/squiggle-lang/README.md b/packages/squiggle-lang/README.md
index e1a6cd98..fcd0c7a2 100644
--- a/packages/squiggle-lang/README.md
+++ b/packages/squiggle-lang/README.md
@@ -1,24 +1,28 @@
# Squiggle language
## Build for development
-We assume that you ran `yarn` at the monorepo level.
-``` sh
+
+We assume that you ran `yarn` at the monorepo level.
+
+```sh
yarn build
```
-`yarn bundle` is needed for a deployment.
+`yarn bundle` is needed for a deployment.
-Other:
-``` sh
+Other:
+
+```sh
yarn start # listens to files and recompiles at every mutation
yarn test
yarn test:watch # keeps an active session and runs all tests at every mutation
-# where o := open in osx and o := xdg-open in linux,
+# where o := open in osx and o := xdg-open in linux,
yarn coverage; o _coverage/index.html # produces coverage report and opens it in browser
```
## Information
+
Squiggle is a language for representing probability distributions, as well as functions that return probability distributions. Its original intended use is for improving epistemics around EA decisions.
This package, `@quri/squiggle-lang`, contains the core language of squiggle. The main feature revolves around evaluating squiggle expressions. Currently the package only exports a single function, named "run", which from a squiggle string returns an object representing the result of the evaluation.
@@ -32,7 +36,9 @@ ReScript has an interesting philosophy of not providing much in the way of effec
`.gen.ts` files are created by the [`@genType`](https://rescript-lang.org/docs/gentype/latest/getting-started) decorator, which creates typescript typings for needed parts of the codebase so that they can be easily used in typescript. These .gen.ts files reference the .bs.js files generated by rescript.
### Errors regarding the `rationale` package
+
You may notice sometimes, that there are errors about the `rationale` package. If you ever get these errors, `yarn build` should fix this issue. These errors occur because `yarn build` also needs to create build files that are in `node_modules`. So if you replace `node_modules` you may need to rebuild to get those files back.
## Distributing this package or using this package from other monorepo packages
-As it says in the other `packages/*/README.md`s, building this package is an essential step of building other packages.
+
+As it says in the other `packages/*/README.md`s, building this package is an essential step of building other packages.
diff --git a/packages/squiggle-lang/__tests__/JS__Test.ts b/packages/squiggle-lang/__tests__/JS__Test.ts
index 8e5961a3..fb9a3697 100644
--- a/packages/squiggle-lang/__tests__/JS__Test.ts
+++ b/packages/squiggle-lang/__tests__/JS__Test.ts
@@ -1,4 +1,9 @@
-import { run, GenericDist, resultMap, makeSampleSetDist } from "../src/js/index";
+import {
+ run,
+ GenericDist,
+ resultMap,
+ makeSampleSetDist,
+} from "../src/js/index";
let testRun = (x: string) => {
let result = run(x);
@@ -39,7 +44,6 @@ describe("Multimodal too many weights error", () => {
});
describe("GenericDist", () => {
-
//It's important that sampleCount is less than 9. If it's more, than that will create randomness
//Also, note, the value should be created using makeSampleSetDist() later on.
let env = { sampleCount: 8, xyPointLength: 100 };
diff --git a/packages/squiggle-lang/bsconfig.json b/packages/squiggle-lang/bsconfig.json
index 958a3af8..4ff06737 100644
--- a/packages/squiggle-lang/bsconfig.json
+++ b/packages/squiggle-lang/bsconfig.json
@@ -11,11 +11,7 @@
"subdirs": true
}
],
- "bsc-flags": [
- "-bs-super-errors",
- "-bs-no-version-header",
- "-bs-g"
- ],
+ "bsc-flags": ["-bs-super-errors", "-bs-no-version-header", "-bs-g"],
"package-specs": [
{
"module": "commonjs",
@@ -27,13 +23,13 @@
"bs-dependencies": [
"@glennsl/rescript-jest",
"@glennsl/bs-json",
- "rationale",
+ "rationale",
"bisect_ppx"
],
"gentypeconfig": {
"language": "typescript",
"module": "commonjs",
- "shims": {"Js": "Js"},
+ "shims": { "Js": "Js" },
"debug": {
"all": false,
"basic": false
@@ -44,10 +40,6 @@
"number": "+A-42-48-9-30-4-102-20-27-41"
},
"ppx-flags": [
- [
- "../../node_modules/bisect_ppx/ppx",
- "--exclude-files",
- ".*_test\\.res$$"
- ]
+ ["../../node_modules/bisect_ppx/ppx", "--exclude-files", ".*_test\\.res$$"]
]
}
diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json
index 6146d1c2..a2c93a54 100644
--- a/packages/squiggle-lang/package.json
+++ b/packages/squiggle-lang/package.json
@@ -10,7 +10,7 @@
"test:reducer": "jest --testPathPattern '.*__tests__/Reducer.*'",
"test": "jest",
"test:watch": "jest --watchAll",
- "coverage": "rm -f *.coverage; yarn clean; BISECT_ENABLE=yes yarn build; yarn test; bisect-ppx-report html",
+ "coverage": "rm -f *.coverage; yarn clean; BISECT_ENABLE=yes yarn build; yarn test; bisect-ppx-report html",
"all": "yarn build && yarn bundle && yarn test"
},
"keywords": [
@@ -25,7 +25,7 @@
"mathjs": "10.4.3",
"pdfast": "^0.2.0",
"rationale": "0.2.0",
- "rescript": "^9.1.4",
+ "rescript": "^9.1.4",
"bisect_ppx": "^2.7.1"
},
"devDependencies": {
diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts
index a9f2080c..e904eb7b 100644
--- a/packages/squiggle-lang/src/js/index.ts
+++ b/packages/squiggle-lang/src/js/index.ts
@@ -7,12 +7,8 @@ import type {
} from "../rescript/ProgramEvaluator.gen";
export type { SamplingInputs, exportEnv, exportDistribution };
export type { t as DistPlus } from "../rescript/OldInterpreter/DistPlus.gen";
-import {
- genericDist,
- env,
- error,
-} from "../rescript/TypescriptInterface.gen";
-export {makeSampleSetDist} from "../rescript/TypescriptInterface.gen";
+import { genericDist, env, error } from "../rescript/TypescriptInterface.gen";
+export { makeSampleSetDist } from "../rescript/TypescriptInterface.gen";
import {
Constructors_mean,
Constructors_sample,
@@ -68,7 +64,10 @@ type result =
value: b;
};
-export function resultMap(r: result, mapFn: ((x: a) => b)): result {
+export function resultMap(
+ r: result,
+ mapFn: (x: a) => b
+): result {
if (r.tag === "Ok") {
return { tag: "Ok", value: mapFn(r.value) };
} else {
@@ -76,8 +75,8 @@ export function resultMap(r: result, mapFn: ((x: a) => b)): result(r: result): a | c {
- return r.value
+export function resultExn(r: result): a | c {
+ return r.value;
}
export class Distribution {
@@ -90,55 +89,55 @@ export class Distribution {
return this;
}
- mapResultDist(r: result) : result{
+ mapResultDist(r: result): result {
return resultMap(r, (v: genericDist) => new Distribution(v, this.env));
}
- mean() : result {
+ mean(): result {
return Constructors_mean({ env: this.env }, this.t);
}
- sample(): result {
+ sample(): result {
return Constructors_sample({ env: this.env }, this.t);
}
- pdf(n: number): result {
+ pdf(n: number): result {
return Constructors_pdf({ env: this.env }, this.t, n);
}
- cdf(n: number): result {
+ cdf(n: number): result {
return Constructors_cdf({ env: this.env }, this.t, n);
}
- inv(n: number): result {
+ inv(n: number): result {
return Constructors_inv({ env: this.env }, this.t, n);
}
- normalize() : result {
+ normalize(): result {
return this.mapResultDist(
Constructors_normalize({ env: this.env }, this.t)
);
}
- toPointSet() : result{
+ toPointSet(): result {
return this.mapResultDist(
Constructors_toPointSet({ env: this.env }, this.t)
);
}
- toSampleSet(n: number) : result{
+ toSampleSet(n: number): result {
return this.mapResultDist(
Constructors_toSampleSet({ env: this.env }, this.t, n)
);
}
- truncate(left: number, right: number) : result {
+ truncate(left: number, right: number): result {
return this.mapResultDist(
Constructors_truncate({ env: this.env }, this.t, left, right)
);
}
- inspect() : result {
+ inspect(): result {
return this.mapResultDist(Constructors_inspect({ env: this.env }, this.t));
}
@@ -150,37 +149,37 @@ export class Distribution {
return Constructors_toSparkline({ env: this.env }, this.t, n);
}
- algebraicAdd(d2: Distribution) : result {
+ algebraicAdd(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicAdd({ env: this.env }, this.t, d2.t)
);
}
- algebraicMultiply(d2: Distribution) : result {
+ algebraicMultiply(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicMultiply({ env: this.env }, this.t, d2.t)
);
}
- algebraicDivide(d2: Distribution) : result {
+ algebraicDivide(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicDivide({ env: this.env }, this.t, d2.t)
);
}
- algebraicSubtract(d2: Distribution) : result {
+ algebraicSubtract(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicSubtract({ env: this.env }, this.t, d2.t)
);
}
- algebraicLogarithm(d2: Distribution) : result {
+ algebraicLogarithm(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicLogarithm({ env: this.env }, this.t, d2.t)
);
}
- algebraicPower(d2: Distribution) : result{
+ algebraicPower(d2: Distribution): result {
return this.mapResultDist(
Constructors_algebraicPower({ env: this.env }, this.t, d2.t)
);
@@ -192,31 +191,31 @@ export class Distribution {
);
}
- pointwiseMultiply(d2: Distribution) : result{
+ pointwiseMultiply(d2: Distribution): result {
return this.mapResultDist(
Constructors_pointwiseMultiply({ env: this.env }, this.t, d2.t)
);
}
- pointwiseDivide(d2: Distribution) : result{
+ pointwiseDivide(d2: Distribution): result {
return this.mapResultDist(
Constructors_pointwiseDivide({ env: this.env }, this.t, d2.t)
);
}
- pointwiseSubtract(d2: Distribution) : result{
+ pointwiseSubtract(d2: Distribution): result {
return this.mapResultDist(
Constructors_pointwiseSubtract({ env: this.env }, this.t, d2.t)
);
}
- pointwiseLogarithm(d2: Distribution) : result{
+ pointwiseLogarithm(d2: Distribution): result {
return this.mapResultDist(
Constructors_pointwiseLogarithm({ env: this.env }, this.t, d2.t)
);
}
- pointwisePower(d2: Distribution) : result{
+ pointwisePower(d2: Distribution): result {
return this.mapResultDist(
Constructors_pointwisePower({ env: this.env }, this.t, d2.t)
);
diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/README.md b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/README.md
index e69e449e..1deaa40b 100644
--- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/README.md
+++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/README.md
@@ -4,11 +4,12 @@ This library provides one interface to generic distributions. These distribution
Different internal formats (symbolic, point set, sample set) allow for benefits and features. It's common for distributions to be converted into either point sets or sample sets to enable certain functions.
-In addition to this interface, there's a second, generic function, for calling functions on this generic distribution type. This ``genericOperation`` standardizes the inputs and outputs for these various function calls. See it's ``run()`` function.
+In addition to this interface, there's a second, generic function, for calling functions on this generic distribution type. This `genericOperation` standardizes the inputs and outputs for these various function calls. See it's `run()` function.
Performance is very important. Some operations can take a long time to run, and even then, be inaccurate. Because of this, we plan to have a lot of logging and stack tracing functionality eventually built in.
## Diagram of Distribution Types
+
```mermaid
graph TD
A[Generic Distribution] -->B{Point Set}
@@ -34,7 +35,8 @@ graph TD
## Diagram of Generic Distribution Types
## Todo
-- [ ] Lots of cleanup
+
+- [ ] Lots of cleanup
- [ ] Simple test story
- [ ] Provide decent stack traces for key calls in GenericOperation. This could be very useful for debugging.
- [ ] Cleanup Sample Set library
@@ -45,4 +47,4 @@ graph TD
- [ ] Allow these functions to be run on web workers
- [ ] Refactor interpreter to use GenericDist. This might not be necessary, as the new reducer-inspired interpreter is integrated.
-## More todos
\ No newline at end of file
+## More todos
diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js
index c901dd96..460846e8 100644
--- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js
+++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js
@@ -1,4 +1,4 @@
-const pdfast = require('pdfast');
+const pdfast = require("pdfast");
const _ = require("lodash");
const samplesToContinuousPdf = (
@@ -6,13 +6,17 @@ const samplesToContinuousPdf = (
size,
width,
min = false,
- max = false,
+ max = false
) => {
let _samples = _.filter(samples, _.isFinite);
- if (_.isFinite(min)) { _samples = _.filter(_samples, r => r > min) };
- if (_.isFinite(max)) { _samples = _.filter(_samples, r => r < max) };
+ if (_.isFinite(min)) {
+ _samples = _.filter(_samples, (r) => r > min);
+ }
+ if (_.isFinite(max)) {
+ _samples = _.filter(_samples, (r) => r < max);
+ }
let pdf = pdfast.create(_samples, { size, width });
- return {xs: pdf.map(r => r.x), ys: pdf.map(r => r.y)};
+ return { xs: pdf.map((r) => r.x), ys: pdf.map((r) => r.y) };
};
module.exports = {
diff --git a/packages/squiggle-lang/src/rescript/Utility/MathjsWrapper.js b/packages/squiggle-lang/src/rescript/Utility/MathjsWrapper.js
index 3546ba42..99bb3776 100644
--- a/packages/squiggle-lang/src/rescript/Utility/MathjsWrapper.js
+++ b/packages/squiggle-lang/src/rescript/Utility/MathjsWrapper.js
@@ -1,9 +1,9 @@
const math = require("mathjs");
function parseMath(f) {
- return JSON.parse(JSON.stringify(math.parse(f)))
-};
+ return JSON.parse(JSON.stringify(math.parse(f)));
+}
module.exports = {
- parseMath,
-};
\ No newline at end of file
+ parseMath,
+};
diff --git a/packages/squiggle-lang/webpack.config.js b/packages/squiggle-lang/webpack.config.js
index 685cecd3..c352544d 100644
--- a/packages/squiggle-lang/webpack.config.js
+++ b/packages/squiggle-lang/webpack.config.js
@@ -1,26 +1,26 @@
-const path = require('path');
+const path = require("path");
module.exports = {
- mode: 'production',
- entry: './src/js/index.ts',
+ mode: "production",
+ entry: "./src/js/index.ts",
module: {
rules: [
{
test: /\.tsx?$/,
- use: 'ts-loader',
+ use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
- extensions: ['.tsx', '.ts', '.js'],
+ extensions: [".tsx", ".ts", ".js"],
},
output: {
- filename: 'bundle.js',
- path: path.resolve(__dirname, 'dist'),
+ filename: "bundle.js",
+ path: path.resolve(__dirname, "dist"),
library: {
- name: 'squiggle_lang',
- type: 'umd',
+ name: "squiggle_lang",
+ type: "umd",
},
},
};