Comments (5)
I just check the formatting conventions again, it seems there is no example with redundant parenthesis.
I have the same preference as yours. I'm not sure it is in the scope of the formatting conventions. This is a style problem rather than a formatting problem, but I don't know any good place for discussing this. My next dream project would be StyleCop for F# where this style question is of interest. However, it's still far away while I'm struggling with this one :-).
from fantomas.
I think there is a blur boundary between formatting and style. It seems you're more interested in something like style checker for F#.
Regarding ^
, this is a style question. The operator is there due to OCaml compatibility. I prefer +
since it's more natural for concatenation purpose. More importantly, OCaml doesn't support operator overloading, so they have +
for adding integers, +.
for adding floats and ^
for adding strings.
Wouldn't it be nicer with just +
in F#?
from fantomas.
I tried to fix formatting in the Github comment, It seems broken and ignores my linebreaks now... maybe I am just destined to have formatting problems ;)
from fantomas.
Ah, my reasoning is that due to the polymorphism of +, you require a type annotation to correctly compile let f s s’ = s + s’ if you wish to use it for strings, but for let f s’ = s ^ s’ you do not.
Obviously this is an overly simplistic example but I take personal offense when I need to use lots of type signatures (don’t ask me why) it means I probably wrote something incorrectly. For me it feels like the more I use polymorphism, the more I am required to add type annotations, it really is powerful but it does get in the way of inference.
I think keeping operators that work on strings and operators that work on ints separate is good. This is potentially less of a formatting issue and just a style issue, I don’t expect others to take up a similar stance with polymorphism, but I’ll stand strong on this within my own code base J, and I am very interested in what others think about this.
I am unsold on exploiting polymorphism of ‘+’ over types such as matrices and other data structures, with the risk of sounding like a hypocrite I think it would be cool (or even stuff like lists [1;2] + [2;3] could product [3;5]), but this raises more issues than it solves I guess.. Yay F# discussions actually on the internet, what are your thoughts?
Edit: cleaned up comment.
from fantomas.
Ah, my reasoning is that due to the polymorphism of +, you require a type annotation to correctly compile let f s s’ = s + s’ if you wish to use it for strings, but for let f s’ = s ^ s’ you do not.
Point taken. But you know that you can always use inline
to make the function more generic without type annotation:
let inline f s s' = s + s'
That is exactly the benefits of polymorphism when you have a generic function which work on many similar contexts.
I think keeping operators that work on strings and operators that work on ints separate is good.
Agree. This is good for the type checker when it doesn't have to work hard to figure out types. But point of views may vary depending on backgrounds. If you come from OCaml, this is what you usually do and find it clear. If you come from .NET background, operator overloading has been stucked in your mind for a long time and you would like to push it further.
Nowadays, F#'s .NET interoperability is more important than OCaml compatibility. I'm glad that F# gives you choices. Just use what you like; when working on a team, you should reach a consensus and stick with one convention.
I understand why this is a vicious discussion on Internet. There is no right or wrong answer; they are personal.
from fantomas.
Related Issues (20)
- Unable to format F# 8 extended interpolated strings with curly braces HOT 3
- Move editor config to library rather than tool HOT 6
- "Incomplete declaration of a static construct" which the F# compiler accepts HOT 2
- Multiline secondary constructor HOT 4
- Equals sign should only be on same line if last tuple is multiline HOT 2
- Return type should go on next line
- Invalid F# code after formatting HOT 1
- Formatting removes necessary additional closing brackets for multiline interpolated strings HOT 1
- Fantomas reports an error when formatting interpolated string with tripple quotes HOT 7
- Idempotency problem when _.Property shorthand
- Regression: Stroustrup bracket style in anonymous record type parameter is not respected
- HashDirective before closing `]`
- Long parameter attribute gives weird line break before type annotation
- Fantomas corrupts an explicit constructor with `then` clause HOT 2
- FormatASTAsync loses single quotes for characters HOT 4
- Regression: An empty line or comment at the end of a list breaks Stroustrup formatting HOT 2
- `SpaceBeforeUppercaseInvocation` corrupts underscore lambda invocation HOT 1
- Non needed parentheses are added around lambda call from tuple/members HOT 3
- [Feature request] Make newline experience consistent across match branches HOT 1
- Make Fantomas AOT compatible HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fantomas.