-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto generate def
arguments
#39
Comments
That would be very cool indeed! It could even transform… // concat :: Semigroup a => a -> a -> a
const concat = (x, y) => x + y; into… // concat :: Semigroup a => a -> a -> a
const concat =
def('concat',
{a: [Semigroup]},
[a, a, a],
(x, y) => x + y); |
This is the tool I'd love to use in our project! |
fwiw I'm chipping away at this when I can. Got some stuff working, currently turns // foo :: Integer -> Integer
var foo = function(x) {
return x + 10;
};
// concat :: a -> a -> a
const concat = (x, y) => x.concat(y);
// head :: [a] -> Maybe a
const head = x => x.length === 0 ? Nothing() : Just(x[0]); into // foo :: Integer -> Integer
var foo = def("foo", {}, [$.Integer, $.Integer], function (x) {
return x + 10;
});;
// concat :: a -> a -> a
const concat = def("concat", {}, [a, a, a], (x, y) => x.concat(y));;
// head :: [a] -> Maybe a
const head = def("head", {}, [$.Array(a), $.Maybe(a)], x => x.length === 0 ? Nothing() : Just(x[0]));; Does that all look correct (I'm in a bit of a hurry at the moment, I've hardly even looked at the results)? (I notice an extra I think there are a lot of options/decisions/different directions we can go, so I'm just trying to get a minimum useful product up and then we can make all those fun decisions together. |
This looks fantastic, Kevin! Your |
Hey @kedashoe i was having the exact same thought that babel plugin would be great and then was pointed to this issue when I asked on gitter. Could you possibly make your current work-in-progress plugin code available? Would love to look at it and ideally contribute too. I just wouldn't want to start from zero knowing have something that works ;) |
Yep, just a few kinks to work out and clean things up a bit. I'll shoot for next weekend. |
Another thought, I saw something like this recently, can't remember where now, but a similar thing we could either add to sanctuary-def or to another lib: const head = hmDef(
'head :: [a] -> Maybe a',
x => x.length === 0 ? Nothing() : Just(x[0])
); and |
That would be nice too. :) |
Weekend! I want your awesome plugin!! ;-) |
haha wait until you see it before you call it awesome ;) In any event, the WIP is up here: https://github.com/kedashoe/babel-sanctuary-def which depends on this (also just written, also a WIP): https://github.com/kedashoe/hindley-milner-parser-js I chatted with @davidchambers briefly, I think the plan is to move these under the sanctuary-js org, so I don't plan on publishing an npm package for now. You can just depend on it via github, eg
I have quite a bit more to say, but it's already well past my bedtime 😴 I will be posting some issues of my own on both repos tomorrow. If you can't wait to get started contributing, just run |
@kedashoe thanks for sharing! Looking forward to playing around with that a bit! |
@kedashoe indeed thanks for sharing 👍 very interesting i've chatted with some folks and thought about creating a babel-plugin that uses the HM comments to provide a way to check your js (akin to flow, etc) code while you are developing its good to see progress in a similar direction |
For those who’re interested in It’s not quite complete regarding complex cases but usable enough for usual scenarios. Works fine on a hundred of functions in our project. |
Very cool, @nkrkv! I look forward to trying hm-def. |
This was the first thing I thought of when reading about babel macros. Seems like the perfect size project for a macro. It's been a couple years since this got attention: I would be interested in contributing to this if it's still being worked on or perhaps forking anything that could renew interest. The idea of being able to get Quick question, is there anything |
It is intended to be one-to-one. :) |
@davidchambers ”better late than never”? 😂 |
Let's just say that my system for managing my inbox is imperfect. 🤪 |
it will be nice to have babel plugin or something like that to transform code from this
to this:
The text was updated successfully, but these errors were encountered: