2020-05-31 03:36:54 +03:00
|
|
|
import Language.Reflection
|
|
|
|
|
|
|
|
%language ElabReflection
|
|
|
|
|
|
|
|
powerFn : Nat -> TTImp
|
|
|
|
powerFn Z = `(const 1)
|
|
|
|
powerFn (S k) = `(\x => mult x (~(powerFn k) x))
|
|
|
|
|
2020-06-03 01:56:30 +03:00
|
|
|
powerFn' : Nat -> Elab (Nat -> Nat)
|
|
|
|
powerFn' Z = pure (const 1)
|
|
|
|
powerFn' (S k) = do powerk <- powerFn' k
|
|
|
|
pure (\x => mult (powerk x) x)
|
|
|
|
|
2020-06-01 19:55:54 +03:00
|
|
|
%macro
|
2020-06-03 00:41:37 +03:00
|
|
|
power : Nat -> Elab (Nat -> Nat)
|
2020-06-01 19:55:54 +03:00
|
|
|
power n = check (powerFn n)
|
|
|
|
|
2020-06-03 01:56:30 +03:00
|
|
|
%macro
|
|
|
|
power' : Nat -> Elab (Nat -> Nat)
|
|
|
|
power' n = powerFn' n
|
|
|
|
|
2020-05-31 03:36:54 +03:00
|
|
|
cube : Nat -> Nat
|
2020-06-01 19:55:54 +03:00
|
|
|
cube = power 3
|
2020-06-03 01:56:30 +03:00
|
|
|
|
|
|
|
cube' : Nat -> Nat
|
|
|
|
cube' = power' 3
|