Saturday, May 9, 2015

How to write a list in Haskell that is similar to this python code

How to write a list in Haskell that is similar to this python code
l1 = []
l1 * 5 
Thank you

You should not try to think in Haskell like you were in Python.
For example, you want to treat Haskell lists like Python lists. They are really different things though.
Lists in Haskell are to be read sequentially. Manipulating them with index is really inefficient. On the other side, Haskell lists are lazy.
infiniteList = repeat 0 -- Infinite list ? No problem, it is not yet evaluated
take 5 infiniteList     -- will return [0,0,0,0,0]
When you want to do computation on each element of your list, you will create a recursive function or use functions like map or fold, you won’t use a for loop like you would do in imperative languages.
If what you really want is to strictly hold 5 values (no less, no more), maybe a 5 element tuple is the way to go.

replicate 5 []