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

Chris Eidhof chris at eidhof.nl
Sun Feb 25 21:01:48 EST 2007


Hey,

you're almost there:

drop :: Integer -> [a] -> [a]
drop 0 xs = xs
drop n (x:xs) = drop (n-1) xs

Your version fails when trying to do drop 10 [1..10]. My version  
fails when trying to do drop 10 [1..9], so you might want to try to  
see if you can come up with a solution for that!

Good luck,
-chris

On 25 Feb, 2007, at 18:43 , iliali16 wrote:

>
> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list