question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Const and its Applicative constraints.

See original GitHub issue

Hello.

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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
evilsoftcommented, Oct 28, 2018

Shipped with 0.11.0

1reaction
evilsoftcommented, May 31, 2018

@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 provided Array and String 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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Const Applicative and Monoids - in Code
There is a very fundamental link here: the Applicative laws for IntConst are satisfied if and only if <*> acts monoidally on the...
Read more >
haskell - What is the 'Const' applicative functor useful for?
It's useful when you have a function or data structure that works for all ( Applicative ) Functor s, and wish to reuse...
Read more >
const - JavaScript - MDN Web Docs - Mozilla
The const declaration creates block-scoped constants, much like variables declared using the let keyword. The value of a constant can't be ...
Read more >
Constraint-based clustering and its applications in ...
Both mixed data types and cluster constraints are frequently encountered in the classification problems of construction management.
Read more >
CKI0059E The constraint constraint defines a constant value ...
An application constraint defined a constant value that exceeded the maximum length that is supported by an attribute that references the constraint.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found