storable-tuple 0.0.3.3 → 0.1
raw patch · 3 files changed
+54/−79 lines, 3 filesdep ~storable-record
Dependency ranges changed: storable-record
Files
- Changes.md +5/−0
- src/Foreign/Storable/Tuple.hs +29/−74
- storable-tuple.cabal +20/−5
+ Changes.md view
@@ -0,0 +1,5 @@+# Change log for the `storable-tuple` package++## 0.1++* `Tuple`: implement instances using `Record.Tuple`
src/Foreign/Storable/Tuple.hs view
@@ -1,84 +1,39 @@-{--This should be in the standard library.--} module Foreign.Storable.Tuple where +import qualified Foreign.Storable.Newtype as Newtype+import Foreign.Storable.Record.Tuple (Tuple(Tuple, getTuple))+import Foreign.Storable (Storable, sizeOf, alignment, peek, poke) import Data.Orphans ()-import Foreign.Storable (Storable (..), )-import qualified Foreign.Storable.Record as Store-import Control.Applicative (liftA2, liftA3, pure, (<*>), ) -import Data.Tuple.HT (fst3, snd3, thd3, ) - instance (Storable a, Storable b) => Storable (a,b) where- sizeOf = Store.sizeOf storePair- alignment = Store.alignment storePair- peek = Store.peek storePair- poke = Store.poke storePair--{-# INLINE storePair #-}-storePair ::- (Storable a, Storable b) =>- Store.Dictionary (a,b)-storePair =- Store.run $- liftA2 (,)- (Store.element fst)- (Store.element snd)-+ {-# INLINABLE sizeOf #-}+ sizeOf = Newtype.sizeOf Tuple+ {-# INLINABLE alignment #-}+ alignment = Newtype.alignment Tuple+ {-# INLINABLE peek #-}+ peek = Newtype.peek getTuple+ {-# INLINABLE poke #-}+ poke = Newtype.poke Tuple instance (Storable a, Storable b, Storable c) => Storable (a,b,c) where- sizeOf = Store.sizeOf storeTriple- alignment = Store.alignment storeTriple- peek = Store.peek storeTriple- poke = Store.poke storeTriple--{-# INLINE storeTriple #-}-storeTriple ::- (Storable a, Storable b, Storable c) =>- Store.Dictionary (a,b,c)-storeTriple =- Store.run $- liftA3 (,,)- (Store.element fst3)- (Store.element snd3)- (Store.element thd3)--instance (Storable a, Storable b, Storable c, Storable d) => Storable (a,b,c,d) where- sizeOf = Store.sizeOf storeQuadruple- alignment = Store.alignment storeQuadruple- peek = Store.peek storeQuadruple- poke = Store.poke storeQuadruple+ {-# INLINABLE sizeOf #-}+ sizeOf = Newtype.sizeOf Tuple+ {-# INLINABLE alignment #-}+ alignment = Newtype.alignment Tuple+ {-# INLINABLE peek #-}+ peek = Newtype.peek getTuple+ {-# INLINABLE poke #-}+ poke = Newtype.poke Tuple -{-# INLINE storeQuadruple #-}-storeQuadruple ::+instance (Storable a, Storable b, Storable c, Storable d) =>- Store.Dictionary (a,b,c,d)-storeQuadruple =- Store.run $- pure (,,,)- <*> (Store.element $ \(x,_,_,_) -> x)- <*> (Store.element $ \(_,x,_,_) -> x)- <*> (Store.element $ \(_,_,x,_) -> x)- <*> (Store.element $ \(_,_,_,x) -> x)-{-- liftA4 (,,,)- (Store.element $ \(x,_,_,_) -> x)- (Store.element $ \(_,x,_,_) -> x)- (Store.element $ \(_,_,x,_) -> x)- (Store.element $ \(_,_,_,x) -> x)--}---{--{- Why is this allowed? -}-test :: Char-test = const 'a' undefined--{- Why is type defaulting applied here? The type of 'c' should be fixed. -}-test1 :: (Integral a, RealField.C a) => a-test1 =- let c = undefined- in asTypeOf (round c) c--}+ Storable (a,b,c,d) where+ {-# INLINABLE sizeOf #-}+ sizeOf = Newtype.sizeOf Tuple+ {-# INLINABLE alignment #-}+ alignment = Newtype.alignment Tuple+ {-# INLINABLE peek #-}+ peek = Newtype.peek getTuple+ {-# INLINABLE poke #-}+ poke = Newtype.poke Tuple
storable-tuple.cabal view
@@ -1,5 +1,6 @@+Cabal-Version: 2.2 Name: storable-tuple-Version: 0.0.3.3+Version: 0.1 Category: Data, Foreign Synopsis: Storable instance for pairs and triples Description:@@ -9,7 +10,18 @@ The only purpose of this package is to provide a standard location for this instance so that other packages needing this instance can play nicely together.-License: BSD3++ Note however, that the original purpose of the @Storable@ class+ was the transfer of primitive types between Haskell and foreign code.+ This purpose was already extended by HSC,+ which creates @Storable@ instances for records from C header files.+ Nonetheless,+ @Storable@ instances for tuples were omitted from @base@ by intention.+ Instead of using the orphan instances from this package,+ you may instead use the custom class or the wrapper type+ from the module @Foreign.Storable.Record.Tuple@+ from the package @storable-record@.+License: BSD-3-Clause License-file: LICENSE Author: Henning Thielemann <storable@henning-thielemann.de> Maintainer: Henning Thielemann <storable@henning-thielemann.de>@@ -17,8 +29,10 @@ Stability: Experimental Build-Type: Simple Tested-With: GHC==6.8.2, GHC==8.0.1-Cabal-Version: >=1.6 +Extra-Source-Files:+ Changes.md+ Source-Repository head Type: darcs Location: http://code.haskell.org/~thielema/storable-tuple/@@ -26,14 +40,14 @@ Source-Repository this Type: darcs Location: http://code.haskell.org/~thielema/storable-tuple/- Tag: 0.0.3.3+ Tag: 0.1 Flag splitBase Description: Choose the new smaller, split-up base package. Library Build-Depends:- storable-record >=0.0.1 && <0.1,+ storable-record >=0.0.5 && <0.1, utility-ht >=0.0.1 && <0.1, base-orphans >= 0.5 && <1 If flag(splitBase)@@ -43,6 +57,7 @@ special-functors >= 1.0 && <1.1, base >= 1.0 && < 2 + Default-Language: Haskell98 GHC-Options: -Wall -fno-warn-orphans Hs-Source-Dirs: src