Use lambdas in all wrappers for consistency
This is partly with a view to eventually abstracting away much of the boilerplate.
This commit is contained in:
parent
a9c69c4927
commit
7853204758
@ -57,24 +57,24 @@ withBTree =
|
||||
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
|
||||
|
||||
hello :: ByteString -> IO ()
|
||||
hello s = useAsCString s $ Raw.hello . unsafeFromPtr
|
||||
hello bs = useAsCString bs \ptr -> Raw.hello $ unsafeFromPtr ptr
|
||||
|
||||
helloStruct :: T -> IO ()
|
||||
helloStruct = flip with (Raw.hello_struct . unsafeFromPtr) . convertT
|
||||
helloStruct t = with (convertT t) \ptr -> Raw.hello_struct $ unsafeFromPtr ptr
|
||||
|
||||
helloShape :: Shape -> IO ()
|
||||
helloShape = flip with (Raw.hello_shape . unsafeFromPtr) . convertShape
|
||||
helloShape s = with (convertShape s) \ptr -> Raw.hello_shape $ unsafeFromPtr ptr
|
||||
|
||||
add :: Int64 -> Int64 -> Int64
|
||||
add = Raw.add
|
||||
|
||||
sumTree :: BTree Int64 -> Int64
|
||||
sumTree = unsafePerformIO . flip withBTree (flip with $ Raw.sum_tree . unsafeFromPtr)
|
||||
sumTree t = unsafePerformIO $ withBTree t \tc -> with tc \ptr -> Raw.sum_tree $ unsafeFromPtr ptr
|
||||
|
||||
sumSlice :: V.Vector Int64 -> Int64
|
||||
sumSlice v = unsafePerformIO $ V.unsafeWith v \p -> Raw.sum_slice (unsafeFromPtr p) (fromIntegral $ V.length v)
|
||||
sumSlice v = unsafePerformIO $ V.unsafeWith v \ptr -> Raw.sum_slice (unsafeFromPtr ptr) (fromIntegral $ V.length v)
|
||||
|
||||
printOptional :: Maybe Int8 -> IO ()
|
||||
printOptional = \case
|
||||
Nothing -> Raw.print_optional (unsafeFromPtr nullPtr)
|
||||
Just t -> with t (Raw.print_optional . unsafeFromPtr)
|
||||
Nothing -> Raw.print_optional $ unsafeFromPtr nullPtr
|
||||
Just t -> with t \ptr -> Raw.print_optional $ unsafeFromPtr ptr
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user