I am trying to implement forward/Backward chaining in haskell something with a very a small database i.e some kind of text file and basic rules. Help would be appreciated. Thanks
-
Nice, go ahead! (You should post more info: what have you done, what is your problem, what is not working in your code...) – kyticka Mar 13 '13 at 17:51
-
My question in truth is does haskell have an implementation of backward and forward chaining that does what I want. Help would be appreciated. – chestchindian Mar 13 '13 at 18:15
1 Answers
Here are some monads that might be helpful:
These monads have a notion of failure which automatically backtracks to previous states (they backtrack in different ways -- which to use depends on what behavior you want).
If you are doing unification, use StateT
on one of these monads with a dictionary from variables to their values.
With these pieces, a backward-chaining logic engine is actually quite small and easy in Haskell. I wrote something similar for one of my projects in about 30 lines (it's in the latter part of this file, if you want a reference. I doubt you'll be able to use it exactly.).
Warning: although this task is easy for an experienced Haskell programmer, it uses some relatively advanced concepts, so if you do not already know Haskell, the necessary 30 lines will be quite hard to come up with. Do an extended tutorial first.

- 59,485
- 12
- 145
- 204
-
Thank you luqui I have done a little haskell at university, all be it, at a very basic level although i'm not an experienced haskell programmer. Thank you all the same i.m sure this will be very helpful. – chestchindian Mar 13 '13 at 19:23