7

In researching a topic related to programming I came across a pointfree refactoring tool for Haskell in the lambdabot and was wondering if F# can be refactored into a pointfree style?

I am not advocating the use of pointfree style, but see it as a means to better comprehend a function.

Note: pad answered an earlier version of this question, but I reworded this question as the answer is of value to others learning and using F# and I did not want this to be deleted because of some close votes.

Note: Just because I changed the question, don't take the answer to mean that one can not code in a point free style using F#. It can be done in many cases but there are restrictions you have to follow.

Community
  • 1
  • 1
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
  • "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Ramon Snir Jul 22 '14 at 15:28

1 Answers1

11

Short answer

No.

Long answer

There are a few things in F# that make such a tool impractical. (1) Due to .NET interop, F# code often has side effects and automatic code transformation becomes really difficult when side effects come in play. It's not the case with Haskell; equational reasoning is much easier in Haskell and you can rewrite left-hand sides by right-hand sides without altering their evaluations. (2) Point-free programming in F# is limited by value restriction. I'm not sure you can do code transformation aggressively without hitting this issue.

I think it's more practical to assume that F# code is pure and value restriction doesn't occur in particular cases in order that we can give users some hints. Users can apply suggestions discretely after evaluating that the suggestions are actually correct. It's closer to HLint approach than the one you referred to. FSharpLint has added some linting rules in this direction.

pad
  • 41,040
  • 7
  • 92
  • 166
  • Thanks for giving detail on why such a tool cannot exist for F#. It makes for a nice fact to keep tucked away in case of a future need. Maybe some day I will make such a tool but identify the places that cause a value restriction and thus everyone can learn from it. – Guy Coder Jul 22 '14 at 16:32
  • You can identify a subset of the language that is safe to apply point-free refactoring. However, without some special markers like `pure` keyword or `Pure` attribute, it's difficult to ensure that you stay within the safe zone. – pad Jul 23 '14 at 06:54