Avoid IO for tree sum
This commit is contained in:
parent
71e4ffaede
commit
20b47594c6
@ -21,6 +21,7 @@ import Foreign.C
|
|||||||
import GarnetRs qualified as Raw
|
import GarnetRs qualified as Raw
|
||||||
import GarnetRs.Safe qualified as Raw
|
import GarnetRs.Safe qualified as Raw
|
||||||
import HsBindgen.Runtime.PtrConst
|
import HsBindgen.Runtime.PtrConst
|
||||||
|
import System.IO.Unsafe
|
||||||
|
|
||||||
data T = T
|
data T = T
|
||||||
{ a :: Bool
|
{ a :: Bool
|
||||||
@ -65,5 +66,5 @@ helloShape = Raw.hello_shape . convertShape
|
|||||||
add :: Int64 -> Int64 -> Int64
|
add :: Int64 -> Int64 -> Int64
|
||||||
add = Raw.add
|
add = Raw.add
|
||||||
|
|
||||||
sumTree :: BTree Int64 -> IO Int64
|
sumTree :: BTree Int64 -> Int64
|
||||||
sumTree = flip withBTree Raw.sum_tree
|
sumTree = unsafePerformIO . flip withBTree Raw.sum_tree
|
||||||
|
|||||||
@ -10,4 +10,4 @@ main = do
|
|||||||
helloShape $ Circle 3.14
|
helloShape $ Circle 3.14
|
||||||
helloShape $ Rectangle 10.0 5.0
|
helloShape $ Rectangle 10.0 5.0
|
||||||
putStrLn $ "3 + 4 = " <> show (add 3 4)
|
putStrLn $ "3 + 4 = " <> show (add 3 4)
|
||||||
putStrLn . ("Tree sum: " <>) . show =<< sumTree (Fork (Fork (Leaf 1) (Fork (Leaf 2) (Leaf 3))) (Leaf 4))
|
putStrLn $ "Tree sum: " <> show (sumTree (Fork (Fork (Leaf 1) (Fork (Leaf 2) (Leaf 3))) (Leaf 4)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user