[mercury-users] Impurity and foreign language calls

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Thu Mar 16 08:04:32 AEDT 2006

Dear Ian, thanks for your reply.  You wrote:

>Yes, but you could make it pure by declaring it as:
>:- pred battery_power(float::out, io::di, io::uo) is det.
>This seems to be the right thing to do here, since you're
>interacting with the outside world (i.e. the camera).  If
>you reflect this fact in the declarative semantics, using
>the abstract io.state arguments, then it needn't be impure.

Thanks for that.  I also saw this approach under the
debugging thread as well.  I have a slight problem with
this, and that is material use:  the 'camera' is the 
entire world for this app, and there's no stdin and stdout
that reads/writes ASCII characters.  So, should I then
modify module io so that stdin is the battery power
reading and stdout is the command interface?

Or should I just suck it up and grimace everytime I
add this unused state variable (IO1 = IO0 all over the
place, ugh!)?

Or should I choose a reasonable, aesthetic alternative
-- if battery power is the state variable (altered at
each C call that obtains the current charge), then every
non-unique call will produce the same result, right?
Making the call-out pure, correct?

Anyway, your suggestion works, and gets rid of the
impurities, so I'll revisit the code, translating
it to a pure version using something that works.

Thank you for pointing me toward purity.

Doug Auclair

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list