Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在F#中的歧视联盟中直接使用代理吗?_F# - Fatal编程技术网

我可以在F#中的歧视联盟中直接使用代理吗?

我可以在F#中的歧视联盟中直接使用代理吗?,f#,F#,我有以下资料: type CallbackString = delegate of string -> unit type CallbackByte = delegate of byte[] -> unit type CallbackType = | String of CallbackString | Byte of CallbackByte 由于我可能有很多类型,是否有类似的语法(即编译): 如果这是完全从F#使用的API,则可以避免进行委托,并直接将函数用作第一类值: ty

我有以下资料:

type CallbackString = delegate of string -> unit
type CallbackByte = delegate of byte[] -> unit

type CallbackType =
| String of CallbackString
| Byte of CallbackByte
由于我可能有很多类型,是否有类似的语法(即编译):


如果这是完全从F#使用的API,则可以避免进行委托,并直接将函数用作第一类值:

type CallbackType =
| String of (string -> unit)
| Byte of (byte[] -> unit)
如果这将从C#中使用,并且您需要特定的委托类型,另一种方法是使用系统命名空间类型中预定义的
Action
Func
委托来处理此问题:

// Assumes 
// open System

type CallbackType =
| String of Action<string>
| Byte of Action<byte[]>
//假设
//开放系统
类型回调类型=
|一连串的行动
|动作字节

如果这是完全从F#使用的API,则可以避免进行委托,并直接将函数用作第一类值:

type CallbackType =
| String of (string -> unit)
| Byte of (byte[] -> unit)
如果这将从C#中使用,并且您需要特定的委托类型,另一种方法是使用系统命名空间类型中预定义的
Action
Func
委托来处理此问题:

// Assumes 
// open System

type CallbackType =
| String of Action<string>
| Byte of Action<byte[]>
//假设
//开放系统
类型回调类型=
|一连串的行动
|动作字节

这纯粹是F#;不使用委托,如果我有一个像:MyFunc(callback:CallbackType)=…,并且我有一个函数a myString:unit=…,我不能直接做MyFunc a,对吗?@Thomas你需要做CallbackType,否则,它应该可以正常工作-看它是纯F#;不使用委托,如果我有一个像:MyFunc(callback:CallbackType)=…,并且我有一个函数a myString:unit=…,我不能直接执行MyFunc a,对吗?@Thomas您需要创建CallbackType,否则,它应该可以正常工作-请参阅