[Haskell-cafe] "show" for functional types
lennart at augustsson.net
Wed Apr 5 15:45:50 EDT 2006
Neil Mitchell wrote:
> First, its useful to define referential transparency.
> In Haskell, if you have a definition
> f = not
> Then this means that anywhere you see f, you can replace it with not.
> For example
> "f True" and "not True" are the same, this is referentially transparent.
> Now lets define "super show" which takes a function, and prints its
> code behind it, so:
> superShow f = "not"
> superShow g = "\x -> case ..."
> now superShow f /= superShow g, so they are no longer referentially transparent.
> Hence, you have now broken referential transparency.
> So you can't show these two functions differently, so what can you do
> instead? You can just give up and show all functions the same
> instance Show (a -> b) where
> show x = "<function>"
> This is the constant definition of show mentioned.
You can be less restrictive than that. The show function can give
different results when applied to functions with different types
without breaking anything.
More information about the Haskell-Cafe