# [Haskell-cafe] Hi can u explain me how drop works in Haskell

Thomas Hartman tphyahoo at gmail.com
Mon Feb 26 02:44:21 EST 2007

```Here's my, probably very obvious, contribution.

What I'd like feedback on is

1) code seem ok? (hope so!)
2) What do you think of the tests I did to verify that this
behaves the way I want? Is there a better / more idiomatic way to do
this?

**********************************************

mydrop :: Int -> [Int] -> [Int]
mydrop 0 xs = xs
mydrop n xs = mydrop (n-1) (tail xs)

main = test
test = do print test1
print test2
print test3

test1 = mydrop 3 [1,2,3] == []
test2 = mydrop 2 [1,2,3] == [3]
test3 = mydrop 0 [1,2,3] == [1,2,3]
True
True
True

2007/2/26, iliali16 <iliali16 at gmail.com>:
>
> Hi I am trying to implement the function drop in haskell the thing is that I
> I have been trying for some time and I came up with this code where I am
> trying to do recursion:
>
> drop :: Integer -> [Integer] -> [Integer]
> drop 0 (x:xs) = (x:xs)
> drop n (x:xs)
>         |n < lList (x:xs) = dropN (n-1) xs :
>         |otherwise = []
>
> So I want to understand how would this work and what exacttly should I put
> as an answer on line 4 couse that is where I am lost. I know I might got the
> base case wrong as well but I don't know what to think for it. I have done
> the lList as a function before writing this one. Thanks to those who can
> help me understand this. Thanks alot in advance! Have a nice day!
> --
> View this message in context: http://www.nabble.com/Hi-can-u-explain-me-how-drop-works-in-Haskell-tf3290490.html#a9152251
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________