[Haskell-cafe] Course-of-value recursion by defining a sequence as a self-referential infinite list
Pranshu Sharma
pranshu at bauherren.ovh
Sat Feb 8 00:03:35 UTC 2025
Vanessa McHale <vamchale at gmail.com> writes:
> I came up with a one-liner for computing coefficients of the generating function for integer
> partitions:
>
> part :: Int → [Integer ]
> part n = take n $ product [cycle (1 : replicate n 0) | n ← [0 . . (n − 2)]]
>
> Karczmarczuk’s solution via the Haskell prelude:
>
> part = 1 : b 1
> where b n = (1 : b (n + 1)) + (replicate n 0 ++ b n)
>
This is broken code, no?, just 2 reasons I can spot why:
- function 'b n' calls 'b n' unconditionally (infite loop)
- What is the reutrn type of 'b'? It seems like it returns list, but the
return value is in the form 'a + b' , where (+) is instance of num so
I don't think prelude contains any ad-hoc definition of (+) that
returns list
More information about the Haskell-Cafe
mailing list