sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

improve performance of NullaryType #258

Closed davidchambers closed 5 years ago

davidchambers commented 5 years ago

This pull request brings $.NullaryType into line with $.UnaryType and $.BinaryType, which as of #244 do not type-check predicate functions.

On my computer, the following program takes about 40 seconds to run on this branch compared with about 140 seconds on master:

'use strict';

const $ = require ('.');

const a = $.TypeVariable ('a');

const zeros = []; for (let x = 0; x < 1e6; x += 1) zeros.push (0);

$.create
  ({checkTypes: true,
    env: [$.Array ($.Unknown),
          $.NullaryType ('Zero') ('') ([]) (x => x === 0)]})
  ('I')
  ({})
  ([a, a])
  (x => x)
  (zeros);