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

new System.IO.MemoryStream // Now without parentheses! #753

Open
Happypig375 opened this issue Jun 14, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@Happypig375
Copy link
Contributor

commented Jun 14, 2019

new with partial application

I propose we support new with partial application.

The existing way of approaching this problem in F# is having that ugly closure AND parentheses surrounding it.

Consider

x
|> System.Convert.FromBase64String
|> (fun x -> new System.IO.MemoryStream(x))

The following should all be supported:

x
|> System.Convert.FromBase64String
|> (fun x -> new System.IO.MemoryStream x)
x
|> System.Convert.FromBase64String
|> (new System.IO.MemoryStream)
x
|> System.Convert.FromBase64String
|> new System.IO.MemoryStream
x
|> (System.Convert.FromBase64String >> new System.IO.MemoryStream)

Pros and Cons

The advantages of making this adjustment to F# are

  1. Conciseness
  2. Beauty
  3. Consistency
  4. Ease of understanding

The disadvantage of making this adjustment to F# is the implementation effort required.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@yatli

This comment has been minimized.

Copy link

commented Jun 14, 2019

It doesn't look like a "partial application" because the constructor is tuple-based.
Will cause confusion in some cases, e.g:

type Foo() =
    new Foo(x: int)

let a = new Foo
let b = new Foo()

in the example, a ends up being a method group without actually calling the constructor, or resolving the correct overload.

@Happypig375

This comment has been minimized.

Copy link
Contributor Author

commented Jun 14, 2019

If all type information are present, then the correct overload should be inferred. Error otherwise.

@yatli

This comment has been minimized.

Copy link

commented Jun 14, 2019

hmm, looks like it's already possible now:

image

@yatli

This comment has been minimized.

Copy link

commented Jun 14, 2019

the warning though, is about not using new, and aligns with your proposal.

@charlesroddie

This comment has been minimized.

Copy link

commented Jun 24, 2019

Conciseness is a minor issue here.

A larger issue is how to keep track of disposables.

new is used on construction, but a function that returns a new IDisposable isn't called with new.
Not sure if there is in theory any way to track when a new IDisposable is created and output when calling a function and then needing to be marked with new to avoid a warning.

(Related work: color dotnet/fsharp#4618)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.