[Haskell-beginners] Use of (n + 1) as parameter - is it more efficient?

David McBride toad3k at gmail.com
Fri Dec 20 18:20:12 UTC 2013


n+k patterns is a concept that used to be common in haskell but was later
determined to be a misfeature and now you have to explicitly enable it in
ghc.  It was kind of a fun thing that turned out not to be necessary.

The way that you do it is the way that it is recommended now and the code
generated should be identical.



On Fri, Dec 20, 2013 at 1:00 PM, Angus Comber <anguscomber at gmail.com> wrote:

> I created my own drop' function like this:
>
> drop' :: Int -> [a] -> [a]
> drop' 0 xs     = xs
> drop' n []     = []
> drop' n (x:xs) = drop' (n - 1) xs
>
>
> But in the Haskell book I am reading it is written like this:
>
> drop' :: Int -> [a] -> [a]
> drop' 0 xs             = xs
> drop' (n + 1) []       = []
> drop' (n + 1) (x:xs) = drop' n xs
>
> My version seems to work but I am concerned about my third line (drop' n
> []     = []).  Is that a problem?
>
> Why does this author use n + 1 as a parameter as opposed to n - 1 like I
> do in body?
>
> Or does it make no difference?
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131220/fa74e37d/attachment.html>


More information about the Beginners mailing list