~jojo/Carth

4f2488083be773a6aebd6671f454dce022e9b188 — JoJo 1 year, 6 months ago ef8e4e0
Make Pair a builtin datatype
3 files changed, 8 insertions(+), 11 deletions(-)

M examples/fizzbuzz.carth
M examples/std.carth
M src/Check.hs
M examples/fizzbuzz.carth => examples/fizzbuzz.carth +4 -8
@@ 8,14 8,10 @@

(define (fizzbuzz' n)
  (match (Pair (divisible? n 3) (divisible? n 5))
    (case (Pair false false)
          (my-show-int n))
    (case (Pair true false)
          "Fizz")
    (case (Pair false true)
          "Buzz")
    (case (Pair true true)
          "Fizzbuzz")))
    (case (Pair false false) (my-show-int n))
    (case (Pair true false) "Fizz")
    (case (Pair false true) "Buzz")
    (case (Pair true true) "Fizzbuzz")))

(define my-show-int
  (fun-match

M examples/std.carth => examples/std.carth +0 -3
@@ 1,6 1,3 @@
(type (Pair a b)
  (Pair a b))

(define fst
  (fun-match (case (Pair a _) a)))
(define snd

M src/Check.hs => src/Check.hs +4 -0
@@ 133,6 133,10 @@ builtinDataTypes' =
      , [("Array", [TBox (TVar (TVImplicit 0)), TPrim TNat])]
      )
    , ("Str", [], [("Str", [TConst ("Array", [TPrim TNat8])])])
    , ( "Pair"
      , [TVImplicit 0, TVImplicit 1]
      , [("Pair", [TVar (TVImplicit 0), TVar (TVImplicit 1)])]
      )
    ]

type Bound = ReaderT (Set TVar) (Except TypeErr) ()