[Haskell-beginners] code critique

Arlen Cuss celtic at sairyx.org
Tue Jul 26 07:25:24 CEST 2011


I have one suggestion:

> sumCheck total (x:xs) ys = if total' == Nothing 
>                                 then sumCheck total xs ys
>                                 else return (x, (ys !! ( fromJust total')))
>                            where total' = (total - x) `elemIndex` ys 

I might write this:

> sumCheck total (x:xs) ys =
>   let diff = total - x
>   in  if diff `elem` ys
>          then Just (x, diff)
>          else sumCheck total xs ys

Cheers,

A



More information about the Beginners mailing list