[Haskell-cafe] "show" for functional types
Greg Buchholz
haskell at sleepingsquirrel.org
Fri Mar 31 23:10:56 EST 2006
Brian Hulley wrote:
] Here is another example. Consider two functions f and g which, given the
] same inputs, always return the same outputs as each other such as:
]
] f x = x + 2
] g x = x + 1 + 1
]
] Now since f and g compute the same results for the same inputs, anywhere in
] a program that you can use f you could just replace f by g and the
] observable behaviour of the program would be completely unaffected. This is
] what referential transparency means.
]
] However, if you allowed a function such as superShow, superShow f == "x +
] 2" and superShow g == "x + 1 + 1" so superShow f /= superShow g thus you
] could no longer just use f and g interchangeably, since these expressions
] have different results.
Hmm. It must be a little more complicated than that, right? Since
after all you can print out *some* functions. That's what section 5 of
_Fun with Phantom Types_ is about. Here's a slightly different example,
using the AbsNum module from...
http://www.haskell.org/hawiki/ShortExamples_2fSymbolDifferentiation
> import AbsNum
>
> f x = x + 2
> g x = x + 1 + 1
>
> y :: T Double
> y = Var "y"
>
> main = do print (f y)
> print (g y)
...which results in...
*Main> main
(Var "y")+(Const (2.0))
(Var "y")+(Const (1.0))+(Const (1.0))
...is this competely unrelated?
Thanks,
Greg Buchholz
More information about the Haskell-Cafe
mailing list