
Just a style question: What's the community's verdict when it comes to using `return` to bind names instead of `let`? E.g. if instead of ` let p1 <- mkName "p1" a <- newName "a" ` , we use ` p1 <- return $ mkName "p1" a <- newName "a" `. I have seen this a couple of times in other people's code now, and I am ambivalent about it: `let` states intention better, and refrains from redundancy, but when you know why the writer behind the code is using the `return`-variant, it's somewhat easier on the eyes (at least when some actions in do-notation follow). In my opinion, `let` *is* the better alternative, but there is code in the wild[1] that uses the `return`-variant, so I wanted to gauge the community's opinion on the matter. [1] http://monads.haskell.cz/html/statemonad.html -- fredrik

On Sat, Jul 13, 2013 at 1:56 PM, Obscaenvs
` let p1 <- mkName "p1" a <- newName "a" ` , we use ` p1 <- return $ mkName "p1" a <- newName "a" `.
The first case should start "let p1 = mkName ...". The reason to avoid the second case is to avoid unnecessary function applications. Predicating on a bona fide monad (can't be too careful these days), the second is equivalent to the first because of the unit law. (This being the beginners list, I should point out that it's pretty important to learn how to desugar do notation in one's head. Normally, reading lots of haskell code is enough to pick up that skill subconsciously.) You might try re-asking the question on cafe if you're really interested in surveying this. Personally, I'd start asking questions about code provenance when I see the second case. -- Kim-Ee

Good points, thank you. f Le 2013-07-13 16:29, Kim-Ee Yeoh a écrit :
On Sat, Jul 13, 2013 at 1:56 PM, Obscaenvs
mailto:obscaenvs@gmail.com> wrote: ` let p1 <- mkName "p1" a <- newName "a" ` , we use ` p1 <- return $ mkName "p1" a <- newName "a" `.
The first case should start "let p1 = mkName ...".
The reason to avoid the second case is to avoid unnecessary function applications. Predicating on a bona fide monad (can't be too careful these days), the second is equivalent to the first because of the unit law.
(This being the beginners list, I should point out that it's pretty important to learn how to desugar do notation in one's head. Normally, reading lots of haskell code is enough to pick up that skill subconsciously.)
You might try re-asking the question on cafe if you're really interested in surveying this.
Personally, I'd start asking questions about code provenance when I see the second case.
-- Kim-Ee
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- haskellBlog: http://www.monoid.se/categories/haskell/
participants (2)
-
Kim-Ee Yeoh
-
Obscaenvs