Insufficient definition of replicate

Viewed 136

I have a question that I think is rather tricky.

The standard prelude contains the function

replicate :: Int -> a -> [a]

The following might seem like a reasonable definition for it

replicate n x = take n [x,x,..]

But it is actually not sufficient. Why not?

I know that the replicate function is defined as:

replicate        :: Int -> a -> [a]       
replicate n x    =  take n (repeat x)

And repeat is defined as:

repeat           :: a -> [a]  
repeat x         =  xs where xs = x:xs

Is the definition insufficient (from the question) because it uses an infinite list?

1 Answers
Related