[Haskell-beginners] Code review: Go challenge #1 in Haskell
Ramakrishnan Muthukrishnan
ram at rkrishnan.org
Mon Mar 23 01:16:12 UTC 2015
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
> <ram at rkrishnan.org> 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.
> >
> > <https://github.com/vu3rdd/drum>
>
>
> 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
More information about the Beginners
mailing list