Question, re: illegal instance error.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question, re: illegal instance error.

David Banas-2
Hi all,

I don’t understand why this code:

50: instance (IsNat n, RealFloat a) => FFT (RTree n) a where

is generating this error:

fft_test.hs:50:36:
    Illegal instance declaration for ‘FFT (RTree n) a’
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use FlexibleInstances if you want to disable this.)
    In the instance declaration for ‘FFT (RTree n) a’

and was hoping someone could help me get it.

Thanks!
-db


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Question, re: illegal instance error.

Andrey Chudnov
From the Haskell 2010 report: "An instance declaration introduces an instance of a class. Let class cx => C u where { cbody } be a class declaration. The general form of the corresponding instance declaration is: instance cx => C (T u1  uk) where { d } where k 0."

Note that your instance declaration has a form C (T u1) u2.

I think adding the FlexibleInstances extension, as suggested by the compiler, will work. Although, depending on the context, you might need UndecidableInstances too.

The core problem is that the FFT class must have been defined with the MultiParamTypeClasses extension, which usually leads to nastiness like this.

On 11/10/2015 11:15 AM, David Banas wrote:
Hi all,

I don’t understand why this code:

50: instance (IsNat n, RealFloat a) => FFT (RTree n) a where

is generating this error:

fft_test.hs:50:36:
    Illegal instance declaration for ‘FFT (RTree n) a’
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use FlexibleInstances if you want to disable this.)
    In the instance declaration for ‘FFT (RTree n) a’

and was hoping someone could help me get it.

Thanks!
-db



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Question, re: illegal instance error.

Chris Wong-2
In reply to this post by David Banas-2
Hi David,

Andrey's answer is correct.

I asked a similar question on StackOverflow a few years back [1]. You
might find the resulting discussion useful.

Chris

[1] http://stackoverflow.com/q/8633470/617159

On Wed, Nov 11, 2015 at 5:15 AM, David Banas <[hidden email]> wrote:

> Hi all,
>
> I don’t understand why this code:
>
> 50: instance (IsNat n, RealFloat a) => FFT (RTree n) a where
>
> is generating this error:
>
> fft_test.hs:50:36:
>     Illegal instance declaration for ‘FFT (RTree n) a’
>       (All instance types must be of the form (T a1 ... an)
>        where a1 ... an are *distinct type variables*,
>        and each type variable appears at most once in the instance head.
>        Use FlexibleInstances if you want to disable this.)
>     In the instance declaration for ‘FFT (RTree n) a’
>
> and was hoping someone could help me get it.
>
> Thanks!
> -db
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>



--
Chris Wong (https://lambda.xyz)

"I had not the vaguest idea what this meant and when I could not
remember the words, my tutor threw the book at my head, which did not
stimulate my intellect in any way." -- Bertrand Russell
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe