[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Small package or big dependencies?



+++ Joachim Breitner [Aug 03 10 14:04 ]:
> Hi,
> 
> Am Dienstag, den 03.08.2010, 00:40 -0700 schrieb John MacFarlane:
> > > slightly diverging from the original question: Couldn’t Cabal directly
> > > provides support for this? It automatically detects files like ".y". It
> > > could convert a file ending in ".blob" to a haskell file containing the
> > > data as a raw bytestring, or even convert it directly to a .o file with
> > > a corresponding FFI wrapper that can be linked into the libraries.
> > > 
> > > I’m sure there are a few use cases. E.g. icons for executables on
> > > windows, or binaries which contain the manpage as the documentation
> > > source.
> > 
> > I think that's an excellent idea, and, though I can't change Cabal,
> > I've whipped up a little program that can be integrated with Cabal
> > using the preprocessor hook.
> > 
> > http://github.com/jgm/hsb2hs
> > 
> > You can look at an example of its use in the sample directory.
> > If this seems a good idea, I may revise filestore to use this
> > technique.
> 
> very nice.
> 
> I’m wondering if you should enforce the use via ByteStrings, and not via
> strings, as strings consist of characters, and files consist of bytes.
> If the user wants a string, he can still convert it using
> Data.ByteString.Utf8 or the like.
> 
> Additionally, your current scheme might be inefficient with very large
> files. It should be more efficient to use (untested)
> 
> {-# LANGUAGE MagicHash #-}
> 
> import qualified Data.ByteString.Unsafe
> 
> foo :: ByteString
> foo = Data.ByteString.Unsafe.unsafePackAddressLen 13 "Hello World!\n"#
> 
> See 
> file:///usr/share/doc/ghc6-doc/html/libraries/bytestring-0.9.1.5/Data-ByteString-Unsafe.html#v%3AunsafePackAddress
> and
> file:///usr/share/doc/ghc6-doc/html/users_guide/syntax-extns.html#magic-hash
> for more information. The Pragma and the import statement could be
> inserted by hsb2hs, so that the user is not confused if he forgets to
> add it. The current behavior could be a fallback solution when working
> with other compilers.

Yes, I think this is the way to go. I didn't know about Data.ByteString.Unsafe!

I don't really have time to develop this further right now. If you're interested
in doing something with it, feel free to take it over, change it as you see fit, and
release it.

John


Reply to: