4 ms·
It's remarkable how similar this code looks to the monadic way of doing it. For this Kal code... task getUserFriends(userName) wait for user from db
by rybosome 13y ago
It's remarkable how similar this code looks to the monadic way of doing it.
For this Kal code...
task getUserFriends(userName)
wait for user from db.users.findOne {name:userName}
wait for friends from db.friends.find {userId:user.id}
if user.type is 'power user'
for parallel friend in friends
wait for friendsOfFriend from db.friends.find friend
for newFriend in friendsOfFriend
friends.push newFriend unless newFriend in friends
return friends
Here's a pseudo-ish implementation in pseudo-ish Haskell.
getUserFriends userName = do
user <- findUser userName
friends <- findFriends user
if (User.type user) == "power user"
then friends ++ parMap rdeepseq $ (getSecondNodes friends) friends
else friends
getSecondNodes firstNodes friend = do
secondNodes <- findFriends friend
diff firstNodes secondNodes
I like the concept of Kal, and I look forward to seeing what people do with it. Regarding syntax, I have to admit that I share the opinions of a few others in terms of preferring symbols over so many keywords, but that's a minor nitpick. Great job!
- rzimmerman 13y agoThanks! I had not thought to make the comparison to Haskell and monads. That's pretty interesting. A lot of people prefer symbols over keywords, and I think that's mainly a readability issue. I personally prefer more keywords with good syntax highlighting, so that's what I went with (and why I almost immediately made a .tmbundle).
- iandanforth 13y agoComing from a Python background I appreciate the verbosity. There are times when symbols and being concise may be necessary, but I find a non-expert human readable default to be very appealing. Thanks for your hard work!
- pcj 13y agoThis is beautiful work! I see small shades of inspiration from the .Net TPL[1] and the more recent async-await paradigm[2] in C#. But, this is way more concise and beautiful implementation :-) [1] - http://msdn.microsoft.com/en-us/library/vstudio/system.threading.tasks.task.aspx http://msdn.microsoft.com/en-us/library/vstudio/system.threa... [2] - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp... and http://msdn.microsoft.com/en-us/library/vstudio/hh156528.aspx http://msdn.microsoft.com/en-us/library/vstudio/hh156528.asp...
- rzimmerman 13y agoThanks! I was wondering if someone would make that comparison. I saw async-await a little after I started working on this and felt it was good confirmation that this was actually a reasonable idea.
- GeZe 13y agoIf you are looking for a syntax closer to Haskell's, you can take a look at LiveScript (http://livescript.net/ http://livescript.net/) eg. getUserFriends = (userName) -> user <- findUser userName friends <- findFriends user ... Specifically, the section on "backcalls": http://livescript.net/#backcalls http://livescript.net/#backcalls
- seanmcdirmid 13y agoBack calls look like array programming gone even crazier. Was live script inspired by APL?
- damncabbage 13y agoIf you are looking for Haskell, you can take a look at Fay (https://github.com/faylang/fay/wiki https://github.com/faylang/fay/wiki).
- chx 13y agoWhat about Haste? https://github.com/valderman/haste-compiler https://github.com/valderman/haste-compiler
- hijackson 13y agoI quit engaging at shoprite and currently I build $35h - $80h...how? i am operating online! My work did not precisely build Pine Tree State happy therefore i made a decision to require an opportunity on one thing new… when four years it absolutely was therefore onerous to quit my day job however currently i could not be happier. Heres what I do, www.jobs34.ℂom
- eru 13y agoAnd, of course, the Haskell do-notation gets de-sugared into tons of call-backs by the compiler.