example_in_haskell.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef EXAMPLE_IN_HASKELL_HPP
  2. #define EXAMPLE_IN_HASKELL_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/config.hpp>
  8. #if BOOST_METAPARSE_STD < 2011
  9. // We have to fall back on the handcrafted one
  10. #include <example_handcrafted.hpp>
  11. #else
  12. #define BOOST_MPL_LIMIT_STRING_SIZE 50
  13. #define BOOST_METAPARSE_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE
  14. #include <meta_hs.hpp>
  15. #include <double_number.hpp>
  16. #include <boost/metaparse/string.hpp>
  17. #include <boost/mpl/int.hpp>
  18. #ifdef _STR
  19. # error _STR already defined
  20. #endif
  21. #define _STR BOOST_METAPARSE_STRING
  22. typedef
  23. meta_hs
  24. ::import1<_STR("f"), double_number>::type
  25. ::import<_STR("val"), boost::mpl::int_<11> >::type
  26. ::define<_STR("fib n = if n<2 then 1 else fib(n-2) + fib(n-1)")>::type
  27. ::define<_STR("fact n = if n<1 then 1 else n * fact(n-1)")>::type
  28. ::define<_STR("times4 n = f (f n)")>::type
  29. ::define<_STR("times11 n = n * val")>::type
  30. metafunctions;
  31. typedef metafunctions::get<_STR("fib")> fib;
  32. typedef metafunctions::get<_STR("fact")> fact;
  33. typedef metafunctions::get<_STR("times4")> times4;
  34. typedef metafunctions::get<_STR("times11")> times11;
  35. #endif
  36. #endif