core.km 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. module Core;
  2. /**
  3. * IMPORTANT: The following type definitions should be kept update
  4. * with `loader/symbol.go` and `checker/special.go`.
  5. */
  6. // Basic Types
  7. type Bit native;
  8. type Byte native;
  9. type Word native;
  10. type Dword native;
  11. type Qword native;
  12. type Integer native;
  13. type Float64 native;
  14. // Container Types
  15. type Bytes native;
  16. type String native;
  17. type Seq[T] native;
  18. type Array[T] native;
  19. type Heap[T] native;
  20. type Set[T] native;
  21. type Map[K,V] native;
  22. // Effect Type
  23. type Effect*[T,E] native;
  24. type Effect[T,E] protected Effect*[T,E];
  25. // Fixed Integer Types
  26. type Int64 Qword;
  27. type Uint64 Qword;
  28. type Int32 Dword;
  29. type Uint32 Dword;
  30. type Int16 Word;
  31. type Uint16 Word;
  32. type Int8 Byte;
  33. type Uint8 Byte;
  34. // Basic Boxed Types
  35. type Char Dword;
  36. type Natural protected Integer;
  37. type Float protected Float64;
  38. // Basic Sum Types
  39. type Bool union {
  40. type Yes;
  41. type No;
  42. };
  43. type Maybe[T] union {
  44. type Just T;
  45. type N/A;
  46. };
  47. type Result[T,E] union {
  48. type OK T;
  49. type NG E;
  50. };
  51. public function map![A,B,E] {
  52. lambda(Effect*[A,E], lambda A B) Effect*[B,E]:
  53. native 'effect-map'
  54. };
  55. public function then[A,B,E] {
  56. lambda(Effect[A,()], lambda A Effect[B,E]) Effect[B,E]:
  57. native 'effect-then'
  58. };
  59. public function then[T,E] {
  60. lambda(Effect[(),()], Effect[T,E]) Effect[T,E]:
  61. native 'effect-then-preset'
  62. };
  63. public function then*[A,B,E] {
  64. lambda(Effect[A,()], lambda A Effect*[B,E]) Effect*[B,E]:
  65. native 'effect-then*'
  66. };
  67. public function then*[T,E] {
  68. lambda(Effect[(),()], Effect*[T,E]) Effect*[T,E]:
  69. native 'effect-then*-preset'
  70. };
  71. public function next![A,B,E] {
  72. lambda(Effect[A,E], lambda A Effect[B,E]) Effect[B,E]:
  73. native 'effect-next'
  74. };
  75. public function next*[A,B,E] {
  76. lambda(Effect[A,E], lambda A Effect*[B,E]) Effect*[B,E]:
  77. native 'effect-next*'
  78. };
  79. public function map-error[T,E,F] {
  80. lambda(Effect[T,E], lambda E F) Effect[T,F]:
  81. native 'effect-map-error'
  82. };
  83. public function map-error[T,E,F] {
  84. lambda(Effect*[T,E], lambda E F) Effect*[T,F]:
  85. native 'effect-map-error-*'
  86. };
  87. public function catch[T,E] {
  88. lambda(Effect[T,E], lambda E Effect[(),()]) Effect[T,()]:
  89. native 'effect-catch'
  90. };