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-07-17 17:18:23 +03:00
|
|
|
-- Note: this example doesn't quite do what we want yet. Ideally, we'd find
|
|
|
|
-- a way to block reduction under the 'pure' while running the script
|
2020-06-03 01:56:30 +03:00
|
|
|
powerFn' : Nat -> Elab (Nat -> Nat)
|
|
|
|
powerFn' Z = pure (const 1)
|
2020-07-17 17:18:23 +03:00
|
|
|
powerFn' (S k)
|
|
|
|
= do powerk <- powerFn' k
|
|
|
|
pure (\x => mult (powerk x) x)
|
2020-06-03 01:56:30 +03:00
|
|
|
|
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
|