[Haskell-cafe] Comparing functions
timon.gehr at gmx.ch
Thu Jul 11 20:00:17 CEST 2013
On 07/11/2013 07:33 PM, Vlatko Basic wrote:
> Hello Cafe,
> I have
> 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')
Yes, (==) is a variable name in a pattern. Hence you are creating a new
definition for (==) bound to the constructor argument to CF, which hides
the (==) defined within the Eq type class.
> Is it possible at all to compare two functions
Function types are opaque and values do not have an identity.
> or how to solve this problem, to show some string for a specific function?
You could store the string alongside the function inside the data type
in some way.
More information about the Haskell-Cafe