Idris2 FFI

Idris2 FFI

Sep 30, 2021

Idris has a simple FFI, the following code is an example.

%foreign "C:puts,libc"
prim__puts : String -> PrimIO Int

To avoid duplicate typing, we usually would write

libc : String -> String
libc fname = "C:" ++ fname ++ ",libc"

%foreign libc "puts"
prim__puts : String -> PrimIO Int

Then we would like to wrap puts as more general type. Thus, we get

puts : HasIO io => String -> io Int
puts s = primIO $ prim__puts s

Enjoy this post?

Buy 林子篆 a coffee