Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Uhh, how would you make a linked list with a circle in it with the Haskell List type?


  makeCircle rst = rst ++ makeCircle rst
The thing is that a circular list is actually an infinite list in Haskell. ;)


If you want to prevent that then you want to take general recursion out of your programming language and if you're gonna do that you might as well make it Turing incomplete.

These aren't "circles" per se, they are partially evaluated recursive structures. If you expand them you end up with evaluated list structures that are non-self referential.


This is not a real circular list though, since it does not tie the knot as in dbaupp's comment.


  a = 1:a


This trick is often called "Tying the Knot", if anyone is interested.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: