[Haskell-beginners] coding style: instead of let, return?
Kim-Ee Yeoh
ky3 at atamo.com
Sat Jul 13 16:29:47 CEST 2013
On Sat, Jul 13, 2013 at 1:56 PM, Obscaenvs <obscaenvs at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130713/6a1588e0/attachment.htm>
More information about the Beginners
mailing list