Jump to content

Função elem com any


crislanio_macedo
 Share

Recommended Posts

Pessoal a função abaixo está dando erros, a ideia é simples porém não está sendo usado os argumentos de forma correta.

verify a b =if a==b then True else False
elem' e [] = False
elem' e a@(x:xs) = if any (verify e x) a then True else any (verify e (head a) )(elem' e xs)
--
elem' e [] = False
elem' e a@(x:xs) = if any (e==x) a then True else any (e==head a ) (elem' e xs)
Edited by thoga31
GeSHi
Link to comment
Share on other sites

Se usas a função any, para que precisas de recursividade?

Desta vez a resolução é tão simples que simplesmente a vou dar para que vejas o embróglio de complicação que estás a criar 😛

elem1 a = any (== a)

E aí está o uso do any para verificar se um elemento a está presenta numa lista. 😉

Uma outra questão: isto é código desnecessário...

verify a b =if a==b then True else False

Basta-te isto:

verify a b =  a == b

O resultado de a == b é True ou False, portanto não precisas de nenhum if.

Knowledge is free!

Link to comment
Share on other sites

E já agora:

-- se:
verify a b = a == b

-- então:
verify = (==)

Ou seja, uma função como essa é completamente redundante. Quando tentas refazer código por ti próprio, crislanio_macedo, nem todas as funções precisam de ser reinventadas (o caso da verify é prova disso -- fica tudo muito mais simples se utilizares (==) directamente)

  • Vote 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.