Skip to content
Discussions/App Development/Example for the DA.Logic moduleForum ↗

Example for the DA.Logic module

App Development4 posts142 views3 likesLast activity May 2022
GY
gyorgybalazsiOP
May 2022

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?

CO
cocreature
May 2022

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.

GY
gyorgybalazsi
May 2022

Thank you!

I leave this question open for a few days in case somebody can show me concrete examples.

GY
gyorgybalazsi
May 2022

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"
← Back to Discussions