4

我正在尝试加载文件。

我有:

wf :: STMutable a File
wf = File.new "worlds/seed_77.world"

data PickleSerialization = pure native com.github.lands.PickleSerialization where
native loadWorld com.github.lands.PickleSerialization.loadWorld :: MutableIO File -> IO World throws IOException, IncorrectFileException

如果我尝试这样做:

PickleSerialization.loadWorld wf

我收到此错误,这对我来说似乎很困惑:

[ERROR: 4]: type error in  expression wf
type is   IOMutable File
used as   MutableIO File
4

1 回答 1

5

wf返回一个产生文件的动作。loadWorld获取文件,而不是操作。我认为这应该有效:wf >>= loadWorld.

MutableIO File表示一个可变文件,而IOMutable是一个返回可变文件的动作。IOMutable定义为(取自源):

--- This is an abbreviation for @ST RealWorld (Mutable RealWorld d)@ type IOMutable d = IO (MutableIO d)

同样STMutable定义为,

--- The type of 'ST' actions that return a mutable value of type _d_ --- This is an abbreviation for @ST s (Mutable s d)@ type STMutable s d = ST s (Mutable s d)

于 2014-09-25T18:25:38.953 回答