将自定义数据类型列表从Haskell传递到C ++

时间:2017-04-09 18:30:22

标签: c++ haskell custom-data-type

我正在使用foreign export ccall将Haskell函数用于C ++程序。

将基本类型从一种语言传递到另一种语言很容易,但是如何传递更复杂的类型,如下所示:

piecesList::[Piece]
piecesList = [Piece _type _color _coords, ..., ... Piece _type _color _coords]

with:

data Piece = Piece {
  _type :: PieceType,
  _color :: PieceColor,
  _position :: Position
} deriving Eq

data PieceColor = Black | White deriving Eq
data PieceType = Rook | Knight | Bishop | King | Queen | Pawn deriving Eq
type Position = (Int, Int)

如果我这样做(例如):

get_piecesList::[Piece]
get_piecesList = piecesList

foreign export ccall get_piecesList :: [Piece]

我得到了:

 Unacceptable result type in foreign declaration:
    ‘[Piece]’ cannot be marshalled in a foreign call
• When checking declaration:
    foreign export ccall "get_piecesList" get_piecesList :: [Piece]

如何传递此类数据,如何在c ++中处理?

谢谢

0 个答案:

没有答案