[cpp] make tmp/list.cpp

This commit is contained in:
Julin S 2023-10-01 10:35:55 +05:30
parent 7ade069098
commit 0da344b045
1 changed files with 31 additions and 0 deletions

31
cpp/tmp/list.cpp Normal file
View File

@ -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;
}