r/rust • u/[deleted] • May 03 '20
Pijama: A functional programming language written in Rust
Hi people!
I've decided to apply some of the concepts I've learned by studying TAPL and write an small functional PL. You can find its source code and more information here
I've received a lot of feedback from my blog series about writing an interpreter for the lambda calculus, so I hope you'll enjoy this project too.
5
u/a5sk6n May 03 '20
Looks like a cool project! I guess your syntax makes it easier to read for people coming from procedural, imperative languages.
But: Isn't it inappropriate for a pure function to do something? I know it's just a traditional keyword for starting blocks but here it doesn't seem to fit.
Also, are you planning to allow currying? You use that A -> B -> C syntax but otherwise your syntax strictly discriminates between the arguments and the return type.
Final question: How did you come up with the name?
5
May 03 '20
the do syntax is used by Elixir too (that's where I got the idea), I didn't want to rely on brackets nor indentation, so do/end blocks were the only option I could come up with.
I have plans to support currying. Right now a basic form of it can be seen in the Readme.
The name came up to me in a dream... JK, I wanted to build a comfy language. So the name seems to capture that idea.
2
u/a5sk6n May 03 '20
What about
begin? But sure, that's a really minor point ;)Oh I missed that example! But as I said, it looks curious with that syntax...
That's an awesome reason for a name :D
2
May 04 '20
yes the syntax is kinda wonky. I don't like having the types in a separate line because it causes a lot of indirection when reading. Maybe something like
fn foo (c: Bool -> Int) -> (x: Bool) -> Int do ... endwould work but idk... it feels too cumbersome.1
8
u/Dentosal May 03 '20
How are you planning to implement IO? You declare that the language has no state at all, but IO inherently requires having some state, especially if you are going to work with things like files, ffi or shared memory. Waiting until the other parts are done is quite risky, as fitting IO to a functional language as an afterthought isn't going to be pretty nor easy.
11
u/zesterer May 03 '20
There are pretty well-established solutions to this sort of thing: monadic IO, universe values, etc. that allow functional languages to manipulate state without being impure
7
24
u/tripsledge May 03 '20
Very cool! We did something similar to this as a final assignment in my functional programming course, expect we wrote our interpreter in ocaml. The world of PL implementation is definitely interesting, and while it’s not for me, I appreciate all the work you put into this and look forward to diving in and seeing just how you’ve done this in Rust!
2
u/hector_villalobos May 03 '20
I didn't feel comfortable with their syntax
I know how you feel, sometimes I wish there were a language like Rust (no garbage collector) and feel like Ruby.
3
u/m3rls3c May 03 '20
Have you seen Crystal?
3
u/hector_villalobos May 03 '20
Yeah! I like Crystal, but I have a few problems with it, the lack of a 1.0 version is really a problem, besides, it feels do not have the same attention Rust have, besides the garbage collector is an issue because it will bring limitations to the language.
2
u/m3rls3c May 03 '20
Oh, I actually didn’t realize it had a garbage collector. It’s not immediately clear from the homepage.
Attention for a language is a chicken/egg thing I think, the more people that try it, the more people will use it in the figure.
These days the popular languages all have some sort of corporate backing too, funding always helps.
1
u/hector_villalobos May 03 '20
These days the popular languages all have some sort of corporate backing too, funding always helps.
yeah, this is very important too.
2
u/im_caeus May 03 '20
Sounds very very cool! Gonna read that book you got inspired with. I'm designing a language similar to this one but not typed (lazy and pure with first class effect based IO), gonna check your source code!
12
u/MinRaws May 03 '20 edited May 03 '20
I would really be interested in seeing the language going with Lazy Eval.
Being pure puts the language in a special place where laziness or even explicit laziness can be quite useful.
Just noticed: Call-by-need evaluation. Seems nice I am not very sure what you meant from it but it seems like what I thought it should be.