The native-gen tool generates the native declaration for the
showOpenDialog
method in javafx.stage.FileChooser
like so
data FileChooser = mutable native javafx.stage.FileChooser where
native showOpenDialog :: FileChooser -> Window -> IO File
Compiling leads to the message
Non pure native type File must be MutableIO
File in IO actions.
Now setting
native showOpenDialog :: FileChooser -> Window -> MutableIO File
leads to
FileChooser.showOpenDialog has an illegal
return type for a method that is not pure, perhaps ST s (MutableIO
File) would work
but following the advice leads to first error message again.
The compiler accepts IOMutable File
as return type, which makes sense
since it is an IO action that returns a mutable type.
If possible, the compiler error message should be adapted to avoid frustration on the user side.
However, in this special situation, the file can be null and so
the core type is not File
but Maybe File
.
But then just using IOMutable (Maybe File)
leads to the rather surprising message
The type MutableIO (Maybe File) is illegal,
Maybe File must be a native type.
Any advice on how to properly declare this type?