Sven:
Assuming you have a limited number types which are to be a member of the
class BaseClass, your best bet would be to create a union type, with
constructors for the various types that are class members (essentially,
you're just wrapping the values).
so you could have:
data Baseclass a => BaseclassMember a = Base a | Inst1 a | Inst2 a
instance Baseclass BaseclassMember where
showme (Base x) = showme x
showme (Inst1 x) = showme x
showme (Inst2 x) = showme x
and wrap the values as needed to create a an entity of type [BaseclassMember].
It's not the prettiest method (and there's an active thread going on on the
Clean list concerning an extension by which it could be done
automatically--which should be pretty tractable), but it should suffice for
now.
Best of luck.
--Artie
>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
>-----------------------------------------------------------------------
Arthur Gold Austin, Texas
** [EMAIL PROTECTED] [EMAIL PROTECTED] **
"`Go to' considered harmful" -- E. Dijkstra
"Go to, go to!" -- W. Shakespeare (Hamlet Act I. Sc. III L. 118)