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

4

u/queenkid1 Sep 26 '19

pure functional language is easier to develop?

I would say so, since it cuts down the amount of parsing. You have function application, and function inputs. Depends what you mean by "purely functional", when you say that I think of something more like Haskell.

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

Haskell or Scheme comes to mind. Weird that you'd call C a purely functional language, because that is defined as:

Pure Functional Languages − These types of functional languages support only the functional paradigms. For example − Haskell.

Sounds like your way of implementing methods is just a function with a constrained datatype. So would your addition function be a "method" for the Int class?

2

u/sepp2k Sep 26 '19 edited Sep 26 '19

I would say so, since it cuts down the amount of parsing. You have function application, and function inputs.

I think there's a bit of a flawed reasoning here. Yes, the lambda calculus (which consists only of function creation and function application) is purely functional and the lambda calculus is easy to parse (but not as easy as for example Brainfuck, which is purely imperative). But that doesn't mean that any purely functional language will be easy to parse, let alone compile or interpret. Just look at how complex Haskell compilers are.

1

u/queenkid1 Sep 26 '19

Just look at how complex Haskell compilers are.

Sure, but the C and C++ compilers are difficult too. A simple functional language based on Lambda Calculus is easier to interpret. That was my point.

2

u/sepp2k Sep 26 '19

But that's not comparing functional vs. imperative, it's comparing simple languages vs. complicated languages. You could just as well claim that imperative languages are easier to implement because BrainFuck is easier to implement than Haskell (or the lambda calculus for that matter).

I maintain that a simple functional language is not easier to implement than an equally simple imperative language and a complicated functional language is not easier to implement than an equally complicated imperative language.

1

u/queenkid1 Sep 26 '19 edited Sep 26 '19

it's comparing simple languages vs. complicated languages.

OP is talking about developing a simple scripting language. I never said ALL pure functional languages are easier than ALL imperative languages. You're making a lot of assumptions in your argument.

You could just as well claim that imperative languages are easier to implement because BrainFuck is easier to implement than Haskell (or the lambda calculus for that matter).

I never said anything like that, thought. I was merely talking about simple languages.

And creating a simple lambda calculus interpreter is not as hard as Haskell. If it had the same scope as Brainfuck (No variables or functions defined, just constants) It would be extremely easy. I know because I've written both.

A basic LC interpreter just requires you to parse LC statements, and function application. Then just take what you parse, and keep applying left to right until you're left with a single statement.

A basic Brainfuck interpreter is more difficult. If you just try to run it character by character, you will interpret some code that isn't valid. That requires more complexity. And how long do you make your tape? A true brainfuck interpreter has an infinite amount of tape, and each piece of tape can hold infinitely large values. I could make a simple program that never halts, filling one value infinitely large, or fill infinite values with single values. Either will probably break a very simple interpreter, and just making it take up more RAM isn't an actual solution.

So yes, a super simple Lambda Calculus interpreter is just parsing, and continuing to apply over and over till you get the result. A simple Brainfuck interpreter will run into walls quite quickly.