[Haskell-cafe] "show" for functional types

Lennart Augustsson lennart at augustsson.net
Wed Apr 5 15:50:40 EDT 2006


Brian Hulley wrote:
> Greg Buchholz wrote:
>>
>>    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?
> 
> Interesting! Referential transparency (as I understand it) has indeed 
> been violated. Perhaps the interaction of GADTs and type classes was not 
> sufficiently studied before being introduced to the language.
> 
> So I'm now just as puzzled as you.

There's no mystery.  The + operator used in that example
does not obey '1+1=2'.

	-- Lennart


More information about the Haskell-Cafe mailing list