Here is a curiosity of the Haskell update mechanism;
you can map one type to another using it. 
Consider this datatype and function...

data Foo a = Foo { foo :: a
                 , bar :: Int 
                 } deriving Show

up s t = s { foo = t }

Now, what should the type of the function 'up' be?

  up :: Foo a -> a -> Foo a
      ** OR **
  up :: Foo a -> b -> Foo b

Both Hugs and GHC give the later type, 
ie. the updated object can have
a different type than the parent object. 
Pages 26,27 of the Haskell98 report does not
say anything about polymorphic fields in records.

I was somewhat surprised by the type of up, but it
did come in useful in a piece of code I was writing.. 

What do people think about this? Does it surprise anyone 
else, or is this a known design decision?

Andy

-------------------------------------------------------------
-- [To complete the example]

obj = Foo { foo = 1 :: Int
          , bar = 99 
          }

main = print (obj                -- plain object        :: Foo Int
             ,up obj ()          -- updated object      :: Foo ()
             ,obj { foo = True } -- updated object      :: Foo Bool
             )

Reply via email to