diff --git a/src/index.js b/src/index.js index 53a5192..d2969da 100644 --- a/src/index.js +++ b/src/index.js @@ -20,6 +20,10 @@ export const create = def $priv.AnyFunction, ]) (({$, checkTypes, env, typeClasses}) => { + if (!checkTypes) { + return _ => f => f; + } + const $def = $.create ({checkTypes, env}); const resovleSig = Sig.resolve ($) (typeClasses) (env); diff --git a/test/def.spec.js b/test/def.spec.js index 030321a..50df0e9 100644 --- a/test/def.spec.js +++ b/test/def.spec.js @@ -19,7 +19,7 @@ const $Wrapper = $.UnaryType (S.allPass ([S.is ($.Object), hasProp ('value')])) (S.pipe ([S.prop ('value'), S.of (Array)])); -const def = create ({ +const config = { $, checkTypes: true, env: $.env.concat ([ @@ -30,7 +30,8 @@ const def = create ({ Z.Functor, Z.Semigroup, ], -}); +}; +const def = create (config); describe ('def', () => { it ('should work with unary functions', () => { @@ -185,4 +186,18 @@ describe ('README examples', () => { qux: 1, }); }); + + it ('should return function as-is if `checkTypes` is `false`', () => { + const defNoCheck = create ({ + ...config, + checkTypes: false, + }); + const foo = s => `${s}bar`; + const f = defNoCheck + ('f :: String -> String') + (foo); + + assert.strictEqual (f, foo); + assert.equal (f ('foo'), 'foobar'); + }); });