Replies: 2 comments 3 replies
-
This is a fantastic experiment! Once upon a time, we had quite a few combinators and bits of syntactic sugar so that hand-writing GOOL was not too too painful. At least, within a narrow range of "things you might want to say". Meta-comment: it looks like you solved the problem in Julia, then you tried to reproduce that with GOOL. While that ought to work, it's not quite the best process. Better would be to look at the Julia and figure out "what is this really saying" for each logical block of code (which is sometimes a single line). Then figuring out how to say that in GOOL. Really great debrief. We should think hard about each of those 'experiential issues'. I think some of them are not nearly as difficult to deal with as I used to think. The 'missing features' are also interesting, but for a lot, see back to the meta-comment. Certainly your list clearly points to the external API missing a variety of features, though perhaps not quite the ones your list. Your list is a great start for the requirements to adding to that API. |
Beta Was this translation helpful? Give feedback.
-
I'm late to the party on looking at this, but now that I've looked at the work, I really like it. Thank you for taking the initiative to do this @B-rando1. Looks like you had some fun! 😄 Did you submit the generated code to see if it passes whatever checks the advent of code people use? Even though the generated Julia code is ugly compared to the handwritten code, it is still a positive if it has the right behaviour. 😄 |
Beta Was this translation helpful? Give feedback.
-
The other day I had some time on my hands, and I wanted to try doing question 1 of this year's Advent of Code in GOOL. I find the idea of hand-writing GOOL interesting, even if that's not its primary purpose, and I figured Advent of Code would be a good place to try it. It was an interesting experience, and I think it's be worth writing about here.
Background
The Advent of Code problem can be viewed here. Basically, the puzzle input is a
.txt
file with two columns of numbers separated by spaces. These two lists of numbers must be parsed and sorted, and then their element-wise absolute difference (i.e. Manhattan distance) is the answer to the problem. It's a simple problem, with parsing and sorting being the biggest topics.My code is on the branch advent-of-code, with these relevant files:
The code can be generated with
make codegenTest_gen
. Only the Python code runs without issue, but as mentioned the Julia code can be run with only one small modification.What I found was that it took much longer (several hours instead of <30 minutes) to solve this problem in GOOL, and missing functionality impacted the code in a few ways. These included longer code because more consise options were not available, extra functions to implement what is included in the standard library but not accessible by GOOL, and one missing pattern that did not have a workaround.
Debrief
I had a few problems writing code in GOOL, which fall into three main categories. I will outline them below.
'Experiential' issues
These mostly come down to the fact that GOOL is embedded in Haskell, which of course has some downsides. While they are difficult and make writing code in GOOL feel more like writing C than Python, they aren't actually the cause of the biggest issues I faced. Plus, they would be the hardest to address.
Drasil.GOOL
.block
s. They're like semicolons, but worse since the last line can't have one.Actual bugs
forRange
includes theend
value; it should not. This should be a quick fix, and indeed I made the fix on this branch so I could continue focusing on Julia. I can replicate the change inmain
soon.Missing features
These ended up causing the most pain. I had to implement list sorting and parsing an integer from a string manually because they were required, and there were a number of other features that I would have used if I had the chance.
CommonRenderSym
but not part of the external API)strToInt
required this, I had to lie to GOOL and say that the input was not astring
, but alistType char
. And this had its own problems of course, requiring me to modify the generated code in all targets except Python, since their typecheckers failed.litList
not allowed in C++?litArray
instead so that I didn't have to disable C++ from the list of outputs, but that caused issues with the generated code for Java and likely other languages.selectionSort
function I wrote is only forint
s. This would be a big can of worms, but it would be nice to have polymorphism for that sort of thing.map
,filter
,zip
, or list comprehensions. Those would come in handy, even if they can be replaced by loops.abs
,max
,min
, etc.abs
was another function I had to do without, and there are more, of course. These are easy to implement as needed, but it's nice to have them.Conclusion
I mainly did this to see how much more work it would be to solve an Advent of Code problem in GOOL compared to a real language like Julia. It was a little disheartening to see how wide this gap is, as well as the difference in quality between the generated code and the idealized code I wrote. I suppose that in large part that is an effect of this being a research project; my understanding is that GOOL is meant not to replace any programming languages but to inspire new languages. With that said, there are some actionable items:
cast
function (or at least parsing from a string) available to the GOOL frontend is virtually required for problems like this, and shouldn't be too much work to do.sort
function would be very handy as well. We would need to decide if we want to provide different algorithms, but even if we only provide one it would be a good start.forRange
. I can do this, it should be a quick fix.We could go further on more of the points I mentioned above, but these seem to be the most essential to me. There could be a risk of going too far: e.g. adding functional techniques would be awesome, but do we really need them? The answer to this depends on what GOOL is meant to be and where we want to direct our energy.
I hope this wasn't too much of a meander 😄. I'm not exactly sure what to do with this, but I think it's worth writing it down and seeing if there's anything here that we can work on.
Beta Was this translation helpful? Give feedback.
All reactions