37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using System.Linq;
|
|
using static System.Console;
|
|
|
|
namespace Amb
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
|
|
var amb = new Amb();
|
|
|
|
var set1 = amb.Choose("the", "that", "a");
|
|
var set2 = amb.Choose("frog", "elephant", "thing");
|
|
amb.Require(() => set1.Value.Last() == set2.Value[0]);
|
|
var set3 = amb.Choose("walked", "treaded", "grows");
|
|
amb.Require(() => set2.Value.Last() == set3.Value[0]);
|
|
var set4 = amb.Choose("slowly", "quickly");
|
|
amb.RequireFinal(() => set3.Value.Last() == set4.Value[0]);
|
|
|
|
WriteLine($"{set1} {set2} {set3} {set4}");
|
|
Read();
|
|
|
|
// problem from http://www.randomhacks.net/articles/2005/10/11/amb-operator
|
|
amb = new Amb();
|
|
|
|
var x = amb.Choose(1, 2, 3);
|
|
var y = amb.Choose(4, 5, 6);
|
|
amb.RequireFinal(() => x.Value* y.Value == 8);
|
|
|
|
WriteLine($"{x} * {y} = 8");
|
|
Read();
|
|
Read();
|
|
}
|
|
}
|
|
}
|