Quite new to functional languages, but I'm maintaining someone else's code with a lot of F#. Can anyone offer some insight into this?
let mtvCap = Rendering.MTViewerCapture(mtViewer)
mtvCap.GetCapture()
mtvCap.ToWpfImage()
grid.Children.Add(mtvCap.ImageElement)
MTViewer.ImageViewer is of type System.Windows.Controls.Image, and grid is System.Windows.Controls.Grid.
Again, error is: The type int is not compatible with type unit
F# does not allow for you to silently ignore return values. The type unit
is F#'s version of void
. So the error is saying essentially
I expected the statement to have no return but instead it returns an int value
Or the opposite. I tend to incorrectly read this error message.
What's likely happening is one of the following
int
return value but the method Add
returns void hence F# is just asking for a return valueunit
but Add
is returning an int
and F# needs you to ignore the value. GetCapture
or ToWpfImage
return values that need to be explicitly handled.For the last 2 cases you can fix this by passing the value to the ignore
function
mtvCap.GetCapture() |> ignore
mtvCap.ToWpfImage() |> ignore
grid.Children.Add(mtvCap.ImageElement) |> ignore
After digging around a bit I believe #2 is the issue because UIElementCollection.Add
returns an int
value. Try modifying the final line to look like this
grid.Children.Add(mtvCap.ImageElement) |> ignore
I know remarkably little about F#, but as I recall, "unit" is their way of saying "void", so I'm gonna guess that you are trying to assign the "return value" of a function that doesn't have one, to a varaible. That would make the most likely candidate, this line:
let mtvCap = Rendering.MTViewerCapture(mtViewer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With