[Haskell-cafe] Data types and field labels and "Show"

bbrown bbrown at botspiritcompany.com
Thu Sep 27 14:14:32 EDT 2007

I am trying to print the data from a data type and also get the field 
values.  How would I reference those values if I am declaring a Show function.

I should probably use a class for this, but so far it is working.

I have something along the lines of this.

data SimplePlayer = SimplePlayer { 
      shape :: MechShape,
      angle :: GLfloat,
      posX :: GLfloat,
      posY :: GLfloat

and then to use "Show", I was declaring this.

instance Show SimplePlayer where
	show a = "<Simple> posX [" ++ show a{posX} ++ "]"

Of course, this didn't compile.

How should I change this code to get the field label values of the type.

Tests/GLTests.hs:20:42: parse error on input `}'

Berlin Brown
[berlin dot brown at gmail dot com]

More information about the Haskell-Cafe mailing list