Reputation: 12966
Why is the return function called return?
The description is:
Inject a value into the monadic type.
The name not only doesn't make sense (to me), it is confusing for people coming from an imperative language where return
is a language keyword that returns from the function.
Upvotes: 12
Views: 837
Reputation: 663
The answer is because it returns something. It you use in PHP for example - echo something in it, it returns that text or data. But functions primary power is not in echoing data directly. Their power is in storing data and returning variable/array or similar where are data is stored.
You can also return true or false based on data/calculation. In classes, functions are named methods and do the same thing - return something. In java return can be void (echoed data), or strict data type (boolean for example, or String, Array, etc).
After return function data is not being returned.
Upvotes: -3
Reputation: 4828
It's purely historical. Most Haskell developers agree it's a bad name. It breaks the principle of least surprise. Quite a few of the older library functions are a bit wonky (the plethora of error handling schemes and a few other typeclass element names come to mind).
As @bheklilr says, there is a restructuring underway which should help:
These are good places to start if you are interested in the meta of Haskell:
Upvotes: 10
Reputation: 62848
Why is it called that? Because it's usually the very last function in a monadic block of code. Usually the only good reason to use return
is to set the final return value from your monadic action.
I too think that this is a very, very poor name choice. But it's not like we can fix it now...
Upvotes: 10