mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-15 22:32:19 +03:00
f303e469fb
In a 'Bind', normalise the result of the first action, rather than quoting the HNF. This improves performance since the HNF could be quite big when quoted back. Ideally, we wouldn't have to quote and unquote here, and we can probably achieve this by tinkering with the evaluator. This has an unfortunate effect on the reflection002 test, in that the "typed template Idris" example now evaluates too much. But, I think the overall performance is too important for the primary motivation behind elaborator reflection. I will return to this!
30 lines
649 B
Idris
30 lines
649 B
Idris
import Language.Reflection
|
|
|
|
%language ElabReflection
|
|
|
|
powerFn : Nat -> TTImp
|
|
powerFn Z = `(const 1)
|
|
powerFn (S k) = `(\x => mult x (~(powerFn k) x))
|
|
|
|
-- 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
|
|
powerFn' : Nat -> Elab (Nat -> Nat)
|
|
powerFn' Z = pure (const 1)
|
|
powerFn' (S k)
|
|
= do powerk <- powerFn' k
|
|
pure (\x => mult (powerk x) x)
|
|
|
|
%macro
|
|
power : Nat -> Elab (Nat -> Nat)
|
|
power n = check (powerFn n)
|
|
|
|
%macro
|
|
power' : Nat -> Elab (Nat -> Nat)
|
|
power' n = powerFn' n
|
|
|
|
cube : Nat -> Nat
|
|
cube = power 3
|
|
|
|
cube' : Nat -> Nat
|
|
cube' = power' 3
|