Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assertTypeArity (t) (argTypes);
switch (t.type) {
case 'BINARY':
return fromBinaryType (t) (argTypes[0]) (argTypes[1]);
case 'UNARY':
return fromUnaryType (t) (argTypes[0]);
default: {
throw new TypeError (`Type ${t.name} should be recreated with `
+ `Types: ${S.map (name, argTypes)} but it haven't got `
+ `a proper function recreator for type ${t.type}.`);
}
}
};
// Helper Type to wipe out thunks
const Thunk = $.NullaryType ('hm-def/Thunk') ('') (S.K (false));
// convertType :: SignatureEntry -> Reader (TypeMap Type)
const convertType = memoize (entry => cond ([
[typeEq ('typeConstructor'), convertTypeConstructor],
[typeEq ('function'), convertFunction],
[typeEq ('list'), convertList],
[typeEq ('record'), convertRecord],
[typeEq ('constrainedType'), convertConstrainedType],
[typeEq ('typevar'), S.pipe ([convertTypevar, Reader.of])],
[typeEq ('thunk'), S.K (Reader.of (Thunk))],
[S.K (true), e => {
throw new Error
(`Don't know what to do with signature entry ${e.type}`);
}],
]) (entry));
it ('should resolve namespaced user types', () => {
const Widget = $.NullaryType ('x/y/z/Widget') ('http://example.com/Widget') (S.K (true));
const env = $.env.concat ([Widget]);
const {types} = resolve ($) ([]) (env) ('foo :: Widget -> String');
assert.deepEqual (types, [Widget, $.String]);
});
it ('should resolve maybes', () => {
const Maybe = $.UnaryType
('my-package/Maybe')
('http://example.com/my-package#Maybe')
(S.K (true))
(S.K ([]));
const env = $.env.concat ([
Maybe ($.Unknown),
]);
const {types} = resolve ($) ([]) (env) ('foo :: Maybe String -> String');
assertTypePairs (S.zip (types) ([Maybe ($.String), $.String]));
});
const convertType = memoize (entry => cond ([
[typeEq ('typeConstructor'), convertTypeConstructor],
[typeEq ('function'), convertFunction],
[typeEq ('list'), convertList],
[typeEq ('record'), convertRecord],
[typeEq ('constrainedType'), convertConstrainedType],
[typeEq ('typevar'), S.pipe ([convertTypevar, Reader.of])],
[typeEq ('thunk'), S.K (Reader.of (Thunk))],
[S.K (true), e => {
throw new Error
(`Don't know what to do with signature entry ${e.type}`);
}],
]) (entry));
const convertType = memoize (entry => cond ([
[typeEq ('typeConstructor'), convertTypeConstructor],
[typeEq ('function'), convertFunction],
[typeEq ('list'), convertList],
[typeEq ('record'), convertRecord],
[typeEq ('constrainedType'), convertConstrainedType],
[typeEq ('typevar'), S.pipe ([convertTypevar, Reader.of])],
[typeEq ('thunk'), S.K (Reader.of (Thunk))],
[S.K (true), e => {
throw new Error
(`Don't know what to do with signature entry ${e.type}`);
}],
]) (entry));