4 ms·
repeat :: a -> [a] repeat something = [something] ++ repeat something print (head (repeat "hello")) For performance reasons, you wouldn't implement it
by runeks 10y ago
repeat :: a -> [a]
repeat something = [something] ++ repeat something
print (head (repeat "hello"))
For performance reasons, you wouldn't implement it exactly like this, but the principle is the same. The list can contain an infinite number of elements, but not unless some function tries to consume all elements does it become a problem.
- chalst 10y agoThe defintion of 'something' uses it twice.