hsc2hs example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
data Point = Point {
    x :: {-# UNPACK #-} !Double,
    y :: {-# UNPACK #-} !Double,
    z :: {-# UNPACK #-} !Double}
    deriving (Show)

#def typedef struct {
    double x;
    double y;
    double z;
} point;

#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)

instance Storable Point where
    sizeOf    _ = #{size      point}
    alignment _ = #{alignment point}
    peek p = Point
     <$> #{peek point, x} p
     <*> #{peek point, y} p
     <*> #{peek point, z} p
    poke p (Point x y z) = do
        #{poke point, x} p x
        #{poke point, y} p y
        #{poke point, z} p z