Conversation
|
@Smaug123 this is a good first example. I do have some follow-up questions on this, I'll get back on this later this week. |
|
I'm guessing this also applies when no infix operators are involved? let printListWithOffset a list1 =
List.iter (
((+) a)
>> printfn "%d"
) list1Is What happens if there is an extra argument before the parenthesis? let mySuperFunction a =
someOtherFunction a (fun b ->
// doing some stuff her
b * b
)Did I assume correctly that the lambda is one further indented? What happens when there a two multiline lambda's? let mySuperFunction v =
someOtherFunction (fun a ->
let meh = "foo"
a
) (fun b ->
// probably wrong
42
) v |
|
I think your examples are right except for the last one where there's too much indentation: let mySuperFunction v =
someOtherFunction (fun a ->
let meh = "foo"
a
) (fun b ->
// probably wrong
42
) vBut I am toying instead with: let mySuperFunction v =
someOtherFunction
(fun a ->
let meh = "foo"
a
)
(fun b ->
// probably wrong
42
)
vwhich at least generalises nicely to having arbitrary small arguments (e.g. we could move |
|
I like the let mySuperFunction v =
someOtherFunction
(fun a ->
let meh = "foo"
a
)
(fun b ->
// probably wrong
42
)
vthe idea, I'll ask some questions along the way to nail down the patterns that Fantomas would need to respect. |
| printfn "%d" (a + elem) | ||
| ) | ||
|
|
||
| // OK |
There was a problem hiding this comment.
Hi @Smaug123, what if I have something like
innerFunc<'a, 'b>
path'
elementNameThatHasThisRatherLongVariableNameToForceTheWholeThingOnMultipleLines
(foo >> bar value >> List.item a)
shapeshould this be
innerFunc<'a, 'b> path' elementNameThatHasThisRatherLongVariableNameToForceTheWholeThingOnMultipleLines (
foo >> bar value >> List.item a
) shapeOr is there a stricter rule in this case?
There was a problem hiding this comment.
I think the whole thing wants to split then, i.e. your first example:
innerFunc<'a, 'b>
path'
elementNameThatHasThisRatherLongVariableNameToForceTheWholeThingOnMultipleLines
(foo >> bar value >> List.item a)
shapeThere was a problem hiding this comment.
So when is it
A:
let printListWithOffset a list1 =
list1
|> List.iter (
((+) a)
>> printfn "%d"
)and when is it
B:
innerFunc<'a, 'b>
path'
elementNameThatHasThisRatherLongVariableNameToForceTheWholeThingOnMultipleLines
(foo >> bar value >> List.item a)
shapeI'm still sort of looking for a technical rule so to speak.
A could be because:
- No additional arguments are passed to
List.iter - A pipe operator is preceding
List.iter
B could be because:
- Everything before
(foo >> bar value >> List.item a)already makes the whole thing too long. - There are additional arguments next to
(foo >> bar value >> List.item a), in A there are not.
There was a problem hiding this comment.
I think it's due to the fact that the lambda is the only argument (ignoring the one we are getting piped in).
For instance:
let foo =
List.iter (
((+) a)
>> printfn "%d"
)
Would be allowed whereas:
let foo =
someOtherThing a b c d (
((+) a)
>> printfn "%d"
) f g h
Would be reformatted like B
There was a problem hiding this comment.
I agree: if there is just one argument that is too long, the whole thing gets split over many lines.
There was a problem hiding this comment.
To be clear, the A example is a bit misleading. These are both right:
let printListWithOffset a list1 =
list1
|> List.iter (
((+) veryVeryVeryVeryVeryVeryVeryVeryVeryLongThing)
>> printfn "%d"
)
let printListWithOffset' a list1 =
list1
|> List.iter (((+) a) >> printfn "%d")|
@JackMatusiewiczGR Mind approving this again? I didn't know we had stale review dismissal enabled. |
|
@Smaug123 how would lambdaList
|> List.map (function
| Abs(x, body) -> 1 + sizeLambda 0 body
| App(lam1, lam2) -> sizeLambda (sizeLambda 0 lam1) lam2
| Var v -> 1)look like in this case? |
|
That structure is a little awkward. Personally I format it as: lambdaList
|> List.map (
function
| Abs (x, body) -> 1 + sizeLambda 0 body
| App (lam1, lam2) -> sizeLambda (sizeLambda 0 lam1) lam2
| Var v -> 1
)But I recognise this rule is rather ugly in how specific it is. (In this case only, I put This doesn't really come up in GR's code, I think. |
This is to help resolve an inconsistency in the report at fsprojects/fantomas#1189 .