logoalt Hacker News

solomonb • today at 8:28 AM • 1 reply • view on HN

This is fun. His array example `Σ len: usize . Array(Int, len)` is the list polynomial functor (1 + X + X² + ...) applied to ints.


Replies

Sharlin • today at 11:41 AM

I find it particularly pleasing how a list can be defined as either:

1) a tagged union of homogeneous tuples of every possible size, ie. (1 + X + X² + ...), or

2) the inductive form, favored in FP: either the empty list or the first element and another list, ie. 1 + X * L

and how it’s easy to show that the two definitions are equivalent:

  L = 1 + X + X² + ...
    // factor out X
    = 1 + X (1 + X + X² + ...)
    // note that the (...) is the definition of L
    = 1 + X * L