Jump to content

Delete element in a set {Haskell}

- - - - -

  • Please log in to reply
2 replies to this topic

#1
abderrahim

abderrahim

    Newbie

  • Members
  • PipPip
  • 14 posts
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell
Hi everybody!
i'm a new Haskell guy!! and my question is simple: i don't know why the first definition works as the second doesn't??

delete a (x:xs) = if (x==a) then (delete a xs) else (x: (delete a xs))

delete a [] = []
delete a r   

                 |r==[] = []

		 |otherwise = if (a==(head r)) then (delete a (tail r)) else ((head a) :(delete a (tail r)))


#2
Sysop_fb

Sysop_fb

    Programmer

  • Members
  • PipPipPipPip
  • 160 posts
  • Location:Missouri
((head a) :(delete a (tail r)))

Look carefully at how you're treating a in (head a) and what haskell is inferring the type of a to be based on how you've used it thus far.
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.

#3
abderrahim

abderrahim

    Newbie

  • Members
  • PipPip
  • 14 posts
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell
aaaaa, thank you, it should be (tail r) not (tail a),
Thank you!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users