storable-record: Elegant definition of Storable instances for records
With this package you can build a Storable instance of a record type from Storable instances of its elements in an elegant way. It does not do any magic, just a bit arithmetic to compute the right offsets, that would be otherwise done manually or by a preprocessor like C2HS. I cannot promise that the generated memory layout is compatible with that of a corresponding C struct. However, the module generates the smallest layout that is possible with respect to the alignment of the record elements. If you encounter, that a record does not have a compatible layout, we should fix that. But also without C compatibility this package is useful e.g. in connection with StorableVector.
We provide Storable instance support for several cases:
If you wrap a type in a
newtype
, then you can lift itsStorable
instance to thatnewtype
with the module Foreign.Storable.Newtype. This way you do not need theGeneralizedNewtypeDeriving
feature of GHC.If you have a type that is an instance of
Traversable
, you can use that feature for implementation ofStorable
methods. The module Foreign.Storable.Traversable allows manipulation of the portion of your type, that is accessible byTraversable
methods. For instance with the typedata T a = Cons Int [a]
and an accordingTraversable
implementation, you can load and store the elements of the contained list. This may be part of aStorable
implementation of the whole type.If you have a record containing elements of various types, then you need module Foreign.Storable.Record.
Note however that the Storable instances defined with this package are quite slow in (up to) GHC-6.12.1. I'm afraid this is due to incomplete inlining, but we have still to investigate the problem.
For examples see packages storable-tuple
and sample-frame
.
Modules
[Index] [Quick Jump]
Flags
Automatic Flags
Name | Description | Default |
---|---|---|
splitbase | Choose the new smaller, split-up base package. | Enabled |
buildtests | Build speed test | Disabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- storable-record-0.0.7.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
Versions [RSS] | 0.0.1, 0.0.2, 0.0.2.1, 0.0.2.2, 0.0.2.3, 0.0.2.4, 0.0.2.5, 0.0.3, 0.0.3.1, 0.0.4, 0.0.4.1, 0.0.5, 0.0.6, 0.0.7 |
---|---|
Dependencies | base (>=1.0 && <2 || >=3 && <6), QuickCheck (>=2 && <3), semigroups (>=0.1 && <1.0), special-functors (>=1.0 && <1.1), storablevector (>=0.2.7 && <0.3), timeit (>=1.0 && <1.1), transformers (>=0.2 && <0.7), utility-ht (>=0.0.14 && <0.1) [details] |
Tested with | ghc ==6.8.2, ghc ==6.10.4, ghc ==6.12.1, ghc ==8.0.1 |
License | BSD-3-Clause |
Author | Henning Thielemann <storable@henning-thielemann.de> |
Maintainer | Henning Thielemann <storable@henning-thielemann.de> |
Category | Data, Foreign |
Home page | http://code.haskell.org/~thielema/storable-record/ |
Source repo | head: darcs get http://code.haskell.org/~thielema/storable-record/ this: darcs get http://code.haskell.org/~thielema/storable-record/ --tag 0.0.7 |
Uploaded | by HenningThielemann at 2023-02-21T10:32:07Z |
Distributions | Arch:0.0.7, Debian:0.0.5, LTSHaskell:0.0.7, NixOS:0.0.7, Stackage:0.0.7 |
Reverse Dependencies | 32 direct, 163 indirect [details] |
Executables | storable-record-speed |
Downloads | 26675 total (128 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs uploaded by user Build status unknown [no reports yet] |