首页 > 解决方案 > 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.

标签: f#pattern-matchinglet

解决方案


我怀疑(不知道哪个let语句导致了错误)你需要从模式匹配中返回一些东西(即后面的部分| Log (message, ack) ->)。

如果你不需要返回任何东西,你可以()在最后返回,与两个外部s的缩进级别相同let,但注意模式匹配的所有分支都需要返回相同的类型。


推荐阅读