Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This is partly genuine curiosity, and partly a check on my understanding. I'm probably missing the point.

In Haskell, why does a monad use operations called return or unit to describe putting a type into the container -- lifting it into the monadic space? It seems more intuitive to call the operation lift.

Right now, in my (probably incorrect) port of monads into my own project, I'm using (pseudocode):

MyThing.lift(x).bind(f)...

rather than

MyThing.unit(x).bind(f)...

because it's more intuitive for me to think of lifting x into the monadic space.

Is that wrong-headed? I keep getting burned by not thinking abstractly enough, and I suspect that's the case again.

share|improve this question
2  
In Haskell the word lift is usually reserved for the idea of lifting functions into the world of monads, ie liftM :: Monad m => (a -> b) -> (m a -> m b). –  Benjamin Hodgson Mar 4 at 0:12
    
ah ok thanks :) –  Rob Y Mar 4 at 0:15

2 Answers 2

up vote 3 down vote accepted

The term unit comes from category theory where we define a monad as two natural transformations unit : Identity ~> m and join : m x m ~> m. In case you're curious, bind f = join . fmap f.

return comes from do notation where return looks appropriately algol-ish. It's actually debatable whether this was a good name since it tends to suggest that return is some sort of control flow instead of just being a plain old function.

We usually reserve lift for things that are more like a functor and lift whole functions or monads. lift :: m a -> t m a and liftM :: (a -> b) -> m a -> m b.

share|improve this answer

As Benjamin Hodgson mentioned in his comment, the term lift is usually applied to lifting non-monadic functions into the monad.

As for why the function is specifically called return, that is because it is used in the do syntactic sugar, which is meant to resemble an imperative C/ALGOL style code block, which typically used the return keyword to return a value.

Similarly, bind is called SelectMany in .NET, because its monad comprehensions are meant to resemble SQL queries.

share|improve this answer
    
George W. Noon sounds like some spaghetti western star, you should be a sheriff. Also +1 for the SQL influence on LINQ mention, it's a great anecdote that too few people are aware of. –  Jimmy Hoffa Mar 4 at 0:39
1  
possibly also worth mentioning that () is pronounced unit so that is also a possible place for confusion –  jk. Mar 10 at 11:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.