Writing quicksort in pkl #141
Replies: 4 comments 5 replies
-
If you feed it large enough lists, you'll see why we don't recommend Pkl as a general purpose programming language, even though it is Turing Complete ;)
This observation once lead Lennart Augustsson to write a wonderful blogpost on why QuickSort in Haskell really isn't and Conor McBride (if memory serves; I can't find the reference right now) to demonstrate that it is really Deforested Tree Sort (which your algorithm is as well). The syntax error that you're seeing genuinely is a syntax error (although the error message leaves something to be desired). There is no expression in Pkl that starts with |
Beta Was this translation helpful? Give feedback.
-
With the help of
Pretty neat! |
Beta Was this translation helpful? Give feedback.
-
To me
I.e. you can achive the same effect by extending I'd be interested to hear from authors intuition on why is expression |
Beta Was this translation helpful? Give feedback.
-
Tell me, when you wrote your code, did you use information about syntax only from the pkl documentation?😉 |
Beta Was this translation helpful? Give feedback.
-
Of course there is a built-in sorting method, but I was curious about implementing quicksort to try out pkl in scenarios more challenging than basic moving of vaues between fields.
Here is what I've got:
And it works! 😄
I know this is not in-place, which is a major selling point of quicksort, but that's OK.
However it's unnatural to have such long expressions. Can we put them to a varibale?
Here is how I could make it work.
I had to create a class, because if we do it without a class like this:
then we get a syntax error:
This seems like a bug in the parser, right?
Here is CoLab with the code.
Anyway, hope this exercise is interesting. Thanks to the team for working on this language!
Beta Was this translation helpful? Give feedback.
All reactions