# Functional Programming for Writing Programming Languages

**URL:** <https://discourse.mc-stan.org/t/functional-programming-for-writing-programming-languages/31051>\
**Category:** General\
**Created:** [April 12, 2023, 2:27pm UTC](https://discourse.mc-stan.org/t/functional-programming-for-writing-programming-languages/31051 "2023-04-12T14:27:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drezap](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/drezap/32/11168_2.png) [@drezap](https://discourse.mc-stan.org/u/drezap)\
**Post date:** [April 12, 2023, 2:27pm UTC](https://discourse.mc-stan.org/t/functional-programming-for-writing-programming-languages/31051/1 "2023-04-12T14:27:30Z")

</div>

Just curious, what makes functional programming useful for writing programming languages?

Integrating multiple C/C++/python, etc. Just curious what the motivation is. I haven’t dug into it much.

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [April 13, 2023, 8:57am UTC](https://discourse.mc-stan.org/t/functional-programming-for-writing-programming-languages/31051/2 "2023-04-13T08:57:14Z")

</div>

I believe the main advantages are pattern matching and garbage collection because they make AST manipulation easier.

There’s a thread on the choice of language for the Stan compiler (although the discussion ends up being mostly RStan installation issues)

> [@Choosing the new Stan compiler's implementation language](https://discourse.mc-stan.org/t/choosing-the-new-stan-compilers-implementation-language/6203):
>
> Hey all, @sakrejda asked for a write-up for how we thought about which language to choose. Here are the desiderata for language features when choosing a language to write a compiler in, some of which are specific to the needs of Stan given that we essentially create desktop apps (vs cloud something something). Pattern matching - this makes tree transformations first-class in a language, enabling you to write compiler phases much more easily. Fun - we want something that will inspire programme…
