Const and its Applicative constraints.
See original GitHub issueHello.
Firstly, I would like to thank you for providing this library, it’s lovely.
I’m learning Javascript so maybe you are already aware of this and haven’t implemented it for reasons that are beyond my knowledge. I noticed that the Const doesn’t behave as expected, since it doesn’t ‘enforce’ the monoid contraint. For the Const to be able to be an Applicative, it has to provide a pure/return function:
class Functor f => Applicative f where
pure :: a -> f a
...
data a b = Const a
Looking at “pure”'s signature, we observe that is impossible to provide a value for the monoid, since it only accepts one parameter. But by enforcing the first type variable of Const to be a monoid, we can conjure a value for Const out of nothing, by just providing a monoid type.
repl> pure "hello" :: Const <which monoid?> String
But with monoid:
repl> pure "hello" :: Const (Sum Int) String
repl> Const (Sum 0) // Sum Int! I know how to provide you with the empty value of that!
That also allows gives us other abilities like:
repl> liftA3(_ => _ => _ => undefined, Const(10), Const(30), Const(50))
repl> Const (90)
Again, thank you so much for the open-source.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
Shipped with 0.11.0
@neonphlux So in playing around last night I found a couple reasons to add this. As it sits right now, it is kinda pointless as we have
First
. It also will open the gate for adding the ability to providedArray
andString
constructors as type reps for Monoids.So I think we should implement and gong to go with the second suggestion as we can do things like lens implementations and what have you. Thanks so much for taking the time to put in an issue for this!