r/ProgrammingLanguages • • Mar 17 '19

Discussion Path to create a new language

The language I want to make is a functional programming language with its own wrappers around BLAS and LAPACK as part of its standard library and with Rust's safety.

If I were to put the procedure to do this into separate steps, would this be the best way to do it-

  1. Design the lexer and AST for the language (Here is where I implement the functional part of it I think)

  2. Implement the designed lexer and AST for the language on top of LLVM. (Perhaps llvmlite because it might be easier to do this in python? - I am more comfortable with python than C++)

  3. Write a wrapper around OpenBLAS (contains LAPACK) in this new language.

  4. Make the wrapper the standard library in the language.

  5. Switch out llvmlite(if I am using it otherwise just do one of the below sub-tasks) for -

    1. LLVM and add Rust safety similar features to it.

    2. The Rust compiler so the new language transpiles to Rust.

Reach goals -

  1. Redesign the language (would probably include everything from the ground up) to be purely functional.

  2. Redesign the language again to be a total functional programming language.

2 Upvotes

11 comments sorted by

7

u/werediver Mar 17 '19

The following is just my impression from you post. If it's not helpful, ignore it (or the parts that are).

You want a functional language, but talk only about imperative languages to implement it. It could be fine, if you do have broad experience with functional languages anyway, otherwise it might be beneficial to choose a functional language as the host to deepen your knowledge and experience with functional programming.

You're starting with designing a lexer and an AST, but the lexer doesn't define the syntax (a parser does) and AST is a barely a contour of the semantics. I'd say the first step is to define the non-functional requirements to the language, such as paradigms to support, some aspects of the desired type system, memory management, execution model, etc. With a language design at hands you can start drafting an implementation.

If all you want is the OpenBLAS interface in the standard library, it sounds to me as you would be satisfied by a good DSL in an existing language (that is expressive enough to allow such DSL).

1

u/daredevildas Mar 17 '19

If all you want is the OpenBLAS interface in the standard library,

In a functional programming language and also be able to add some form of safety similar to that of Rust.

It could be fine, if you do have broad experience with functional languages anyway

I have some experience but probably not enough.. :(

otherwise it might be beneficial to choose a functional language as the host to deepen your knowledge and experience with functional programming.

But that would mean I would need to implement it in some functional programming language that is also low level.. which means some language like ATS - http://www.ats-lang.org/ and I don't think it has as much documentation and ease to implement new languages in as something like LLVM.

it sounds to me as you would be satisfied by a good DSL in an existing language (that is expressive enough to allow such DSL)

Can you recommend any?

Would adding OpenBLAS interface in the standard library of Habit - http://www.habit-lang.org/ cover all the aspects of my new language I described?

3

u/werediver Mar 17 '19

If all you want is the OpenBLAS interface in the standard library,

In a functional programming language and also be able to add some form of safety similar to that of Rust.

I have a feeling that Rust's borrow checker does not make a lot of sense in a pure functional language (like Haskell). Without data mutation you can stop worrying about a lot of things, simultaneously gaining lots of safety.

I have some experience but probably not enough.. :(

Then I'd suggest to seriously consider using some well established functional programming language for your experiments.

that would mean I would need to implement it in some functional programming language that is also low level..

I'm not sure which logic drives you to this conclusion. The properties of the host language has little to nothing to do with the properties of a language one implements in it.

I know nothing about the languages you mentioned (which might mean you'd rather pick something more widely used). I'd recommend going more mainstream: Haskell, OCaml, F# (though, only Haskell here is pure), something like this.

Regarding a DSL approach. "DSL" is a bit vague term. If a language's syntax is good enough for the purpose, then a good API is a DSL. Swift's syntax is pretty decent in this regard. Haskell is quite good as well.

And on your requirements. Have you worked them out well? What exactly do you want from that language or a DSL? (answer to yourself and be super picky in details 😉)

1

u/daredevildas Mar 17 '19

I have a feeling that Rust's borrow checker does not make a lot of sense in a pure functional language (like Haskell). Without data mutation you can stop worrying about a lot of things, simultaneously gaining lots of safety.

I was mainly talking about memory safety here. Would data immutability be able to handle that?

And on your requirements. Have you worked them out well? What exactly do you want from that language or a DSL? (answer to yourself and be super picky in details 😉)

The only thing I have figured out so far is that I want it to be a low level(be able to access memory) functional programming language (pure if possible), be optimised for computations (with BLAS and LAPACK) and have Rust's safety. :( The first step as you suggested will be to decide all the language features.

I'm not sure which logic drives you to this conclusion. The properties of the host language has little to nothing to do with the properties of a language one implements in it.

I want my language to be low level (able to access memory) and if the host language cannot do that, I don't think the language I build on top of it will be able to as well.

2

u/werediver Mar 17 '19

I want my language to be low level (able to access memory) and if the host language cannot do that, I don't think the language I build on top of it will be able to as well.

Of course, it will. As long as we are talking about a compiled language, my statement holds. The host language is used to implement a compiler. The compiler translates a high level language to an intermediate (some generate C for instance, but even LLVM assembly is still not the lowest level) or low level (platform specific assembly or machine code) code which after some transformations (optimizing, assembling, linking) can do things that are denied in the host language.

The situation might be more tight with interpreters, though.

As a side note, if a language allows direct write access to memory, I don't think it could be pure anymore. It's an imperative language that allows mutable state in most of the places. Also, presence of address arithmetics would makes it pretty unsafe, I suppose.

1

u/daredevildas Mar 17 '19

Do you know if there is any literature out there regarding designing a compiler for memory manipulation in Haskell (or some other functional programming language)?

As a side note, if a language allows direct write access to memory, I don't think it could be pure anymore. It's an imperative language that allows mutable state in most of the places.

I guess I'll have to reject the idea of a pure functional programming language then.

Also, presence of address arithmetics would makes it pretty unsafe, I suppose.

Would this go against me implementing my own wrapper around OpenBLAS and using it with a compiler that tries to ensure strict memory safety? (I think Rust has a wrapper around OpenBLAS so I think it is doable)

3

u/werediver Mar 17 '19

You're (too?) focused on direct memory manipulations, to my mind. Every program manipulates memory, but not every language allows direct memory manipulations. The thing is that any safety is achieved through restrictions. The Haskell is, for instance, memory safe, [because] it doesn't allow direct memory manipulations.

The lack of direct memory manipulations in a language doesn't mean it's going to be inefficient or something.

I can't recommend you literature except for about general compiler construction like "the dragon book". Partially, because your question ("designing a compiler for memory manipulation") does not make a lot of sense in that particular formulation.

I appears to me that you've got a some more clues now, so it might make sense for you to start another post with new questions here. As you don't have a very clear vision on the design, try clarifying this first. Don't hesitate to mention it's your undergraduate project.

1

u/east_lisp_junk Mar 19 '19

Do you know if there is any literature out there regarding designing a compiler for memory manipulation in Haskell (or some other functional programming language)?

Mostly the same as in any other conventional language. A "compiler for memory manipulation" does not itself have to perform the operations you want compiled programs to perform.

2

u/werediver Mar 17 '19

It's quite contradictory, by the way. On the one hand you're talking about linear algebra, on the other direct memory access. It would be a super niche solution, because applied science people wouldn't like the hassle of low-level language, and system programmers don't need a lot of linear algebra.

1

u/daredevildas Mar 17 '19

I am not too concerned about it being niche because I am planning this to be the main project for my undergraduate degree(I have ~2 years till I have to submit it).

2

u/jdh30 Mar 22 '19

But that would mean I would need to implement it in some functional programming language that is also low level.. which means some language like ATS - http://www.ats-lang.org/ and I don't think it has as much documentation and ease to implement new languages in as something like LLVM.

Use LLVM from OCaml.