logoalt Hacker News

bmacho11/07/20242 repliesview on HN

I don't think Haskell can do this, can have a growable linked list for example. 'last a' is 'last a', regardless what is between them (modulo shadowing and such).

And I suspect that Prolog's Partial Instantiation is, while not mutating data, but it is mutating references somewhere


Replies

whateveracct11/07/2024

Technically, Haskell laziness is just mutability under the hood :)

And the "difference list" mentioned in the article is also in Haskell - although framed differently (more "functionally")

    type DList a = [a] -> [a]

    concat :: DList a -> DList a -> DList a
    concat = (.)

    toList :: DList a -> [a]
    toList d = d []

    fromList :: [a] -> DList a
    fromList = (++)
skybrian11/07/2024

Haskell has cyclic data structures, which also can’t be implemented without a mutable reference somewhere, though it may be buried in the implementation.

The difference is being able to define an incomplete data structure (with a forward reference) and then defining the target of the reference at runtime. Most languages will complain about an undefined reference if it’s not defined by the end of a module.

You could do it with soft references, though. Use a symbol or string to refer to something and define it later.

show 2 replies