Is there an equivalent operator to Haskell's list difference operator \\
in F#?
Was bounced, yet I believe it is worth to write here the implementation of ( /-/ )
(the F# version of Haskell's \\
):
let flip f x y = f y x
let rec delete x = function
| [] -> []
| h :: t when x = h -> t
| h :: t -> h :: delete x t
let inline ( /-/ ) xs ys = List.fold (flip delete) xs ys
This will operate as Haskell's \\
, so that (xs @ ys) /-/ xs = ys
. For example: (7 :: [1 .. 5] @ [5 .. 11]) /-/ [4 .. 7]
evaluates into [1; 2; 3; 5; 7; 8; 9; 10; 11]
.
Nope... Just write it and make it an infix operator --using the set of special characters. Backslash (\
) is not in the list below, so it will not work as an infix operator. See the manual:
infix-op :=
or || & && <OP >OP $OP = |OP &OP ^OP :: -OP +OP *OP /OP %OP **OP
prefix-op :=
!OP ?OP ~OP -OP +OP % %% & &&
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With