
I'm developing a typesafe record library (akin to HList but starting with key/val pairs and enforcing uniqueness and sorted order of keys). I'm having a GHC problem I've had with other projects and seen comments regarding it in other people's code (HList for instance: "GHC doesn't like it's own type" to paraphrase). I have a function |update|
--update :: forall sel val rec val' rec' . -- SetField sel val rec val' rec' => sel -> (val -> val') -> rec -> rec' update sel f rec = rec' where --val :: val val = value sel rec --val' :: val' val' = f val --rec' :: rec' rec' = set sel val' rec
The commented out signature is the signature that GHC infers for the function. When I uncomment that signature, it will no longer type check. Why does this happen? Even with the forall and the explicit signatures in the where clause, it chokes. I don't plan on sharing the code for |SetField| because it's that wild looking type class hackery, and the problem isn't specific to this example--I remember having it happen in far simpler cases which I can't seem to find right now... Is there a canonical example example that exhibits this behavior? Or a ticket for it already? I'd like to understand what's happening. Thanks for your time, Nick