[Haskell-beginners] joining lists sharing multiple type classes

Christopher Howard christopher.howard at frigidcode.com
Fri Aug 31 21:34:40 CEST 2012


Hi. I've got two data structures, Star and Asteroid (eventually I'll
make more) that both belong to the following type classes: Locatable,
and Animation. I wanted to do something like so in part of the code:

code:
--------
let stars = ... in      -- of type [Star]
let asteroids = ... in  -- of type [Asteroid]
let visibleObjects = do visibleObject <- (stars ++ asteroids)
                        ... -- prep each object for graphics system
                            -- using funcs from both type classes
... -- feed visibleObjects to graphics system
--------

However, this does not work because the two lists are not automatically
downgraded when joined together by (++). The compiler complains about
"asteroids" not being of type [Star]. What is the simplest way to do
what I am trying to do? I tried this, but I think my syntax is off:

code:
--------
let visibleObjects =
  do visibleObject <- ((stars :: [(Locatable a, Animation a) => a)
                      ++ (asteroids :: [(Locatable a, Animation a) => a)
                      )
--------

Compiler complains about "Illegal polymorphic or qualified type".


-- 
frigidcode.com
indicium.us

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 554 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120831/4861e910/attachment.pgp>


More information about the Beginners mailing list