[m-users.] Impurity needed?

Volker Wysk post at volker-wysk.de
Mon Feb 13 22:46:00 AEDT 2023


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20230213/1eacd192/attachment-0001.sig>


More information about the users mailing list