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:
George Thomas 2026-04-14 00:42:05 +01:00
parent 8f7a1c31f3
commit 4f57e96071

View File

@ -57,24 +57,24 @@ withBTree =
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr) Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
hello :: ByteString -> IO () hello :: ByteString -> IO ()
hello s = useAsCString s $ Raw.hello . unsafeFromPtr hello bs = useAsCString bs \ptr -> Raw.hello $ unsafeFromPtr ptr
helloStruct :: T -> IO () 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 :: 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 :: Int64 -> Int64 -> Int64
add = Raw.add add = Raw.add
sumTree :: BTree Int64 -> Int64 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.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 :: Maybe Int8 -> IO ()
printOptional = \case printOptional = \case
Nothing -> Raw.print_optional (unsafeFromPtr nullPtr) Nothing -> Raw.print_optional $ unsafeFromPtr nullPtr
Just t -> with t (Raw.print_optional . unsafeFromPtr) Just t -> with t \ptr -> Raw.print_optional $ unsafeFromPtr ptr