develwoutacause’s avatardevelwoutacause’s Twitter Archive—№ 606

      1. Lesson I learned today: imperative languages can't express data structures that are both immutable *and* circular. For example, you can't build an immutable, doubly linked list in #csharp without ugly runtime assertions. 🤮
    1. …in reply to @develwoutacause
      The reason for this is because you can't construct an immutable object without having all its dependencies first. So if A <-> B, you can't construct A without B, but you also can't make B without A.
  1. …in reply to @develwoutacause
    Mutability works around this because you can just construct A without a reference to B (such as null) then add it later once you've made B. This made me wonder, are there other languages which can provide a compiler-guaranteed immutable *and* circular data structure? 🤔
    1. …in reply to @develwoutacause
      Like most esoteric #ComputerScience problems, the answer is: functional programming languages. For example, #Haskell does this by "tying the knot", leveraging laziness to define two symbols that reference each other. 🤯 wiki.haskell.org/Tying_the_Knot
      1. …in reply to @develwoutacause
        You can use delegates to kind of do the same thing in #csharp, but it's still mutating state and the compiler doesn't understand it like #Haskell does. I don't really have a point to make here, just sharing some interesting stuff I learned today.