There is a common problem that F# does not natively support infix-style use of functions that is available in Haskell:
isInfixOf :: Eq a => [a] -> [a] -> Bool
isInfixOf "bar" "foobarbaz"
"bar" `isInfixOf` "foobarbaz"
The best known solution for F# can be found here:
let isInfixOf (what:string) (where:string) =
where.IndexOf(what, StringComparison.OrdinalIgnoreCase) >= 0
let found = "bar" |>isInfixOf<| "foobarbaz"
Also, it is easy to improve it a bit, employing native operators precedence:
let ($) = (|>)
let (&) = (<|)
let found = "bar" $isInfixOf& "foobarbaz"
There's also XML-ish </style/>
, described here.
I would like to find a better solution, with the following criteria:
- Single character operator (or a pair) that does not destroy commonly used operators;
- It should be the same character, likewise grave accent (back quote) character serves in Haskell;
It should not destroy associativity (support chaining):
let found = "barZZZ" |>truncateAt<| 3 |>isInfixOf<| "foobarbaz"
Optionally, it should support functions taking tuples:
let isInfixOf (what:string, where:string) = ... // it will not work with |> and <|
Optionally, it should gracefully handle functions/3:
val f: 'a -> 'b -> 'c -> 'd = ... let curried = a |>f<| b c // this wouldn't compile as the compiler would attempt to apply b(c) first
P.S. Various coding tricks are also welcome as I believe the good one (when checked by the F# Dev team) can be a part of the language in the future.