Aha Moments From Types

Types force a certain way of thinking about code (see Dynamic​Types​Have​Advantages).

Sometimes I've found static types have given me new perspectives on data types.

Can you give an example?

I was writing a lot of Python when I first learnt Haskell. Generally I could express in Haskell any logic I'd previously written in Python.

I hit a function that I couldn't port. I'd written a function that would flatten an arbitrarily nested list.

You can't do this in Haskell. You can write a function that flattens any particular level of nested list, but not the general case.

The natural Haskell equivalent is a tree. This can nest arbitrarily, and it's easy to work with.

I realised that my Python code was really dealing with trees! That's the underlying use case that led to arbitrarily nested collections.