Pure: a modern functional programming language based on term rewriting
agraef.github.io
agraef.github.io
> As a bonus, you also get "constructors with equations" for free. E.g., suppose that we want lists to automagically stay sorted and eliminate duplicates. In Pure we can do this by simply adding the following equations for the : constructor:
> x:y:xs = y:x:xs if x>y; x:y:xs = x:xs if x==y;
> [13,7,9,7,1]+[1,9,7,5];
[1,5,7,9,13]
(The point about this global override is addressed later. The rewriting can be lexically scoped.)---
One important difference between this and quotient-inductive types is that there are examples of "types with equations" which cannot be expressed as a rewriting system, e.g., free groups.
It's a still a cool feature to have this built into the language.
But in the example, the list is built by adding two lists. This means that in the example, it uses insertion sort which like bubble sort is O(n^2).
One way of getting better performance "by default" is to construct lists with constructors for empty list, singletons and append and then adding equations to ensure that the resulting binary tree is balanced.
> nonfix nil;
> insert nil y = bin y nil nil;
> insert (bin x L R) y = bin x (insert L y) R if y<x;
> = bin x L (insert R y) otherwise;
> foldl insert nil [7,3,9,18];
bin 7 (bin 3 nil nil) (bin 9 nil (bin 18 nil nil))
Lines beginning with > are what you type; the extra line is the evaluated response.So the language is dynamically typed and it seems you don't need to declare constructor symbols that take arguments. A constructor seems to be something that is irreduceable according to the rules already defined, whereas a function is something with reduction rules available.
I'm not sure I agree with the rationale for the dynamic typing. The designer says it means the language supports an arbitrary degree of polymorphism, but obviously it means it accepts invalid programs with undefined behavior. I think by adopting a Typescript style system you'd get huge advantages ("Typescript-style" meaning structural, adhoc and evolving towards correctness, rather than meeting the wrong design constraints upfront). But I'm still not at all sure my intuitions for this language are useful.
Anyway that's my review in five minutes. I hope someone writes something relevant here.
Congratulations! This is the most entitled sentence in all of computing. The prize ceremony will be held at your house, tomorrow. I'll be casting a statue of gold for you, but first I have to rebuild all the software between me and the CNC machine in Coq or Typescript.
That said, I guess it's much better than nothing at all (JS).
Ocaml also has ad-hoc products (objects and tuples).
If I recall correctly, Clean is BSD licensed. By 'proprietary' do you mean their main source of funding was building proprietary solutions over what they release open source ? They did seem they were more of a 'windows first' group, but I may be wrong about that.
Too bad. Clean's graph rewriting and unique types approach was very good and practical direction for functional programming.
Declaring unique types allows functional paradigm in much lower lever programming and it's easy to grasp. (it's part of the linear types paradigm).
Why Pure?
Thanks to LLVM, Pure offers state-of-the-art JIT compiler technology in an interactive environment, and makes it easy to interface to C in a direct fashion. Recent releases also provide the ability to directly import LLVM bitcode modules into Pure scripts and to inline code written in various languages (currently C/C++, Fortran and Faust). Scripts can also be compiled to standalone native executables (they are also executed during compilation, which makes it possible to employ partial evaluation techniques).
Pure has an efficient MATLAB-like, GSL-compatible matrix type which makes it easy to interface to languages and libraries for doing numeric computations and digital signal processing. In particular, Pure interfaces to (GNU) Fortran, Octave and Grame's Faust, and you can directly invoke GSL routines on Pure matrices. In a way, this is like having Haskell, Octave, DSP programming and the term rewriting capabilities of a computer algebra system under one hood.
It goes without saying that Pure can be used used for mathematical applications, but there's also a growing collection of extension modules for GUI, graphics, multimedia, database and web programming which makes Pure useful as a kind of algebraic/functional scripting language for a variety of purposes.
I'm sure there's something Pure was designed to solve which could be brought forward as something it solves beautifully. It's not really obvious what that is from this text, though.
While not a production ready language, I'm really surprised it or something like it doesn't get more attention.