-
Notifications
You must be signed in to change notification settings - Fork 867
Implement direct delegates #19993
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
base: main
Are you sure you want to change the base?
Implement direct delegates #19993
Changes from 25 commits
baf99e8
87cff9a
6682524
894f6f0
67b1ca7
4270507
2d60fe4
dc32fcd
8017ff0
cd6e3c6
adc9b61
be7517d
80a8668
f2f8999
9ddc0f1
d8f11c6
1f6ea38
fa4c43b
e96523d
8127868
49ba6f0
05a3970
0e5d1ce
0410172
f485b25
2b9d108
69a1c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| module DelegateCustomType | ||
|
|
||
| open System | ||
|
|
||
| // Custom, F#-declared delegate types exercise construction with delegates defined in the *compiled* assembly | ||
| // (local scope, unlike imported BCL Func/Action) and with Invoke signatures the Func/Action tests do not | ||
| // cover: a multi-argument (tupled) signature, a generic delegate, and a byref parameter. (F# forbids curried | ||
| // delegate signatures — FS0950 — so every F# delegate has a single tupled Invoke parameter group.) | ||
|
|
||
| type DTupled = delegate of int * int -> int | ||
| type DGen<'T> = delegate of 'T -> 'T | ||
| type DByref = delegate of byref<int> -> unit | ||
|
|
||
| let acc (x: int) (y: int) : int = x + y | ||
|
|
||
| let ident (x: 'T) : 'T = x | ||
|
|
||
| type C() = | ||
| member _.M (x: int) (y: int) : int = x * y | ||
|
|
||
| // Tupled-signature custom delegate: Invoke(int, int). | ||
| // 28. non-eta module function, custom delegate | ||
| let tupledNonEta () = DTupled(acc) | ||
| // 14. eta module function, custom delegate | ||
| let tupledEta () = DTupled(fun a b -> acc a b) | ||
|
|
||
| // Instance member through a custom delegate: the receiver becomes the delegate's Target. | ||
| // 29. non-eta instance member, custom delegate | ||
| let instanceNonEta (c: C) = DTupled(c.M) | ||
| // 15. eta instance member, custom delegate | ||
| let instanceEta (c: C) = DTupled(fun a b -> c.M a b) | ||
|
|
||
| // Generic custom delegate instantiated at int: Invoke(int):int over the generic target. | ||
| // 30. non-eta generic method, generic custom delegate | ||
| let genNonEta () = DGen<int>(ident) | ||
| // 16. eta generic method, generic custom delegate | ||
| let genEta () = DGen<int>(fun x -> ident x) | ||
|
|
||
| // byref-parameter custom delegate: the body mutates through the byref, so it is not a transparent forwarding | ||
| // call and stays a closure. Documents that a byref Invoke parameter does not break the recognizer. | ||
| // 53. byref-parameter delegate (mutating body) | ||
| let byrefMutate () = DByref(fun x -> x <- x + 1) |
Uh oh!
There was an error while loading. Please reload this page.