3 ms·
This is a little tricky, Types can be pretty broad. First, you could define a tree type with all sorts of different leaves, you could have a list of tree parts,
by jfoutz 19y ago
This is a little tricky, Types can be pretty broad. First, you could define a tree type with all sorts of different leaves, you could have a list of tree parts, something like:
Tree = Branch Tree Tree
| ILeaf Int
| SLeaf String
then a list like [ILeaf 1, SLeaf "foo"].
Another way to go takes advantage of type erasure. Currently it's just a popular extension but it lets you have lists of stuff in the same type class.
A good example is "Show" you can have a list off stuff that knows how to turn itself into strings. always a handy thing.
Basically you get the big two, group things based on what they are, or group things based on what you can do to them.
Perhaps there is a big pile of random stuff you want to hang on to, but i'd bet 99.9% of the time you really want to collect the stuff into a coherent type.