Skip to content

implement functional programming by C++ template meta programming

Notifications You must be signed in to change notification settings

harryoooooooooo/CPPTMP_FunctionalProgramming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CPPTMP_FunctionalProgramming

implement functional programming by C++ template meta programming

Rules

  • Functions' return value is stored in the member type value. ex. f<x,y>::value
  • Struct names starting with uppercase are Type Constructors. They are final type, thus there is no member value. For convenience, they can be converted to Int_<> by toInt. ex. Just<Int_<5>>::toInt
  • Struct names starting with '_' are helper interfaces, usually derive them with CRTP. ex. template<class... a> struct f : _curry<f,3,a...>{};

Base type

In order to deal all the stuff only on type, that is, not something non-type(ex. 7, 'a', false). We wrap int and bool to Int_<> and Bool_<>. The member real is a real variable, so we can print them by cout. ex. Int_<12>::real

Maybe

constructors:

  • Nothing::toInt == Int_<-1>
  • Just<Int_<8>>::toInt == Int_<8>

List

constructors:

  • Empty::toInt == Int_<0>
  • App<App<App<Empty,Int_<2>>,Int_<1>>,Int_<3>>::toInt == Int_<213>. Simply concat them. It would mess up if elems are not in [1..9], but it is just a presentation error.

About

implement functional programming by C++ template meta programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published