benmachine/haskell-src-meta — pull request #18 by elliottt (2012-12-01 01:44:45+00:00)
Title: Add toTypeName to fix a bug in AST translation

This patch addresses a bug that was showing up when translating the result of parseHsType with toType. The test case is this program:

```haskell
{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.Exts
import Language.Haskell.Meta

f :: $( let Right ty = parseHsType "()" in return (toType ty) )
f = ()
```

Which gives a kind error on at least ghc 7.4 and 7.6.

The problem stems from how names get translated, namely special names like `()` and `[]`. As ghc supports promoting values to the type level, translating the type `()` using `'()` causes a value name to be written out, instead of a type name.

This patch solves this problem by introducing another function to the `ToName` class, `toTypeName`. With the addition of `toTypeName`, `()` can now be translated as `''()` in the context where it's a type name, and `'()` in the context where it's a value name.

I also added a .gitignore :)