Fp-ts: Stack safety

Created on 4 May 2020  路  7Comments  路  Source: gcanti/fp-ts

Couple years ago I was playing with stack safety in JS. but now I'm sort of playing with typescript and looks like the IO, free monad and free applicative all are nonstacksafe.

I have written optimized stack safe implementations for all of them in past years:

I can port them to TS and open PR's if this would be valuable for people

Most helpful comment

@shinzui I haven't made port in TS. If there is interest I can make one and open PR for fp-ts.

All 7 comments

As answered also in slack:

Stack-safety hasn't been one of the major objectives for fp-ts core up to now, but at the same time having safer defaults would help IMO -> I still see value on making more constructs in fp-ts core stack-safe, as long as the complexity/maintenance burden is not too much

Great, then my question would be where should I start implementing this structures? I guess IO here and FreeAp and FreeMonad in fp-ts-contrib?

Implementations are linked in the issue so if they seam to be fine I can start adding types and preparing PRs.

well I would let @gcanti speak his mind first 馃槃

It should be possible to change the Effect into Effect like this (haven't tested tho, but something like that should do the trick). Then it could be used to implement this structures in performant and stack safe way:

  • IO a would be represented with Effect unit a
  • ReaderTask e a would be represented with Effect e (Promise a)
  • Task would be represented with ReaderTask unit
  • (same for the Maybe/Either variations of IO and Task)

If this works out, all this would be at the cost of little complex implementation of the base synchronous ReaderT+IO, without braking API and with all the performance + stacksafety benefits. Tho I haven't done much TS and not sure how hard would it be to actually change representations like that but I think it shouldn't be too hard either.

of course for non basic cases people can use matechs-effect & waveguide.

@safareli Do you mind sharing your Free Applicative port if you have it?

@shinzui I haven't made port in TS. If there is interest I can make one and open PR for fp-ts.

@safareli I just started using fp-ts, and a free applicative was one of the first things I needed. It looks like fp-ts used to have it, but it got removed at some point.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmkal picture mmkal  路  3Comments

steida picture steida  路  4Comments

miguelferraro picture miguelferraro  路  3Comments

steida picture steida  路  4Comments

Crashthatch picture Crashthatch  路  4Comments