2 ms·
If you are interested in logic programming languages (like Prolog) and in functional programming languages (like Haskell), you should definitely take a look at
by tralarpa 8y ago
If you are interested in logic programming languages (like Prolog) and in functional programming languages (like Haskell), you should definitely take a look at the Curry language.
For people who know Haskell, such a type definition should look very familar:
data IntTree = Leaf | Branch Int IntTree IntTree
The mind-bending stuff starts when you see "function" definitions like
choose x y = x
choose x y = y
- adimitrov 8y agochoose x y = x choose x y = y :-) That's mind bending if you don't know logic programming. So how can the above statement even make sense? You have to understand that a logic program will try all possible statements until it finds a match, or simply all possible statements if its job is to do an exhaustive search of the problem space. So in the choose function above, the execution algorithm (the runtime, as it were) would try to choose x first, and see if that yields a result that matches the query. It then chooses y. This may yield no, one, or many results, depending on the exact constraints of the search space. If you posed the problem as choose 'a' 'b' then the answer would be 'a' if you're content with any solution (it gives you the first it finds), or ['a','b'] if you wanted all solutions. Man, now I wanna go do some Prolog… pity there's nobody who's gonna pay me to do it, and I have to do PHP and JS.