Higher order programming

BlitzMax Forums/BlitzMax Programming/Higher order programming

Warpy(Posted 2008) [#1]
I've been on a bit of a functional programming fugue this week, which those of you who watch the code archives will probably have noticed.

Here's the result. It's called Masala after Haskell Curry and Haskell and Curry are already programming languages.

I've implemented the following features:

- higher-order functions, i.e. functors that take functions or other variables as input and return a function.
- lazy evaluation, so things are only evaluated when they need to be.
- function currying, which is a functor which applies some given parameters to a function and returns another function which takes the rest of the parameters it needs.
- a very simple scope system, for looking up variables.
- algebraic data types, so you can define a type like 'Person (String name, Integer age, String hometown)' and then pass around the constructor for that type and perform functions on it.
- the beginnings of a generic function type so you could feasibly write a scripting language on top of this
- an arbitrary precision integer type for big computations.

I had a go at writing a parser for a Haskell dialect using this but I tried to be too clever and got lost. I might have another go later with much simpler syntax.

I know this isn't the usual fare for these forums, but it's quite interesting to see how far BMax can be stretched. If we had operator overloading it could look very nice indeed, because at the moment there's a lot of faff and keypresses involved in making it work.


johnnyfreak(Posted 2008) [#2]
Interesting! I love functional programming, i'll take a look in masala ;)