Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '#type' mean in Haskell Foreign Function Interface?

I have found this piece of code in the Haskell sendfile package:

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)

1) What does #type mean and 2) why do I get this error,

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

splice.hs:40:12: parse error on input `type'

when I myself try to use it as follows?:

ghc --make splice.hs

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)

(using GHC 7.4.x)

like image 878
Cetin Sert Avatar asked Apr 09 '12 16:04

Cetin Sert


1 Answers

As pointed out by scdvvc, this uses the C preprocessing macros defined by hsc2hs to customize the code specifically to the system it's being compiled on. You'd need to use hsc2hs to get the appropriate macros defined for your code.

like image 147
Louis Wasserman Avatar answered Sep 21 '22 02:09

Louis Wasserman