Idris2/tests/idris2/reflection002/power.idr
Edwin Brady d5b5af91d1 Implement %macro flag
A %macro must always be fully applied. Whenever the elaborator
encounters a %macro application (except in a function LHS) it evaluates
the application and sends the result to %runElab. So:

%macro
foo : args -> Elab TT
...
def = foo a b c

is equivalent to

foo : args -> Elab TT
...
def = %runElab foo a b c
2020-06-01 17:55:54 +01:00

15 lines
242 B
Idris

import Language.Reflection
%language ElabReflection
powerFn : Nat -> TTImp
powerFn Z = `(const 1)
powerFn (S k) = `(\x => mult x (~(powerFn k) x))
%macro
power : Nat -> Elab TT
power n = check (powerFn n)
cube : Nat -> Nat
cube = power 3