Feedback, resources, and information for a declarative programming language

I was thinking about some of the concepts underlying the new language. At first it was some kind of toy, but now I wonder if it can mean anything. I am posting this question to Stack Overflow to find out if this has been done before, and if I can get any feedback, ideas or other information.

I started thinking about it mainly after reading Jonathan Edward's presentation on declarative programming . Then I mixed it with some of my old ideas and what I saw in modern languages.

The main idea of ​​declarative programming is what versus how. However, I have heard this many times, so it seems like it almost always resembles the word “interesting,” where it actually doesn't tell you anything, which is frustrating.

In Jonathan Edward's version, he first began by emphasizing a lazy assessment . This has some interesting implications, namely functional reactive programming (FRP) . Here is an example of FRP with animation (using the syntax I compiled):

x as time * 2 // time is some value representing the current time
y as x + (2 * 500)

new Point(x, y)

, , . D "" "" . - , . . , , .

, . time. time, x, y, , , new Point(x, y) . (2 * 500) . , , , . , :

(x ^ 2) + 3x + 5
(4 ^ 2) + 3x + 5 = 16 + 3x + 5 = 21 + 3x = 3(7 + x)

, , , . - . , . , , , . , , . . . . , :

void main ()
{
    String input = "";

    writeln("Hello, world!");
    writeln("What your name? ");

    input = readln();

    writeln("Hello, %s!", input);
    writeln("What your friends name? ");

    input = readln();

    writeln("Hello to you too, %s!", input);
}

bind , , begin . mutable , , . , " " .

program:
    mutable step := 0

    bind begin:
        writeln("Hello, world!")
        writeln("What your name? ")
        ++step

    bind readln() as input when step = 1:
        writeln("Hello, %s!", input)
        writeln("What your friends name? ")
        ++step

    bind readln() as input when step = 2:
        writeln("Hello to you too, %s!", input)

-, . step . , :

program:
    bind begin:
        writeln("Hello, world!")
        writeln("What your name? ")

    bind readln() as input:
        writeln("Hello, %s!", input)
        writeln("What your friends name? ")
        yield // This just means the program jumps to here instead of at the beginning
        writeln("Hello to you too, %s!", input)
        halt

. . , , ?

, :

class VideoManager:
    bind begin: // Basically a static constructor, will only be called once and at the beginning
        // Some video set up stuff

    bind end: // Basically a static destructor
        // Some video shut down stuff

class Input:
    quitEvent     as handle // A handle is an empty value, but can be updated so code that bound to it changes.
    keyboardEvent as handle(KeyboardEvent) // This handle does return a value though
    mouseEvent    as handle(MouseEvent)

    // Some other code manages actually updating the handles.

class Sprite:
    mutable x := 0
    mutable y := 0

    bind this.videoManager.updateFrame:
        // Draw this sprite

class FieldState:
    input  as new Input
    player as new Sprite

    bind input.quitEvent:
        halt

    bind input.keyboardEvent as e:
        if e.type = LEFT:
            this.player.x -= 2
        else if e.type = RIGHT:
            this.player.x += 2
        else if e.type = UP:
            this.player.y -= 2
        else if e.type = DOWN:
            this.player.y += 2

, , - , . , , , Python. , , , , , goto : . if-then-else, , goto , , , . , , .

, , . , , , , , . , , .

, . . , , ( 2 , ), . , , .

, . :

int add (int a, int b)
{
    return a + b;
}

, add int, ? , int. . , , , , - . , , . , , + → :

  • + →
  • + →
  • + →
  • + →
  • + + →

. , . ? , . , - , - . . :

(x ^ 2) + 3x + 5
(4 ^ 2) + 3x + 5 = 16 + 3x + 5 = 21 + 3x = 3(7 + x)

, . add , . , , .

. , , . , , , .

+3
1

Haskell.

Haskell , - . , , Haskell , .. , , .

, , Haskell , IO.

, . Haskell monads, , , bind (>>= ), .

, IO: ... IO , - . IO

do
    putStr "Enter your name: "
    name <- getLine
    putStrLn ("Hello " ++ name)

,

(putStr "Enter your name: ") >>
(getLine >>= \name ->
 putStrLn ("Hello " ++ name))

bind/>>= . , , , - FRP.

Haskell Stackoverflow; . , , , , .

+2

Source: https://habr.com/ru/post/1777160/


All Articles