• Nix scaffolding for running Haskell plugins June 24, 2018

    I’ve been all about writing source plugins recently but have been dissatisfied with how rough it is to use them practically. In particular, I am writing plugins which don’t change the semantics of my programs but are useful for debugging. I only sometimes want to run them and don’t want them to appear as dependencies at all on Hackage. It needs to be easy to apply them to my own and other people’s packages.

    Of course, the solution was to leverage my knowledge of nix to wrap up everything into a nice interface. The key to the interface is a new function haskell.lib.addPlugin which augments an existing package with a plugin.

    addPlugin dump-core-plugin either

    This invocation will now also output an HTML representation of the core program of the either package by using the dump-core plugin.

    This post will explain this interface in more detail but will not get into the gritty implementation details. The implementation can be found in the haskell-nix-plugin repo.

    Read more

  • Fixing the missing `ar` error with a development build of GHC (on NixOS) June 21, 2018

    On NixOS, if you build GHC from source using Make or hadrian and try to use it with cabal then you will be greeted with the following error:

    cabal: The program 'ar' is required but it could not be found.

    The way to fix this problem is to run cabal in an environment with the binutils-unwrapped package available. You can then use cabal as normal.

    nix-shell -p binutils-unwrapped

  • Source Plugins: Four ways to build a typechecked Haskell expression June 11, 2018

    A source plugin allows users to modify and analyse code after typechecking. They have access to all the features of the compiler to create and modify bindings.

    Sounds great right? GHC is all about creating and modifying bindings so this should be a doddle. However, it isn’t immediately obvious how to make a typechecked binding using the provided API.

    In this post, I’ll demonstrate and explain four different ways of arriving at a typechecked expression which can then be inserted into a program. All these examples are packaged up into a complete plugin on my GitHub page.

    Read more

  • Replacing type classes with records affects optimisation March 20, 2018

    It is somewhat common to suggest using records instead of type classes for particular domains for which type classes are not deemed idiomatic. However, this suggestion should be taken with caution as the change will have consequences on how your program is optimised. Using records instead of type classes can lead to much slower programs.

    Read more

  • Using a development version of GHC with nix January 5, 2018

    Most documentation for using nix with Haskell concentrates on quite simple use cases such as how to modify or add new dependencies. What about when you want to do something more complicated? In this post we look at combining modifications from different sources. The goal is to create a package set which can be used to compile packages with HEAD.

    Read more