2

I am working my way through the real world haskell book. Many of the examples don't compile on recent GHCs. I'm not sure where to look for changes that have happened to GHC and Google hasn't been very forthcoming when looking for the error messages I am seeing. It seems like there must be something that has changed in the implementation of MArrays?

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1

And:

$ ghc -o bloom BloomFilter/Mutable.hs
[2 of 2] Compiling BloomFilter.Mutable ( BloomFilter/Mutable.hs, BloomFilter/Mutable.o )

BloomFilter/Mutable.hs:21:36:
    No instance for (Data.Array.Base.MArray
                       Data.Array.Base.UArray Bool (ST s))
      arising from a use of `newArray'
    Possible fix:
      add an instance declaration for
      (Data.Array.Base.MArray Data.Array.Base.UArray Bool (ST s))
    In the second argument of `liftM', namely
      `newArray (0, numBits - 1) False'
    In the expression: MB hash `liftM` newArray (0, numBits - 1) False
    In an equation for `new':
        new hash numBits = MB hash `liftM` newArray (0, numBits - 1) False

BloomFilter/Mutable.hs:26:36:
    No instance for (Data.Array.Base.MArray
                       Data.Array.Base.UArray Bool (ST s))
      arising from a use of `getBounds'
    Possible fix:
      add an instance declaration for
      (Data.Array.Base.MArray Data.Array.Base.UArray Bool (ST s))
    In the second argument of `liftM', namely
      `getBounds (mutArray filt)'
    In the expression: (succ . snd) `liftM` getBounds (mutArray filt)
    In an equation for `length':
        length filt = (succ . snd) `liftM` getBounds (mutArray filt)

BloomFilter/Mutable.hs:30:77:
    Couldn't match expected type `MutBloom s0 a0'
                with actual type `Word32'
    In the second argument of `writeArray', namely `bit'
    In the expression: writeArray (mutArray) bit True
    In the first argument of `mapM_', namely
      `(\ bit -> writeArray (mutArray) bit True)'

BloomFilter/Mutable.hs:40:44:
    No instance for (Data.Array.Base.MArray
                       Data.Array.Base.UArray Bool (ST s))
      arising from a use of `readArray'
    Possible fix:
      add an instance declaration for
      (Data.Array.Base.MArray Data.Array.Base.UArray Bool (ST s))
    In the first argument of `allM', namely
      `(readArray (mutArray filt))'
    In the second argument of `(>>=)', namely
      `allM (readArray (mutArray filt))'
    In the expression:
      indices filt elt >>= allM (readArray (mutArray filt))
duplode
  • 33,731
  • 7
  • 79
  • 150
  • Welcome to Stack Overflow. Could you be more specific about what is your question? – Petr Jun 23 '13 at 17:25
  • And when you ask a question please post or link the source code if at all possible. – Thomas M. DuBuisson Jun 23 '13 at 18:13
  • Copying the source from [the online chapter](http://book.realworldhaskell.org/read/advanced-library-design-building-a-bloom-filter.html) compiles cleanly. You have apparently miscopied, for example the incriminated `(\ bit -> writeArray (mutArray) bit True)` actually has `writeArray (mutArray filt) bit True`. The others look like you have `UArray Word32 Bool` copied from the immutable data type to the mutable one. Also, `ghc -o bloom BloomFilter/Mutable.hs` is wrong, you don't want to redirect the output with `-o` for a non-Main module. – Daniel Fischer Jun 23 '13 at 19:34
  • Hey Daniel, I have copied the source code directly from the book's website (i.e.http://examples.oreilly.com/9780596514983/rwh-examples2.zip). I still get the same error. Remember that I am using ghc 7.4.1. I continue to get the same error whether or not I include the -o bloom in the compile line. The source is that which Daniel references, and which is in the zip file I link, Thomas. Thanks for your help all. – user2514049 Jun 23 '13 at 20:45
  • I just downloaded the zipfile and the BloomFilter/Mutable example works for me with ghc-7.4.1 and ghc-7.6.2, although the top-level BloomFilter.hs module doesn't build with either. – John L Jun 24 '13 at 00:50
  • Thanks man. Yep, I had typos in the BloomFilter/Internal class. I also can't build BloomFilter.hs now. – user2514049 Jun 24 '13 at 07:06
  • 3
    You can make BloomFilter.hs compile by changing: `B hash . runSTUArray $` to `B hash $ runSTUArray $` As per: http://stackoverflow.com/questions/9468963/runst-and-function-composition – user2514049 Jun 24 '13 at 07:25
  • Also have a look at the [Bloom filter library][1] written by Bryan O'Sullivan, one of the authors of Real World Haskell. It's much more mature than the code presented in the book. [1]: https://github.com/bos/bloomfilter – ars-longa-vita-brevis Aug 10 '14 at 10:38

0 Answers0