I know just enuf about existential types in Haskell to be dangerous.  While
trying to learn a little more about how to use them, I keep running into
problem.  The existential types work great for code that I constructed if the
functions take a single argument.  However, if the function takes more than
one argument, I can't seem to figure out how to get them to work.

In the test code below, everything compiles in Hugs (hugs98-Feb2001) except
the last line in the instance declaration (setx).  Is there something
fundamental that I'm missing about how to create an existential instance
and/or data declaration - given the listed class definition?

module Test


  class Shape a where
     getx :: a -> Int
     setx :: a -> Int -> a

  data ExistentialShape =
     forall a. Shape a => MakeExistentialShape a

  instance Shape ExistentialShape where
     getx (MakeExistentialShape a) = getx a
     setx (MakeExistentialShape a) newx = setx a newx

-- here's the error message I get when I try to :load the module
ERROR test.hs:14 - Type error in instance member binding
*** Term           : setx
*** Type           : ExistentialShape -> Int -> _12
*** Does not match : ExistentialShape -> Int -> ExistentialShape
*** Because        : cannot instantiate Skolem constant

Chris Rathman

Reply via email to