derive-storable: Derive Storable instances with GHC.Generics.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Derive Storable instances with GHC.Generics. The derived Storable instances have the same alignment as C structs.


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.1.0, 0.1.1.1, 0.1.2.0, 0.1.2.0
Change logChangeLog.md
Dependenciesbase (>=4.8 && <5) [details]
LicenseMIT
AuthorMateusz Kloczko
Maintainermateusz.p.kloczko@gmail.com
CategoryForeign
Home pagehttps://www.github.com/mkloczko/derive-storable/
Source repositoryhead: git clone https://github.com/mkloczko/derive-storable -b master
UploadedSat May 26 14:00:09 UTC 2018 by mkloczko

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for derive-storable-0.1.2.0

[back to package description]

Introduction

Build Status

The derive-storable package allows you to automatically generate Storable instances for your datatypes. It uses GHC.Generics, which allows the coders to derive certain instances automatically. To derive a (G)Storable instance, the data-type has to:

Note on performance

There are some problems with performance of derived Storable instances. For now there exists a solution in form of GHC Core plugin - derive-storable-plugin.

Usage

Here's an example:

{-# LANGUAGE DeriveGeneric #-}

import Foreign.Storable
import Foreign.Storable.Generic
import Foreign.Ptr
import Foreign.Marshal.Alloc

import Generics.Deriving

data Position = Position {
   x :: Double, 
   y :: Double
} deriving (Show,Read, Generic)

instance GStorable Position

updatePosition :: Ptr Position -> Position -> IO ()
updatePosition ptr pos = poke ptr pos


main = do
    let val = Position 0.0 10.0
    ptr <- malloc :: IO (Ptr Position)      
    putStrLn "Created a ptr with value of"
    putStrLn =<< show <$> peek ptr
    updatePosition ptr val
    putStrLn "And now the value of ptr is:"   
    putStrLn =<< show <$> peek ptr