Example for the DA.Logic module
- gyorgybalazsiOP
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?
- cocreature 3
I think the formulas
Formula tfromDA.Logicare best thought of as limited serializable functions(t -> Bool) -> Bool. A common option isFormula Textwhere 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 viainterpretwhere you map eachtto a boolean.I don’t have a publicly available example unfortunately.
- gyorgybalazsi
Thank you!
I leave this question open for a few days in case somebody can show me concrete examples.
- gyorgybalazsi
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"