npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

haskell-polycall

v1.0.0

Published

Haskell binding for the Polycall core (binding ABI v1, polycall >= 1.1.0): direct C FFI (foreign import ccall) for config validation, RPC calls and peer nodes. Source distribution of a Haskell package (modules Polycall, Polycall.Raw); not a JavaScript lib

Readme

haskell-polycall

Haskell binding for the Polycall core, binding ABI v1 (polycall >= 1.1.0). Modules Polycall (idiomatic layer) and Polycall.Raw (the 19 foreign import ccall declarations).

Quick start

1. Install the package (a Haskell source package delivered through npm):

npm i haskell-polycall

2. Have the Polycall core and GHC >= 9.4 (tested with 9.10.3; only the boot packages base and bytestring are used, so neither cabal nor stack nor Hackage is needed). Build the core from https://github.com/obinexus/polycall and note two directories:

| | link library (POLYCALL_LIB_DIR) | run-time library (POLYCALL_BIN_DIR) | | --- | --- | --- | | Windows | polycall\build\windows-cmake\lib (polycall.lib) | polycall\build\windows-cmake\bin (polycall.dll) | | Linux | <prefix>/lib (libpolycall.so) | the same directory |

# Windows (PowerShell), in a polycall checkout
.\build-windows.ps1
# Linux, in a polycall checkout
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib
cmake --build build --parallel && cmake --install build --prefix "$HOME/polycall"

3. Build and run the packaged example from your project directory (the one that now contains node_modules). scripts/ghcbuild.mjs is a thin wrapper around one ghc --make command that adds the package's src and links the core:

# Windows (PowerShell)
$env:POLYCALL_LIB_DIR = "C:\path\to\polycall\build\windows-cmake\lib"
$env:POLYCALL_BIN_DIR = "C:\path\to\polycall\build\windows-cmake\bin"
$env:GHC = "C:\path\to\ghc-9.10.3-x86_64-unknown-mingw32\bin\ghc.exe"   # or have ghc on PATH
$fx = "node_modules\haskell-polycall\tests\fixtures"
node node_modules\haskell-polycall\scripts\ghcbuild.mjs -o polycall-consumer --run node_modules\haskell-polycall\examples\consumer\Main.hs -- "$fx\good.polycallrc" "$fx\bad.polycallrc"
# Linux
export POLYCALL_LIB_DIR="$HOME/polycall/lib"
fx=node_modules/haskell-polycall/tests/fixtures
node node_modules/haskell-polycall/scripts/ghcbuild.mjs -o polycall-consumer --run node_modules/haskell-polycall/examples/consumer/Main.hs -- "$fx/good.polycallrc" "$fx/bad.polycallrc"

The two arguments are a configuration file the core accepts and one it refuses; the package ships one of each. A third argument, the host:port of a running polycall start, adds one RPC round trip. Expected output (paths shortened):

core 1.1.0, binding ABI 1
OK       good.polycallrc
REFUSED  Config
         POLYCALL_E_CONFIG: invalid configuration: bad.polycallrc:1: malformed key=value entry
peer     listening on 127.0.0.1:53124
all checks passed

Without POLYCALL_LIB_DIR (or --lib-dir) the build stops before ghc runs with the Polycall core was not located ... Set POLYCALL_LIB_DIR (or pass --lib-dir <dir>) .... If the program is built but polycall.dll is not found at run time (Windows reports only exit code 0xC0000135), the wrapper says could not load the Polycall core ... Set POLYCALL_BIN_DIR (or pass --bin-dir) ....

Using it in your own Haskell project

With the wrapper (any number of modules; other -flags go to ghc):

node node_modules/haskell-polycall/scripts/ghcbuild.mjs -O2 -o myapp app/Main.hs

Or call GHC yourself; this is all the wrapper does:

ghc --make -threaded -inode_modules/haskell-polycall/src app/Main.hs -o myapp -L"$POLYCALL_LIB_DIR" -lpolycall

At run time the loader must find the shared library: polycall.dll on PATH or next to the executable on Windows, LD_LIBRARY_PATH or an installed libpolycall.so.1 on Linux. Build with -threaded.

A polycall.cabal is included for cabal users (cabal build --extra-lib-dirs=<POLYCALL_LIB_DIR>); it is untested -- this package is built and tested with plain ghc --make only.

{-# LANGUAGE OverloadedStrings #-}
import Polycall

main :: IO ()
main = do
  checkAbi                                  -- throws Unsupported unless the library is ABI v1
  runConfig "Polycallfile" Run              -- throws PolycallError (Config, NotFound ...)
  json <- call "127.0.0.1:8084" "inventory" "get" (Just "{\"item_id\":\"widget-a\"}") 5000
  withPeer "alpha" defaultPeerOptions { peerBind = Just "127.0.0.1:0" } $ \node -> do
    endpoint node >>= putStrLn
    send node "127.0.0.1:9000" "\0binary\0" Nothing 5000

What it covers

Interop route: direct C FFI. src/Polycall/Raw.hs declares the 19 functions of polycall.h by hand with foreign import ccall (CInt, CSize, CString, Ptr, Word32 for uint32_t, Int32 for polycall_peer_t), so the headers are not needed, and src/Polycall.hs wraps them. GHC's bundled LLVM linker links the MSVC import library polycall.lib directly (linking against polycall.dll itself with -L<bin dir> also works); no MinGW import library is generated. Nothing is reimplemented in Haskell and no CLI is spawned.

| area | Haskell API (Polycall) | C function | | --- | --- | --- | | library | abiVersion, checkAbi, version, strerror, lastError | polycall_ffi_abi_version, polycall_ffi_version, polycall_strerror, polycall_last_error | | configuration | runConfig path Validate / Run, describe, describeWithCapacity | polycall_ffi_run_config, polycall_ffi_describe | | RPC | call, callRaw | polycall_call | | peer node | openPeer, withPeer, closePeer, endpoint, nodeId, register, unregister, list, ping, send, recv, recvWithCapacity, cancel, health | polycall_peer_* |

  • Errors: every negative status is thrown as PolycallError (an Exception) with errorStatus (e.g. -13), errorKind (Config, NotFound, Timeout ...; UnknownStatus n for a newer library), errorMessage (the library's strerror text) and errorDetail (the library's per-thread detail, e.g. bad.polycallrc:1: malformed key=value entry). kindFromStatus / statusFromKind convert. callRaw and the *WithCapacity functions report instead of throwing.
  • Thread-local detail: polycall_last_error is per OS thread. The wrapper reads it on the same OS thread as the failing call (in a bound thread; free on the main thread, one short-lived OS thread per call from a forkIO thread).
  • Blocking: call, ping, send, recv, openPeer and closePeer are safe foreign calls, so with -threaded other Haskell threads keep running. A blocked recv cannot be interrupted by an async exception: wake it with cancel (Cancelled) or closePeer (Closed) from another thread.
  • Ownership: the library never returns memory to free. Outputs are copied into Haskell values: String (UTF-8) for ids and endpoints, strict ByteString for JSON and payloads. Payloads are binary-safe (NUL bytes included). A Peer owns one library handle until closePeer; a second close or any use afterwards throws InvalidHandle, never crashes. withPeer closes it with bracket and tolerates an earlier explicit close.
  • Buffers: describe, list, health grow their buffer as needed; recv uses a 1 MiB buffer (the maximum payload). recvWithCapacity p t n returns Left needed when n bytes are too few, and the message stays queued.

Tests

Every test runs against the real core; nothing is mocked.

# POLYCALL_LIB_DIR, POLYCALL_CLI (and POLYCALL_BIN_DIR on Windows) point at a built core;
# GHC is the path to ghc (default: ghc on PATH)
npm test                # builds and runs tests/Main.hs: 11 integration tests + diagnostics
npm run test:consumer   # npm pack -> install into a clean project -> packaged example

npm test also checks both missing-core diagnostics with every POLYCALL_* variable unset and the core removed from PATH. npm run test:consumer installs the packed tarball into a temporary project outside the checkout, builds the example there from node_modules/haskell-polycall only and checks a known-good file, a known-bad file, the peer lifecycle, one RPC round trip against polycall start, a malformed file passed as known-good, and the build-time and run-time missing-core diagnostics.

Tested: Windows 11 x64, GHC 9.10.3 (official bindist, bundled clang/lld), core 66c744d (1.1.0, MSVC build). Linux runs in CI (.github/workflows/ci.yml) and has not been run yet.

License

MIT -- see LICENSE.