[Haskell-beginners] shortening code

Lyndon Maydwell maydwell at gmail.com
Wed Jun 30 00:20:17 EDT 2010


I agree. If you're aiming for really terse code, have a look at the
J/K languages. These seem to win most golf-shootout type competitions.
Haskell is more focused on expressiveness and abstraction.

On Wed, Jun 30, 2010 at 11:25 AM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
>
>
> rizwan hudda wrote:
>>
>> I have recently started learning haskell, and was trying to write a code
>> for this problem http://www.spoj.pl/problems/KAMIL in haskell. The aim is to
>> write a shortest possible code for the given task. I have previously solved
>> this in c,c++,perl,python.My best was 57 characters using perl. So here's my
>> code in HASKELL:
>>
>> main = interact $ unlines. map (show.foldl (\a x-> if null $ filter (==x)
>> "TDLF" then a else a+a) 1) .lines
>>
>> It is 107 characters [ non white space and newline ]. I was interested in
>> knowing how i could further optimize the size of this code.
>
> This kind of contest is fun, but I can't help thinking I hope you are
> learning Haskell to appreciate the things that functional programming is
> good at. Real-world Haskell is often more concise than other languages
> because Haskell has mechanisms for eliminating unnecessary and redundant
> code, but Haskell's strength is not winning "shortest program" contests.
>
> Mike
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list