Providing Haskell Libraries wrapped for other Languages

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Providing Haskell Libraries wrapped for other Languages

Leonhard Applis
Hi, 

I am currently writing a small library. 
I will provide a small web-api for it, however I have some colleagues who neither have experience in haskell, nor in web-dev. 
Also they maybe want to produce programs using my library without internet / docker / etc. 

So in addition I'd like to provide the library "wrapped" for other languages, especially python, but maybe java as well. 
These wrappers should do nothing except invoking their pardons on the library, and should somewhat contain the library. 

What is the common way to do this? 



I've seen "hyphen" as a super heavyweight solution, and I've seen people starting the haskell library listening on system-pipes. 
I don't feel that these are the "best" solutions, atleast for my intention. 

best regards
Leonhard

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

publickey - Leonhard.Applis@protonmail.com - 0x807FDDF3.asc (2K) Download Attachment
signature.asc (490 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Providing Haskell Libraries wrapped for other Languages

Simon Jakobi
Hi Leonhard,

I don't have any experience with calling Haskell from other languages
but I am aware of this project:

https://github.com/nh2/call-haskell-from-anything

I hope it's useful to you.

Cheers,
Simon

Am Do., 28. Nov. 2019 um 15:15 Uhr schrieb Leonhard Applis
<[hidden email]>:

>
> Hi,
>
> I am currently writing a small library.
> I will provide a small web-api for it, however I have some colleagues who neither have experience in haskell, nor in web-dev.
> Also they maybe want to produce programs using my library without internet / docker / etc.
>
> So in addition I'd like to provide the library "wrapped" for other languages, especially python, but maybe java as well.
> These wrappers should do nothing except invoking their pardons on the library, and should somewhat contain the library.
>
> What is the common way to do this?
>
>
>
> I've seen "hyphen" as a super heavyweight solution, and I've seen people starting the haskell library listening on system-pipes.
> I don't feel that these are the "best" solutions, atleast for my intention.
>
> best regards
> Leonhard
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Providing Haskell Libraries wrapped for other Languages

鲍凯文
In reply to this post by Leonhard Applis
Hi,

Have you looked into Apache thrift ()? You’d provide interface definitions and the thrift compiler generates client/server code from those. If the overhead of that is intolerable and you really want to call functions “directly”, you could try exporting haskell functions to c and then writing bindings to that for your language, e.g. using the python c api or JNI. I’m just not sure how one’s supposed to ensure initialization of the haskell runtime in any case.

Good luck

On Fri, Nov 29, 2019 at 5:00 AM <[hidden email]> wrote:
Send Beginners mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Providing Haskell Libraries wrapped for other    Languages
      (Leonhard Applis)
   2. Re:  Providing Haskell Libraries wrapped for      other Languages
      (Simon Jakobi)
   3.  strange error inside a case (PICCA Frederic-Emmanuel)
   4. Re:  strange error inside a case (Sylvain Henry)


----------------------------------------------------------------------

Message: 1
Date: Thu, 28 Nov 2019 14:15:27 +0000
From: Leonhard Applis <[hidden email]>
To: "[hidden email]" <[hidden email]>
Subject: [Haskell-beginners] Providing Haskell Libraries wrapped for
        other   Languages
Message-ID:
        <GWMEmGPietL5BGMOXNm_vOI1zYWXem1x6GOctodu3ftdJVurBPz36E5Jjq_lzGz7XC4t1CNeY-XajQCrh0j4NKVFXBTTGG4pBmJL6bh4U4s=@protonmail.com>

Content-Type: text/plain; charset="utf-8"

Hi, 
I am currently writing a small library. I will provide a small web-api for it, however I have some colleagues who neither have experience in haskell, nor in web-dev. 
Also they maybe want to produce programs using my library without internet / docker / etc. 

So in addition I'd like to provide the library "wrapped" for other languages, especially python, but maybe java as well. 
These wrappers should do nothing except invoking their pardons on the library, and should somewhat contain the library. 

What is the common way to do this? 
I've seen "hyphen" as a super heavyweight solution, and I've seen people starting the haskell library listening on system-pipes. 
I don't feel that these are the "best" solutions, atleast for my intention. 

best regards
Leonhard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20191128/38f52f24/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - [hidden email] - 0x807FDDF3.asc
Type: application/pgp-keys
Size: 1843 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20191128/38f52f24/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 477 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20191128/38f52f24/attachment-0001.sig>

------------------------------

Message: 2
Date: Thu, 28 Nov 2019 16:43:30 +0100
From: Simon Jakobi <[hidden email]>
To: Leonhard Applis <[hidden email]>,  The
        Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[hidden email]>
Subject: Re: [Haskell-beginners] Providing Haskell Libraries wrapped
        for     other Languages
Message-ID:
        <CAGtp2ShEN3HqQb2GAsPniZecStDSkqunUOz=[hidden email]>
Content-Type: text/plain; charset="UTF-8"

Hi Leonhard,

I don't have any experience with calling Haskell from other languages
but I am aware of this project:

https://github.com/nh2/call-haskell-from-anything

I hope it's useful to you.

Cheers,
Simon

Am Do., 28. Nov. 2019 um 15:15 Uhr schrieb Leonhard Applis
<[hidden email]>:
>
> Hi,
>
> I am currently writing a small library.
> I will provide a small web-api for it, however I have some colleagues who neither have experience in haskell, nor in web-dev.
> Also they maybe want to produce programs using my library without internet / docker / etc.
>
> So in addition I'd like to provide the library "wrapped" for other languages, especially python, but maybe java as well.
> These wrappers should do nothing except invoking their pardons on the library, and should somewhat contain the library.
>
> What is the common way to do this?
>
>
>
> I've seen "hyphen" as a super heavyweight solution, and I've seen people starting the haskell library listening on system-pipes.
> I don't feel that these are the "best" solutions, atleast for my intention.
>
> best regards
> Leonhard
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

Message: 3
Date: Fri, 29 Nov 2019 10:55:35 +0000
From: PICCA Frederic-Emmanuel
        <[hidden email]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <[hidden email]>
Subject: [Haskell-beginners] strange error inside a case
Message-ID:
        <[hidden email]>

Content-Type: text/plain; charset="Windows-1252"

Hello, I aheve some code whcih look like this

thumbnail' :: (MonadIO m, MonadReader Beamline m, MonadThrow m) => ThumbnailInput -> m ()
thumbnail' (ThumbnailInput col) = do
  cwd <- toResultsPath "thumbnail" col
  let shakeFiles' =  cwd </> $(mkRelDir ".shake/")
  let shakeReport' = shakeFiles' </> $(mkRelFile "report.html")

  liftIO $ shake shakeOptions{ shakeFiles=fromAbsDir shakeFiles'
                             , shakeReport=[fromAbsFile shakeReport']
                             , shakeVerbosity=Diagnostic
                             } $ do
    let uploaded = fromAbsFile $ cwd </> $(mkRelFile "thumbnail.uploaded")

    want [uploaded]

    -- (Rule 1) merge the image files
    uploaded %> \_out -> do
      -- need [xml]
      masters <- liftIO $ expectedInputFiles col
      liftIO $ hdf2mergedcbf' (head masters) 1 1
      liftIO $ case col of
        (SomeDataCollection SCollect SHdf5 _)          -> hdf2mergedcbf' (head masters) 1 1
        (SomeDataCollection SCollect SHdf5' _)         -> undefined -- hdf2mergedcbf' (head masters) 1 1
        (SomeDataCollection SCaracterization SHdf5 _)  -> undefined
        (SomeDataCollection SCaracterization SHdf5' _) -> undefined
        _                                              -> error "show not arrive here !!!"

      -- hdf2mergedcbf
      -- command [] "touch" [uploaded]
      return ()


When I try to compile it, it give me this error

    • Couldn't match type ‘a0’ with ‘()’
        ‘a0’ is untouchable
          inside the constraints: f ~ 'ISPyB.DataCollection.Hdf5
          bound by a pattern with constructor:
                     SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5,
                   in a case alternative
          at src/Thumbnail.hs:180:38-42
      Expected type: IO a0
        Actual type: IO ()
    • In the expression: hdf2mergedcbf' (head masters) 1 1
      In a case alternative:
          (SomeDataCollection SCollect SHdf5 _)
            -> hdf2mergedcbf' (head masters) 1 1
      In the second argument of ‘($)’, namely
        ‘case col of
           (SomeDataCollection SCollect SHdf5 _)
             -> hdf2mergedcbf' (head masters) 1 1
           (SomeDataCollection SCollect SHdf5' _) -> undefined
           (SomeDataCollection SCaracterization SHdf5 _) -> undefined
           (SomeDataCollection SCaracterization SHdf5' _) -> undefined
           _ -> error "show not arrive here !!!"’
    |
180 |         (SomeDataCollection SCollect SHdf5 _)          -> hdf2mergedcbf' (head masters) 1 1
    |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


What I do not understand is how to fix this since it seems that

  liftIO $ hdf2mergedcbf' (head masters) 1 1  works out of the case

thanks for your help

Frederic

------------------------------

Message: 4
Date: Fri, 29 Nov 2019 12:29:23 +0100
From: Sylvain Henry <[hidden email]>
To: <[hidden email]>
Subject: Re: [Haskell-beginners] strange error inside a case
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="utf-8"; format=flowed

Hello,

What is the type of hdf2mergedcbf' ?

Does it work if you write `void (hdf2mergedcbf' (head masters) 1 1)` ?


On 29/11/2019 11:55, PICCA Frederic-Emmanuel wrote:
> Hello, I aheve some code whcih look like this
>
> thumbnail' :: (MonadIO m, MonadReader Beamline m, MonadThrow m) => ThumbnailInput -> m ()
> thumbnail' (ThumbnailInput col) = do
>    cwd <- toResultsPath "thumbnail" col
>    let shakeFiles' =  cwd </> $(mkRelDir ".shake/")
>    let shakeReport' = shakeFiles' </> $(mkRelFile "report.html")
>
>    liftIO $ shake shakeOptions{ shakeFiles=fromAbsDir shakeFiles'
>                               , shakeReport=[fromAbsFile shakeReport']
>                               , shakeVerbosity=Diagnostic
>                               } $ do
>      let uploaded = fromAbsFile $ cwd </> $(mkRelFile "thumbnail.uploaded")
>
>      want [uploaded]
>
>      -- (Rule 1) merge the image files
>      uploaded %> \_out -> do
>        -- need [xml]
>        masters <- liftIO $ expectedInputFiles col
>        liftIO $ hdf2mergedcbf' (head masters) 1 1
>        liftIO $ case col of
>          (SomeDataCollection SCollect SHdf5 _)          -> hdf2mergedcbf' (head masters) 1 1
>          (SomeDataCollection SCollect SHdf5' _)         -> undefined -- hdf2mergedcbf' (head masters) 1 1
>          (SomeDataCollection SCaracterization SHdf5 _)  -> undefined
>          (SomeDataCollection SCaracterization SHdf5' _) -> undefined
>          _                                              -> error "show not arrive here !!!"
>
>        -- hdf2mergedcbf
>        -- command [] "touch" [uploaded]
>        return ()
>
>
> When I try to compile it, it give me this error
>
>      • Couldn't match type ‘a0’ with ‘()’
>          ‘a0’ is untouchable
>            inside the constraints: f ~ 'ISPyB.DataCollection.Hdf5
>            bound by a pattern with constructor:
>                       SHdf5 :: SCollectSourceFormat 'ISPyB.DataCollection.Hdf5,
>                     in a case alternative
>            at src/Thumbnail.hs:180:38-42
>        Expected type: IO a0
>          Actual type: IO ()
>      • In the expression: hdf2mergedcbf' (head masters) 1 1
>        In a case alternative:
>            (SomeDataCollection SCollect SHdf5 _)
>              -> hdf2mergedcbf' (head masters) 1 1
>        In the second argument of ‘($)’, namely
>          ‘case col of
>             (SomeDataCollection SCollect SHdf5 _)
>               -> hdf2mergedcbf' (head masters) 1 1
>             (SomeDataCollection SCollect SHdf5' _) -> undefined
>             (SomeDataCollection SCaracterization SHdf5 _) -> undefined
>             (SomeDataCollection SCaracterization SHdf5' _) -> undefined
>             _ -> error "show not arrive here !!!"’
>      |
> 180 |         (SomeDataCollection SCollect SHdf5 _)          -> hdf2mergedcbf' (head masters) 1 1
>      |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>
> What I do not understand is how to fix this since it seems that
>
>    liftIO $ hdf2mergedcbf' (head masters) 1 1  works out of the case
>
> thanks for your help
>
> Frederic
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 137, Issue 13
******************************************

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners