module Main (main) where import Data.ByteString import Data.Word import Foreign.C import GarnetRs import GarnetRs.Safe import HsBindgen.Runtime.PtrConst import Unsafe.Coerce main :: IO () main = do useAsCString "Haskell" $ hello . unsafeFromPtr hello_struct $ convertT T'{a = True, b = 42} hello_struct $ convertT T'{a = False, b = 42} hello_shape $ convertShape $ Circle 3.14 hello_shape $ convertShape $ Rectangle 10.0 5.0 data T' = T' { a :: Bool , b :: Word8 } convertT T'{a, b} = -- T{a = CBool $ unsafeCoerce @Bool @Word8 a, b} T{a = CBool $ fromIntegral $ fromEnum a, b} data Shape' = Circle CDouble | Rectangle CDouble CDouble convertShape = \case Circle r -> Shape (Shape_Tag 0) $ set_shape_body_circle $ Circle_Body r Rectangle w h -> Shape (Shape_Tag 1) $ set_shape_body_rectangle $ Rectangle_Body w h