{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Raaz.Random
(
RT, RandM
, randomByteString
, random, randomiseCell
, RandomStorable(..), unsafeFillRandomElements
, fillRandomBytes
, reseed
) where
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import Data.ByteString ( ByteString )
import Data.Int
import Data.Vector.Unboxed hiding ( replicateM, create )
import Data.Word
import Foreign.Ptr ( Ptr , castPtr)
import Foreign.Storable ( Storable, peek )
import Prelude
import Raaz.Core
import Raaz.Cipher.ChaCha20.Internal(KEY, IV)
import Raaz.Random.ChaCha20PRG
newtype RT mem a = RT { RT mem a -> MT (RandomState, mem) a
unRT :: MT (RandomState, mem) a }
deriving (a -> RT mem b -> RT mem a
(a -> b) -> RT mem a -> RT mem b
(forall a b. (a -> b) -> RT mem a -> RT mem b)
-> (forall a b. a -> RT mem b -> RT mem a) -> Functor (RT mem)
forall a b. a -> RT mem b -> RT mem a
forall a b. (a -> b) -> RT mem a -> RT mem b
forall mem a b. a -> RT mem b -> RT mem a
forall mem a b. (a -> b) -> RT mem a -> RT mem b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RT mem b -> RT mem a
$c<$ :: forall mem a b. a -> RT mem b -> RT mem a
fmap :: (a -> b) -> RT mem a -> RT mem b
$cfmap :: forall mem a b. (a -> b) -> RT mem a -> RT mem b
Functor, Functor (RT mem)
a -> RT mem a
Functor (RT mem)
-> (forall a. a -> RT mem a)
-> (forall a b. RT mem (a -> b) -> RT mem a -> RT mem b)
-> (forall a b c.
(a -> b -> c) -> RT mem a -> RT mem b -> RT mem c)
-> (forall a b. RT mem a -> RT mem b -> RT mem b)
-> (forall a b. RT mem a -> RT mem b -> RT mem a)
-> Applicative (RT mem)
RT mem a -> RT mem b -> RT mem b
RT mem a -> RT mem b -> RT mem a
RT mem (a -> b) -> RT mem a -> RT mem b
(a -> b -> c) -> RT mem a -> RT mem b -> RT mem c
forall mem. Functor (RT mem)
forall a. a -> RT mem a
forall mem a. a -> RT mem a
forall a b. RT mem a -> RT mem b -> RT mem a
forall a b. RT mem a -> RT mem b -> RT mem b
forall a b. RT mem (a -> b) -> RT mem a -> RT mem b
forall mem a b. RT mem a -> RT mem b -> RT mem a
forall mem a b. RT mem a -> RT mem b -> RT mem b
forall mem a b. RT mem (a -> b) -> RT mem a -> RT mem b
forall a b c. (a -> b -> c) -> RT mem a -> RT mem b -> RT mem c
forall mem a b c. (a -> b -> c) -> RT mem a -> RT mem b -> RT mem c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: RT mem a -> RT mem b -> RT mem a
$c<* :: forall mem a b. RT mem a -> RT mem b -> RT mem a
*> :: RT mem a -> RT mem b -> RT mem b
$c*> :: forall mem a b. RT mem a -> RT mem b -> RT mem b
liftA2 :: (a -> b -> c) -> RT mem a -> RT mem b -> RT mem c
$cliftA2 :: forall mem a b c. (a -> b -> c) -> RT mem a -> RT mem b -> RT mem c
<*> :: RT mem (a -> b) -> RT mem a -> RT mem b
$c<*> :: forall mem a b. RT mem (a -> b) -> RT mem a -> RT mem b
pure :: a -> RT mem a
$cpure :: forall mem a. a -> RT mem a
$cp1Applicative :: forall mem. Functor (RT mem)
Applicative, Applicative (RT mem)
a -> RT mem a
Applicative (RT mem)
-> (forall a b. RT mem a -> (a -> RT mem b) -> RT mem b)
-> (forall a b. RT mem a -> RT mem b -> RT mem b)
-> (forall a. a -> RT mem a)
-> Monad (RT mem)
RT mem a -> (a -> RT mem b) -> RT mem b
RT mem a -> RT mem b -> RT mem b
forall mem. Applicative (RT mem)
forall a. a -> RT mem a
forall mem a. a -> RT mem a
forall a b. RT mem a -> RT mem b -> RT mem b
forall a b. RT mem a -> (a -> RT mem b) -> RT mem b
forall mem a b. RT mem a -> RT mem b -> RT mem b
forall mem a b. RT mem a -> (a -> RT mem b) -> RT mem b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> RT mem a
$creturn :: forall mem a. a -> RT mem a
>> :: RT mem a -> RT mem b -> RT mem b
$c>> :: forall mem a b. RT mem a -> RT mem b -> RT mem b
>>= :: RT mem a -> (a -> RT mem b) -> RT mem b
$c>>= :: forall mem a b. RT mem a -> (a -> RT mem b) -> RT mem b
$cp1Monad :: forall mem. Applicative (RT mem)
Monad, Monad (RT mem)
Monad (RT mem) -> (forall a. IO a -> RT mem a) -> MonadIO (RT mem)
IO a -> RT mem a
forall mem. Monad (RT mem)
forall a. IO a -> RT mem a
forall mem a. IO a -> RT mem a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> RT mem a
$cliftIO :: forall mem a. IO a -> RT mem a
$cp1MonadIO :: forall mem. Monad (RT mem)
MonadIO)
seedAndRunRT :: RT m a
-> MT (RandomState, m) a
seedAndRunRT :: RT m a -> MT (RandomState, m) a
seedAndRunRT RT m a
action = ((RandomState, m) -> RandomState)
-> MT RandomState () -> MT (RandomState, m) ()
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, m) -> RandomState
forall a b. (a, b) -> a
fst MT RandomState ()
reseedMT MT (RandomState, m) ()
-> MT (RandomState, m) a -> MT (RandomState, m) a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RT m a -> MT (RandomState, m) a
forall mem a. RT mem a -> MT (RandomState, mem) a
unRT RT m a
action
type RandM = RT VoidMemory
instance MemoryThread RT where
insecurely :: RT mem a -> IO a
insecurely = MT (RandomState, mem) a -> IO a
forall (mT :: * -> * -> *) mem a.
(MemoryThread mT, Memory mem) =>
mT mem a -> IO a
insecurely (MT (RandomState, mem) a -> IO a)
-> (RT mem a -> MT (RandomState, mem) a) -> RT mem a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RT mem a -> MT (RandomState, mem) a
forall mem a. RT mem a -> MT (RandomState, mem) a
seedAndRunRT
securely :: RT mem a -> IO a
securely = MT (RandomState, mem) a -> IO a
forall (mT :: * -> * -> *) mem a.
(MemoryThread mT, Memory mem) =>
mT mem a -> IO a
securely (MT (RandomState, mem) a -> IO a)
-> (RT mem a -> MT (RandomState, mem) a) -> RT mem a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RT mem a -> MT (RandomState, mem) a
forall mem a. RT mem a -> MT (RandomState, mem) a
seedAndRunRT
liftMT :: MT mem a -> RT mem a
liftMT = MT (RandomState, mem) a -> RT mem a
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) a -> RT mem a)
-> (MT mem a -> MT (RandomState, mem) a) -> MT mem a -> RT mem a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((RandomState, mem) -> mem) -> MT mem a -> MT (RandomState, mem) a
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, mem) -> mem
forall a b. (a, b) -> b
snd
onSubMemory :: (mem -> submem) -> RT submem a -> RT mem a
onSubMemory mem -> submem
proj = MT (RandomState, mem) a -> RT mem a
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) a -> RT mem a)
-> (RT submem a -> MT (RandomState, mem) a)
-> RT submem a
-> RT mem a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((RandomState, mem) -> (RandomState, submem))
-> MT (RandomState, submem) a -> MT (RandomState, mem) a
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, mem) -> (RandomState, submem)
forall a. (a, mem) -> (a, submem)
projP (MT (RandomState, submem) a -> MT (RandomState, mem) a)
-> (RT submem a -> MT (RandomState, submem) a)
-> RT submem a
-> MT (RandomState, mem) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RT submem a -> MT (RandomState, submem) a
forall mem a. RT mem a -> MT (RandomState, mem) a
unRT
where projP :: (a, mem) -> (a, submem)
projP (a
rstate, mem
mem) = (a
rstate, mem -> submem
proj mem
mem)
reseed :: RT mem ()
reseed :: RT mem ()
reseed = MT (RandomState, mem) () -> RT mem ()
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) () -> RT mem ())
-> MT (RandomState, mem) () -> RT mem ()
forall a b. (a -> b) -> a -> b
$ ((RandomState, mem) -> RandomState)
-> MT RandomState () -> MT (RandomState, mem) ()
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, mem) -> RandomState
forall a b. (a, b) -> a
fst MT RandomState ()
reseedMT
fillRandomBytes :: LengthUnit l => l -> Pointer -> RT mem ()
fillRandomBytes :: l -> Pointer -> RT mem ()
fillRandomBytes l
l = MT (RandomState, mem) () -> RT mem ()
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) () -> RT mem ())
-> (Pointer -> MT (RandomState, mem) ()) -> Pointer -> RT mem ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((RandomState, mem) -> RandomState)
-> MT RandomState () -> MT (RandomState, mem) ()
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, mem) -> RandomState
forall a b. (a, b) -> a
fst (MT RandomState () -> MT (RandomState, mem) ())
-> (Pointer -> MT RandomState ())
-> Pointer
-> MT (RandomState, mem) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> Pointer -> MT RandomState ()
forall l. LengthUnit l => l -> Pointer -> MT RandomState ()
fillRandomBytesMT l
l
class Storable a => RandomStorable a where
fillRandomElements :: Memory mem
=> Int
-> Ptr a
-> RT mem ()
unsafeFillRandomElements :: (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements :: Int -> Ptr a -> RT mem ()
unsafeFillRandomElements Int
n Ptr a
ptr = BYTES Int -> Pointer -> RT mem ()
forall l mem. LengthUnit l => l -> Pointer -> RT mem ()
fillRandomBytes BYTES Int
totalSz (Pointer -> RT mem ()) -> Pointer -> RT mem ()
forall a b. (a -> b) -> a -> b
$ Ptr a -> Pointer
forall a b. Ptr a -> Ptr b
castPtr Ptr a
ptr
where totalSz :: BYTES Int
totalSz = Int -> BYTES Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n BYTES Int -> BYTES Int -> BYTES Int
forall a. Num a => a -> a -> a
* a -> BYTES Int
forall a. Storable a => a -> BYTES Int
sizeOf (Ptr a -> a
forall a. Ptr a -> a
getElement Ptr a
ptr)
getElement :: Ptr a -> a
getElement :: Ptr a -> a
getElement Ptr a
_ = a
forall a. HasCallStack => a
undefined
random :: (RandomStorable a, Memory mem) => RT mem a
random :: RT mem a
random = MT (RandomState, mem) a -> RT mem a
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) a -> RT mem a)
-> MT (RandomState, mem) a -> RT mem a
forall a b. (a -> b) -> a -> b
$ PointerAction IO a a -> PointerAction (MT (RandomState, mem)) a a
forall a b mem. PointerAction IO a b -> PointerAction (MT mem) a b
liftPointerAction PointerAction IO a a
forall a. Storable a => (Pointer -> IO a) -> IO a
alloc (Ptr a -> MT (RandomState, mem) a
forall a mem.
(RandomStorable a, Memory mem) =>
Ptr a -> MT (RandomState, mem) a
getIt (Ptr a -> MT (RandomState, mem) a)
-> (Pointer -> Ptr a) -> Pointer -> MT (RandomState, mem) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pointer -> Ptr a
forall a b. Ptr a -> Ptr b
castPtr)
where getIt :: Ptr a -> MT (RandomState, mem) a
getIt Ptr a
ptr = RT mem a -> MT (RandomState, mem) a
forall mem a. RT mem a -> MT (RandomState, mem) a
unRT (RT mem a -> MT (RandomState, mem) a)
-> RT mem a -> MT (RandomState, mem) a
forall a b. (a -> b) -> a -> b
$ Int -> Ptr a -> RT mem ()
forall a mem.
(RandomStorable a, Memory mem) =>
Int -> Ptr a -> RT mem ()
fillRandomElements Int
1 Ptr a
ptr RT mem () -> RT mem a -> RT mem a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO a -> RT mem a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
ptr)
alloc :: Storable a => (Pointer -> IO a) -> IO a
alloc :: (Pointer -> IO a) -> IO a
alloc Pointer -> IO a
action = Alignment -> BYTES Int -> (Pointer -> IO a) -> IO a
forall l b.
LengthUnit l =>
Alignment -> l -> (Pointer -> IO b) -> IO b
allocaAligned Alignment
algn BYTES Int
sz Pointer -> IO a
action
where getElement :: (Pointer -> IO b) -> b
getElement :: (Pointer -> IO b) -> b
getElement Pointer -> IO b
_ = b
forall a. HasCallStack => a
undefined
thisElement :: a
thisElement = (Pointer -> IO a) -> a
forall b. (Pointer -> IO b) -> b
getElement Pointer -> IO a
action
algn :: Alignment
algn = a -> Alignment
forall a. Storable a => a -> Alignment
alignment a
thisElement
sz :: BYTES Int
sz = a -> BYTES Int
forall a. Storable a => a -> BYTES Int
sizeOf a
thisElement
randomiseCell :: RandomStorable a => RT (MemoryCell a) ()
randomiseCell :: RT (MemoryCell a) ()
randomiseCell = RT (MemoryCell a) (Ptr a)
forall (mT :: * -> * -> *) a.
(MemoryThread mT, Storable a) =>
mT (MemoryCell a) (Ptr a)
getCellPointer RT (MemoryCell a) (Ptr a)
-> (Ptr a -> RT (MemoryCell a) ()) -> RT (MemoryCell a) ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Ptr a -> RT (MemoryCell a) ()
forall a mem.
(RandomStorable a, Memory mem) =>
Int -> Ptr a -> RT mem ()
fillRandomElements Int
1
randomByteString :: LengthUnit l
=> l
-> RT mem ByteString
randomByteString :: l -> RT mem ByteString
randomByteString l
l = MT (RandomState, mem) ByteString -> RT mem ByteString
forall mem a. MT (RandomState, mem) a -> RT mem a
RT (MT (RandomState, mem) ByteString -> RT mem ByteString)
-> MT (RandomState, mem) ByteString -> RT mem ByteString
forall a b. (a -> b) -> a -> b
$ ((RandomState, mem) -> RandomState)
-> MT RandomState ByteString -> MT (RandomState, mem) ByteString
forall (mT :: * -> * -> *) mem submem a.
MemoryThread mT =>
(mem -> submem) -> mT submem a -> mT mem a
onSubMemory (RandomState, mem) -> RandomState
forall a b. (a, b) -> a
fst (MT RandomState ByteString -> MT (RandomState, mem) ByteString)
-> MT RandomState ByteString -> MT (RandomState, mem) ByteString
forall a b. (a -> b) -> a -> b
$ PointerAction IO () ByteString
-> PointerAction (MT RandomState) () ByteString
forall a b mem. PointerAction IO a b -> PointerAction (MT mem) a b
liftPointerAction (l -> PointerAction IO () ByteString
forall l. LengthUnit l => l -> PointerAction IO () ByteString
create l
l) PointerAction (MT RandomState) () ByteString
-> PointerAction (MT RandomState) () ByteString
forall a b. (a -> b) -> a -> b
$ l -> Pointer -> MT RandomState ()
forall l. LengthUnit l => l -> Pointer -> MT RandomState ()
fillRandomBytesMT l
l
instance RandomStorable Word8 where
fillRandomElements :: Int -> Ptr Word8 -> RT mem ()
fillRandomElements = Int -> Ptr Word8 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Word16 where
fillRandomElements :: Int -> Ptr Word16 -> RT mem ()
fillRandomElements = Int -> Ptr Word16 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Word32 where
fillRandomElements :: Int -> Ptr Word32 -> RT mem ()
fillRandomElements = Int -> Ptr Word32 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Word64 where
fillRandomElements :: Int -> Ptr Word64 -> RT mem ()
fillRandomElements = Int -> Ptr Word64 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Word where
fillRandomElements :: Int -> Ptr Word -> RT mem ()
fillRandomElements = Int -> Ptr Word -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Int8 where
fillRandomElements :: Int -> Ptr Int8 -> RT mem ()
fillRandomElements = Int -> Ptr Int8 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Int16 where
fillRandomElements :: Int -> Ptr Int16 -> RT mem ()
fillRandomElements = Int -> Ptr Int16 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Int32 where
fillRandomElements :: Int -> Ptr Int32 -> RT mem ()
fillRandomElements = Int -> Ptr Int32 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Int64 where
fillRandomElements :: Int -> Ptr Int64 -> RT mem ()
fillRandomElements = Int -> Ptr Int64 -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable Int where
fillRandomElements :: Int -> Ptr Int -> RT mem ()
fillRandomElements = Int -> Ptr Int -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable KEY where
fillRandomElements :: Int -> Ptr KEY -> RT mem ()
fillRandomElements = Int -> Ptr KEY -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable IV where
fillRandomElements :: Int -> Ptr IV -> RT mem ()
fillRandomElements = Int -> Ptr IV -> RT mem ()
forall mem a. (Memory mem, Storable a) => Int -> Ptr a -> RT mem ()
unsafeFillRandomElements
instance RandomStorable w => RandomStorable (LE w) where
fillRandomElements :: Int -> Ptr (LE w) -> RT mem ()
fillRandomElements Int
n = Int -> Ptr w -> RT mem ()
forall a mem.
(RandomStorable a, Memory mem) =>
Int -> Ptr a -> RT mem ()
fillRandomElements Int
n (Ptr w -> RT mem ())
-> (Ptr (LE w) -> Ptr w) -> Ptr (LE w) -> RT mem ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr (LE w) -> Ptr w
forall w. Ptr (LE w) -> Ptr w
lePtrToPtr
where lePtrToPtr :: Ptr (LE w) -> Ptr w
lePtrToPtr :: Ptr (LE w) -> Ptr w
lePtrToPtr = Ptr (LE w) -> Ptr w
forall a b. Ptr a -> Ptr b
castPtr
instance RandomStorable w => RandomStorable (BE w) where
fillRandomElements :: Int -> Ptr (BE w) -> RT mem ()
fillRandomElements Int
n = Int -> Ptr w -> RT mem ()
forall a mem.
(RandomStorable a, Memory mem) =>
Int -> Ptr a -> RT mem ()
fillRandomElements Int
n (Ptr w -> RT mem ())
-> (Ptr (BE w) -> Ptr w) -> Ptr (BE w) -> RT mem ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr (BE w) -> Ptr w
forall w. Ptr (BE w) -> Ptr w
bePtrToPtr
where bePtrToPtr :: Ptr (BE w) -> Ptr w
bePtrToPtr :: Ptr (BE w) -> Ptr w
bePtrToPtr = Ptr (BE w) -> Ptr w
forall a b. Ptr a -> Ptr b
castPtr
instance (Dimension d, Unbox w, RandomStorable w) => RandomStorable (Tuple d w) where
fillRandomElements :: Int -> Ptr (Tuple d w) -> RT mem ()
fillRandomElements Int
n Ptr (Tuple d w)
ptr = Int -> Ptr w -> RT mem ()
forall a mem.
(RandomStorable a, Memory mem) =>
Int -> Ptr a -> RT mem ()
fillRandomElements (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
sz) (Ptr w -> RT mem ()) -> Ptr w -> RT mem ()
forall a b. (a -> b) -> a -> b
$ Ptr (Tuple d w) -> Ptr w
forall (d :: Nat) w. Ptr (Tuple d w) -> Ptr w
tupPtrToPtr Ptr (Tuple d w)
ptr
where getTuple :: Dimension d => Ptr (Tuple d w) -> Tuple d w
getTuple :: Ptr (Tuple d w) -> Tuple d w
getTuple Ptr (Tuple d w)
_ = Tuple d w
forall a. HasCallStack => a
undefined
tupPtrToPtr :: Ptr (Tuple d w) -> Ptr w
tupPtrToPtr :: Ptr (Tuple d w) -> Ptr w
tupPtrToPtr = Ptr (Tuple d w) -> Ptr w
forall a b. Ptr a -> Ptr b
castPtr
sz :: Int
sz = Tuple d w -> Int
forall (dim :: Nat) a. Dimension dim => Tuple dim a -> Int
dimension (Tuple d w -> Int) -> Tuple d w -> Int
forall a b. (a -> b) -> a -> b
$ Ptr (Tuple d w) -> Tuple d w
forall (d :: Nat) w. Dimension d => Ptr (Tuple d w) -> Tuple d w
getTuple Ptr (Tuple d w)
ptr