F#可以重构为无点样式吗? [英] Can F# be refactored into a pointfree style?

查看:73
本文介绍了F#可以重构为无点样式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究与编程相关的主题时,我遇到了一个用于Haskell的 pointfree 重构工具lambdabot,想知道F#是否可以重构为无点样式?

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.

注意:回答了该问题的早期版本,但我改写了该问题,因为答案对其他人正在学习和使用F#,但我不希望因为某些投票而将其删除.

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.

注意:仅仅因为我改变了问题,所以不要以回答来表示不能使用F#编写无点样式的代码.在很多情况下都可以做到这一点,但是您必须遵守一些限制.

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.

推荐答案

简短答案

否.

详细答案

F#中有一些东西使这种工具不切实际. (1)由于.NET互操作,F#代码通常具有副作用,并且当出现副作用时,自动代码转换就变得非常困难. Haskell并非如此.在Haskell中,方程式推理要容易得多,您可以在不更改其求值的情况下,用左侧重写右侧. (2)F#中的无点编程受到价值限制.我不确定您是否可以在不遇到此问题的情况下主动进行代码转换.

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.

我认为假设F#代码是纯净的,并且在某些情况下不会发生值限制的做法更为实用,以便我们可以为用户提供一些提示.用户可以在评估建议确实正确之后,离散地应用建议.与您所提到的方法相比,它更接近 HLint 方法. FSharpLint 在此方向上添加了一些掉毛规则.

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.

这篇关于F#可以重构为无点样式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆