[Haskell-cafe] Collection of objects?
donn at drizzle.com
Fri Nov 17 13:08:35 EST 2006
On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote:
> 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.
I looked in a couple of on-line tutorials, thinking I would quickly
find something about this, but -- maybe in my haste I missed something.
Objective CAML documentation gets right to it, I wonder if we're assuming
prior exposure to strongly typed functional languages?
Anyway, you need to define a type that accounts for the types you
want to support -
data Object = IntObject Int | StringObject String
objectString :: Object -> String
objectString (IntObject v) = show v
objectString (StringObject v) = v
main = mapM (putStrLn . objectString) [(IntObject 7), (StringObject "eight")]
Donn Cave, donn at drizzle.com
More information about the Haskell-Cafe