Hello everybody!
================

I love Haskell and it has helped me a lot to understand geometric
modelling, the subject of my diploma thesis.

But I have encountered a serious problem. I would like to have lists
of instances of a class, but it doesn't seem possible. I have
played around with new data-declarations, but what I actually need is
the comfortable flexibility of Haskell built-in lists.

I have written the program below which produces the nice output

["Instance_One", "Instance_One", "Instance_One"]
["Instance_Two", "Instance_Two", "Instance_Two"]
["Baseclass", "Baseclass", "Baseclass"]

But I would like to have a program with the following output:

["Instance_One", "Instance_Two", "Baseclass"]

So my question to all Haskell experts is: Is there any way to obtain
this output in the way I conceived? Or am I simply too stupid?

           looking forward to hear from anybody, Greetings, Sven.

PS. Please write back to the address below, if you don't mind.

======================================================================

import GHCio
import Channel

class Baseclass m where
   showme::m->String
   showme m = "Baseclass"

data Instance_One = Inst_One
instance Baseclass Instance_One where
   showme m = "Instance_One"

data Instance_Two = Inst_Two
instance Baseclass Instance_Two where
   showme m = "Instance_Two"

instance Baseclass Integer

list_one  = [Inst_One,Inst_One,Inst_One]
list_two  = [Inst_Two,Inst_Two,Inst_Two]
list_base::[Integer]
list_base = [1,2,3]

-- ### This is what I need but Haskell won't let me do that ###
-- list_needed::[Baseclass]
-- list_needed = [Inst_One,Inst_Two,2]

showlist::Baseclass m => [m]->String
showlist l = show (map showme l) ++ "\n"

main = putStr $ (showlist list_one ) 
             ++ (showlist list_two ) 
             ++ (showlist list_base) 
--           ++ (showlist list_needed)

======================================================================

-- 
-----------------------------------------------------------------------
 Sven Havemann, Rosental 24, 53111 Bonn, Deutschland, 0049/228/656860
 Keywords:  Freeform Curves & Surfs,  Generative Modeling, 4D Animation  
 FG Computergrafik: Institut f. Informatik III
 Universitaet Bonn         Tel:  (0228) 73-4315/-4292, Fax: -4382
 Roemerstr. 164,           Mail: [EMAIL PROTECTED]
 D-53117 Bonn, Deutschland WWW:  http://hyperg.cs.uni-bonn.de/~havemann 
-----------------------------------------------------------------------



Reply via email to