r/purescript • • Jan 02 '17

RFC: purescript-infinite-list

This is the first library that I am submitting to Pursuit. I wanted a library that gave me infinite lists with a few properties:

  • It would be memory efficient
  • You would only pay the cost of the elements in your infinite list when you requested them.
  • Functions like 'head' and 'tail' would not require the use of the Maybe type to be complete (non-partial) functions.

This is my best attempt: https://pursuit.purescript.org/packages/purescript-infinite-list/0.2.1

The thing that I am least pleased about is that Purescript does not support "Tail Call Optimization modulo cons" and, as a result, the 'take' and 'takeWhile' functions needed to be reimplemented using the FFI to prevent too many nested function calls. (See: https://github.com/robertmassaioli/purescript-infinite-list/blob/master/src/Data/InfiniteList.js) It would be great if the purescript community reconsidered that decision.

Please have a look at the library and give feedback if you have any.

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/robertmassaioli Jan 02 '17

Thank you; this is exactly what I was hoping for! These are excellent comments and I'll work on implementing this! Those Semigroup and Monoid suggestions are great.