Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

.net - Function Application Operator ($) in F#?

Let's say I have this code

let identifier = spaces_surrounded (many1Satisfy isLetter)

I was wondering if it there was any native F# function that allowed me to refactor it to

let identifier = spaces_surrounded $ many1Satisfy isLetter

that is, something such as

let ($) f1 f2 = f1 (f2)

(that is if I am not mistaken, my Haskell skills are not too sharp..).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The standard F# idiom for this is the forward pipe operator |> were you would rewrite

let identifier = spaces_surrounded (many1Satisfy isLetter)

as

let identifier = many1Satisfy isLetter |> spaces_surrounded 

you can also use the backward pipe operator <| if you want to maintain the original order, but this tends to be a little less common

let identifier = spaces_surrounded <| many1Satisfy isLetter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...