嗨,我有一个应该返回通用值选项的函数,它看起来像:
let HandleHeaderConfirmation (client : TcpClient) (message : BaseFrame) (responseId : uint32, frameId: uint32) (isAcknowledgment : bool): Async<(Option<'TCommand> * TcpClient)> =
async{
match isAcknowledgment with
| false ->
let reason : NackRejectionReason = NackRejectionReason.InvalidCrc
let nack : NackCommand = Confirmations.BuildNackResponse reason message (responseId, frameId)
_logger.Info(sprintf "Sending header(CRC8) NACK reason %s" ((NackRejectionReason.InvalidCrc).ToString()))
_logger.Info(sprintf "Invalid header CRC8: %o raw header data %A" message.HeaderCrc message.RawHeaderData)
return (Some nack, client)
| _ ->
_logger.Info(sprintf "Correct header(CRC8) message accepted")
let ack : AckCommand = new AckCommand(responseId)
return (Some ack, client)
}
有关更多详细信息,Nack和Ack Commands继承自BaseResponseCommand,并且继承自基本框架。
我的问题是F#仅将'TCommand定义为NackCommand,如果我将其更改为
Async<(Option<BaseFrame> * TcpClient)>
它期望基本帧不是Nack或Ack Command。那么这有可能吗?
将值BaseFrame
传递到Some
需要具有以下值的位置时,您需要将值上载option<BaseFrame>
:
return (Some (nack :> BaseFrame), client)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句