john skaller | 3 Jun 13:00 2015

Re: [felix] Active programming revolution

On 03/06/2015, at 6:41 PM, srean wrote:

> This ought to be a blog post.

Blogs are too much work. No one reads mine anyhow.
No one reads the email either but its easier to do them.

> And if you are still in touch with Stepanov, I think he would be quite excited to read this.

I'm not in touch with anyone.

john skaller

john skaller | 3 Jun 02:10 2015

Active programming revolution

There is about to be a major paradigm shift in the world of
programming: Active Programming.

I have spent over 15 years developing a strong enough core to
actually implement what the original commercial job required,
and it leads to complete paradigm shift: Active Programming.

Here's what happens. in the old world we have imperative
stateful programming languages with expressions thrown in.
Control flow was king. The pairing of data flow and control
flow was broken by C and similar languages with the notion
of functions using the machine stack (data and control passed
together on the stack).

On the other side, functional programming touted declarative
specifications based on mathematics, and because of the mathematical
basis this style is ostensibly easier to analyse because of the wealth
of mathematical skills and knowledge available. But purely functional
languages just don't cut it in practice: performance is one issue but
the simple reality is recursion is too hard to understand and doesn't
match reality.

Active programming MERGES stateful imperative programming
and functional programming into a single paradigm. The paradigm
is fully declarative and so amenable to analysis. 

At present I am just doing the basics. The simplest form is a pipeline:

  #((1,2,3,4,5).iterator |-> (fun (x:int) => x + 1) |-> (fun (x:int) => x * x) |-> println[int]);

(Continue reading)

john skaller | 28 Apr 03:26 2015

function product

This works:

fun \times[u1,u2,r1,r2] (f1:u1->r1,f2:u2->r2) : u1 * u2 -> r1 * r2 => 
    fun (x1:u1,x2:u2) => f1 x1, f2 x2;

fun \otimes[D1,C1,D,C] (f1:(D1->C1), f:(D->C)) : (D1 ** D) -> (C1 ** C) =>
  fun (a:D1 ** D) : C1 ** C => match a with
   | (x1,,x) => f1 x1,,f x 

fun i2s (x:int)=>x.str+"!";
fun i2i (x:int)=>x+1;

var fs = i2s,i2i,i2s,i2s;
var r = fs.0 \otimes fs.1 \otimes (fs.2 \times fs.3);

println$ r (1,2,3,4);

But it isn't pretty. The final \times is requires as the ground case
(and need parens because of grammar issues, \otimes is right assoc).

However \prod (f,g,h) still can't be defined, i have ravel (f,g,h) in the 
library for up to 5 cases.

john skaller

(Continue reading)

john skaller | 26 Apr 01:16 2015


I'm changing the display rules for mathmode.

First, { } will not be displayed in mathmode.
Use \{ \} if you want to see something.

Second, a Felix identifier will usually emit


which will cause it to be typeset in teletype font, similar to the usual
program text font I hope.

Next, I am thinking instead of the above, if you specify a font operator:

	\mathcal { ... }

that overrides \mathtt. In fact I think a stack of fonts will be maintained.

Fourth, i think I will make a single character identifier an exception
and typeset that using \mathit.

This means \mathit and \mathtt probably should NOT be used as operators!

In general formulae like

	\mathcal X
	\mathcal {x + y}
	\mathcal (x + y)

etc affect typesetting and are ALSO Felix functions. So take care
(Continue reading)

john skaller | 25 Apr 01:20 2015

Re: [felix] stumped

On 25/04/2015, at 3:44 AM, Shayne Fletcher wrote:

> On Fri, Apr 24, 2015 at 1:07 PM, john skaller <skaller <at>> wrote:
> fun ravel[u1,u2,r1,r2] (f1:u1->r1,f2:u2->r2) : u1 * u2 -> r1 * r2
> ‚ÄčNeat function.

But I want

	ravel[D1,C1,D2,C2,D3,C3,....D9,C9] (f1:D1->D2, f2:D2->C2 ... f9:D9->C9): D1 * D2 *..D9 -> C1 *C2 .. C9;

I can do

	str[D1,D2, ... D9] (p1:D1, p2:D2,.. p9:D9):string 

given str:T->string which should be harder, since it involves polymorphic recursion.

However the latter is just a string fold of the individual components. 
However I don't think Ocaml can do this using any method,
and I'm not sure Haskell can either (in fact Haskell doesn't
even HAVE tuples AFAIK)

Felix and C++ can do it.

However I can't generalise it, even if you want a bool fold of some property,
i.e. fix the return type.

The ravel doesn't need any typeclass, it can be done with a purely
(Continue reading)

john skaller | 24 Apr 19:07 2015


I am stumped at the moment defining certain operators on tuples.

If you look at src/lib/std/datatype/tuple.flx you will see there is general way
to apply a function

	T -> K
	T * T -> K

to a tuple, where K is a constant type. For example 

	T -> string         // Str
	T * T -> bool  // Eq

are defined. See also that we can do

	F T0, F T1 ... F TN -> F (T0, T1 .. TN)

in some cases, such as in src/lib/std/algebra/set.flx we can "almost" define

	\otimes (set_form[T0], set_form[T1],.. set_form[TN] )

I say almost because actually we can do 

var x = { x: int | x > 0} \otimes { x: double | x > 0.0} \otimes { x:string | x > "H" };
println$ (24,3.2,"Hello") \in x;

but this is right associative. What I REALLY want to define is:

	\otimes (s1,s2,s3);

(Continue reading)

john skaller | 24 Apr 09:56 2015

Maths DSSL

The below will give cute display in Felix code, if displayed by flx_web.
The "font" operators are just ordinary functions .. so you have to actually
define them if you want stuff to work!

// ordinary and mathmode
var x = X; // ordinary
var x = \(X\); // mathmode

// these are all TeX commands so x ^ \font y
// typesets correctly: note \sin is an OP symbol
// so x ^ \sin y fails, and x ^ \Gamma y works
// since \Gamma is an ORD, but the y is not raised.

// font operators
var x = \(\mathrm X\); // mathrm
var x = \(\mathit X\); // mathit
var x = \(\mathfrak X\); // mathfrak
var x = \(\mathbb X\); // mathbb
var x = \(\mathbf X\); // mathbf
var x = \(\mathcal X\); // mathcal
var x = \(\mathscr X\); // mathscr
var x = \(\mathsf X\); // mathscr
var x = \(\mathtt X\); // mathtt

// modifiers
var x = \(\acute X\); // acute
var x = \(\check X\); // check

var x = \( x ^ \binom {\mathtt x} {\mathtt y} \);
(Continue reading)

john skaller | 3 Apr 20:18 2015

negated comparisons

Next commit, you can write:

	x not < y


	\( x \not\less y \)

Both not and \not mean the same, however not is printed "not" as written,
whereas \not IN MATH MODE ONLY will cause the following TeX operator
to be negated by strikeout.

We need this because whilst TeX defines


it does not define \nsubset. You have to write \not\subset.
Note \not\subseteq will work as well, however, the special
form \nsubseteq is provided to make the struck out symbol
more beautiful.

Do not confuse \not with \lnot. The latter is boolean negation operator,
it applies to expressions, and it has looks like logic not symbol,
this has a different precedence than "not" applied to an expression.

Do not write \not expr, it will neither work, nor typeset correctly.
use \not to cancel comparison operators.

john skaller
(Continue reading)

john skaller | 30 Mar 13:01 2015

Re: [felix] fix patterns

On 30/03/2015, at 7:18 PM, Martin DeMello wrote:
>> This won't work as you might expect because in that pattern NIL is a variable.
>> Easy to miss. You have to write
>>        | A (_, #NIL) => ..
>> to tell the parser the NIL is a type constructor.
> Would it be hard to make this an actual warning, viz
> warning: variable NIL has same name as constructor. did you mean #NIL?

I don't know, it could be quite hard. It would mean at least doing a lookup
on EVERY variable name used. The problem is that the "desugaring"
of pattern matching is done long before it is possible to do any lookup.
So by the time the compiler comes to bind the code, it has no idea
it's dealing with a pattern match variable.

Pattern matches are basically macros. You can, in fact, invent your own.
It basically goes:

	if  (!_match_ctor_CTOR (arg)) goto next_case;
	var arg1, arg2 = _ctor_arg_CTOR (arg);

	// do handler

	goto endmatch;
(Continue reading)

john skaller | 30 Mar 04:14 2015

fix patterns

Using a nice tool, flx_batch_replace:

/usr/local/lib/felix/felix-latest/host/bin/flx_batch_replace -v src '.*\.(flx|fdoc)'
'fixup/src/${0}' '\?([A-Za-z][A-Za-z0-9_]*)' '\1'
cp -r fixup/src/* src

Be interested how to do that with standard unix tools.

I do note the inconsistent replacement notation ${group} for files,
but \group for strings. Internally these search and replace operations
are in fact similar. I put the ${group} in because its so hard to type \1
inside a string and get the quoting right. OTOH in bash ${1} is the first
command line argument so that needs to be quoted right too.

john skaller

Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now.
john skaller | 29 Mar 20:42 2015

review of brackets

Apart from in structs, unions, and function/procedure definitions,
here is a possibly incomplete catalogue:

	{ expr } --> function returning expr
	{ stmt; stmt; expr } -> function returning expr
	{ stmt; stmt; return expr; } -> function returning expr
	{ stmt; stmt; } --> procedure
	{ pattern : type | expr } --> set form

	( expr ) --> expr
	( expr, expr ) --> tuple
	(x=expr, y=expr) -> record
	struct {x = expr; y=expr; } -> record (deprecated)
        ( stmt; stmt; expr ) --> expr // means #{ stmt; stmt; expr }
	() --> unit tuple
	( var expr ) --> expr (eagerly evaluated, same as (let x = expr in x))

I am looking at some more short forms, such as


like C. It's not clear these will work, since they're ambiguous.
An alternative (from COBOL):

	if x perform stmt;
	while x perform stmt;

Note these are already allowed:

(Continue reading)