I would like to implement the show method for (binary) functions and make it able to distingish endofunctions (a -> a).
Something like the pseudo-haskell code:
instance Show (a->b) where
show fun = "<<Endofunction>>" if a==b
show fun = "<<Function>>" if a\=b
How can I distinguish the two cases?
You need to enable some extensions:
You need
OverlappingInstancessince the instancea -> balso matches endofunctions, so there’s overlap, and you needFlexibleInstancesbecause the language standard mandates that the type variables in instance declarations are distinct.