3 ms·
Prolog has definite clause grammars (DCGs), which are very similar to monads. You can think of a DCG as giving you two implicit arguments, which you can use to
by zmonx 9y ago
Prolog has definite clause grammars (DCGs), which are very similar to monads.
You can think of a DCG as giving you two implicit arguments, which you can use to express concatenations and in fact arbitrary relations between states.
There are also ways to access these implicit arguments, which are similar to the corresponding constructs in Haskell.
DCGs are a very important feature of Prolog. They are frequently used for parsing and state transformation tasks. Like monads in Haskell, DCGs often make working with immutable data much more convenient, because you can make the more uninteresting parts of your code implicit.
Other logic programming languages like Mercury also support DCGs.
- gmfawcett 9y agoIt never occurred to me that there were similarities between DCGs and monads, but that's an interesting argument. Thank you for this!