Created
December 16, 2012 18:45
-
-
Save dvdsgl/4311118 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I see this a lot in F# code: | |
control.OnClick.Add (fun _ -> | |
printfn "%A was clicked" control | |
) | |
// The entire lamda is parenthesized so it can be | |
// passed to Add, resulting in an ugly, dangling ')'. | |
// F# has a reverse pipeline operator called <| that's | |
// really useful in this case. It simply passes the value | |
// on the right to the function on the left: | |
let (<|) f x = f x | |
// Using this, you don't have to parenthesize the lambda: | |
control.OnClick.Add <| fun _ -> | |
printfn "%A was clicked" control | |
printfn "Yay for indentation-awareness!" | |
// While you're at it, you could even do something silly like this: | |
// HELP: Is this generic version typed correctly? I've only tried a simplisticly-typed variant. | |
// HELP: Ignore this! I think it's totally wrong. | |
let (+=) (handler: #EventHandler<'args>) (f: (obj * 'args) -> unit) = | |
handler.Add f | |
control.OnClick += fun _ -> | |
printfn "Whoa, very C#-y" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment