Skip to content

Added monadErrorMaybe instance #31

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

Merged
merged 1 commit into from
Mar 23, 2015
Merged

Added monadErrorMaybe instance #31

merged 1 commit into from
Mar 23, 2015

Conversation

pseudonom
Copy link
Contributor

If you all think the instance makes sense.

@garyb
Copy link
Member

garyb commented Mar 18, 2015

👍

@paf31
Copy link
Contributor

paf31 commented Mar 18, 2015

It's not law-abiding though, because of the catch implementation. Maybe restrict e ~ Unit?

@garyb
Copy link
Member

garyb commented Mar 18, 2015

Good point, I didn't think of that.

@pseudonom
Copy link
Contributor Author

not law-abiding

Yeah, it is sort of unusual behavior (though I don't see a statement of the laws anywhere). I do find it quite useful though (for combining with functions that return a Maybe or "choosing verbosity"):

big ::  forall m a. (MonadError String m, Monad m) => Number -> m Number
big n | n < 0 = throwError "Negative"
         | n < 2 = throwError "Small"
         | otherwise = pure n

bigHead :: [Number] -> Maybe Number
bigHead = big <=< head

I guess the alternative is sprinkling something like right :: Either a b -> Maybe b around.

@jdegoes
Copy link

jdegoes commented Mar 19, 2015

Yeah, the Maybe instance must be restricted to Unit if it exists at all.

@paf31
Copy link
Contributor

paf31 commented Mar 19, 2015

I'm happy to merge this if we can change over to Unit.

@pseudonom
Copy link
Contributor Author

Done. @paf31

@paf31
Copy link
Contributor

paf31 commented Mar 19, 2015

Sorry, we need to fix catchError too.

@pseudonom
Copy link
Contributor Author

Oh yeah.

@paf31
Copy link
Contributor

paf31 commented Mar 23, 2015

Any chance you could rebase this please?

@pseudonom
Copy link
Contributor Author

Done.

paf31 added a commit that referenced this pull request Mar 23, 2015
Added `monadErrorMaybe` instance
@paf31 paf31 merged commit 94b8465 into purescript:master Mar 23, 2015
@paf31
Copy link
Contributor

paf31 commented Mar 23, 2015

👍 Thanks!

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

Successfully merging this pull request may close these issues.

4 participants