1

I wrote this code to make a function removing every character c in string s.

delete :: Char -> String -> String
delete c s =
    case s of
        ("") -> ""
        (c:t) -> delete c t 
        (a:t) -> a : delete c t

I understand that c is just a placeholder for any Char, not the actual c given as first arg.

Is there a way I can use the c argument provided in delete c s in the case construct ?

  • Character literals are written with single quotes, so look for the literal `'c'`. You could, for example, use pattern matching: `delete 'c' s = ...` – Mark Seemann Nov 12 '19 at 10:18
  • See my edit. I don't want to delete actual c's, but whatever char given. – Poor Standard Nov 12 '19 at 10:30
  • In the LHS use a different name for pattern matching (say `a`). In the RHS of the pattern match use `if a == c then ...` – lsmor Nov 12 '19 at 10:42

0 Answers0