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.

Is really necessary specify "No parts of <...> value should be checked"?

See original GitHub issue

Hi!

After reading #210, I still don’t understand why these kind of law are needed. The topic starts talking about "No parts of b return value should be checked. But, finally, it concludes that the implementations that perform this kind of checks are breaking other laws.

For example:

class Maybe {
    static of(val) {
      return new Just(val);
    }
}

class Just extends Maybe {
    constructor(val) {
        super()
        this.val = val;
    }
    map(f) {
        const r = f(this.val)
        return r === null ? new Nothing() : Maybe.of(r);
    }
}

class Nothing extends Maybe {
    map(f) {
        return this;
    }
}

This implementation breaks No parts of f's return value should be checked. However, it is also breaking the composition law:

const f = x => x === 2 ? null : x;
const g = x => x === null ? 2 : x;

Maybe.of(2).map(f).map(g) // Nothing {}
Maybe.of(2).map(x => g(f(x))) // Just {val: 2}

Then, I wonder if No parts of f's return value should be checked is a really necessary law. For me it’s a weird law because is talking about the implementation. For example these two implementations of Maybe:

class Just extends Maybe {
    ...
    map(f) {
        const r = f(this.val);
        return Maybe.of(r);
    }
}

and

class Just extends Maybe {
    ...
    map(f) {
        const r = f(this.val)
        return r === null ? Maybe.of(r) : Maybe.of(r);
    }
}

behave the same and are identity and composition law compliant. However, the second breaks the No parts of f's return value should be checked and is not functor lawful. It doesn’t make sense for me.

Cheers!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
Avaqcommented, Nov 19, 2018

I think the law is there to serve as a more direct deterrent for unlawful implementations. Specifically, Maybe.of = x => x ? Just(x) : Nothing kind of implementations were very common.

I also believe that the law is redundant with regards to preventing these bad implementations, and in fact, overly restrictive otherwise. Sanctuary breaks this law in multiple ways:

  1. Input type checking
  2. Constrained type instances

In my view, both of these cases should be allowed.

2reactions
CrossEyecommented, Feb 18, 2019

I guess I’d simply like to see a section in the prefix similar to the “Terminology”, “Type Signatures”, etc. ones, something like:

forAll

Parametric polymorphism is essential to these algebras. When the rules for any type are specified as applied to all values (forall a or ∀ a) the rule must hold for any Javascript values unless otherwise specified. This implies, for instance, that code that behaves differently for the null or undefined value than for other values is unlikely to comply with the rule.

… and then simply use <forall ...> where needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 30 Elements of Consumer Value: A Hierarchy
When customers evaluate a product or service, they weigh its perceived value against the asking price. Marketers have generally focused much of their...
Read more >
Value Proposition: How to Write It with Examples - Investopedia
A value proposition in marketing is a concise statement of the benefits that a company is delivering to customers who buy its products...
Read more >
Restrict data input by using validation rules - Microsoft Support
1. Field Validation Rule You can use a field validation rule to specify a criterion that all valid field values must meet. You...
Read more >
How to Create a Unique Value Proposition: 7 Best Examples
Your value proposition determines if people read more about your product or hit the back button. Here's how to get it right, with...
Read more >
Easy Checks – A First Review of Web Accessibility - W3C
Easy Checks – A First Review of Web Accessibility. Introduction. This page helps you start to assess the accessibility of a web page....
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