mgsloan/th-orphans

Incorrect result when comparing values of type Type

ddssff opened this issue · 6 comments

ghci
> :set -XTemplateHaskell
> :m +Language.Haskell.TH Language.Haskell.TH.Instances
> compare (AppT (ConT ''Maybe) (ConT ''Int)) (AppT (ConT ''Maybe) (ConT ''Char))
EQ

I'm really not sure what's going on here. The generated code looks correct. I tried copying the results of building th-orphans with -ddump-splices into a file, and running your example produces the correct output, GT.

This made me suspect that there's a TH bug in GHC 7.8, perhaps related to "unique names" actually aliasing eachother. So, I made your repro into a test, so that travis will test it on multiple versions. However, travis shows the same results regardless of if it's running on GHC 7.4, 7.6, or 7.8. Bizarre!

I will look into this further another day.

I sent a pull request that updates the travis script to get the different compilers to install - I discovered that this bug is fixed in GHC-7.10, but not in 7.8. I don't think th-orphans Ord instances will ever be safe to use in 7.8.

Interesting! Thanks for investigating further. The solution will be simple but gnarly: copy the results of -ddump-splices for each GHC version.

Any thoughts on the specifics of the TH bug?

Another solution is to use standalone deriving to create the instances. I wonder if you can [d|deriving instance Ord $typ |] ?

Good point! Unfortunately, TH can't generate standalone deriving instances. However, that's better than copying a ton of code.

According to travis, this is now fixed! Released as v0.9.1. Thanks for finding these issues!