Look up or insert new element to string list in Haskell -


so want have function takes string , list argument, , checks if element on list, if is, returns same list, if isnt, adds list , returns it, 'im begginer haskell heres have tried no sucess:

check:: string ->[string] ->[string] check x [] = []++[x] check x (y:xs)               | x==y = (y:xs)              | otherwise = check x xs  

can point me way ? thks

you can use existing function elem http://hackage.haskell.org/package/base-4.7.0.0/docs/prelude.html#v:elem

check x ls     | x `elem` ls = ls     | otherwise   = (x:ls) 

if want on own learning purpose, suggest re-implementing elem.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -