[Haskell-beginners] Code review: Go challenge #1 in Haskell
Henk-Jan van Tuyl
hjgtuyl at chello.nl
Sun Mar 22 22:25:32 UTC 2015
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)
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 at 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
--
More information about the Beginners
mailing list