Re: [m-users.] Impurity needed?

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Am Dienstag, dem 14.02.2023 um 00:40 +1100 schrieb Zoltan Somogyi:
> 2023-02-14 00:24 GMT+11:00 "Volker Wysk" <[email protected]>:
> 
> > The type of the odbc.transaction predicate is:
> > 
> > :- pred odbc.transaction(data_source::in, user_name::in, password::in,
> >      transaction(T)::transaction, odbc.result(T)::out, io::di, io::uo) 
> > is det.
> > 
> > 
> > Would it be possible to just change the transaction type from this:
> > 
> > :- type odbc.transaction(T) ==  pred(T, odbc.state, odbc.state).
> > :- mode odbc.transaction ==  (pred(out, di, uo) is det).
> > 
> > 
> > To this:
> > 
> > 
> > :- type odbc.transaction(T) ==  
> >      pred(T, odbc.state, odbc.state, io.state, io.state).
> > :- mode odbc.transaction ==  (pred(out, di, uo, di, uo) is det).
> > 
> > 
> > So the transaction predicate can do IO, when called. This looks rather easy,
> > but I'm not sure I've understood correctly.
> 
> It would be trivial to change the signature as you ask. It would also be
> a very bad idea to do so. The point of making an operation a transaction
> is to ensure that only two things can happen:
> 
> - the transaction succeeds, and ALL of its effects happen, or
> - the transaction fails, and NONE of its effects happen.

In my understanding, this applies only to the effects on the database...

> If you allowed I/O in the middle of a transaction, and then later
> it turned out that the transaction cannot succeed, then neither
> of those end states would be reachable.

So someone using a vanilla imperative language is forbidden to do IO when
being inside a transaction, too -?  You're effectively saying that it can't
be done with one transaction (if the effects of the IO alter the state of
the world).

> For more about why transaction predicate is designed the way it is,
> have a look at the paper
> 
> - Database transactions in a purely declarative logic programming language
> 
> which is available at https://mercurylang.org/documentation/papers.html#mu_96_45

Okay, thanks. I'll look into it.

> In your use case, you propose to do I/O only to read from a file; you don't
> intend to update the state of the world. In such cases, using impure code
> to read in the file, and wrapping a promise_pure scope around that code
> to signify that the impure code implements a pure interface, would be ok.

That makes sense.

Cheers,
Volker

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmPqU7EACgkQ+K4ydFOs
HoUxPw/9EaR1/YmheHOL4YXzWrWsk0SXY90opvnPHZ1EoojBsAUE0AKkDigSTLt8
y4WlBclGtUaLtzK5kPD5BtIJdAMxIkdxduCfG/m/xbAVabav+S/Kz5pa07g4SmI6
lCbFR7ufG/sXrkdpVJLc29tvPJO81ZEbHKML+UyjGM3J0yehmhFFmmsUg1kyboiz
/NuZ+jtt8B3BBu44mmWAZEcQfLozXDMIs2hG0rbh1sZXcR2258aaCQQv0eLePBgg
DeByqKOB+aBV3G5g0VZrNvwP250om9O257OTra8TinkeW0E0YQTohmhMheguXkwV
PgnTwK5Jt5iNgjcCU3pih6R+EMFi0/x6SI8zFizYdqkUHUDSibWQfrbfzjFgRDqq
dLq2ZLlQR4PwElZQEMdiaqrzpJFRQuCdFVArXS2WSlJn3xOtNRA3L9QAzPCbqvBm
6SmcH3ZYFQcwJXSIRPna0H9N0H+tJ8NNSk647PCIHRU4gH0P3Uo1sFLO3gqGuAPl
F0lAZ9u7emRXsi95UTLjMFeiQdyxm4nvBadst1EaG1ZSMY7m3ZaZNkNZICvBCmR9
Z8EOK3mEyOVDhds8AwtBVO0hDG2kNq/mXVi0vQYUwISDlPF7+0Bz7mUtEKCjEhis
MbYRQVyuaEwTI5oRljYy/fh5/FF9NBD+JKxja29ji3v2KXJDvPQ=
=P4qK
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.