Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can F# be refactored into a pointfree style?

Tags:

f#

pointfree

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.

like image 520
Guy Coder Avatar asked Jul 22 '14 14:07

Guy Coder


People also ask

Is Kevin can f himself Cancelled?

In August 2021, the series was renewed for a second season. In November 2021, AMC confirmed the series would end after two seasons. The second and final season premiered on August 22, 2022, on AMC and AMC+.

How many episodes are there in season 1 of Kevin Can f Himself?

Episodes (8) Kevin throws his annual "Anniversa-rager" party with help from Patty, Neil and Pete.

How long is an episode of Kevin can f himself?

Maybe a pared-down plot within a tight 30-minute episode runtime is one sitcom convention Kevin Can F*** Himself would have been better off adhering to. Perhaps the real reason to watch Kevin is for a simply stunning performance from Murphy.


1 Answers

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.

like image 88
pad Avatar answered Sep 30 '22 15:09

pad