Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Type theory in practice

198 views

Published on

After amazing presentation “Propositions as Types” by Philip Wadler, I felt intrigued and lost. What is the type theory? How can I benefit from it as a software engineer? The story of how I end up applying Type Theory in static configurations files like JSON and YAML. What I learn in the process of this experiment, and how it changed my perspective in software design.

Published in: Engineering
  • Login to see the comments

Type theory in practice

  1. 1. Type Theory in Practice Software Engineer Perspective Gabriel Habryn
  2. 2. Agenda. ● Motivation ● Learning Type Theory ● Build toy type system ● Typing judgment, Type rules Type derivation,... ● Takeaways
  3. 3. This is beginner point of view type of presentation!
  4. 4. Motivation.
  5. 5. “Infrastructure as a code”
  6. 6. “Infrastructure as a code”
  7. 7. “Infrastructure as a code”
  8. 8. Research.
  9. 9. Research. - json-schema.org - yaml.org/type - github.com/google/starlark-go - dhall-lang.org
  10. 10. https://github.com/dhall-lang/dhall-lang
  11. 11. Dhall features ● Total - Evaluation always terminates and never hangs or infinitely loops ● Safe - Evaluation never crashes or throws exceptions ● Distributed - Expressions can reference other expressions by URL or path ● Strongly normalizing - All expressions (even functions) have a normal form ● Statically typed - Configurations can be validated ahead-of-time ● Strongly typed - No coercions, casts or subtyping ● Built-in data types - Includes lists, anonymous records and anonymous unions
  12. 12. Motivation?
  13. 13. Fire up 🔥
  14. 14. Prototype.
  15. 15. Prototype. ● Type safe ● Backward compatible ● Self-documenting
  16. 16. Example config.json
  17. 17. Type definition
  18. 18. Type definition
  19. 19. Type definition
  20. 20. Type definition
  21. 21. Type checking
  22. 22. Type checking
  23. 23. Type checking
  24. 24. Backward compatible
  25. 25. … coding time ...
  26. 26. Questions time. ● How to write type checker? ● Can type check regex? ● Can term of a type ReadFileIO do IO?
  27. 27. .... stop this madness.
  28. 28. Specification.
  29. 29. Let’s learn Type Theory
  30. 30. Let's build type system for “calculator”
  31. 31. Syntax
  32. 32. 1+2
  33. 33. 1+2 : Nat
  34. 34. The language of formal specification
  35. 35. Well-formed judgment.
  36. 36. Typing judgment.
  37. 37. Valid and invalid judgements.
  38. 38. Type rules.
  39. 39. Type derivations!
  40. 40. It’s like pattern matching.
  41. 41. Complete source code: https://github.com/widmogrod/typed-config/pull/13/files
  42. 42. Takeaway.
  43. 43. Takeaway. ● Type Theory is very useful for constructing formal specification ● Writing in “proper language” results in better desing - by design ● LaTeX…
  44. 44. UnAnswered Questions. I need to learn more and try to find answers in places like... ● Effect systems ● Dependent types ● Read formal specifications of type system of other languages
  45. 45. Interested in learning more? ● Read “Type Systems” by Luca Cardelli ○ Equivalence ○ Type soundness ○ Type inference ○ First & Second Order type systems ○ .... ● Star https://github.com/widmogrod/typed-config
  46. 46. Thank you! Gabriel Habryn ● Twitter: @widmogrod ● Github: widmogrod ● Gmail: widmogrod

×