Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The correctness-by-design duck will bite PHP

The correctness-by-design duck will bite PHP

In this talk, y'all will be introduced to Quack; a type-safe, multi-paradigm, metaprogrammable and extensible programming language which enables you to write consistent and legible code and learn how a language that targets PHP and whose compiler is entirely written in PHP can help you coding better.

Matheus Albuquerque

October 07, 2017
Tweet

More Decks by Matheus Albuquerque

Other Decks in Programming

Transcript

  1. Hello,PHPeste 2017. The correctness-by-design duck will bite PHP • The

    7th of October, 2017. матеус албукерки • @ythecombinator • www.ythecombinator.me
  2. Front-End Engineer @ Beakyn Mobile Development Intern @ Apple Developer

    Academy Evangelist @ Quack Language Contributor @ Lambda I/O, NUG-CE, Golang Brazil, Ionic Brazil and others.
  3. Front-End Engineer @ Beakyn Mobile Development Intern @ Apple Developer

    Academy Curious @ Quack Language Contributor @ Lambda I/O, NUG-CE, Golang Brazil, Ionic Brazil and others.
  4. Front-End Engineer @ Beakyn Mobile Development Intern @ Apple Developer

    Academy Evangelist @ Quack Language Contributor @ Lambda I/O, NUG-CE, Golang Brazil, Ionic Brazil and others.
  5. When it comes to PLT, there’s much awesome stuff happening

    here in ! of which many people out there just have no idea.
  6. Separate each keywords (called tokens) by white space. While we

    separate them, we also assign types to each token (e.g. “T_ECHO” or “T_FOREACH”). Tokenization Parsing Transformation Generation
  7. Tokenization Parsing Transformation Generation Once a blob of text is

    separated into tokens, we go through each of them and try to find a relationship between tokens. By doing this, we start seeing a structure of the code.
  8. Tokenization Parsing Transformation Generation Once we analyze syntax by parsing,

    we transform the structure to something suitable to the final result.
  9. Currying is the technique of transforming a function that takes

    multiple arguments in such a way that it can be called as a chain of functions each with a single argument. - Wikipedia
  10. In computer science, partial application (or partial function application) refers

    to the process of fixing a number of arguments to a function, producing another function of smaller arity. - Wikipedia
  11. Currying always produces nested unary (1-ary) functions. The transformed function

    is still largely the same as the original. Partial application produces functions of arbitrary arity. The transformed function is different from the original – it needs less arguments. - 2Ality
  12. $add = partial(function($x, $y, $z) { return $x + $y

    + $z; }); $a = $add; $b = $add(10); $c = $add(10, 20); $d = $add(10, 20, 30); echo $a(10, 20, 30), PHP_EOL; echo $b(20, 30), PHP_EOL; echo $c(30), PHP_EOL; echo $d, PHP_EOL; https://github.com/haskellcamargo/php-partial-function-application
  13. $add = partial(function($x, $y, $z) { return $x + $y

    + $z; }); $a = $add; $b = $add(10); $c = $add(10, 20); $d = $add(10, 20, 30); echo $a(10, 20, 30), PHP_EOL; echo $b(20, 30), PHP_EOL; echo $c(30), PHP_EOL; echo $d, PHP_EOL; https://github.com/haskellcamargo/php-partial-function-application
  14. $add = partial(function($x, $y, $z) { return $x + $y

    + $z; }); $a = $add; $b = $add(10); $c = $add(10, 20); $d = $add(10, 20, 30); echo $a(10, 20, 30), PHP_EOL; echo $b(20, 30), PHP_EOL; echo $c(30), PHP_EOL; echo $d, PHP_EOL; https://github.com/haskellcamargo/php-partial-function-application
  15. $add = partial(function($x, $y, $z) { return $x + $y

    + $z; }); $a = $add; $b = $add(10); $c = $add(10, 20); $d = $add(10, 20, 30); echo $a(10, 20, 30), PHP_EOL; echo $b(20, 30), PHP_EOL; echo $c(30), PHP_EOL; echo $d, PHP_EOL; https://github.com/haskellcamargo/php-partial-function-application
  16. If your functions are in curried form, that makes it

    more convenient to partially apply them.
  17. A kind of polymorphism in which polymorphic functions can be

    applied to arguments of different types, because a polymorphic function can denote a number of distinct and potentially heterogeneous implementations depending on the type of argument(s) to which it is applied. - Wikipedia
  18. Allows classes and methods to accept types as parameters, meaning

    that classes can be abstracted with respect to types.
  19. A structural type system (or property-based type system) is a

    major class of type system, in which type compatibility and equivalence are determined by the type's actual structure or definition, and not by other characteristics such as its name or place of declaration. - Wikipedia
  20. interface A { value: number } interface B { value:

    number } A "# B $% False &' Nominal Type Systems A "# B $% True &' Structural Type Systems
  21. Pattern matching is not somehow an alternative of switch statement;

    it’s much more like another way of doing dynamic dispatch in OOP. They try to do the same thing: calling a different version of the function based on the dynamic type of the arguments. - Someone over the internet
  22. Pattern matches can act upon ints, floats, strings and other

    types & objects. Method dispatch requires an object. Pattern matches can act upon several different values simultaneously. Method dispatch is limited to the single this case in mainstream languages. Patterns can be nested, allowing dispatch over trees of arbitrary depth. Method dispatch is limited to the non-nested case.
  23. Pattern matches can act upon ints, floats, strings and other

    types as well as objects. Method dispatch requires an object. Pattern matches can act upon several different values simultaneously. Method dispatch is limited to the single this case in mainstream languages. Patterns can be nested, allowing dispatch over trees of arbitrary depth. Method dispatch is limited to the non-nested case.
  24. Pattern matches can act upon ints, floats, strings and other

    types as well as objects. Method dispatch requires an object. Pattern matches can act upon several different values simultaneously. Method dispatch is limited to the single this case in mainstream languages. Patterns can be nested, allowing dispatch over trees of arbitrary depth. Method dispatch is limited to the non-nested case.
  25. Pattern matches can act upon ints, floats, strings and other

    types & objects. Method dispatch requires an object. Pattern matches can act upon several different values simultaneously. Method dispatch is limited to the single this case in mainstream languages. Patterns can be nested, allowing dispatch over trees of arbitrary depth. Method dispatch is limited to the non-nested case.
  26. fn fact(n :: number) *→ number :- match n with

    0 *→ 1 n *→ n * fact(n - 1) end
  27. Mutability is evil! It can set your house on fire,

    kill your cat and buy costumes on e-bay using your credit card! Be careful! - Real world functional programming in JS, by Marcelo Camargo (@haskellcamargo)
  28. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  29. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  30. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  31. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  32. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  33. No nulls. No errors. Just monads. Explicit side-effects Code with

    no side-effects is compile- time optimized Tail Call Optimization over the language AST Pluggable back-ends Syntax-highlighted REPL (which shouts Quack)
  34. 95% of PHP + 5% of Quack ~3 years of

    research over the compiler Self-compiled compiler = ~100KB
  35. Both lexer and parser are finished. Type system in final

    stages. Final code generation tool in progress.
  36. #1

  37. #2

  38. When it comes to PLT, there’s much awesome stuff happening

    here in ! of which many people out there just have no idea.