Hm, I thought it is a pattern match with constant, as in f ('a':xs) ==-------- Original Message --------
Subject: Re: [Haskell-cafe] Comparing functions
From: Brandon Allbery <allbery.b@gmail.com>
To: Vlatko Bašić <vlatko.basic@gmail.com>
Cc: Haskell-Cafe <haskell-cafe@haskell.org>
Date: 11.07.2013 19:50
On Thu, Jul 11, 2013 at 1:33 PM, Vlatko Basic <vlatko.basic@gmail.com> wrote:
data CmpFunction a = CF (a -> a -> Bool)
that contains comparing functions, like ==, <, > ..., and I'm trying to declare the Show instance for it like this
instance Show (CmpFunction a) where
show (CF (==)) = "== " -- no good
show f = case f of -- no good also
CBF (==) -> "=="
_ -> "Other"
but compiler complains for both with
This binding for `==' shadows the existing binding
imported from `Prelude' at src/Main.hs:6:8-11
(and originally defined in `ghc-prim:GHC.Classes')
The problem here isn't quite what you think it is; (==) is not a constructor, therefore it is a *variable*. It's exactly the same problem as
a = 5-- ...foo a = 3 -- this does NOT compare with the previous value of "a"; it's identical to the next line!foo x = x
--Just as with the above, the normal way to do it would be to use a guard... but functions don't have an Eq instance, and *can't* have one. How do you meaningfully compare them? And for a typeclass function like (==), do you want (==) instantiated for Int to compare equal to (==) instantiated for Integer? Does a native-compiled function compare equal to an interpreted function? Remember referential transparency; the concept of comparing pointers used in some languages is not applicable to Haskell.
brandon s allbery kf8nh sine nomine associatesunix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net