Skip to main content

haskell_eval

Macro haskell_eval 

Source
haskell_eval!() { /* proc-macro */ }
Expand description

Embeds and evaluates a Haskell Core expression at runtime.

Accepts either a .cbor path (pre-compiled CBOR) or a .hs path (Haskell source compiled on-demand via nix run .#tidepool-extract).

For .cbor paths, the file is embedded directly via include_bytes!. For .hs paths, the macro invokes GHC through nix at compile time, producing CBOR in target/tidepool-cbor/, then embeds the result. The .hs source file is tracked by cargo for automatic recompilation.

§Haskell Source Support

When given a .hs path, the macro compiles it via nix run .#tidepool-extract. This requires nix to be available on PATH.

Path resolution: .hs paths resolve relative to CARGO_MANIFEST_DIR (the crate root). .cbor paths resolve relative to the calling file (standard include_bytes! behavior).

For modules with multiple top-level bindings, specify which binding to evaluate using the ::binding syntax. If only one binding exists (excluding metadata), it is selected automatically.

§Panics

The generated code will panic during CBOR deserialization if the embedded data is malformed or incompatible with the expected format.

§Dependencies

The expansion of this macro expects the following crates to be available in the caller’s scope:

  • tidepool_repr
  • tidepool_eval

§Returns

Returns a Result<tidepool_eval::Value, tidepool_eval::error::EvalError>.

§Examples

// Pre-compiled CBOR
let val = haskell_eval!("../../haskell/test/Identity_cbor/identity.cbor").unwrap();

// Haskell source (single binding)
let val = haskell_eval!("../../haskell/test/SingleBinding.hs").unwrap();

// Haskell source with binding selector
let val = haskell_eval!("../../haskell/test/Identity.hs::identity").unwrap();