Others have commented already that String.Split
is a method, not a static function.
However, as I mentioned in this other answer here, they recently introduce a new syntax in f#8 for cases like this, so we don't have to write those small and convenient module functions wrapping object members.
It is called _.Property
as a shorthand for (fun x -> x.Property)
, and can be done like this:
let count (text : string) =
text
|> _.Split(' ')
|> Seq.length
There is a limitation though: you can only use this new syntax to replace a lambda that does only an atomic expression, i.e.:
An atomic expression is an expression which has no whitespace unless enclosed in method call parentheses.
That is why, for example, I had to write it like _.Split(' ')
, as it is atomic. It would have not worked as _.Split ' '
(notice the whitespace before the curried parameter).
text.Split ' '
ortext.Split ' ', '\n'
(with or without parens) are perfectly valid. – Hammerhead