r/rust • • 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.

137 Upvotes

20 comments sorted by

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.

4

u/[deleted] May 03 '20

call by need is the lazy evaluation strategy used by Haskell so it seems we are on the same page :)

3

u/im_caeus May 03 '20

Do you have memoization!? While designing my language, making this part fit (not as part of the language per se, but as optimization of the interpretation process) I have struggled quite a bit.

3

u/[deleted] May 03 '20

that's exactly the way I want to go. right now there is no memoization.

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

u/[deleted] 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

u/[deleted] 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 ... end would work but idk... it feels too cumbersome.

1

u/a5sk6n May 04 '20

I guess that idea is quite readable when getting used to it!

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

u/[deleted] May 03 '20

exactly this. Probably something like monads is what I have in mind

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?

https://crystal-lang.org/

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!