[Haskell-cafe] Polymorphic updating with TC/TFs?
hans at hanshoglund.se
Tue Dec 17 00:37:19 UTC 2013
I am working with a set of type classes of the following form (http://lpaste.net/97110). The idea is that every such class provide an associated type Foo, and a lens to the Foo in every instance. I.e. this class is used to provide view/set/modify for all types that contain a Foo somewhere deep in its structure.
For "simple lenses", i.e. functions that does not modify the associated Foo, this is straightforward. However to support polymorphic updates it seems necessary to add another associated type NoFoo, which must be used to constraint the return type of set.
What bothers me is the redundancy of the two set functions. I would intuitively expect set' to be implemented in terms of set (as it seems to be a restriction of that function), but this is not possible, as the compiler can not deduce that (NoFoo a (Foo a) ~ a). Is there a way to add this constraint to the type class?
More information about the Haskell-Cafe