NonEmpty list membership invariants - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Can a type be designed to capture these two invariants?

image.png

Sridhar Ratnakumar

(FWIW, this kind of breadcrumbs is to mimick the stacking behaviour of https://notes.andymatuschak.org/About_these_notes )

Torsten Schmits

two lists for "before" and "after"?

Sridhar Ratnakumar

So it is basically a non-empty list with a pointer (to an existing element).

Sridhar Ratnakumar

But I won't be modifying the pointed value. Just moving the pointer around, or adding a new element and changing the pointer to point to it.

Sridhar Ratnakumar

it is also written by our fellow Isaac Shapira

Sridhar Ratnakumar

/me derives Foldable to simplify further