f# - The block following this 'let' is unfinished, F# error despite returning the value from function
问题描述
| Log (message, ack) ->
let CreateEventSourcingConnection() =
task {
let connection =
let ipEndPoint = IPEndPoint(IPAddress.Loopback, 1113)
EventStoreConnection.Create(ipEndlPoint)
do! connection.ConnectAsync()
return connection
}
let AddEventToStreamAsync (connection: IEventStoreConnection) streamName eventName message =
task {
let serializedEventData =
message
|> JsonConvert.SerializeObject
|> Encoding.UTF8.GetBytes
let event = EventData(Guid.NewGuid(), eventName, true, serializedEventData, null)
let! _ = connection.AppendToStreamAsync(streamName, int64 ExpectedVersion.Any, event)
()
}
Error:
The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result.
I have tried calling these functions after defining them. I have also checked my indentation, I think it should be okay. I understand I need to return the value from the function, but I think I already do that.
解决方案
我怀疑(不知道哪个let
语句导致了错误)你需要从模式匹配中返回一些东西(即后面的部分| Log (message, ack) ->
)。
如果你不需要返回任何东西,你可以()
在最后返回,与两个外部s的缩进级别相同let
,但注意模式匹配的所有分支都需要返回相同的类型。
推荐阅读
- cordova - 使用 cordova-plugin-ble-central 连接 BLE 而无需扫描
- mongoose - 尚未为模型“ModuleSchema”注册架构
- http - 如果我不断增加线程数,平均响应时间如何保持或多或少不变?
- kotlin - 从 gradle kts 中的 sourceSet 中的不同文件调用依赖项指令
- javascript - 根据带有加载更多按钮的自定义查询获取 WordPress 帖子
- c - 如何评估此代码中的后缀表达式?
- ssis - SSIS - 派生列用空字符串替换NULL值
- python - ModuleNotFoundError:没有名为“tokenize”的模块
- reactjs - 当用户访问未分派操作的页面时,反应应用程序崩溃
- swift - 使 UIDatePicker 在黑色背景下可见