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 element x, , 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

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -