[Haskell-cafe] OverlappingInstances-extension-like for type families
eir at cis.upenn.edu
Tue Jul 22 11:58:33 UTC 2014
It's not clear that what you want to do is sound: according to your desired definitions, `ComplexSignalType [C Double]` would be *both* `[C (C Double)]` (from the first type instance) and `[C Double]` (from the second). How do you want to reconcile this? If you want to use the first instance only when the second doesn't match (which is what OverlappingInstances does, as the first is more general than the second), you'll want to use closed type families. If not, then I'm not sure what you want.
Here the closed type families approach:
type family ComplexSignalType e where
ComplexSignalType [C e] = [C e]
ComplexSignalType [e] = [C e]
Now, the second equation will trigger only when GHC is sure that the first equation won't.
I hope this helps!
On Jul 21, 2014, at 5:29 PM, Leza Morais Lutonda <leza.ml at fecrd.cujae.edu.cu> wrote:
> Hello haskell-café,
> I just started working with type families, and come with some difficulties. Now I have a class:
> class (...) ⇒ Complexable s where
> type ComplexSignalType s
> Is there a possibility to have this two instances (in any way)?
> instance (RealFloat e) ⇒ Complexable [e] where
> type ComplexSignalType [e] = [ℂ e]
> instance (RealFloat e) ⇒ Complexable [ℂ e] where
> type ComplexSignalType [ℂ e] = [ℂ e]
> Leza Morais Lutonda, Lemol-C
> 50 Aniversario de la Cujae. Inaugurada por Fidel el 2 de diciembre de 1964 http://cujae.edu.cu
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe