native-gen 工具为
showOpenDialog
方法生成本地声明,javafx.stage.FileChooser
如下所示
data FileChooser = mutable native javafx.stage.FileChooser where
native showOpenDialog :: FileChooser -> Window -> IO File
编译导致消息
Non pure native type File must be MutableIO
File in IO actions.
现在设置
native showOpenDialog :: FileChooser -> Window -> MutableIO File
导致
FileChooser.showOpenDialog has an illegal
return type for a method that is not pure, perhaps ST s (MutableIO
File) would work
但遵循建议会再次导致第一条错误消息。
编译器接受IOMutable File
作为返回类型,这是有道理的,因为它是一个返回可变类型的 IO 操作。
如果可能,应调整编译器错误消息以避免用户方面的挫败感。
但是,在这种特殊情况下,文件可以为 null,因此核心类型不是File
but Maybe File
。但随后仅使用IOMutable (Maybe File)
会导致相当令人惊讶的消息
The type MutableIO (Maybe File) is illegal,
Maybe File must be a native type.
关于如何正确声明这种类型的任何建议?