switch.km 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. type Framework enum {
  2. type React;
  3. type Vue;
  4. type Angular;
  5. type Polymer;
  6. type Svelte;
  7. type Elm;
  8. type Purescript;
  9. };
  10. const React: Framework := { |Framework| { |React| () } };
  11. const Vue: Framework := { |Framework| { |Vue| () } };
  12. const Angular: Framework := { |Framework| { |Angular| () } };
  13. const Polymer: Framework := { |Framework| { |Polymer| () } };
  14. const Svelte: Framework := { |Framework| { |Svelte| () } };
  15. const Elm: Framework := { |Framework| { |Elm| () } };
  16. const Purescript: Framework := { |Framework| { |Purescript| () } };
  17. export function get-color:
  18. &(Framework) => String
  19. &(framework) =>
  20. switch framework:
  21. case React,Elm: 'lightblue',
  22. case Angular,Svelte: 'red',
  23. case Vue: 'green',
  24. case Polymer: 'pink',
  25. case Purescript: 'black',
  26. end;
  27. do
  28. let checklist := [
  29. (React, 'lightblue'),
  30. (Vue, 'green'),
  31. (Angular, 'red'),
  32. (Polymer, 'pink'),
  33. (Svelte, 'red'),
  34. (Elm, 'lightblue'),
  35. (Purescript, 'black')
  36. ],
  37. let ok := checklist
  38. . { Seq }
  39. . { every &(framework, color) =>
  40. (framework.{get-color} = color) },
  41. { os::println { String ok } }
  42. . { crash-on-error };