[Haskell] ANNOUNCE: notcpp-0.0.1

Ben Millwood haskell at benmachine.co.uk
Fri Apr 13 22:49:43 CEST 2012


I'm pleased to announce my first genuinely original Hackage package:
notcpp-0.0.1!

http://hackage.haskell.org/package/notcpp

This was inspired after someone submitted a patch to another of my
packages, applicative-quoters, to improve behaviour on later GHC
versions by using the new lookupValueName function where appropriate.
The patch used CPP to determine if the package versions were such that
lookupValueName would exist.

But I never liked using CPP: it completely defeats haskell-src-exts
and hence things like SourceGraph, and anyway it's not designed for
Haskell and doesn't at all understand its structure, or fit with its
syntax. With a little thought, I wondered if creative use of template
haskell might not achieve the same goal. It turned out it did, and
emboldened with this knowledge I set out to write a new package making
this technique available to others.

Along the way, a second technique occurred to me along the way that
this could provide a hack fix for particularly nasty orphan instances;
provide the class name, type, and method definitions, and my code
detects if an instance exists. If so, it throws away your hard work
and uses that; if not it synthesises (crudely, and probably
inaccurately in some cases) an instance from your information and
includes it in your code. One way or another, the instance will exist.

I should emphasise that the way this is done is strange, and I have
possibly hit a GHC bug or two, so I invite people to test, to
-ddump-splices and make sure the package is behaving, and to let me
know what they discover :) I'm off to fetch a GHC HEAD and see if it
is any more co-operative.

Ben Millwood

(second attempt at sending this, since the first was from an address
not subscribed the the list, whoops)



More information about the Haskell mailing list