nh2 / nh2/call-haskell-from-anything

Exporting own "data" type

Open
#17 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
402
Forks
20
PR merge metrics
No merged PRs in 30d

Description

I am trying to export a module with own types with the following code:

```
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}

module RectangleMover where

import Foreign.C
import FFI.Anything.TypeUncurry.Msgpack

data Point = Point Int Int
movePoint :: Point -> Int -> Int -> Point
movePoint (Point x y) dx dy = Point (x + dx) (y + dy)

data Rectangle = Rectangle { corner :: Point, width :: Int, height :: Int }
move :: Rectangle -> Int -> Int -> Rectangle
move r@(Rectangle {corner=c}) dx dy = r { corner = movePoint c dx dy }

foreign export ccall move_export :: CString -> IO CString
move_export :: CString -> IO CString
move_export = export move
```

But when i try to compile this i get the this error message:

> [1 of 1] Compiling RectangleMover ( test.hs, test.o )
>
> test.hs:19:15:
> No instance for (Data.MessagePack.Object.MessagePack Rectangle)
> arising from a use of ‘export’
> In the expression: export move
> In an equation for ‘move_export’: move_export = export move

What am i missing? Or does this package support exporting own types at all?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.