Tag Info

A ragged list, also called a jagged list, is a list where each element can either be some terminal type (e.g. an integer) or another ragged list.

A ragged list (also called a jagged list, a ragged array etc.) is a list where each element can either be some terminal type (e.g. an integer) or another ragged list.

For example the following is a ragged list:

[1,2,[1,2,3],5,[],[8,[1,2],9]]


Unlike traditional lists in a strongly typed paradigm ragged lists can have elements and lists at the same level.

Ragged lists are common in languages with weaker type systems. For example Python allows ragged lists with no extra requirements.

Languages with strong type system can have a hard time representing ragged lists since they require elements of a list to be of the same type. However often they can still implement them.

For example while regular lists cannot be ragged in Haskell, you can implement them:

data RaggedList a
= TerminalElem a
| ListElem [RaggedList a]