4 ms·
F# Versus Microsoft's Regex. A Lesson in Types
- fleitz 16y agoF# is one of the hidden jewels of the .NET platform, I really hope they give it first class support like C# and VB.NET.
- jrockway 16y agoWow, F#'s backwards function composition is confusing!
- fleitz 16y agoI didn't see the function composition operator in there, I saw a lot of use of the pipe operator (|>), F# does have backwards function composition but it is the << operator. Function composition is >>. You can also define new operators or redefine operators in F#. The annoying upshot of this is that bitwise operations in F# use three character operators &&&, |||, ^^^, <<<, >>> which is weird coming from an imperative background. They use this feature for dynamic invocation on the DLR (.NET 4.0), so to invoke foo() dynamically on bar you'd write bar?foo instead of bar.foo Speaking of regexes and operators, if you're a fan of perl or ruby you can do the following: let (=~) text pattern = Regex.IsMatch(text,pattern) or for maximum F# goodness let (=~) text pattern = Regex.Matches(text,pattern) |> (fun matches -> match matches.Length with 0 -> None | _ -> Some(matches))