The DA.Logic module seems to be interesting, but it’s not immediately obvious to me how I can use it.
Could you show me an example?
The DA.Logic module seems to be interesting, but it’s not immediately obvious to me how I can use it.
Could you show me an example?
I think the formulas Formula t
from DA.Logic
are best thought of as limited serializable functions (t -> Bool) -> Bool
. A common option is Formula Text
where your texts are some sort of identifiers (I’ve seen asset ids used but really anything works). You can store that formula on a template e.g. as eligibility rules and then evaluate it in a choice via interpret
where you map each t
to a boolean.
I don’t have a publicly available example unfortunately.
Thank you!
I leave this question open for a few days in case somebody can show me concrete examples.
This is what I could come up with based on your explanation:
module Logic where
import DA.Logic
import Daml.Script
a = Proposition "abrakadabra"
h = Proposition "hocuspocus"
d = Proposition "dracaeris"
e = Proposition "expectopatronum"
truthFunction : Text -> Optional Bool
truthFunction "abrakadabra" = Some True
truthFunction "hocuspocus" = Some False
truthFunction "dracaeris" = Some False
truthFunction _ = None
formula1 = disj [a,h,d]
formula2 = conj [a,h,d]
formula3 = disj [a,h,e]
test = script do
debug $ "formula1 interpreted: " <> show (interpret truthFunction formula1)
debug $ "formula2 interpreted: " <> show (interpret truthFunction formula2)
debug $ "formula3 interpreted: " <> show (interpret truthFunction formula3)
Results:
Trace:
"formula1 interpreted: Right True"
"formula2 interpreted: Right False"
"formula3 interpreted: Right True"