函数論理プログラミング言語 Curry
Curryはfunctional logic programming languageという聞きなれないカテゴリーに属する言語だ。もっとも、函数型プログラミングと論理型プログラミングは似通った点もあるから、そのふたつのパラダイムを併せ持ったプログラミング言語が存在するのはそんなに奇妙なことでもないと思う。
Curryの処理系はいくつか存在するが、今回はPAKCSを使う。PAKCSはCurryのコードをPrologをターゲットとしてコンパイルする。
早速試してみる。
Prelude> x ++ y =:= [0, 1, 2] where x, y free Free variables in goal: x, y Result: success Bindings: x=[] y=[0,1,2] More solutions? [Y(es)/n(o)/a(ll)] Result: success Bindings: x=[0] y=[1,2] More solutions? [Y(es)/n(o)/a(ll)] Result: success Bindings: x=[0,1] y=[2] More solutions? [Y(es)/n(o)/a(ll)] Result: success Bindings: x=[0,1,2] y=[] More solutions? [Y(es)/n(o)/a(ll)] No more solutions. Prelude>
let ... free
あるいは where ... free
といった構文を使って、自由変数を指定する。
これは、Prologであれば次のコードに相当する。
?- append(X, Y, [0, 1, 2]).
Prologの , と ; に相当する演算子は、それぞれ & と ? だ。
Prelude> x =:= foldr1 (?) [0..10] & 2 * x =:= 10 where x free Free variables in goal: x Result: success Bindings: x=5 More solutions? [Y(es)/n(o)/a(ll)] No more solutions. Prelude>
後で色々試す。