Rule execution now runs, no tests tho

This commit is contained in:
2022-08-19 12:55:02 +02:00
parent 329dea72b7
commit 891d78c112
30 changed files with 925 additions and 560 deletions

View File

@@ -7,14 +7,14 @@ Hello World in Orchid
```orchid
import std::io::(println, out)
main == println out "Hello World!"
main := println out "Hello World!"
```
Basic command line calculator
```orchid
import std::io::(readln, printf, in, out)
main == (
main := (
readln in >>= int |> \a.
readln in >>= \op.
readln in >>= int |> \b.
@@ -31,7 +31,7 @@ Grep
```orchid
import std::io::(readln, println, in, out, getarg)
main == loop \r. (
main := loop \r. (
readln in >>= \line.
if (substring (getarg 1) line)
then (println out ln >>= r)
@@ -41,7 +41,7 @@ main == loop \r. (
Filter through an arbitrary collection
```orchid
filter == @C:Type -> Type. @:Map C. @T. \f:T -> Bool. \coll:C T. (
filter := @C:Type -> Type. @:Map C. @T. \f:T -> Bool. \coll:C T. (
coll >> \el. if (f el) then (Some el) else Nil
):(C T)
```
@@ -122,9 +122,9 @@ types whose defaults have implmentations based on your defaults.
For a demonstration, here's a sample implementation of the Option monad.
```orchid
--[[ The definition of Monad ]]--
Bind == \M:Type -> Type. @T -> @U -> (T -> M U) -> M T -> M U
Return == \M:Type -> Type. @T -> T -> M T
Monad == \M:Type -> Type. (
Bind := \M:Type -> Type. @T -> @U -> (T -> M U) -> M T -> M U
Return := \M:Type -> Type. @T -> T -> M T
Monad := \M:Type -> Type. (
@:Bind M.
@:Return M.
0 --[ Note that empty expressions are forbidden so those that exist
@@ -134,19 +134,19 @@ Monad == \M:Type -> Type. (
)
--[[ The definition of Option ]]--
export Option == \T:Type. @U -> U -> (T -> U) -> U
export Option := \T:Type. @U -> U -> (T -> U) -> U
--[ Constructors ]--
export Some == @T. \data:T. ( \default. \map. map data ):(Option T)
export None == @T. ( \default. \map. default ):(Option T)
export Some := @T. \data:T. ( \default. \map. map data ):(Option T)
export None := @T. ( \default. \map. default ):(Option T)
--[ Implement Monad ]--
default returnOption == Some:(Return Option)
default bindOption == ( @T:Type. @U:Type.
default returnOption := Some:(Return Option)
default bindOption := ( @T:Type. @U:Type.
\f:T -> U. \opt:Option T. opt None f
):(Bind Option)
--[ Sample function that works on unknown monad to demonstrate HKTs.
Turns (Option (M T)) into (M (Option T)), "raising" the unknown monad
out of the Option ]--
export raise == @M:Type -> Type. @T:Type. @:Monad M. \opt:Option (M T). (
export raise := @M:Type -> Type. @T:Type. @:Monad M. \opt:Option (M T). (
opt (return None) (\m. bind m (\x. Some x))
):(M (Option T))
```
@@ -162,7 +162,7 @@ Add has three arguments, two are the types of the operands and one is
the result:
```orchid
default concatListAdd replacing applicativeAdd == @T. (
default concatListAdd replacing elementwiseAdd := @T. (
...
):(Add (List T) (List T) (List T))
```
@@ -170,7 +170,7 @@ default concatListAdd replacing applicativeAdd == @T. (
For completeness' sake, the original definition might look like this:
```orchid
default elementwiseAdd == @C:Type -> Type. @T. @U. @V. @:(Applicative C). @:(Add T U V). (
default elementwiseAdd := @C:Type -> Type. @T. @U. @V. @:(Applicative C). @:(Add T U V). (
...
):(Add (C T) (C U) (C V))
```
@@ -179,7 +179,7 @@ With the use of autos, here's what the recursive multiplication
implementation looks like:
```orchid
default iterativeMultiply == @T. @:(Add T T T). (
default iterativeMultiply := @T. @:(Add T T T). (
\a:int.\b:T. loop \r. (\i.
ifthenelse (ieq i 0)
b
@@ -191,7 +191,7 @@ default iterativeMultiply == @T. @:(Add T T T). (
This could then be applied to any type that's closed over addition
```orchid
aroundTheWorldLyrics == (
aroundTheWorldLyrics := (
mult 18 (add (mult 4 "Around the World\n") "\n")
)
```
@@ -218,20 +218,20 @@ are searched back-to-front. If order is still a problem, you can always
parenthesize subexpressions at the callsite.
```orchid
(...$pre:(seq 2) if $1 then $2 else $3 ...$post:(seq 1)) =2=> (
...$pre
(..$pre:2 if $1 then $2 else $3 ..$post:1) =2=> (
..$pre
(ifthenelse $1 $2 $3)
...$post
)
$a + $b =10=> (add $a $b)
$a == $b =5=> (eq $a $b)
$a = $b =5=> (eq $a $b)
$a - $b =10=> (sub $a $b)
```
The recursive addition function now looks like this
```orchid
default iterativeMultiply == @T. @:(Add T T T). (
default iterativeMultiply := @T. @:(Add T T T). (
\a:int.\b:T. loop \r. (\i.
if (i = 0) then b
else (b + (r (i - 1)))
@@ -249,7 +249,7 @@ environment and can carry structured data payloads.
Here's an example of a carriage being used to turn a square-bracketed
list expression into a lambda expression that matches a conslist. Notice
how the square brackets pair up, as all three variants of brackets
group nodes.
are considered branches in the S-tree rather than individual tokens.
```
-- Initial step, eliminates entry condition (square brackets) and constructs
@@ -303,4 +303,4 @@ ideas.
- [ ] reactive calculation of values that are deemed to be read more often
than written
- [ ] automatic profiling based on performance metrics generated by debug
builds
builds