Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting own "data" type #17

Open
manzznam opened this issue Jul 3, 2016 · 1 comment
Open

Exporting own "data" type #17

manzznam opened this issue Jul 3, 2016 · 1 comment

Comments

@manzznam
Copy link

manzznam commented Jul 3, 2016

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?

@manzznam manzznam changed the title Exporting own type "Rectangle" Exporting own "data" type Jul 3, 2016
@abooij
Copy link

abooij commented Jul 4, 2016

export :: (MSG.MessagePack (TypeList l), ToTypeList f l r, MSG.MessagePack r) => f -> CString -> IO CString

In other words, the type constituents of f (in other words, the respective types of its inputs and outputs) have to be instances of MessagePack (see the msgpack package). Your Rectangle type is missing such an instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants