basic.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Types.TypeType = template (
  2. 'function TypeType (TT: TypeTemplate) -> Type',
  3. TT => Ins(Types.Type, $(x => TT.has_inflated(x)))
  4. )
  5. Types.Maybe = template (
  6. 'function Maybe (T: Type) -> Type',
  7. T => Uni(Nil, T)
  8. )
  9. Types.Arity = template (
  10. 'function Arity (n: Int) -> Type',
  11. n => Ins(Types.Function, $(
  12. f => f[WrapperInfo].proto.parameters.length === n
  13. ))
  14. )
  15. Types.Callable = Uni(ES.Function, Types.TypeTemplate, Types.Class, Types.Schema)
  16. Types.Impl = template (
  17. 'function Impl (i: Interface) -> Type',
  18. i => i.Impl
  19. )
  20. Types.Operand = template (
  21. 'function Operand (op: String) -> Type',
  22. op => Uni (
  23. Ins(Types.Struct, $(s => s.schema.defined_operator(op))),
  24. Ins(Types.Instance, $(i => i.class_.defined_operator(op)))
  25. )
  26. )
  27. Types.OpImpl = template (
  28. 'function OpImpl (op: String) -> Type',
  29. op => Uni (
  30. Ins(Types.Schema, $(s => s.defined_operator(op))),
  31. Ins(Types.Class, $(c => c.defined_operator(op)))
  32. )
  33. )
  34. Types.Index = Ins(Types.Int, $(x => x >= 0))
  35. Types.Size = Types.Index
  36. Types.PosInt = Ins(Types.Int, $(x => x > 0))
  37. Types.Char = Ins(Types.String, $(x => {
  38. let i = 0
  39. for (let _ of x) {
  40. if (i > 0) {
  41. return false
  42. }
  43. i += 1
  44. }
  45. return (i == 1)
  46. }))
  47. Types.Representable = Uni (
  48. Types.Primitive,
  49. Types.Operand.inflate('str')
  50. )
  51. Types.EqualityDefined = Uni (
  52. one_of (
  53. Types.Bool, Types.String,
  54. Types.Number, Types.Int, Types.Index, Types.PosInt
  55. ),
  56. Types.OpImpl.inflate('==')
  57. )
  58. Types.Error = $(x => x instanceof Error)
  59. Types.NotFound = create_value('NotFound') // Types.NotFound !== NotFound