fp-ts-std icon indicating copy to clipboard operation
fp-ts-std copied to clipboard

`when` and `unless` to extend from `Pointed` instead of `Applicative`?

Open imcotton opened this issue 3 years ago • 4 comments

These two:

  • https://samhh.github.io/fp-ts-std/modules/Applicative.ts.html#when
  • https://samhh.github.io/fp-ts-std/modules/Applicative.ts.html#unless

In case of fp-ts which has Pointed type class to support the of, seems unnecessary to require Applicative here, no?

imcotton avatar Jul 04 '22 12:07 imcotton

Code should generally follow the principle of least power for typeclass constraints. In this case however I don't think Pointed is widely used in either Haskell or PureScript, and there's a minor discoverability benefit to limiting things to the "core" typeclasses.

I've never seen a use case for Pointed specifically that didn't also call for Applicative. Do you have a real world example?

samhh avatar Jul 20 '22 13:07 samhh

Yeah, I know that Pointed typeclass sits in a odd position in today's FP constructions, however for what it's worth, in current scope of fp-ts it still plays the lifting part.

I've never seen a use case for Pointed specifically that didn't also call for Applicative. Do you have a real world example?

It occurred to me in the case of choose between when(Task.ApplicativePar) and when(Task.ApplicativeSeq), then just realized it makes no difference after reading the implementation underneath:

https://github.com/samhh/fp-ts-std/blob/b0072c9c3caeea427ea35f291d819ce41d5b502a/src/Applicative.ts#L70-L74

imcotton avatar Jul 25 '22 02:07 imcotton

To be clear, this is only a suggestion that might fit with current fp-ts more economically, perhaps less correct in semantic terms.

imcotton avatar Jul 29 '22 18:07 imcotton

You're right technically but for me it's a case of whether or not there's any real world use cases. I'm cognisant of how hard fp-ts' docs are to read largely on account of these countless intermediary typeclasses that in my experience aren't used much in practice, unlike for example applicatives.

samhh avatar Jul 31 '22 12:07 samhh

I'm going to close this, but if some real world use cases for a Pointed but not Applicative abstraction pop up I'd be happy to revisit. In the meantime if anyone needs this you can safely redefine the relevant exports with an assertion as per the internals.

samhh avatar Aug 08 '22 10:08 samhh