$ let's you start at the same line and indent later at the cost of not being able to apply any other argument afterwards do let's you unindent enough to get access to next argument, at the cost of always having to indent at the beginning if you want to use multiple lines
I never use do ... let ... unless I'm naturally in a do. And I use let ... in or where depending on which is bigger, my let/where declarations or the main body of my function. I try to always put the bigger thing last.
I avoid it, in the interest of simplicity and readability. do suggests monadic context; using it in a pure context is abusing it. I generally use where wherever possible (let is useful in cases where you want access to the closure)
Does anyone else use "let in do" (pun intended) instead of let .. in? :
I never use
let ... in
unless unavoidable
where
is nice, but when it doesn't work/fit, I just go withdo
oh you mean using
do
without any bindersclever
I had no idea this existed...
Language designers probably didn't either at first - I remember reading that they actually dropped type requirement at some point
I mean, I wouldn't even bother implementing
let .. in
if I were to design new language withdo
seeing as how it's syntactic sugar it doesn't make sense to have the requirement in the first place :thinking:
TheMatten said:
well, that trick is ugly if you're writing things that are not multiple lines
let x = y in z
f a = g b where b = h a
orthogonal, the above is an expression
in general I agree that you don't see too many "same line" let-ins though
I don't mind let-in, as long as the "in part" isn't indented
Yeah, my experience is that I'm usually indented anyway when trying to write binding without
where
well, nothing is forcing it in theory
only the hs society
and all formatters, afaik
I mean, technically you can even
do let a = b; c
:big_smile:Formatters are the worst - they never understand what I'm trying to achieve :big_smile: /s
TheMatten said:
this is a bit brittle though, I think? or in general many
do
s on the same line areI run into issues sometimes when I'm abusing
do
as a($)
replacementreally? I never had any problems with
do
as$
replacementI'll try to remember to share next time it happens
$
let's you start at the same line and indent later at the cost of not being able to apply any other argument afterwardsdo
let's you unindent enough to get access to next argument, at the cost of always having to indent at the beginning if you want to use multiple lines@Georgi Lyubenov // googleson78 I guess that may be the problem you're running into
TheMatten said:
same line?
You can't do
though - instead you have to write
you can also do
I never use
do ... let ...
unless I'm naturally in ado
. And I uselet ... in
orwhere
depending on which is bigger, mylet
/where
declarations or the main body of my function. I try to always put the bigger thing last.I avoid it, in the interest of simplicity and readability.
do
suggests monadic context; using it in a pure context is abusing it. I generally usewhere
wherever possible (let
is useful in cases where you want access to the closure)