Wasmedge
Haskell binding to WasmEdge Runtime for hosting
Install / Use
/learn @byteally/WasmedgeREADME
Haskell binding to WasmEdge Runtime for hosting
</div>Introduction
WasmEdge-Haskell is a library that allows you to use WebAssembly code (.wasm) in your Haskell projects at near-native speed. It's a Haskell binding for the WasmEdge C-SDK, allowing you to use Haskell as a host application and embed WebAssembly functions written in other languages.
Getting Started
Prerequisites
-
Install WasmEdge
$ curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -
Clone this repository into your Haskell project.
with-compiler: ghc-9.2.8 source-repository-package type: git location: git@github.com:byteally/wasmedge.git tag: 80f3635a2b3f5346c85ef55bd599b081ebc995d8 -- use latest commit tag here packages: <project-name>.cabal -
Specify the package in your project's
.cabalfile as a dependency.build-depends: base ^>= 4.11.1.0 ,wasmedge
🎈 Usage <a name="usage"></a>
Below is an example of using the vmRunWasmFromFile function, assuming you have a addTwo.wasm file which contains a function named addTwo.
{-# LANGUAGE OverloadedStrings #-} -- for conversion of String and WasmString
module Main where
import WasmEdge.Configure
import WasmEdge.Internal.FFI.Bindings (HostRegistration(HostRegistration_Wasi),WasmVal(WasmInt32))
import WasmEdge.VM
import qualified Data.Vector as V
addTwoNumbers :: Int -> Int -> IO ()
addTwoNumbers x y = do
Just cfg <- configureCreate
configureAddHostRegistration cfg HostRegistration_Wasi --optional
Just vm <- vmCreate (Just cfg) Nothing
addTwoRes <- vmRunWasmFromFile vm "./wasm/addTwo.wasm" "addTwo" (V.fromList [WasmInt32 (fromIntegral x),WasmInt32 (fromIntegral y)]) 1
print (snd addTwoRes)
main :: IO ()
main = addTwoNumbers 2 3
Output
[5]
API Reference
The API Documentation would be available on Hackage soon.
Reference
For more information, please refer to the WasmEdge's Embed Documentation.
✍️ Authors <a name = "authors"></a>
Contribution
Contributions are welcome! Feel free to fork the repository or submit a pull request.
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
