[Haskell-cafe] Simple GADTs, type families and type classes combination with type error.

Serguey Zefirov sergueyz at gmail.com
Fri Jul 22 22:11:41 CEST 2011


2011/7/22 Dan Doel <dan.doel at gmail.com>:
> On Fri, Jul 22, 2011 at 11:12 AM, Serguey Zefirov <sergueyz at gmail.com> wrote:
> GHC cannot decide what instance of FuncVars to use. The signature of
> funcVars is:
>    funcVars :: FuncVars cpu => CPUFunc cpu -> [String]
>
> This does not take any arguments that allow cpu to be determined. For
> instance, if there were instances (rolling them into one declaration
> for simplicity):
>
>    instance FuncVars Int where
>      type CPUFunc Int = Int
>      ...
>
>    instance FuncVars Char where
>      type CPUFunc Char = Int
>
> Then GHC would see that CPUFunc cpu = Int, but from this, it cannot
> determine whether cpu = Int or cpu = Char. CPUFunc is not
> (necessarily) injective.

But "cpu" variable is the same in all places. If we don't dive into
CPUFunc reduction (to Int or whatever) we can safely match funcVars
argument and unify cpu.

This is the case when we write generic functions over type family application.

> Also, if you have a class whose only content is an associated type,
> there's really no need for the class at all. It desugars into:
>
>    type family CPUFunc a :: *
>
>    class CPU a

It would be somewhat inconvenient. I omitted some constraints in CPU
class for the sake of presentation.



More information about the Haskell-Cafe mailing list