semigroup_string_append() {
echo -n "$1$2"
}
monoid_string_empty() {
true
}
semigroup_int_append() {
echo -n $(($1 + $2))
}
monoid_int_empty() {
echo -n 0
}
fold() {
if [ "$#" -eq 1 ]; then
echo -n "$("monoid_$1_empty")"
else
echo -n "$("semigroup_$1_append" "$2" "$(fold "$1" "${@:3}")")"
fi
}
echo "$(fold string foo bar baz)"
echo "$(fold int 1 2 3)"