I actually imported the full source into HackPorts, ripped out its List.hs file, renamed it to my Main.hs file, and then began changing it from a function that prints out a list of available packages, to one that writes the data into properly formatted Portfile entries.
… As it does this, it fetches the current version’s tarball over HTTP, and uses OpenSSL (directly, through FFI) to generate MD5, SHA1 and RIPEMD160 checksums of the tarball image.
…As a stub, I have them all depending on port:ghc , but I think there’s sufficient information in the Cabal package info to figure out what the right dependencies should be, both among the Hackage packages themselves and against any external libraries (like OpenSSL).
…Whereas map takes a list of values and returns a list of values, mapM takes a list of values and returns a list of actions that get invoked in sequence in the current Monad (in this case, IO ).
In the meantime, I’ve picked a toy project that also has a taste of usefulness: a script to convert the Hackage database into MacPorts Portfiles, respecting inter-package and external library dependencies.
…The impure part takes a command-line argument, interprets it as a FilePath (an impure type, since it must concern itself with operating system-dependent naming conventions), and reads the contents of the file at that location.
… This division into pure and impure has an interesting side-effect (no pun intended): Most of a program’s code is written in isolation of its context of usage .
… Too many times I’ve tried to use a utility’s code as a “library”, only to find it was so caught up in its idea of how it should be used, it had never bothered to abstract its core principles into a set of “pure” function, independent from that intent.
