[Haskell-cafe] Collection of objects?
Henning Thielemann
lemming at henning-thielemann.de
Fri Nov 17 13:07:35 EST 2006
On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote:
> Is some kind of collection of object with different types in Haskell exist?
> Except the tuples, which have fixed length.
> I find this
>
> * Tuples heterogeneous, lists homogeneous.
> * Tuples have a fixed length, or at least their length is encoded in
> their type. That is, two tuples with different lengths will have
> different types.
> * Tuples always finite.
>
> But I need something which is heterogeneous and non-fixed length. I'm used do
> Java, and this switch to functional languages is very strange to me. So, to be
> clear, I need something like LinkedList<Object> in java.
>
> Can you please help me or suggest me, what can I use in this case?
If the number of types to cover is fixed, then I suggest a data type like
data T =
ConsInt Int
| ConsString String
| ConsChar Char
Since this is a very FAQ I wonder why I don't find the answer in any of
the Haskell wikis.
More information about the Haskell-Cafe
mailing list