HN user

monzee

22 karma
Posts0
Comments8
View on HN
No posts found.

You can generalize this with TS's fancy mapped types:

    type Sum<K> = <T> (cases: Pattern<K, T>) => T
    type Pattern<K, T> = {
      [V in keyof K]: K[V] extends any[] ? (...args: K[V]) => T : never
    }
which takes TS very close to ML:
    type Shape = Sum<{
      circle: [number, number, number],
      rectangle: [number, number, number, number]
    }>

    function Circle(x: number, y: number, r: number): Shape {
      return ({ circle }) => circle(x, y, r);
    }

    function Rectangle(x: number, y: number, w: number, h: number): Shape {
      return ({ rectangle }) => rectangle(x, y, w, h);
    }

    function area(shape: Shape): number {
      return shape({
        circle: (x, y, r) => Math.PI * r * r,
        rectangle: (x, y, w, h) => w * h
      });
    }

Faster startup, mouse works as you'd expect in a regular desktop app. Switch panes, tabs, open new tab, scroll panes, resize panes, select ranges, all in the terminal. I know not using the mouse is one of the reasons why one would choose vim, but the mouse really is faster/more intuitive in some situations.

For this reason, I think of objects as not equivalent to closures, but rather ML-style functors. I think implementing objects as records with closures as fields is really just a poor man's parameterized module.

Tools I Use - tmux 15 years ago

Here's how to make shift-pgup/pgdn work in screen:

    echo "termcapinfo xterm ti@:te@" >> ~/.screenrc