Last active
April 10, 2024 20:47
-
-
Save mgodf89/ca929b3ce23178c87c837d5436867700 to your computer and use it in GitHub Desktop.
Contract Developer Course 1: Advanced Fundamentals | Functional Programming - 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Contract Developer Course 1: Advanced Fundamentals | Functional Programming - 2 | |
-- https://www.youtube.com/watch?v=WkIiH3IBo8U | |
module TypeExample where | |
import Daml.Script | |
data PersonnelType = Active | Inactive | |
deriving (Eq, Show) | |
data PersonnelRecord = PersonnelRecord with | |
name: Text | |
age: Int | |
typ: PersonnelType | |
class Concatable a where | |
pr_concat : a -> a -> Text | |
instance Concatable PersonnelRecord where | |
pr_concat (PersonnelRecord n1 a1 t1) (PersonnelRecord n2 a2 t2) = n1<>","<>(show a1)<>(if t1 == Active then "* " else " ")<>n2<>","<>(show a2)<>(if t2 == Active then "* " else " ") | |
mainScenario = script do | |
let | |
pr1 = PersonnelRecord with | |
name = "Alice" | |
age = 30 | |
typ = Active | |
pr2 = PersonnelRecord with | |
name = "Bob" | |
age = 40 | |
typ = Inactive | |
debug $ pr_concat pr1 pr2 | |
-- Script Result | |
---------------- | |
-- Transactions: | |
-- | |
-- Active contracts: | |
-- | |
-- Return value: {} | |
-- | |
-- Trace: | |
-- "Alice,30* Bob,40 " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment