'#type'在Haskell外部函数接口中的含义是什么?

Cet*_*ert 5 c haskell types ffi preprocessor-directive

我在Haskell sendfile包中找到了这段代码:

http://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Network/Socket/SendFile/Linux.hsc

-- sendfile64 gives LFS support
foreign import ccall unsafe "sendfile64" c_sendfile
  :: Fd -> Fd -> Ptr (#type off64_t) -> (#type size_t) -> IO (#type ssize_t)
Run Code Online (Sandbox Code Playgroud)

1)什么#type意思和2)为什么我会得到这个错误,

[1 of 1] Compiling Linux.Splice     ( splice.hs, splice.o )

splice.hs:40:12: parse error on input `type'
Run Code Online (Sandbox Code Playgroud)

当我自己尝试使用它如下?:

ghc --make splice.hs
Run Code Online (Sandbox Code Playgroud)

splice.hs:

{-# LANGUAGE ForeignFunctionInterface #-}

module Linux.Splice where

import Data.Word
import System.Posix.Types

-- SPLICE

 -- fcntl.h
 -- ssize_t splice(
 --   int          fd_in,
 --   loff_t*      off_in,
 --   int          fd_out,
 --   loff_t*      off_out,
 --   size_t       len,
 --   unsigned int flags
 -- );

foreign import ccall unsafe "fnctl.h splice" c_splice
  :: Fd
  -> Ptr (#type {- < parse error -} loff_t)
  -> Fd
  -> Ptr (#type loff_t)
  -> (#type size_t)
  -> Word
  -> IO (#type ssize_t)
Run Code Online (Sandbox Code Playgroud)

(使用GHC 7.4.x)

Lou*_*man 5

正如scdvvc所指出的,它使用hsc2hs定义的C预处理宏来专门为其编译的系统定制代码.您需要使用hsc2hs来为您的代码定义适当的宏.

  • 关于你原来问题的评论者,坦率地应该得到比我更多的信任.;) (2认同)