Undecideable instances for one instance?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Undecideable instances for one instance?

Christophe Poucet
Dear,

Recently I was wrapping something in a typeclass (you may argue the
reason for the typeclass, I will admit that's no longer needed, yet the
compile error still begs questioning). Basically if you have only one
global instance of a typeclass (so there is no overlapping), GHC will
still complain about overlapping. Is there any reason this is so or is
this a remnant of more complicated overlapping situations?

The sample code is:

{-# OPTIONS_GHC -fglasgow-exts #-}
module Main where

data Located a = L a

class Locatable a where
value :: Located a -> a
wrap :: a -> Located a

instance Locatable a where
value (L a) = a
wrap a = L a

main :: IO ()
main = do
print . value . wrap $ 1

-- Illegal instance declaration for `Locatable a'
-- (There must be at least one non-type-variable in the instance head
-- Use -fallow-undecidable-instances to permit this)
-- In the instance declaration for `Locatable a'

Christophe(vincenz)

--
Christophe Poucet
Ph.D. Student
Phone:+32 16 28 87 20
E-mail: Christophe (dot) Poucet (at) imec (dot) be
Website: http://notvincenz.com/ 
IMEC vzw – Register of Legal Entities Leuven VAT BE 0425.260.668 – Kapeldreef 75, B-3001 Leuven, Belgium – www.imec.be
*****DISCLAIMER*****
This e-mail and/or its attachments may contain confidential information. It is intended solely for the intended addressee(s).
Any use of the information contained herein by other persons is prohibited. IMEC vzw does not accept any liability for the contents of this e-mail and/or its attachments.
**********

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

Re: Undecideable instances for one instance?

Bulat Ziganshin-2
Hello Christophe,

Wednesday, June 7, 2006, 12:27:22 PM, you wrote:

> global instance of a typeclass (so there is no overlapping), GHC will
> still complain about overlapping. Is there any reason this is so or is

GHC compains here about undecidability, not overlapping :)

> -- Illegal instance declaration for `Locatable a'
> -- (There must be at least one non-type-variable in the instance head
> -- Use -fallow-undecidable-instances to permit this)
> -- In the instance declaration for `Locatable a'

> Christophe(vincenz)




--
Best regards,
 Bulat                            mailto:[hidden email]

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

Fwd: Undecideable instances for one instance?

Christophe Poucet
Hello Bulat,

You are indeed correct. However I fail to see how there is any undecideability.  If instead one specified it as follows, it would be fine:

class Locatable a b | a -> b, b -> a where
   value :: a -> b
   wrap :: b -> a

instance Locatatable (Located a) a where

   value (L a) = a
   wrap a       = L a

It compiles fine, yet this is semantically the same.




On 6/7/06, Bulat Ziganshin <[hidden email]> wrote:
Hello Christophe,

Wednesday, June 7, 2006, 12:27:22 PM, you wrote:

> global instance of a typeclass (so there is no overlapping), GHC will
> still complain about overlapping. Is there any reason this is so or is

GHC compains here about undecidability, not overlapping :)

> -- Illegal instance declaration for `Locatable a'
> -- (There must be at least one non-type-variable in the instance head
> -- Use -fallow-undecidable-instances to permit this)
> -- In the instance declaration for `Locatable a'

> Christophe(vincenz)




--
Best regards,
Bulat                            mailto:[hidden email]



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

Re: Undecideable instances for one instance?

Sergey Zaharchenko
In reply to this post by Christophe Poucet
Hello Christophe!

Wed, Jun 07, 2006 at 10:27:22AM +0200 you wrote:

> The sample code is:
>
> {-# OPTIONS_GHC -fglasgow-exts #-}
> module Main where
>
> data Located a = L a
>
> class Locatable a where
> value :: Located a -> a
> wrap :: a -> Located a
>
> instance Locatable a where
You probably mean ``instance Locatable (Located a)'', don't you?

> value (L a) = a
> wrap a = L a

HTH,

--
DoubleF
No virus detected in this message. Ehrm, wait a minute...
/kernel: pid 56921 (antivirus), uid 32000: exited on signal 9
Oh yes, no virus:)

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

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Undecideable instances for one instance?

Sergey Zaharchenko
Hello Christophe!

Wed, Jun 07, 2006 at 12:39:30PM +0400 I wrote:

> > instance Locatable a where
>
> You probably mean ``instance Locatable (Located a)'', don't you?

Ouch, scratch that...

--
DoubleF
No virus detected in this message. Ehrm, wait a minute...
/kernel: pid 56921 (antivirus), uid 32000: exited on signal 9
Oh yes, no virus:)

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

attachment0 (196 bytes) Download Attachment