[Haskell-cafe] Hi can u explain me how drop works in Haskell
Steve Downey
sdowney at gmail.com
Mon Feb 26 19:03:50 EST 2007
ok maybe i should have read ahead. but still, i can see how to apply
hunit, but not quickcheck. but quickcheck seems more powerful.
On 2/26/07, Steve Downey <sdowney at gmail.com> wrote:
> in addition, a good example of how to apply quickcheck would be really
> awesome.
> without using the standard drop <g>
>
> On 2/26/07, Thomas Hartman <tphyahoo at gmail.com> wrote:
> > 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?
> >
> > **********************************************
> >
> > thartman at linodewhyou:~/learning/haskell/lists$ cat drop.hs
> > 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]
> > thartman at linodewhyou:~/learning/haskell/lists$ runghc drop.hs
> > 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.
> > >
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-Cafe at haskell.org
> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >
> > _______________________________________________
> > 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