File IOMutable vs MutableIO

I am trying to upload a file.

I have:

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

If I try to do:

PickleSerialization.loadWorld wf

I get this error, which seems very confusing to me:

[ERROR: 4]: type error in  expression wf
type is   IOMutable File
used as   MutableIO File
+4
source share
1 answer

wfreturns the action that creates the file. loadWorldaccepts a file, not an action. I think this should work: wf >>= loadWorld.

MutableIO Filerepresents a mutable file, whereas IOMutableis an action that returns a mutable file. IOMutabledefined as (taken from source):

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

Similarly STMutabledefined as,

--- 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)

+5
source

All Articles