[cpp] make tmp/list.cpp
This commit is contained in:
parent
7ade069098
commit
0da344b045
|
@ -0,0 +1,31 @@
|
|||
#include<iostream>
|
||||
|
||||
// https://www.lambdadays.org/static/upload/media/161672564665589vitsefltranslatinglambdacalculusintoctemplates.pdf
|
||||
|
||||
template<int>
|
||||
struct Int {};
|
||||
|
||||
template<bool>
|
||||
struct Bool {};
|
||||
|
||||
// Can't have floating point numbers as non-type parameters to templates.
|
||||
// https://stackoverflow.com/questions/2183087/why-cant-i-use-float-value-as-a-template-parameter
|
||||
//template<double>
|
||||
//struct Float {};
|
||||
|
||||
struct Nil {};
|
||||
|
||||
template<typename, typename>
|
||||
struct Cons {};
|
||||
|
||||
int main() {
|
||||
// [2]
|
||||
Cons<Int<2>, Nil> x;
|
||||
|
||||
// [2, 3, 5]
|
||||
Cons<Int<2>, Cons<Int<3>, Cons<Int<5>, Nil>>> y;
|
||||
|
||||
// It's untyped...
|
||||
// [2, true] possible
|
||||
Cons<Int<2>, Cons<Bool<true>, Nil>> z;
|
||||
}
|
Loading…
Reference in New Issue