On Sun, Mar 15, 2009 at 04:18:41PM -0600, Robin Cockett wrote:
If you want to define the initial object in a functional language you should write (say in Haskell):
data Initial = deriving (Show) -- so we can display the elements
Unfortunately, this wouldn't be initial in Hask, because of two Haskell features: 1) Every Haskell datatype contains at least one element, namely "undefined", which represents (among other things) non-terminating computations. 2) Haskell is a lazy language, and thus functions are not required to preserve undefinedness. So we can write as many functions Initial -> Int as we please: one :: Initial -> Int one _ = 1 -- The _ means "ignore this input" five :: Initial -> Int five _ = 5 seventeen :: Initial -> Int seventeen _ = -17 -- XXX must get round to renaming this function -- to reflect changed functionality Calling these functions is as easy as Hugs> one undefined 1 Hugs> five undefined 5 Hugs> seventeen undefined -17 [D'oh!] Hope that helps, Miles -- Men occasionally stumble over the truth, but most of them pick themselves up and hurry on as if nothing had happened. -- Winston Churchill