Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell list difference operator in F#

Is there an equivalent operator to Haskell's list difference operator \\ in F#?

like image 853
fryguybob Avatar asked Sep 12 '08 18:09

fryguybob


2 Answers

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].

like image 116
Ramon Snir Avatar answered Oct 28 '22 01:10

Ramon Snir


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 % %% & &&
like image 25
nlucaroni Avatar answered Oct 28 '22 01:10

nlucaroni