fun append: list A -> list A -> list A. append [] L = L. append [X | Xs] L = [X | append Xs L].The method is exactly the same that one can found in modern functional programming languages (ML, Miranda, Haskell, etc.).
type signs = positive | zero | negative. fun sign: int -> signs. sign X = (X > 0) => positive. sign X = (X = 0) => zero. sign X = (X < 0) => negative.
fun last : list A -> A. last L = (append _ [X]) = L => X. eval last [2, Z, 6]. > result: 6.
fun sublist: list A -> list A -> bool. sublist L1 L2 = L2 = (append X (append A Y)).
p t1 . . . tN = true. p (t1, . . ., tN). p t1 . . . tN = C => true. p (t1, . . ., tN) :- C. eval p t1 . . . tN => true solve p (t1, . . ., tN).
Usually a matter of taste.
Our definition of expressivity prefers the use of functions to define functions and the use of predicates to define predicates.
It is not a clear source of expressivity.
The possibility of making nested calls.
Cleaner and clearer programs if the level of nesting is high.
Easier to understand than PROLOG programs.
Composed or modal knowledge.
The functional structure of the program makes also easier a static analysis of the program, what it is very useful from the implementation point of view.
Once the hatter expressed his believe that the hare does not believe that all three (the hatter, the hare and the dormouse) are sane. The dormouse also believes that the hare is sane. What is the mental state of these three friends?. (One accepts that sane people tell the truth while mad people always lie).Try to solve it in your favourite language before you check the solution in a functional logic language
The language is usually PROLOG.
Two alternatives:
Although both approaches seem to be different, in practice they converge to very similar solutions.
Current implementations are highly competitive with Prolog implementations.
Efficiency of functional logic programs is often better than their Prolog equivalents when the functional structure of the program is used.
One possible optimization is the detection of deterministic computations.
The implementation can detect that a function call can only return a single result. In such this situation backtracking is not needed and no more rules are tried after a success in case of failure.
=> Implicit cut is inserted before the code for the left hand side of the rule.Speedups reported in Bosco, Cechi, Moiso 89, Kuchen, Loogen, Moreno-Navarro, Rodríguez-Artalejo 92, Loogen 91
Go to index