Skip to content

Commit 632f952

Browse files
committed
WIP
0 parents  commit 632f952

File tree

28 files changed

+1092
-0
lines changed

28 files changed

+1092
-0
lines changed

.ghcid

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--command "wasm32-wasi-cabal repl --enable-multi-repl"
2+
--restart cabal.project
3+
--restart canary.cabal

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: ci
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
11+
jobs:
12+
ci:
13+
name: ci-${{ matrix.flavour }}
14+
runs-on: ubuntu-24.04
15+
continue-on-error: ${{ matrix.experimental }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
flavour:
20+
- "9.12"
21+
- "9.10"
22+
experimental:
23+
- false
24+
include:
25+
- flavour: "gmp"
26+
experimental: true
27+
steps:
28+
29+
- name: checkout
30+
uses: actions/checkout@v4
31+
32+
- name: setup-hscolour
33+
run: |
34+
cabal update --ignore-project
35+
cabal install --ignore-project -O2 hscolour
36+
37+
- name: ghc-wasm-meta
38+
run: |
39+
pushd "$(mktemp -d)"
40+
curl -f -L https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1
41+
PLAYWRIGHT=1 ./setup.sh
42+
~/.ghc-wasm/add_to_github_path.sh
43+
cp cabal.project.local ${{ github.workspace }}
44+
popd
45+
env:
46+
FLAVOUR: ${{ matrix.flavour }}
47+
48+
- name: gen-plan-json
49+
run: |
50+
wasm32-wasi-cabal build --dry-run
51+
52+
- name: cabal-cache
53+
uses: actions/cache@v4
54+
with:
55+
key: ${{ matrix.flavour }}-${{ hashFiles('dist-newstyle/cache/plan.json') }}
56+
restore-keys: ${{ matrix.flavour }}-
57+
path: |
58+
~/.ghc-wasm/.cabal/store
59+
dist-newstyle
60+
61+
- name: ci
62+
run: |
63+
./util/ci

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cabal.project.local
2+
ci.log
3+
dist-newstyle

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for canary
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright (c) 2025, Cheng Shao
2+
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided
13+
with the distribution.
14+
15+
* Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cabal.project

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packages: .
2+
3+
tests: True
4+
5+
haddock-hyperlink-source: True
6+
haddock-quickjump: True
7+
haddock-html-location: https://hackage.haskell.org/package/$pkg-$version/docs
8+
9+
source-repository-package
10+
type: git
11+
location: https://github.com/amesgen/splitmix.git
12+
tag: cea9e31bdd849eb0c17611bb99e33d590e126164
13+
14+
package *
15+
optimization: 2
16+
ghc-options: -fdicts-cheap -fexpose-all-unfoldings -flate-dmd-anal -flate-specialise -fspecialise-aggressively
17+
18+
documentation: True
19+
20+
package aeson
21+
flags: -ordered-keymap
22+
23+
package tasty
24+
flags: -unix
25+
26+
package vector
27+
flags: -boundschecks

canary.cabal

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
cabal-version: 3.14
2+
name: canary
3+
version: 0.1.0.0
4+
license: BSD-3-Clause
5+
license-file: LICENSE
6+
author: Cheng Shao
7+
maintainer: [email protected]
8+
build-type: Simple
9+
extra-doc-files: CHANGELOG.md
10+
11+
common deps
12+
build-depends:
13+
aeson >=2.2.3.0,
14+
async >=2.2.5,
15+
base,
16+
bytestring,
17+
deepseq,
18+
ghc-experimental,
19+
primitive >=0.9.1.0,
20+
servant >=0.20.2,
21+
text,
22+
vector >=0.13.2.0,
23+
vector-stream >=0.1.0.1,
24+
25+
default-language: GHC2024
26+
ghc-options:
27+
-Weverything
28+
-Wno-all-missed-specialisations
29+
-Wno-implicit-prelude
30+
-Wno-missing-export-lists
31+
-Wno-missing-import-lists
32+
-Wno-missing-kind-signatures
33+
-Wno-missing-local-signatures
34+
-Wno-missing-poly-kind-signatures
35+
-Wno-missing-role-annotations
36+
-Wno-missing-safe-haskell-mode
37+
-Wno-prepositive-qualified-module
38+
-Wno-unsafe
39+
40+
library
41+
import: deps
42+
exposed-modules:
43+
Control.Concurrent.Async.Extra
44+
Data.Stream.Monadic.Extra
45+
Data.Stream.Monadic.Instances
46+
Data.Text.Extra
47+
GHC.Wasm.JS.Array
48+
GHC.Wasm.JS.AsyncIterator
49+
GHC.Wasm.JS.ESM
50+
GHC.Wasm.JS.Free
51+
GHC.Wasm.JS.Instances
52+
GHC.Wasm.JS.JSON
53+
GHC.Wasm.JS.Promise
54+
GHC.Wasm.JS.ReadableStream
55+
GHC.Wasm.JS.RuntimeFFI
56+
GHC.Wasm.JS.String
57+
GHC.Wasm.JS.URL
58+
GHC.Wasm.JS.Uint8Array
59+
60+
hs-source-dirs: src
61+
62+
test-suite canary-test
63+
import: deps
64+
type: exitcode-stdio-1.0
65+
hs-source-dirs: test
66+
main-is: Main.hs
67+
build-depends:
68+
canary,
69+
quickcheck-instances >=0.3.32,
70+
tasty >=1.5.3,
71+
tasty-hunit >=0.10.2,
72+
tasty-quickcheck >=0.11.1,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Control.Concurrent.Async.Extra
2+
( concurrentlyR,
3+
)
4+
where
5+
6+
import Control.Concurrent.Async
7+
8+
concurrentlyR :: IO a -> IO b -> IO b
9+
concurrentlyR l r = do
10+
(_, b) <- concurrently l r
11+
pure b

src/Data/Stream/Monadic/Extra.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Data.Stream.Monadic.Extra
2+
( toLazyList,
3+
toVector,
4+
)
5+
where
6+
7+
import Control.Monad
8+
import Control.Monad.Primitive
9+
import Data.Stream.Monadic qualified as VS
10+
import Data.Vector.Fusion.Bundle.Monadic qualified as VB
11+
import Data.Vector.Fusion.Bundle.Size qualified as VB
12+
import Data.Vector.Generic qualified as V
13+
import Data.Vector.Generic.Mutable qualified as MV
14+
15+
toLazyList :: (PrimBase m) => VS.Stream m a -> m [a]
16+
toLazyList (VS.Stream step s) = go s
17+
where
18+
go s0 = unsafeInterleave $ do
19+
r <- step s0
20+
case r of
21+
VS.Yield x s1 -> do
22+
xs <- go s1
23+
pure $ x : xs
24+
VS.Skip s1 -> go s1
25+
VS.Done -> pure []
26+
27+
toVector :: (PrimMonad m, V.Vector v a) => VS.Stream m a -> m (v a)
28+
toVector = V.unsafeFreeze <=< MV.munstream . flip VB.fromStream VB.Unknown
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{-# OPTIONS_GHC -Wno-orphans #-}
2+
3+
module Data.Stream.Monadic.Instances () where
4+
5+
import Control.Exception
6+
import Control.Monad.IO.Class
7+
import Data.Stream.Monadic qualified as VS
8+
import Servant.API
9+
import Servant.Types.SourceT
10+
11+
instance (MonadIO m) => FromSourceIO a (VS.Stream m a) where
12+
fromSourceIO src = unSourceT src $ pure . VS.Stream go
13+
where
14+
go Stop = pure VS.Done
15+
go (Error err) = liftIO $ fail err
16+
go (Skip s1) = pure $ VS.Skip s1
17+
go (Yield x s1) = pure $ VS.Yield x s1
18+
go (Effect m) = go =<< liftIO m
19+
20+
instance ToSourceIO a (VS.Stream IO a) where
21+
toSourceIO (VS.Stream step s) = fromStepT $ go s
22+
where
23+
go s0 = Effect $ do
24+
r <- step s0
25+
evaluate $ case r of
26+
VS.Yield x s1 -> Yield x $ go s1
27+
VS.Skip s1 -> Skip $ go s1
28+
VS.Done -> Stop

0 commit comments

Comments
 (0)