Add haskell binding (#63)
This commit is contained in:
parent
f40a34c04b
commit
fc24366512
27
README.md
27
README.md
@ -304,6 +304,33 @@ func main() {
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
### ruapu with Haskell
|
||||
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
Add ruapu library to your project
|
||||
|
||||
`haskell/Ruapu.hs`, `haskell/ruapu.c` and `ruapu.h` should be copied in your
|
||||
project.
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Use ruapu in Haskell
|
||||
|
||||
```haskell
|
||||
import Ruapu
|
||||
-- Ruapu.rua :: IO [String]
|
||||
-- Ruapu.supports :: String -> IO Bool
|
||||
main = do
|
||||
Ruapu.init
|
||||
Ruapu.supports "mmx" >>= putStrLn . show
|
||||
Ruapu.rua >>= foldl (\m x -> m >> putStrLn x) (return ())
|
||||
```
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
<details>
|
||||
<summary>Github-hosted runner result (Linux)</summary>
|
||||
|
||||
|
21
haskell/Ruapu.hs
Normal file
21
haskell/Ruapu.hs
Normal file
@ -0,0 +1,21 @@
|
||||
{-# Language ForeignFunctionInterface #-}
|
||||
|
||||
module Ruapu where
|
||||
|
||||
import Foreign
|
||||
import Foreign.C.String (CString, newCAString, peekCAString)
|
||||
|
||||
foreign import ccall "ruapu.c ruapu_init"
|
||||
init :: IO ()
|
||||
|
||||
foreign import ccall "ruapu.c ruapu_supports"
|
||||
cSupports :: CString -> IO Bool
|
||||
|
||||
foreign import ccall "ruapu.c ruapu_rua"
|
||||
cRua :: IO (Ptr CString)
|
||||
|
||||
supports :: String -> IO Bool
|
||||
supports xs = (newCAString xs) >>= cSupports
|
||||
|
||||
rua :: IO [String]
|
||||
rua = cRua >>= peekArray0 nullPtr >>= mapM peekCAString
|
2
haskell/ruapu.c
Normal file
2
haskell/ruapu.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define RUAPU_IMPLEMENTATION
|
||||
#include"ruapu.h"
|
Loading…
Reference in New Issue
Block a user