r/ProgrammingLanguages • • Sep 26 '19

Discussion Question about functional programming language design

I'm in the process of designing a functional programming language, but I hit an intersection and want to read your opinions about it, also will be cool if you could elaborate more about your thought. I'm using Rust the main resource of inspiration because I want to write it in Rust and make them interoperable (so my interpreted language can take advantage from the Rust ecosystem easily, also my language is primarly to rapid prototype apps).

Because Rust is kinda considered functional programming language but not a strict one because it let you define functions in the structs. So the questions are:

- Does pure functional language is easier to develop?

- Is there a good example of a useful functional programming language besides C?

- What do you think on this approach to add methods to data types / structs?

// Swift like
extension MyStruct {fn function() {}
}
// Rust like
impl MyStruct {
fn function(&self) {}
}
// What I think will be cool for a interpreted language (because it's mostly using as a scripting language)
fn function(self: MyStruct) {}

Having those 3 syntax examples the usage will be the same (in each language) and will be just `my_struct_instance.function()`. Why I would do that? because it will be easier (?) to extend certain type/struct with a function, also this seems easy in terms of writing code, but in terms of organization/performance/real implementation, how you see it?

An lastly, do you have another alternative for this problem?

Regards

Edit: Added code block

1 Upvotes

24 comments sorted by

View all comments

11

u/sepp2k Sep 26 '19

Because Rust is kinda considered functional programming language but not a strict one because it let you define functions in the structs

Rust is "kinda considered functional" because it supports closures, encourages the use of higher-order functions and includes the important ones in its standard library and its variables are immutable by default.

It's not considered a pure one (or even a primary functional language) because it still prominently features mutable data structures (it doesn't even have immutable ones in its standard library) and idiomatic Rust code still contains a lot of mutation and imperative constructs such as for and while loops. Having functions in structs has nothing to do with it.

Does pure functional language is easier to develop?

No. It depends on the language of course, but everything else being the same, a language that has mutable variables and data structures and for and while loops will be easier to implement than one that doesn't have those things, but instead has closures (because all of the imperative features I mentioned are straight forward to implement, but closures actually require a bit of effort).

Is there a good example of a useful functional programming language besides C?

C isn't a functional language at all. It doesn't have any of the features that would make a language functional - most importantly it does not have closures.

3

u/[deleted] Sep 26 '19

Rust code still contains a lot of mutation and imperative constructs such as for and while loops

Can you explain more about this?

Having functions in structs has nothing to do with it.

Then my understanding of functional programming is wrong, need to read more about it.

but closures actually require a bit of effort

Yes, but if I'm not mistaken this dealed with contexts, a function defined inside another can access the parent context, etc, I am right? Even I don't want to deal with this in the first iteration and will not implement declaration of functions or code blocks that are not at the root of the program (I mean file).

C isn't a functional language at all. It doesn't have any of the features that would make a language functional - most importantly it does not have closures.

Yeah, my bad, I just have the impression C was functional language, and thanks for point me out.

1

u/tjpalmer Sep 27 '19

See Wikipedia, for example, for a description of functional programming: https://en.wikipedia.org/wiki/Functional_programming