[mercury-users] Impurity and foreign language calls
Ian MacLarty
maclarty at cs.mu.OZ.AU
Thu Mar 16 08:34:51 AEDT 2006
On Wed, Mar 15, 2006 at 04:04:32PM -0500, doug.auclair at logicaltypes.com wrote:
> 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!)?
>
I think you're misunderstanding the role of the IO state variables. The
io type abstractly encapsulates the state of the world. You can update
the state of the world by writing to stdin or reading from stdout or you
can update the state of the world by reading the battery power left on
the camera, which has nothing to do with stdin or stdout.
When you're writing foreign procs that do IO, you'll never actually do
anything with the IO states in the foreign code, because IO is not
modelled declaratively in the foreign code, so the IO states are
meaningless there. In fact values of the type io don't have any
concrete representation at all, they are only there to model IO in the
declarative semantics of Mercury.
Ian.
--------------------------------------------------------------------------
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