Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MonadFail docs - isn't 'fail s' always a left zero? #120

Open
tomjaguarpaw opened this issue Apr 17, 2022 · 2 comments
Open

Improve MonadFail docs - isn't 'fail s' always a left zero? #120

tomjaguarpaw opened this issue Apr 17, 2022 · 2 comments

Comments

@tomjaguarpaw
Copy link
Owner

tomjaguarpaw commented Apr 17, 2022

The MonadFail docs say that fail s must be a "left zero", i.e.

fail s >>= f  =  fail s

But given that fail s :: forall a. m a is there any way that it couldn't be a left zero?

@kindaro
Copy link

kindaro commented May 25, 2022

How do you even begin to prove this?

  1. fail s cannot contain any values of an arbitrary type a.
  2. Therefore, f can never be invoked by >>=.
  3. Since f cannot be invoked, >>= must behave the same way for any f.
  4. Take f be pure — by a law of monad >>= pureid. Therefore, by №3 >>= fid for any f.
  5. id (fail s)fail s. ∎

— Maybe like this.

But this all on the assumption that everything is defined. Is this an admissible assumption? Otherwise, we can consider situations where >>= invokes f with undefined — then f can either crash (≢ fail s) or return an arbitrary value (≢ fail s).

@tomjaguarpaw
Copy link
Owner Author

Apparently you can prove it by parametricity. See https://www.reddit.com/r/haskell/comments/u5k4gv/is_it_possible_for_fail_s_not_to_be_a_left_zero/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants