[m-users.] Impurity needed?

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Hi!

I'm using the ODBC "extra" library to store SHA256 hashes in a database. My
program is called with a file name and shall output the hash value. 

It shall check the device and inode numbers of the file, as well as the
modification time. When a new file is encountered, the hash is to be
calculated and stored in the database. When the hash is already known, it
shall be retrieved from the database, not doing the expensive calculation.

The problem is, I need to do the calculation in the middle of a transaction,
if the hash isn't known yet. First the database is to be queried. When that
fails (not known or old hash), then the hash is to be (re)calculated. And
then it is to be stored in the database. All in one transaction.

But the type of a transaction is: pred(T, odbc.state, odbc.state). The
io.state isn't available to the transaction predicate. How can I perform IO
in the middle of a transaction?

I've read the chapter on trace goals in the language reference manual. They
don't seem to fit my needs. The trace goal can't bind any variables in the
surrounding code. It also isn't allowed to use a mutable variable to pass
information from inside the trace goal to outside of it.

So, do I need to use some impure code?

And, I've always wondered, don't trace goals break purity?

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+K4ydFOsHoUFAmPqIvgACgkQ+K4ydFOs
HoU1Sw/+OOkZ30riquoblP80t0IYTPHNEgTddDFdxCnaH08YfH7dUtf2J84p0c2B
SHq2MSuTZQIxiwbr8fsF6wkAa7lTTQvklC1/U30hG1Hu3aNo/+MVobV6BeRpk1or
wF96nCB34GF/HDWSNsFy0cTgysX3ANWbZNdqx/gwDxsEuUGNsNXCasVgC+hE8qO4
uWa5AMsftGmjot9el1I3YPlDhQOI+xi1Z5Q8vJk8tbkILaF3ej73AXujSYl3zatr
QBJ7IffhzLdBAVec7B6tYY2n165JzUTvU6Ir5FrHYai/TefatrpWIF73A3qqlzlU
Y6PIkle+ve4I5CWncVwdhkXzKGqBi8e+oI7RJPFwRyc7NSxuXwhzuL5CvU0Ttpm1
frmKWtQue/asPZoOocsJaCprjMHBu8tOGx0NGJhek+Ns9bvz4vTZraXlpBHUBfQF
aYuTPHHdu9F8g9kLdbgqMJsuv5HmZXYRaCh1Hpey81CzWcez767KvWlLlUS8we91
wrKjcTaR9FJS2kmwKRORjKvheC717ow6VRY68IjF1e9fdbskYgFn5TC+wVmnkS68
FjU9I85yIK0RdogSDW70QxqbcwBSdZWWY7AVpl2VV44nsPfVko1N7UtUM3WzVcyZ
PwhsBPmUs3J8zuSYo9RV+8XDnFv5GuowfjMATmGpvdsgUH8J4BI=
=a9JH
-----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.