[Haskell-beginners] coding style: instead of let, return?

Obscaenvs obscaenvs at gmail.com
Sun Jul 14 10:09:16 CEST 2013


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 <obscaenvs at gmail.com
> <mailto: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
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
> 

-- 
haskellBlog: http://www.monoid.se/categories/haskell/



More information about the Beginners mailing list