Foreign Function Interface

A foreign function interface (FFI) is provided to allow husk to call into arbitrary Haskell code. The interface is available via the load-ffi function:

(load-ffi "Language.Scheme.Plugins.CPUTime" "precision" "cpu-time:precision")

load-ffi accepts the following string arguments:

  • Name of a Haskell module to dynamically load
  • Haskell function to load from that module
  • Name to use for the function after it is loaded into husk
From the previous example, once cpu-time:precision is loaded, it may be called directly from husk just like a regular Scheme function:
(cpu-time:precision)

Any Haskell function loaded via the FFI must be of the following type:

[LispVal] -> IOThrowsError LispVal

See the Language.Scheme.Plugins.CPUTime module for an example of how to use the FFI.

Note by default the FFI is disabled, which allows husk to avoid unnecessarily linking to the GHC API. This significantly reduces its compiled size out-of-the-box. To enable the FFI just pass the option -fuseffi to cabal when installing or upgrading Husk.

husk-scheme online documentation rev 3.2 (2021.03.04)