Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Monad.unit method purpose #4

Closed
ValentinTrinque opened this issue Jun 19, 2015 · 4 comments
Closed

Monad.unit method purpose #4

ValentinTrinque opened this issue Jun 19, 2015 · 4 comments

Comments

@ValentinTrinque
Copy link
Contributor

Hi,

I was studying the library API and ends up on Monad.unit method.

I have some thought about the purpose of this method but I am not sure.

Can you enlighten me?

Thanks.

@cbowdon
Copy link
Owner

cbowdon commented Jun 20, 2015

It wraps a value in the monad. It's there for completeness more than anything else, since the static constructors are more useful.

@ValentinTrinque
Copy link
Contributor Author

I had a look to the of function in fantasy land, but I have to say that it's fairly obscure to me. Then I also had a look to issues dealing with it, but it still looks obscure; whence my question.

What's I don't understand is, why isn't it a static function ? What did I miss ?

@cbowdon
Copy link
Owner

cbowdon commented Jun 26, 2015

IIRC my reasoning was this: it could work as a static function, but all things considered it was slightly better to have it as an instance method (compatible with Fantasy Land) and use the more readable static constructors.

If it was static, you unfortunately wouldn't get the ad-hoc polymorphism of Haskell. It would still be necessary to explicitly say which monad's unit implementation you wanted, e.g. Maybe<T>.unit(1234) rather than simply being able to say unit(1234) and let the type system figure it out. So if you have to be explicit, you might as well say Maybe.just(1234) as it's slightly more readable.

@ValentinTrinque
Copy link
Contributor Author

Ok, I got it. Thanks a lot.

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

No branches or pull requests

2 participants