[Haskell-cafe] type inference and FFI

Sylvain Henry sylvain at haskus.fr
Wed Oct 27 10:00:38 UTC 2021


Hi,

With a type-class maybe?

class Foo a where
   foo :: Ptr a -> IO r -- not sure what is your `r`

instance Foo Word16 where foo = c'foo_uint16_t
instance Foo Word32 where foo = c'foo_uint32_t


Sylvain


On 27/10/2021 11:18, PICCA Frederic-Emmanuel wrote:
> Hello, I have a bunch of C method that I need to call like this
>
> c'foo_unit16_t :: Ptr Word16 -> IO r
> c'foo_uint32_t :: Ptr Word32 -> IO r
> ...
>
> These methodes are called from a method like this
>
>
> process :: NativeType t => Dataframe t => IO r
> process df = do
>     ...
>     <pseudo code>
>     case typeof t of
>         WORD16 -> c'foo_unit16_t ...
>         WORD32 -> c'foo_uint32_t ...
>
> Since there is type erasure, I would like to know what is the best way to write this process method.
>
> thanks for you help
>
> Frederic
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list