[Haskell-cafe] Dispatch a type-function on the existence (or not) of instances?
hans at hanshoglund.se
Fri Jan 31 17:56:00 UTC 2014
I have been curious about the ability to detect the presence of a certain instance (ClassFoo TypeBar) in the type system.
Specifically, is it possible to "dispatch" a type on the existence (or not) of such an instance. For example given two functions:
withInstance :: (ClassFoo TypeBar) => TypeIfInstanceExists
withoutInstance :: TypeIfInstanceDoesNotExists
I would be able to consolidate them into something like this:
(r ~ InstanceExists ClassFoo TypeBar,
a ~ If r TypeIfInstanceExists TypeIfInstanceDoesNotExists) => a
I guess what I need is:
1) A type-level "if".
2) The possibility of "converting" a constraint into a type-level bool.
I am sure (1) is possible but have no idea about (2). Anyone?
More information about the Haskell-Cafe