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

Re: Small package or big dependencies?



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.

Once the interface is fixed I suggest you create a wishlist ticket
against Cabal, requesting support for it.


Greetings,
Joachim
-- 
Joachim "nomeata" Breitner
Debian Developer
  nomeata@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nomeata@joachim-breitner.de | http://people.debian.org/~nomeata

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: