[Haskell-cafe] Course-of-value recursion by defining a sequence as a self-referential infinite list

Kim-Ee Yeoh ky3 at atamo.com
Mon Feb 10 01:00:00 UTC 2025


On Sat, Feb 8, 2025 at 7:04 AM Pranshu Sharma via Haskell-Cafe <
haskell-cafe at haskell.org> wrote:

> Vanessa McHale <vamchale at gmail.com> writes:
>
> > <snipped>
> >
> > 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)


This definition is meaningful:

ones = 1 : ones

Now consider

onesfun () = 1 : onesfun ()

The function onesfun calls itself unconditionally. This is broken code, no?


> - 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
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20250210/4db9b6af/attachment.html>


More information about the Haskell-Cafe mailing list