Code review: Go challenge #1 in Haskell

Hello Haskellers: A few weeks ago, there was this thing called "Go challenge" and a problem was posted¹ on decoding a binary format and printing out the drum sequences in the input binary file. I made a Haskell solution and would love to get some code reviews. https://github.com/vu3rdd/drum One of the input files given does not have the full bitstream and my program cannot parse that yet. I had been thinking about using a Monad transformer to make a `Get (Maybe) a' and output whatever it could parse and leave the rest behind, instead of failing completely. ¹ http://golang-challenge.com/go-challenge1/ (fwiw, the challenge is over.) Thanks in advance, Ramakrishnan

On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan
Hello Haskellers:
A few weeks ago, there was this thing called "Go challenge" and a problem was posted¹ on decoding a binary format and printing out the drum sequences in the input binary file.
I made a Haskell solution and would love to get some code reviews.
in line put _ = do BinaryPut.putWord8 0 -- we don't care about writing the 'do' is not necessary, as there is only one action; you could also write: put _ = undefined -- we don't care about writing or: put _ = error "put is not implemented" The line (intercalate "\n" $ map show tracks') can be simplified to (unlines $ map show tracks') The line putStrLn (show (runGet get bs :: Splice)) can be simplified to print (runGet get bs :: Splice) as print is the same as putStrLn . show Instead of: else do track <- getTrack tracks' <- getTracks return (track:tracks') you could write: else liftM2 (:) getTrack getTracks or: else getTrack ^:^ getTracks where (^:^) = liftM2 (:) (import Control.Monad first) The function splitN is the same as chunksOf from the package split; I found this by entering the type of splitN as a search string in Hoogle. You can use hlint (from Hackage) to get some hints for possible improvements of the code. Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On Mon, Mar 23, 2015, at 03:55 AM, Henk-Jan van Tuyl wrote:
On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan
wrote: Hello Haskellers:
A few weeks ago, there was this thing called "Go challenge" and a problem was posted¹ on decoding a binary format and printing out the drum sequences in the input binary file.
I made a Haskell solution and would love to get some code reviews.
in line put _ = do BinaryPut.putWord8 0 -- we don't care about writing the 'do' is not necessary, as there is only one action; you could also write: put _ = undefined -- we don't care about writing or: put _ = error "put is not implemented"
The line (intercalate "\n" $ map show tracks') can be simplified to (unlines $ map show tracks')
The line putStrLn (show (runGet get bs :: Splice)) can be simplified to print (runGet get bs :: Splice) as print is the same as putStrLn . show
Instead of: else do track <- getTrack tracks' <- getTracks return (track:tracks') you could write: else liftM2 (:) getTrack getTracks or: else getTrack ^:^ getTracks where (^:^) = liftM2 (:) (import Control.Monad first)
Hello Henk-Jan, Thanks a lot for all the suggestions.
You can use hlint (from Hackage) to get some hints for possible improvements of the code.
Thanks. I ran HLint and it gave some more suggestions. Incorporated all the suggestions, thanks a lot. Ramakrishnan
participants (2)
-
Henk-Jan van Tuyl
-
Ramakrishnan Muthukrishnan