Giter Club home page Giter Club logo

Comments (5)

dungpa avatar dungpa commented on July 1, 2024

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.

dungpa avatar dungpa commented on July 1, 2024

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.

 avatar commented on July 1, 2024

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.

 avatar commented on July 1, 2024

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.

dungpa avatar dungpa commented on July 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.