snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
152 stars 61 forks source link

tails, inits, initTails example implementation #214

Closed BebeSparkelSparkel closed 4 months ago

BebeSparkelSparkel commented 1 year ago

Here is my example implementation. I have only added:

Can you review for correctness and then I will add it to the other instances?

I am unsure how to add this to tests. How should I add the tests?

closes #213

BebeSparkelSparkel commented 11 months ago

I'll try to add some tests this week

BebeSparkelSparkel commented 4 months ago

Added tests and fixed error for list instance.

Question: Should initTails [] == [([],[])] or initTails == []?

snoyberg commented 4 months ago

I honestly have no idea, I've never used that function. Is there any prior art you're aware of for a definition?

tomjaguarpaw commented 4 months ago

One invariant of this function seems to be that

length xs + 1 == length (initTails xs)

therefore initTails [] == [([], [])] is the correct choice.

BebeSparkelSparkel commented 4 months ago

I have received comment from @tomjaguarpaw above and Atijohn.

Both recommend initTails [] == [([], [])], as now implemented, with good reasoning.

So, this is ready to go.

snoyberg commented 4 months ago

Thanks!