Skip to content

Comment on Stupid Languagesparent

Comments

Hmm? What is the reverse of (partial map constantFunctionReturnsZero)?

A fold/reduce is just as sometimes-reversible, when paired with an appropriate unfold. (example: multiplication and factorization)

I think you mean that map is self-composable, in the sense that the map function distributes over function-composition, in the same way that (in first-order functions) multiplication distributes over addition.

> What is the reverse of (partial map constantFunctionReturnsZero)?

The function (constantly 0) is implemented as a place in order to maintain reversibility semantics:

  ((constantly 0) 10) ;-> (0 10)
  ((constantly 0) 50) ;-> (0 50)
The information lost by calling the constant function is pushed to the end of the list so that it can be called reversibly. This can be applied on an entire list:
  (map (constantly 0) [1 2 3]) ;-> ([0 0 0] [1 2 3])
> A fold/reduce is just as sometimes-reversible

The reduce function is not reversible, but the reductions function when called with a group is:

  (reductions + [1 2 3 4]) ;-> [1 3 6 10]
The reduce value is the last element of the list so it can be retrieved by the last place:
  (last [1 3 6 10]) ;-> (10 [1 3 6])
> I think you mean that map is self-composable

The preservation of information is more important to me then composition.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.