From 9fe7034c518b6d6ecc42aa2cb21bdd9185acbc0c Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Sat, 30 Apr 2022 11:33:03 -0400 Subject: [PATCH] v0.2.8: `fromSamples` and jsImports --- packages/squiggle-lang/README.md | 15 +++++++++++++++ packages/squiggle-lang/package.json | 6 ++++-- .../DistributionOperation.res | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/squiggle-lang/README.md b/packages/squiggle-lang/README.md index 05bb969c..4513ee76 100644 --- a/packages/squiggle-lang/README.md +++ b/packages/squiggle-lang/README.md @@ -3,6 +3,21 @@ # Squiggle language +## Use the `npm` package + +For instance, in a fresh `create-react-app`, you can + +```sh +yarn add @quri/squiggle-lang +``` + +```js +import {run} from '@quri/squiggle-lang'; +run("normal(0, 1) * fromSamples([-3,-2,-1,1,2,3,3,3,4,9]").value.value.toSparkline().value) +``` + +**However, for most use cases you'll prefer to use our [library of react components](https://www.npmjs.com/package/@quri/squiggle-components)**, and let your app transitively depend on `@quri/squiggle-lang`. + ## Build for development We assume that you ran `yarn` at the monorepo level. diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index 4d146ef8..34930989 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -1,6 +1,6 @@ { "name": "@quri/squiggle-lang", - "version": "0.2.7", + "version": "0.2.8", "homepage": "https://squiggle-language.com", "license": "MIT", "scripts": { @@ -24,6 +24,7 @@ "format:rescript": "rescript format -all", "format:prettier": "prettier --write .", "format": "yarn format:rescript && yarn format:prettier", + "prepack": "yarn build && yarn test && yarn bundle", "all": "yarn build && yarn bundle && yarn test" }, "keywords": [ @@ -35,7 +36,7 @@ "rescript": "^9.1.4", "jstat": "^1.9.5", "pdfast": "^0.2.0", - "mathjs": "10.5.0" + "mathjs": "^10.5.0" }, "devDependencies": { "bisect_ppx": "^2.7.1", @@ -61,6 +62,7 @@ "webpack-cli": "^4.9.2" }, "source": "./src/js/index.ts", + "browser": "./dist/bundle.js", "main": "./dist/src/js/index.js", "types": "./dist/src/js/index.d.ts" } diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation/DistributionOperation.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation/DistributionOperation.res index f323cdcb..db6656b2 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation/DistributionOperation.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation/DistributionOperation.res @@ -189,7 +189,8 @@ let rec run = (~env, functionCallInfo: functionCallInfo): outputType => { ->GenericDist.mixture(~scaleMultiplyFn=scaleMultiply, ~pointwiseAddFn=pointwiseAdd) ->E.R2.fmap(r => Dist(r)) ->OutputLocal.fromResult - | FromSamples(xs) => xs + | FromSamples(xs) => + xs ->SampleSetDist.make ->E.R2.errMap(x => DistributionTypes.SampleSetError(x)) ->E.R2.fmap(x => x->DistributionTypes.SampleSet->Dist)