Bryan Gardiner

Hoppy - C++ FFI Generator for Haskell

Sick and tired of the ease with which Haskell code flows onto the page?  Even the thrill of binding to a C library losing its lustre?  Look no further!  Hoppy is a tool restoring the good old days of pointers, manual memory management, and hours lost to the debugger.

Hoppy is a foreign function interface generator for accessing C++ libraries from Haskell.  Interface descriptions are written in Haskell, then compiled into a generator that produces C++ and Haskell bindings that interact. Hoppy should work on any *nix platform that supports GHC.

The binding definition for Qt's QPushButton class in Qtah looks like:

c_QPushButton :: Class
c_QPushButton =
  addReqIncludes [includeStd "QPushButton"] $
  makeClass (ident "QPushButton") Nothing [c_QAbstractButton]
  [ -- Constructors.
    mkCtor "new" []
  , mkCtor "newWithParent" [ptrT $ objT c_QWidget]
  , mkCtor "newWithText" [objT c_QString]
  , mkCtor "newWithTextAndParent" [objT c_QString, ptrT $ objT c_QWidget]
    -- Methods.
  , mkMethod "showMenu" [] voidT
    -- Getter/setter pairs.
  , mkProp "autoDefault" boolT
  , mkBoolIsProp "default"
  , mkBoolIsProp "flat"
  , mkProp "menu" $ ptrT $ objT c_QMenu



See the changelog for further detail into what's mentioned here.

2021-02-06: I'm happy to announce that Hoppy 0.8.0 has been released, with a few important changes from previous releases. Hoppy generators now packaged as libraries rather than executables, which works better with Cabal and provides a more reliable experience packaging your project as a whole. As a result, Cabal v2 "new-style" builds are now officially supported (both for projects using Hoppy, and Hoppy itself). Additionally, when using automatic enum evaluation, C++ gateway packages now cache the evaluation results and pass this information to their Haskell gateway packages, reducing compile time and also enabling use with enums that are defined only as part of a C++ gateway package.

See the changelog entry for documentation on how to update your packages to work with these changes.

2019-12-23: Hoppy 0.7.0 is released. Automatic evaluation can now be used with scoped enums and not only old-style enums. As part of this, enum evaluation requires at least C++11. Also Cabal 3.0 is now supported.

2019-09-29: Hoppy 0.6.0 has at long last been released. The codebase has undergone significant refactoring to generalize concepts that were baked in before. It is now possible to define one's own exportable entities, and define custom marshalling for function parameters and return values; the built-in function, enum, class, etc. data types are much less special now. Function parameters can now be named and these names will show up in binding documentation. Also, enums have seen many improvements, the main one being that enums' ordinal values can now be autodetected, and no longer have to be written into generators manually. The Nix infrastructure has also been updated for this release.

2018-06-05: Hoppy 0.5.0 is out, with fixes for exception handling, std::string and std::set, and building on macOS. Bindings for STL unordered collections were added.

2018-01-27: Hoppy 0.4.0 is out, fixing an important bug in the generator where non-const class methods could be declared and then called as const functions, breaking const-safety. Please update your bindings. Code changes are only necessary when methods are declared incorrectly.

2017-06-10: New minor versions of Hoppy packages have been released. Hoppy now includes Setup.hs hooks for easy packaging of bindings, and callbacks are default-constructable on the C++ side.

2016-12-16: Released Hoppy 0.3.0 with support for exceptions, function pointers, and class member variables. Simplified class member lists, improved conversion flexibility, and class/enum member naming.

2016-06-29: Released Hoppy 0.2.0 with garbage collector support, and a restructuring of the API specification data types for future flexibility.

2016-02-08: Released!


Hoppy is available in four separate parts:

Of the different packages, only hoppy-runtime is a dependency of generated bindings, but it is required by all generated bindings.  The Hackage version is also suitable for binding development.  There is a users guide available in the hoppy-docs package.

For Gentoo users, my overlay contains Hoppy ebuilds, and Nix expressions are available for Nix users (as well as from Nixpkgs).


Hoppy is hosted on GitLab: project page, issue tracker. Clone the source from one of:


With the aim of preserving the openness of Hoppy as free software, most of Hoppy is licensed under the GNU Affero General Public License v3 or later.  However, some parts are licensed more permissively to allow the use of Hoppy in creating bindings to software of any license.  Parts of Hoppy that have significant portions included in the output (hoppy-std) or are a dependency of generated bindings (hoppy-runtime) are available under the Apache 2.0 license, so in general, projects using Hoppy are only bound by Apache 2.0.