This requires a template to specify what types they are (and what order they are stored in)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
public:
add(
"tail(%s)", +[](
S s) ->
S {
return (s.empty() ?
S(
"") : s.substr(1,
S::npos)); });
add(
"head(%s)", +[](
S s) ->
char {
return (s.empty() ?
' ' : s[0]); }, 5);
add(
"pair(%s,%s)", +[](
S a,
char b) ->
S {
return a+b;
});
add(
"\u00D8", +[]() ->
S {
return S(
""); });
add(
"eq_s(%s,%s)", +[](
S x,
S y) ->
bool {
return x==y; }, 1./2.);
add("eq_c(%s,%s)", +[](char x, char y) -> bool { return x==y; }, 1./2.);
add("and(%s,%s)", +[](bool a, bool b) -> bool { return (a and b); }, 1./3.);
add("or(%s,%s)", +[](bool a, bool b) -> bool { return (a or b); }, 1./3.);
add("not(%s)", +[](bool a) -> bool { return (not a); }, 1./3.);
add(
"(%s<%s)", +[](
S x,
S y) ->
bool {
return x < y; }, 1./2);
add("(%s<%s)", +[](char x, char y) -> bool { return x < y; }, 1./2);
add("incr(%s)", +[](char x) -> char { return x+1;});
add("decr(%s)", +[](char x) -> char { return x-1;});
add(
"reverse(%s)", +[](
S x) ->
S {
return reverse(x); }, 1.);
add(
"repeat(%s,%s)", +[](
S x,
int n) ->
S {
for(int i=0;i<n;i++) {
w = w+x;
}
return w;
}, 1.);
add("int(%s)", +[](char c) -> int {
return int(c-'0');
});
add("x", Builtins::X<MyGrammar>, 3);
add("if_s(%s,%s,%s)", Builtins::If<MyGrammar,S>, 1./3);
add("if_c(%s,%s,%s)", Builtins::If<MyGrammar,char>, 1./3);
add("if_i(%s,%s,%s)", Builtins::If<MyGrammar,int>, 1./3);
add("recurse(%s)", Builtins::Recurse<MyGrammar>);
}
Declare our hypothesis type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~