(:) is O(1), (++) is O(n). Try and implement (++) and it should be easy to see why.

On 11 Apr 2013 10:44, "Angus Comber" <anguscomber@gmail.com> wrote:
LYAH beginner on page 55.

What I try to do is see the heading of a section, eg repeat function and then try to come up with my own version before looking at books implementation.

Here is my implementation:

repeat' :: a -> [a]
repeat' x = [x] ++ repeat' x

Here is books:

repeat' :: a -> [a]
repeat' x = x:repeat' x

Mine appears to work.  Is mine just as good?  Are there problems with my way?  Is books way more idiomatic Haskell?

I want to learn the best approaches hence my question.


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners