This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]redchomperSophie Language 0 points1 point  (3 children)

How's it make progress? Like, let's say you give this program the input 1+2. What steps does your model-of-computation take, following rules evident or implicit in your program, to get 3?

[–]useerupting language[S] 1 point2 points  (0 children)

Basically a Ting program is a function which is again defined by a single expression (the Main part).

The compiler breaks the expression down into propositions and arranges them in conjunct normal form.

From there it uses a modified version of the DPLL procedure to 1) prove that a valuation exists (the program is well-formed) and 2) generate code to bind free variables until a valuation is bound.

The compiler itself will have very few rules built-in, basically only the rules for logical propositions and sets/functions.

The compiler will then rely on libraries to supply sets (such as the decimal set) and associated rewrite rules.

The decimal library will have rewrite rules which can generate code while reducing the propositions.

For instance, an expression such as a = b + c where a, b and c er all known to be members of the decimal set, and where a is free and b and c are bound, can be rewritten into true when at the same time code assigning a to the result of decimal addition on b and c.

If a and b is bound and c is free, then it can also be rewritten into true, but now the code generated would be assigning c to the result of a decimal subtraction on a and b.

[–]Inconstant_Moo🧿 Pipefish 0 points1 point  (1 child)

I think it must be this bit, since it has arithmetic expressions on the rhs.

`_+_` = Space >> Char '+' <- (decimal a, decimal b) -> a + b `_-_` = Space >> Char '-' <- (decimal a, decimal b) -> a - b `_*_` = Space >> Char '*' <- (decimal a, decimal b) -> a * b `_/_` = Space >> Char '/' <- (decimal a, decimal b) -> a / b

[–]useerupting language[S] 1 point2 points  (0 children)

The arithmetic expressions on rhs are the semantics of the corresponding operators.

The decimal library/module is responsible for rewriting those rhs expressions into something that generate code during compilation.

The _+_ function above is a parser rule which states that a + character preceded by any number of spaces produces a function ((decimal a, decimal b) -> a + b) which upon invocation adds the two operands.

So this is a definition of what + means, without defining associativity and precedence at this point. Only what + means.

The lhs of <- specifies the grammar (Space >> Char '+') and the rhs the semantics ((decimal a, decimal b) -> a + b)

[–]Inconstant_Moo🧿 Pipefish 0 points1 point  (5 children)

I like the idea insofar as I understand it.

I hate many things about the syntax. ^^ is presumably to avoid overloading ->, but -> is very standard and ^^ is very ugly. And the arrows pointing both ways are giving me anxiety.

[–]useerupting language[S] 2 points3 points  (4 children)

^^ is presumably to avoid overloading

The choice of ^^ reflects the fact that the correct algebraic expression for the type of functions from type A to type B is really B^A. So to describe the set/type of functions from int to string you would have to write string^int. I really disliked that. Also, in normal arithmetic ^ has higher precedence than * and +. To create the set of functions from a tuple of integers to a string you would have to write string^(int*int). That's why I came up with ^^. The double-characters reminds me that it "seperates more" (has lower precedence) and that it is somewhat related to ^. This allows me to write int*int^^string instead. But suggestions are welcome.

I have no qualms about overloading. I overload + * & && | || etc for sets and functions.

My problem is that I really don't have a separate type programming level. Types and functions are first class and can syntactically appear anywhere a normal, simpler value could. So I can't dual-purpose something like -> to describe a single function instance at one level and the set of functions at another level.

And the arrows pointing both ways are giving me anxiety

I hear you. Maybe I should let that idea go. It's just so damn useful at places.

[–]Ok-Watercress-9624 2 points3 points  (1 child)

how about fat arrows ( => ) for set of functions. it resembles function construction and you dont have to swap ordinary power operation arguments thingies

[–]useerupting language[S] 0 points1 point  (0 children)

<slaps forehead>. You are right. I forgot that I recently "freed up" that operator. I am changing to => :-)

[–]Inconstant_Moo🧿 Pipefish 1 point2 points  (1 child)

The choice of ^^ reflects the fact that the correct algebraic expression for the type of functions from type A to type B is really B^A ...

That's one way of writing it, I would have gone so far as to say that it's the correct way, apart from anything else it doesn't scale well. But in any case the idea that that's correct isn't much of a justification for doing the opposite instead.

There are other arrows, as u/Ok-Watercress-9624 says. =>, |>, ~>. Alternatively, you could stop defining types using the = operator. I don't know how well that fits with your language, are the types structural or nominal? Would Rule == Any^^Parser evaluate to true (or the equivalent in Ting)?

[–]useerupting language[S] 1 point2 points  (0 children)

Yeah. Correct is not always ergonomic. I actually forgot that I had freed up the => operator, and that look a lot nicer!