Skip to content

Updating 'create' and 'replicate'#2

Closed
latkin wants to merge 2 commits intofsharp:masterfrom
latkin:master
Closed

Updating 'create' and 'replicate'#2
latkin wants to merge 2 commits intofsharp:masterfrom
latkin:master

Conversation

@latkin
Copy link
Member

@latkin latkin commented Jul 1, 2014

Existing functions Array.create and List.replicate do the same thing. I moved create up to the main list of functions. How do we want to handle the duplication?

  • Fill out the matrix, implement both create and replicate for all collection types (safest option)
  • Pick one to endorse, deprecate the other (tough - I like the name replicate better, but my hunch is that Array.create is used more often)

I went with option 1 in this change.

@dsyme
Copy link
Contributor

dsyme commented Jul 1, 2014

My resolution was to treat "create" as an imperative operation specific to imperative data structures (since it implies something about identity). Hence only have it on Array. And use "replicate" for the functional operation.

Thoughts?

@latkin
Copy link
Member Author

latkin commented Jul 2, 2014

But the operations are exactly the same. Why is one deemed "procedural" and the other "functional"? The only difference is the name, and surely the name given does not affect the inherent functional-ness or procedural-ness of the operation.

@mexx
Copy link
Contributor

mexx commented Jul 10, 2014

For me replicate means to create a copy of the same thing, i.e. list.
create is probably better than replicate.

@mexx
Copy link
Contributor

mexx commented Jul 10, 2014

Maybe an other name?
I would prefer repeat with signature 'T -> int -> C<'T> or is it another addition candidate?

@dsyme
Copy link
Contributor

dsyme commented Jul 10, 2014

[ Edited after, cc @forki ]

Yes. And both String.replicate and List.replicate already exists. So today we have the irregular:

String.replicate: int -> string -> string
List.replicate: int -> 'T -> list<'T>
Array.create: int -> 'T -> 'T[]

One way to normalize would be

create: int -> X -> C<X>   // for String, Array, List, Seq
repeat: int -> C<X> -> C<X>   // for String, Array, List, Seq

with these additional ones for Seq:

createInfinite: 'T -> C<X>   // for Seq
repeatInfinite: C<X> -> C<X>   // for Seq

Seq.repeatInfinite is sometimes called Seq.cycle, which is a nice name. However the more regular names above appear wise, to align with Seq.init, Seq.initInfinite etc.

Note, I'm not super happy about the name repeat here.

Cheers
Don

dsyme added a commit to dsyme/FSharpLangDesign that referenced this pull request Jul 10, 2014
@latkin latkin closed this Feb 24, 2015
@Thorium Thorium mentioned this pull request Nov 3, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants