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