I'm having a dip into F# and am attempting not to write it like it's C#.
One area that bothers me is using members of System.String. These often need to be chained together, but the only way to do so that I've seen so far is pretty much the same as C#.
For example, I've written a function to generate the pretty bit at the end of a URL (similar to SE):
module String =
open System.Text.RegularExpressions
///Makes a string suitable for use as part of a URL:
///Removes syntax, replaces spaces with dashes and lowers case,
///then trims first word after 30 chars
let prettify (x:string) =
let parsed = Regex.Replace(x.Trim(),"[^0-9a-zA-Z ]","").Replace(" ","-").ToLower()
match String.length parsed with
| m when m > 30 ->
match parsed.IndexOf("-",30-1) with
| p when p < 0 -> parsed
| p -> parsed.[..p]
| _ -> parsed
Is there a way to refactor this to be "better F#"? I'm particularly concerned about how to better handle the methods on System.String and Regex.Replace. (The match part is a little convoluted to handle the edge case of the last word being the one that takes it over 30 chars.)