This is probably very easy, but I cannot figure out how to do the equivalent of Python's
[0]*n
in Haskell, in order to get a list with n zeros.
[0]*n
doesn't work. Am I obliged to do something like: [0 | x <-[1..5]]
?
You can do this:
λ> take 5 (repeat 0)
[0,0,0,0,0]
Or as @obadz points out, this is even more concise:
λ> replicate 5 0
[0,0,0,0,0]
I personally don't like the python syntax. *
means multiplication but it does something else in your case. But that's just my opinion :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With