Skip to content

eliminate MonadWriteFile in favour of MonadCache#600

Open
patritzenfeld wants to merge 7 commits intodevfrom
swap-ad-filewrite
Open

eliminate MonadWriteFile in favour of MonadCache#600
patritzenfeld wants to merge 7 commits intodevfrom
swap-ad-filewrite

Conversation

@patritzenfeld
Copy link
Member

@patritzenfeld patritzenfeld commented Feb 13, 2026

MonadWriteFile is in principle always replaceable by MonadCache, but concerning the simple file writing done in the apps, it seems unnecessary to include the input's hash in the final filename as collisions are not really a concern for those.

Example:

output <- drawOdFromInstance
i
Nothing
possibleLinks
(Just $ 1 % 3)
NoDir
False
"./"
filePrefix

where a filename like filePrefix-HashOfOdInstance.svg is used, even though just filePrefix.svg would probably suffice. But I guess there is no harm in it either.

@patritzenfeld patritzenfeld marked this pull request as ready for review February 13, 2026 14:47
@patritzenfeld patritzenfeld linked an issue Feb 13, 2026 that may be closed by this pull request
@jvoigtlaender
Copy link
Member

For the particular case of drawOdFromInstance, I think it would be more appropriate to not have it use the Autotool capabilities abstraction at all. It is never going to run on Autotool, since it is only used from the "local apps" and from "local tests" in this repo here.

So why is it not simply IO-typed directly?

@jvoigtlaender
Copy link
Member

In fact, drawOdFromInstance might simply be inlined in the three use places it currently has. There is not much abstraction benefit from having it as a function.

adFilename :: FilePath
adFilename = [i|#{path}Diagram.svg|]
drawAdToFile path conf ad = cache path ".svg" "ActivityDiagram-" (conf,ad)
$ drawPlantUmlSvg . uncurry convertToPlantUML'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die bereits vorhandenen cache-Nutzungen hier im Repo sind alle irgendwelche fancyeren Verwendungen. Also zum Beispiel mit Kodierung von Aufgabentypen in die Dateinamen:

prefix =
"petri-"
++ petriType
++ nodeType
und/oder weiteren Bestandteilen, sowohl dort als auch etwa in
ext = short printNavigations
++ short printNames
++ showDigest (sha1 . LBS.fromString $ show marking)
++ ".svg"

Mir ist nicht klar, was davon essentiell, nice to have, oder vielleicht sogar unidiomatisch ist (fmidue/autotool-capabilities#29), und schon gar nicht, ob das Konsequenzen dafür hat, wie der Aufruf hier aussehen sollte.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da bin ich mir auch nicht sicher. Fürs Caching wird ein SHA256 Hash verwendet, es sollte also extrem unwahrscheinlich sein, dass eine Kollision auftritt, auch wenn diese Informationen stattdessen mitgehasht werden.
Diese Teile dem Dateinamen hinzuzufügen hilft vielleicht dabei, die erstellten Dateien später besser einer bestimmten Aufgabe zuordnen zu können, wenn mal etwas debugt werden muss?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ad tasks should use MonadCache instead of MonadWriteFile

2 participants