Skip to content

feat(bindings/haskell): init haskell binding#2463

Merged
Xuanwo merged 5 commits intoapache:mainfrom
silver-ymz:feat/haskell-binding
Jun 15, 2023
Merged

feat(bindings/haskell): init haskell binding#2463
Xuanwo merged 5 commits intoapache:mainfrom
silver-ymz:feat/haskell-binding

Conversation

@silver-ymz
Copy link
Copy Markdown
Member

@silver-ymz silver-ymz commented Jun 15, 2023

This is a demo for haskell binding.

Explanation

I researched 3 ways to complete haskell bindings.

  1. Using hs-bindgen
  2. According completed C binding
  3. Self exporting C-compatible API

The first way is the simplest way. However, the function of hs-bindgen is limited. Moreover, hs-bindgen seems still a working experiment. I raised 2 issues about it which did not receive much attention from the author.
yvan-sraka/hs-bindgen-attribute#2, https://github.com/yvan-sraka/reflexive/issues/1

As for the second way, using the existing C bindings can simplify the process of creating Haskell bindings. However, there are also some potential downsides.

  • Some C APIs are difficult to interact with haskell.
    For example, haskell can't deal with returned struct directly. struct opendal_result_read opendal_operator_blocking_read(struct opendal_operator_ptr ptr, const char *path); will be hard to use in haskell. We need to write some C codes to make it become void opendal_operator_blocking_read(struct opendal_operator_ptr ptr, const char *path, struct opendal_result_read* result);
  • Less flexible
    If we want some features about haskell binding, we must wait it in C bindings.

Because of these reasons, I choose to create a C-compatible interface from the Rust library.

Also ask advices from maintainers.

Example

Exported API will like this.

import OpenDAL
import qualified Data.HashMap.Strict as HashMap

main :: IO ()
main = do
  op <- createOp "memory" HashMap.empty
    case op of
      Left e -> putStrLn $ "Failed to create operator, " ++ e
      Right op' -> do
        _ <- writeOp op' "key1" "value1"
        _ <- writeOp op' "key2" "value2"
        value1 <- readOp op' "key1"
        value2 <- readOp op' "key2"
        print value1
        print value2

Tests

I write a simple test testReadAndWriteToMemory, which can pass now.

Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
@github-actions github-actions Bot added the releases-note/feat The PR implements a new feature or has a title that begins with "feat" label Jun 15, 2023
Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
Comment thread bindings/haskell/Cargo.toml Outdated
Comment thread bindings/haskell/haskell-src/OpenDAL.hs
Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
@silver-ymz silver-ymz marked this pull request as draft June 15, 2023 06:54
Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
Comment thread bindings/haskell/Cargo.toml Outdated
Comment thread bindings/haskell/Cargo.toml Outdated
Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
@silver-ymz silver-ymz marked this pull request as ready for review June 15, 2023 07:13
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM! This PR is good start! Are you willing to create a tracking issue of ongoing tasks? The first thing we should address is building the develop loop:

  • Add contributing docs on how to setup the develop environment
  • Add CI jobs on building and testing hs binding

And than we will need to implement more features, finally, we will handle the release process.

@Xuanwo Xuanwo merged commit 25f2ce4 into apache:main Jun 15, 2023
@silver-ymz
Copy link
Copy Markdown
Member Author

issue #2465 is opened for tracking.

@silver-ymz silver-ymz deleted the feat/haskell-binding branch June 15, 2023 07:26
@PsiACE PsiACE mentioned this pull request Jun 27, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/feat The PR implements a new feature or has a title that begins with "feat"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants