Your example suggests that update  was, perhaps, not the best choice
of terminology!

| 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.

The typing is implied by the translation of update
expressions [*].  Your example translates to:

  up s t = case s of
              Foo f b -> F t b

and the principal type of this is the second type that
you gave above (the one reported by GHC and Hugs).

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

The latter methinks, although it might not have been *well*
known before know :-)

All the best,
Mark

[*] From the beginning of Section 3, cut and pasted direct
from the pdf:

  In this section, we describe the syntax and informal
  semantics of Haskell expressions, including their
  translations into the Haskell kernel, where appropriate.
  Except in the case of let expressions, these translations
  preserve both the static and dynamic semantics.

Reply via email to