module Auto2

ptype World
pfunc log : {A : U} -> A -> World := `(_, a) => console.log(a)`


pfunc i_plus : Int -> Int -> Int := `(x,y) => x + y`

data Nat : U where
  Z : Nat
  S : Nat -> Nat

plus : Nat -> Nat -> Nat
plus Z x = x
plus (S k) x = S (plus k x)

-- a type class
data Add : U -> U where
  MkAdd : {A : U} -> (A -> A -> A) -> Add A

infixl 8 _+_
_+_ : {A : U} -> {{myadd : Add A}} -> A -> A -> A
_+_ {_} {{MkAdd adder}} x y = adder x y

-- Two instances
addInt : Add Int
addInt = MkAdd i_plus

addNat : Add Nat
addNat = MkAdd plus

-- sequencing hack
infixl 2 _>>_
_>>_ :  {a b : U} ->  a -> b -> b
a >> b = b

main : World -> World
main _ = log (40 + 2) >> log (Z + Z)
