samhh / fp-ts-std

The missing pseudo-standard library for fp-ts.
https://samhh.github.io/fp-ts-std/
MIT License
207 stars 27 forks source link

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

Closed imcotton closed 2 years ago

imcotton commented 2 years ago

These two:

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

samhh commented 2 years ago

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?

imcotton commented 2 years ago

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 commented 2 years ago

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

samhh commented 2 years ago

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 commented 2 years ago

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.