[Haskell] Re: help with some basic code that doesn't work
Simon Peyton-Jones
simonpj at microsoft.com
Thu Mar 3 13:46:07 EST 2005
Happily, with GHC 6.4, your code works fine, both with 'deriving' and
with a hand-written instance.
It works because 6.4 can build recursive dictionaries.
Simon
| -----Original Message-----
| From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org]
On Behalf Of Shin-Cheng
| Mu
| Sent: 14 February 2005 05:32
| To: haskell at haskell.org
| Cc: Malcolm.Wallace at cs.york.ac.uk
| Subject: [Haskell] Re: help with some basic code that doesn't work
|
| Malcolm Wallace <Malcolm.Wallace at cs.york.ac.uk> wrote:
| > Just a comment, since a couple of people have made similar
statements.
| > Haskell will derive Eq for arbitrarily complex types - there is no
| > restriction to "simple" types, whatever they might be.
|
| Now that this topic is brought up...
|
| Occasionally I would need to define recursive datatypes
| using an explicit fixed-point operator, such as:
|
| > data Fix f = In (f (Fix f)) deriving (Show, Eq)
| > data L a x = Nil | Cons a x deriving (Show, Eq)
|
| However, Haskell was not able to derive from Fix f any
| instances. The following is what happens in GHCi:
|
| *Main> In Nil == In Nil
|
| Context reduction stack overflow; size = 21
| Use -fcontext-stack20 to increase stack size to (e.g.) 20
| `Eq (L e (Fix (L e)))' arising from use of `==' at
<interactive>:1
| `Eq (Fix (L e))' arising from use of `==' at <interactive>:1
| <<deleted>>
|
| *Main> In Nil
|
| Context reduction stack overflow; size = 21
| Use -fcontext-stack20 to increase stack size to (e.g.) 20
| `Show (L e (Fix (L e)))'
| arising from use of `print' at <interactive>:1
| <<deleted>>
|
| Probably Malcolm meant that Haskell will derive standard instances
| for arbitrarily complex type **if they are definable manually**.
| If so Malcolm's statement is true -- indeed I cannot even declare
| the instances by hand. The following declaration is acceptable
| by GHC after using the option -fallow-undecidable-instances,
| but even though, I got the same error message as I try to print
| In Nil.
|
| > Instance Show (f (Fix f)) => Show (Fix f) where
| > showsPrec _ (In x) = ("In ("++) . showsPrec 1 x . (')':)
|
| This is rather unsatisfactory, because I would not be able
| to inspect values of type Fix f in the interpreter. Is there
| a way to get around this?
|
| sincerely,
| Shin
|
| _______________________________________________
| Haskell mailing list
| Haskell at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell
More information about the Haskell
mailing list