Is there any way that input values to a function can be pre-defined so that a user doesn't have to define them each time?
For example, assuming I had a function "zr" which returned a list zeros of size n, such that:
zr 1 = [0] zr 5 = [0, 0, 0, 0, 0] And so on.
My current way of implementing it is:
zr :: [Int] -> Int -> [Int] zr x y | length x == y = x | otherwise = zr x++[y] But this isn't particularly elegant as every time I call zr I need to include an empty list as a parameter:
zr [] 5 Any ideas?
Thanks!
yin the result andyis not expected to always equal0. Actually it doesn't even compile. Changing the recursive case tozr (x ++ [0]) ymakes it work, but it's still inelegant and inefficient (appending at the end -- although prepending would work just as well -- and recomputinglengthat every step) and we havereplicatefor this.