[Haskell-cafe] OverlappingInstances-extension-like for type families
Richard Eisenberg
eir at cis.upenn.edu
Tue Jul 22 11:58:33 UTC 2014
Hi Leza,
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!
Richard
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]
>
>
> Thanks.
> --
> Leza Morais Lutonda, Lemol-C
> http://lemol.github.io
>
>
>
> 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
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list