xodio / hm-def Goto Github PK
View Code? Open in Web Editor NEWRuntime type checking for JS with Hindley Milner signatures
License: MIT License
Runtime type checking for JS with Hindley Milner signatures
License: MIT License
Hello,
One of the things introduced on the great PR #8 was some lodash deps. I understand that the intention was to minimize the dependencies introduced by using just two subpackages of lodash instead of the entire lodash.
However, I see this as an anti pattern for 3 main reasons:
So it may be a better idea to just use lodash.
What do you think ?
It would be nice if there were a way to add RecordTypes, for example:
const User = $.RecordType({
id: $.Number,
first: $.String,
last: $.String
})
const env = $.env.concat([User])
This doesn't work (as far as I can tell) because the Type name
in the env is 'RECORD'
, so hm-def can't find a User type.
A workaround is to define a NullaryType
, but to do this I have to provide my own test
function (can't use the more declarative style like when creating a RecordType).
const R = require('ramda')
const User = $.NullaryType(
'User',
'https://github.com/blockchain/blockchain-wallet-v4-frontend#User',
R.where({
id: R.is(Number),
first: R.is(String),
last: R.is(String)
})
)
const env = $.env.concat([User])
const def = hmDef.default.create({
env: env,
checkTypes: true
})
const getUserName = def(
'getUserName :: User -> String',
(user) => user.first + ' ' + user.last
)
Do you know if there is a better way to accomplish this?
The signature passed to the created def
function is resolved regardless whether checkTypes
is true
or not, meaning there is currently a potential, unnecessary performance drain from resolving those signatures which are then subsequently discarded immediately in production environments.
import $ from 'sanctuary-def';
import {create} from 'hm-def';
const def = create ({
checkTypes: false,
env: $.env,
typeClasses: [],
});
const foo = def
// This signature will be parsed and resolved to an `Array Type`, regardless of `checkTypes` above.
('foo :: Boolean -> Boolean')
(x => !x);
The resolved signature is never used by sanctuary-def
's def
when checkTypes
is false
anyways.
Hello,
I noticed that you use several dependencies, like Ramda, and Ramda-fantasyland.
Ramda fantasyland has been recently deprecated, and since you are targeting sanctuary already, why not just using sanctuary ?
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.