3
votes

In F# what is the most functional and idiomatic way of creating or "newing up" 100 new objects into a List.

I guess for an example we could use DateTime as an example object.

3
in scheme we just did (and I'm rusty at this): declare appendlist list xtogo append (if (> x 0) (appendlist (cons list append) (- xtogo 1) append) (list)) - Jean-Bernard Pellerin

3 Answers

5
votes
List.init 100 (fun x -> x * 2)
3
votes

Alternatively, as a list expression:

[for i in 1..100 -> new System.DateTime()]

But I think this is less idiomatic.

0
votes

I would consider using

[|for i in 1..100 -> new System.DateTime() |]

since you are working with mutable data.