Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
F# Versus Microsoft's Regex. A Lesson in Types (whattofix.com)
18 points by DanielBMarkham on July 10, 2010 | hide | past | favorite | 3 comments


F# is one of the hidden jewels of the .NET platform, I really hope they give it first class support like C# and VB.NET.


Wow, F#'s backwards function composition is confusing!


I 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))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: