what does this function do in Haskell? -
what does this function do in Haskell? -
what function in haskel ?
i don't understand way recursion works here
f[]=[] f(x:xs)=x: [y|y <- f xs, x/=y]
f[]=[] f(x:xs) = x : [y|y <- f xs, x/=y]
this function removes duplicates list. here's how works:
base case, list empty, returns empty list. otherwise take first elementx
, , assume (inductive hypothesis) f xs
gives list without duplicates. now, thing have create sure don't insert x
again. so, list comprension means: take rest of elements (which inductive hypothesis unique), remove x
. does sense right now?
ps. can write sec clause as: f(x:xs) = x : filter (/= x) (f xs)
haskell
Comments
Post a Comment