News for hackers. Stuff that matters.

monzee

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
      });
    }
Re:NeoVim 0.2.0 released on Tuesday May 02, 2017 @08:01AM (#14245636)
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.
Re:Closures and Objects Are Equivalent on Sunday April 12, 2015 @06:54PM (#9365045)
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.
Re:I won't be using Angular for my next project on Monday April 06, 2015 @01:22AM (#9326719)
It's a view generation library, not a DOM-diffing library. That's like asking how to rotate a subtree in an RB tree library.
Is this guy really a former Google employee? Those posts sound like they were written by an elementary school kid.
Re:Codestre.am: streaming your code to the masses on Sunday April 01, 2012 @08:55PM (#3785665)
This is so cool. I only wish the screen were a little bigger and could show all the colors.
Re:Codestre.am: streaming your code to the masses on Sunday April 01, 2012 @07:14PM (#3785387)
Looking forward to this. Registration doesn't seem to work yet.

Please add 'monospace' to the font-family declaration. The site looks terrible in Ubuntu.

Re:Tools I Use - tmux on Sunday January 08, 2012 @07:45AM (#3439441)
Here's how to make shift-pgup/pgdn work in screen:

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