https://github.com/lightandlight/idris-lambda-reflection
Reflecting simply-typed lambda calculus into Idris
https://github.com/lightandlight/idris-lambda-reflection
Last synced: 5 months ago
JSON representation
Reflecting simply-typed lambda calculus into Idris
- Host: GitHub
- URL: https://github.com/lightandlight/idris-lambda-reflection
- Owner: LightAndLight
- Created: 2018-05-29T06:37:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-29T21:42:16.000Z (about 8 years ago)
- Last Synced: 2025-06-13T04:42:20.561Z (about 1 year ago)
- Language: Idris
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reflecting simply typed lambda calculus into Idris
--------------------------------------------------
## Runtime Reflection
Culminates in this definition:
```idris
example_3 : Maybe (Int -> Int -> Int)
example_3 = ofType "\\x : int. \\y : int. x" (TyArr TyInt (TyArr TyInt TyInt))
```
which evaluates to `Just (\a, b => a)`
It says "This string should express a lambda calculus term of type `Int -> Int -> Int`".
If the term fails to parse or typecheck, `ofType` will return `Nothing`.
## Compile Time Reflection
Using elaborator reflection, we can parse and typecheck the string at compile
time, and build up the corresponding Idris syntax tree. If the Idris function
has a type that doesn't match the lambda expression, or the expression fails
to parse, then an error will be reported.
```idris
test1 : (Int -> Int) -> Int -> Int
test1 = %runElab (reflect "\\f : int -> int. \\x : int. f x")
test2 : Int -> Int
test2 = %runElab (reflect "\\x : int. x")
test3 : Int -> Bool
test3 = %runElab (reflect "\\x : int. true")
test4 : Bool
test4 = %runElab (reflect "(\\x : bool. x) true")
```