gvrooyen, I'm evaluating #Prolog for use in a project where the client requires a scriptable expert system for risk management.
I'm pretty thankful for my recent deep-dive into #OCaml, since a better understanding of functional languages is certainly a good stepping stone to logic programming (a generalisation of functional programming).
For example, one of the "aha!"s in OCaml for me was that you can create most list processing functions from 1st principles with a tail-recursive cons, and that once you've derived
fold
you've got the Swiss army knife of data processing.Similarly, this beautiful little Prolog program by Erik Schierboom on #Exercism was an "aha!" for me, because it shows how succinct a fold can be. Here he's converting a string of binary numbers into its decimal equivalent as an integer.
Coming from #OCaml the type inference here is sweet. Since
foldl/4
has an integer as third parameter in thebinary
predicate,Dec
must be an integer too for it to hold. Type inference seems to come almost as a given in logic programming. If it doesn't quack like a duck it isn't a duck, and the predicate is false.
Add comment