[Haskell-cafe] Musings on lists

Olaf Klinke olf at aatal-apotheke.de
Thu Jul 13 14:44:12 UTC 2023


Perhaps, if the students have been in contact with a language that has
explicit pointers (C or C++), let them implement linked lists and
concatenation in that procedural language. (An AI will likely also
produce a correct implementation nowadays.) The advantage is that one
can inspect the values of the pointers to see whether any copying has
happened. Then the students easily see that only the spine (structure
holding pointers) is re-created, but the memory the list elements point
to is never touched. That is an instance of parametricity, I believe. 
The fact that
 
    length (replicate 3 undefined ++ replicate 2 undefined)

evaluates to 5 also shows this. 


Olaf



More information about the Haskell-Cafe mailing list