Last active
January 4, 2023 19:38
-
-
Save DamianReeves/252e1daa4c821b885318cb616c366d4b to your computer and use it in GitHub Desktop.
Morphir Macro ideas
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
trait PersonModule { | |
trait Person { def name: String; def age: Int } | |
} | |
trait ModuleDef[T] { | |
val value: T | |
} | |
// val myModule: ModuleDef[PersonModule] = | |
// new ModuleDef[PersonModule] { | |
// val value: PersonModule = new PersonModule {} | |
/// } | |
val myModule: ModuleDef[PersonModule] = moduleDef[PersonModule] | |
case class Person(name: String, age: Int) extends myModule.MyPerson |
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
@Module | |
trait Math { | |
@Native(Morphir.Add) | |
def add(a: Int, b: Int) | |
} | |
@Module | |
trait AddressModule { | |
case class Address(street: String, zip: Int) | |
def addZips(a: Address, b: Address) = a.zip + b.zip | |
} | |
@Module | |
trait PersonModule { | |
@ImportModule | |
val addressModule: AddressModule | |
case class Person(def name: String; address: addressModule.Address) | |
@Import Module | |
val mathModule: Math | |
def addAgeAndZip(p: Person, a: Address) = mathModule.add(a.age, a.zip) | |
} | |
val packageBundle: PackageBundle[PersonModule] = makePackageBundle[PersonModule] | |
// compile with yPreserveTrees |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment