Alexander Ryan Baggett
Alexander Ryan Baggett

Reputation: 2397

F# WPF events: "Block following this 'let' is unfinished. Expect an expression"

This is driving me nuts. I am looking here at Microsoft's function examples. I can't see what I am doing wrong.

So, I am trying to use F# with WPF, I found a working online project template for it. Here it is .I was about to get started. Unfortunately, the designer does not work for generating events in the F# code by double clicking an element like it does in C#. But oh well, I can set what the Click does anyway. I decided I would do it all manually.

Here is my flawed attempt:

module MainApp

open System
open System.Windows
open System.Windows.Controls
open FSharpx

let mutable doc = ""

type MainWindow = XAML<"MainWindow.xaml">

let loadWindow() =
   let window = MainWindow()

   // Your awesome code code here and you have strongly typed access to the XAML via "window"

   window.Root

   let make (sender:Object, e:RoutedEventArgs) =
    doc<- doc +"<?xml version=\"1.0\" standalone=\"no\"?>"
    0


[<STAThread>]
(new Application()).Run(loadWindow()) |> ignore

In any event, It does not like the line with let make on it. It gives me this error:

Block following this 'let' is unfinished. Expect an expression

And yet, clearly I read on the MSDN

  The compiler uses the final expression in a function body to determine the return value and type

So, it has a return, how is it an unfinished expression?

Upvotes: 2

Views: 582

Answers (1)

latkin
latkin

Reputation: 16792

You are supposed to return window.Root from loadWindow. Right now the last bit of code inside loadWindow is the declaration of a make function, which is not valid. Remember, indentation determines scope in F#.

If you wanted to add a new function make, but leave the body of loadWindow basically empty, you need to align the indentation properly:

let loadWindow() =
   let window = MainWindow()

   // Your awesome code code here and you have strongly typed access to the XAML via "window"

   window.Root

let make (sender:Object, e:RoutedEventArgs) =
    doc<- doc +"<?xml version=\"1.0\" standalone=\"no\"?>"
    0

Upvotes: 5

Related Questions