[Haskell-beginners] A simple remove function

Tobias tobnels at freenet.de
Sun Feb 19 19:27:08 CET 2012


Am 19.02.2012 19:00, schrieb bahadýr altan:
> myremove x s = (take  (s-1) x):(drop (s+1) x)

take :: Int -> [a] -> [a]
drop:: Int -> [a] -> [a]

Both functions return a list, therefore you need the "++" operator to 
append two lists:
(++):  [a] -> [a] -> [a]

So this is what you get:

(I changed s and x becausee I associate s with a string and x with a number)

myremove :: String -> Int -> String
myremove s x = (take  (x-1) s) ++ (drop (x) s)

Notice that you have to drop x elements (and not x+1).


<http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:take> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120219/5e46bed0/attachment.htm>


More information about the Beginners mailing list