[Haskell-beginners] How do I define data types with arbitrary content?

Alexander Raasch info at alexraasch.de
Sun Sep 11 14:21:10 CEST 2011


Hi,

just for the sake of deepening my understanding of Haskell types, I'm 
looking for a way to define a data type, like list or tree, that takes 
arbitrary values as its content.

In Java, I would write

class Tree { Object node; Tree left; Tree right; }

and that allows me to put Integers, Strings, or anything into the tree, 
since they all inherit from Object. How would I go about defining such a 
type in Haskell?

I'm reading www.learnyouahasell.com and all of the examples use only a 
single type parameter as in

data Tree a = Nil | Node a (Tree a) (Tree a)

so you can't mix Integers and Strings for example.

Alex



More information about the Beginners mailing list