1. 35

  2. 12

    Neither of these approaches are perfect: With the uniform representation approach we lose control over how our data is laid out in memory, and with the template instantiation approach we lose modularity and polymorphic recursion.

    Which is why I have been saying for a while - these ought to be two different forms of polymorphism, so that you can explicitly choose the form you need when you write your program. More precisely:

    ML-style polymorphism:

    • ∀, not Π
    • Always rank-1
    • Always inferred
    • Always monomorphized

    Fω-style polymorphism:

    • Π, not ∀
    • Rank-N or even impredicative if you want
    • Explicit type function application
    • Never monomorphized

    I’d even advertise them as “static” and “dynamic” polymorphism.

    1. 2

      Could you write up a blog post or something about this? It sounds really interesting and deserves to be spread more widely!

      1. 3

        I suspect I haven’t expressed myself sufficiently clearly, but anyway, here it goes: https://meaningfulcomputing.wordpress.com/2017/10/23/two-kinds-of-parametric-polymorphism/

        1. 1


    2. 8

      Boxed values vs. unboxed. I think most people understand C here so lets put it with those concepts. It helps to understand the subject of the link.

      A boxed value:

      typedef struct { int number; } box;
      box* number = box_integer(5);

      Unboxed value:

      int number = 5;

      The box_integer allocates a place from heap where to write the integer, whereas the lower writes an integer directly. The implementation and the rules may vary here.

      How the data is stored in memory matters a lot because tighter it is packed, more information the processor can load to work on at once. Being able to work on an array of unboxed integers vs. boxed values can triple the performance. List strategies in PyPy rely on that difference, by attempting to use simpler list representations when it can.

      1. 4

        Memory layout control is one thing I particuarly find interesting in the Jai programming language.