
Hi all, GHC is not happy with this: f = [] == [] nor this: f' = ([]::(Eq a) => [a]) == ([]::(Eq a) => [a]) but this is OK: f'' = ([]::[Integer]) == ([]::[Integer]) GHCI is comfortable with [] == [], so why not GHC? 'Just curious. Cheers, Paul

2009/5/29 Paul Keir
Hi all,
GHC is not happy with this:
f = [] == []
This fails because GHC doesn't know which 'a' you mean, and can't choose an Eq instance.
nor this:
f' = ([]::(Eq a) => [a]) == ([]::(Eq a) => [a])
This fails for the same reason.
but this is OK:
f'' = ([]::[Integer]) == ([]::[Integer])
GHCI is comfortable with [] == [], so why not GHC? 'Just curious.
Because GHCI has some 'default' instances, whereas GHC doesn't. This time, it probably chooses a=().
Cheers, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Eugene Kirpichov Web IR developer, market.yandex.ru

f''' = ([]::[()]) == ([]::[()])
(Very pretty.)
So why doesn't ghc have 'default' instances?
-----Original Message-----
From: Eugene Kirpichov [mailto:ekirpichov@gmail.com]
Sent: Fri 29/05/2009 10:51
To: Paul Keir
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] [] == [][MESSAGE NOT SCANNED]
2009/5/29 Paul Keir
Hi all,
GHC is not happy with this:
f = [] == []
This fails because GHC doesn't know which 'a' you mean, and can't choose an Eq instance.
nor this:
f' = ([]::(Eq a) => [a]) == ([]::(Eq a) => [a])
This fails for the same reason.
but this is OK:
f'' = ([]::[Integer]) == ([]::[Integer])
GHCI is comfortable with [] == [], so why not GHC? 'Just curious.
Because GHCI has some 'default' instances, whereas GHC doesn't. This time, it probably chooses a=().
Cheers, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Eugene Kirpichov Web IR developer, market.yandex.ru

On Fri, May 29, 2009 at 12:29 PM, Paul Keir
f''' = ([]::[()]) == ([]::[()])
(Very pretty.)
So why doesn't ghc have 'default' instances?
It does. I believe Num defaults to Integer and then to Double. Generally, though, defaults are convenient in exploratory usage but confusing in compiled code. In compiled code, you don't want arbitrary choices of defaults to affect performance and correctness. I've had programs run much slower than expected because the types defaulted to Integer rather than Int. --Max

On Fri, May 29, 2009 at 5:36 AM, Max Rabkin
On Fri, May 29, 2009 at 12:29 PM, Paul Keir
wrote: f''' = ([]::[()]) == ([]::[()])
(Very pretty.)
So why doesn't ghc have 'default' instances?
It does. I believe Num defaults to Integer and then to Double.
Generally, though, defaults are convenient in exploratory usage but confusing in compiled code. In compiled code, you don't want arbitrary choices of defaults to affect performance and correctness.
I've had programs run much slower than expected because the types defaulted to Integer rather than Int.
http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluati...

* Paul Keir
Hi all,
GHC is not happy with this:
f = [] == []
nor this:
f' = ([]::(Eq a) => [a]) == ([]::(Eq a) => [a])
Here, there's no guarantee that the answer will be the same independent of what 'a' you choose. Potentially, you could define different instances [Int] and [Bool] for Eq, so that [] == [] = True for [Int] but [] == [] = False for [Bool]. Actually, instance Eq [a] is defined parametrically on 'a', which implies that equality of lists depends only on equality of underlying types, therefore [] == [] should be constant, but compiler doesn't use this information. If you just want to test a list for emptyness, use 'null'. -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain
participants (5)
-
Derek Elkins
-
Eugene Kirpichov
-
Max Rabkin
-
Paul Keir
-
Roman Cheplyaka