Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating 'create' and 'replicate' #2

Closed
wants to merge 2 commits into from
Closed

Updating 'create' and 'replicate' #2

wants to merge 2 commits into from

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
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