[Haskell-beginners] Defeating type inference

Philip Scott pscott at foo.me.uk
Thu Feb 26 06:21:31 EST 2009


Hi Alex,
> The problem is that when you go fro
>> months = range (Jan,Dec) : months
>> realmonths = concat months
>>     
> to
>> months = concat (range (Jan,Dec) : months)
>>     
> you're not just collapsing the two functions, you're changing the
> definition (and type!) of "months" which you referred to within the
> months function. Since months is a recursive function, you can't
> necessary fold in the definition of realmonths because you want the
> recursion to apply to the original months, not the original
> realmonths.
>
>   
Of course, why didn't I see that :) I think I had managed to get my head 
into its own recursive loop.. I think I might have to replace my evening 
glass or three of wine with some Red Bull while I am getting my mind 
around this stuff.
> As you suspected, there are better and simpler ways of doing this
> available, although your way is good for getting the hang of
> recursion, even though experienced haskellers really don't use
> recursion all that much. (Most prefer to use functions that
> encapsulate recursion *patterns* such as map, filter, folds and many
> more.) 
>   
Thank you very much for you help and suggestions, I shall bear them in mind.

- Philip


More information about the Beginners mailing list