[Haskell-beginners] Extract and integer from a ByteString
tvhobbs at googlemail.com
Wed Jun 16 03:40:12 EDT 2010
Thanks for the answer, I shall give it a go later tonight (UK time).
Why would I want to keep my functions monadic? It's not that I'm against
the idea, rather it's that I don't understand the choice. I was under the
(possibly wrong) impression that (IO) monadic functions were just to "get
around" the issue of side-effects and that where possible functions should
be coded outside of monads. Is that just plain wrong, or does it boil down
to "It depends on what you're doing, and in this case..."?
Also I think I've already encountered the hidden Data.Binary problem in GHC.
I have got around it already by (if memory serves) starting GHC and telling
it to ignore it's own Data.Binary so I can then include it in my own
projects. But I created an alias which starts this Data.Binary-capable GHC
and I can't remember what's behind it now!
What's the reason for GHC hiding packages and preventing them from being
imported/used in loaded projects?
Thanks again for the help.
On Tue, Jun 15, 2010 at 9:15 PM, Stephen Tetley <stephen.tetley at gmail.com>wrote:
> Hi Tom
> Try ...
> extractInt :: [Word8] -> Int
> extractInt = foldl addDigit 0
> addDigit num d = 10*num + (fromIntegral d)
> You might find you want to keep your functions monadic, and mostly use
> the Get monad from the module Data.Binary.Get for working with binary
> data.For instance there is a function getWord32be to do the work that
> extractInt is doing
> Best wishes
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners