Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibaryshnikov/future-hs
Future Monad
https://github.com/ibaryshnikov/future-hs
haskell rust tokio
Last synced: 6 days ago
JSON representation
Future Monad
- Host: GitHub
- URL: https://github.com/ibaryshnikov/future-hs
- Owner: ibaryshnikov
- License: mit
- Created: 2024-04-17T12:59:52.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-05-31T07:26:47.000Z (7 months ago)
- Last Synced: 2024-11-09T06:44:04.326Z (2 months ago)
- Topics: haskell, rust, tokio
- Language: Haskell
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# future-hs
`Future` Monad for Rust futures in Haskell.
This is a research project which started as part
of [iced-hs](https://github.com/ibaryshnikov/iced-hs)Built with [tokio](https://github.com/tokio-rs/tokio)
## Semantics
```
pure a
is
async move { a }callA >> callB
is
call_a.await;
call_b.await;callA >>= callB
is
let a = call_a.await;
call_b(a).await;
```## Example
```haskell
import Future
import Future.TimecallA :: Future Int
callA = do
delaySecs 2
pure 1callB :: Int -> Future Int
callB a = do
delaySecs 2
pure $ a + 4example :: Future ()
example = do
a <- callA
b <- callB a
liftIO $ putStrLn $ show b -- prints 5main :: IO ()
main = run example
```There are `race` and `concurrent` functions:
```haskell
race :: Future a -> Future b -> Future (Either a b)
concurrent :: Future a -> Future b -> Future (a, b)
```For example:
```haskell
do
let ma = callA
let mb = callB
(a, b) <- concurrent ma mb
````race` is a wrapper around
[tokio::select!](https://docs.rs/tokio/1.37.0/tokio/macro.select.html)
and `concurrent` uses
[tokio::join!](https://docs.rs/tokio/1.37.0/tokio/macro.join.html)## Usage
```bash
# build libfuture_hs.a
./build_rust.sh# call ghc
# note that -threaded is required
ghc -threaded -ipath/to/this/repo path/to/libfuture_hs.a main.hs
```