Existential Type Declarations in Hugs
Critterrathman@aol.com
Critterrathman@aol.com
Thu, 3 May 2001 02:54:26 EDT
--part1_da.5caeee1.28225aa2_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
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
where
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
Thanks,
Chris Rathman
--part1_da.5caeee1.28225aa2_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
<HTML><FONT FACE=arial,helvetica><FONT SIZE=4 FAMILY="SERIF" FACE="Times New Roman" LANG="0">I know just enuf about existential types in Haskell to be dangerous. While
<BR>trying to learn a little more about how to use them, I keep running into
<BR>problem. The existential types work great for code that I constructed if the
<BR>functions take a single argument. However, if the function takes more than
<BR>one argument, I can't seem to figure out how to get them to work.
<BR>
<BR>In the test code below, everything compiles in Hugs (hugs98-Feb2001) except
<BR>the last line in the instance declaration (setx). Is there something
<BR>fundamental that I'm missing about how to create an existential instance
<BR>and/or data declaration - given the listed class definition?
<BR>
<BR>
<BR>module Test
<BR>
<BR> where
<BR>
<BR> class Shape a where
<BR> getx :: a -> Int
<BR> setx :: a -> Int -> a
<BR>
<BR> data ExistentialShape =
<BR> forall a. Shape a => MakeExistentialShape a
<BR>
<BR> instance Shape ExistentialShape where
<BR> getx (MakeExistentialShape a) = getx a
<BR> setx (MakeExistentialShape a) newx = setx a newx
<BR>
<BR>
<BR>-- here's the error message I get when I try to :load the module
<BR>ERROR test.hs:14 - Type error in instance member binding
<BR>*** Term : setx
<BR>*** Type : ExistentialShape -> Int -> _12
<BR>*** Does not match : ExistentialShape -> Int -> ExistentialShape
<BR>*** Because : cannot instantiate Skolem constant
<BR>
<BR>
<BR>Thanks,
<BR>Chris Rathman</FONT></HTML>
--part1_da.5caeee1.28225aa2_boundary--