[Haskell-cafe] Best practice for embedding files in a GHC-compiled tool?

Dave Bayer bayer at cpw.math.columbia.edu
Wed Feb 6 23:29:38 EST 2008

What is the best way to embed an arbitrary file in a Haskell program?

I would like to use GHC to compile command-line tools to be used with  
OS X. I want the tool to be a single file, not a package or a  
directory, that makes no assumptions about what else is present. For  
example, it should be able to run as part of an OS X install disk.

I want this tool to be "self reproducing" in the sense that one of its  
options causes it to output its own documentation and source code. I  
want this data to be stored as a compressed file within the tool  
binary itself.

The distribution model I'm imagining here is where one writes a  
program anonymously, that isn't hosted anywhere but is passed from  
user to user because it is useful, and eventually reaches another user  
who wants to modify the code. Assume that intermediate users will care  
less about this, and will try to delete anything that they can. That  
rules out storing the data in a separate file. Think of the M.I.T.  
game "Core Wars" from the dawn of the computer age. I'm looking for a  
strategy here that will be evolutionarily successful in a fairly  
hostile environment.

In other words, I want to be able to write in Haskell, without losing  
the automatic distribution of source code enjoyed by interpreted  
languages. No one deletes the source code for a Perl script, because  
by doing so they're killing the program.

There must be some library I'm overlooking that would make this very  
easy. All I can think of is to use Template Haskell to read a  
compressed tar file into a Haskell variable. Is that what one does, or  
is there a better way?

Thanks in advance,

More information about the Haskell-Cafe mailing list