lampepfl / dotty-macro-examples Goto Github PK
View Code? Open in Web Editor NEWVarious tasks solved via metaprogramming in Dotty
Various tasks solved via metaprogramming in Dotty
It would be nice to have an example where a macro runs inside a function, but it returns a tuple of the function name and an Object that has the parameters as vals and the parameter values as typed values.
def blah(x: Int, y: String, z: Float) =
val (name, params) = functionMacro
println("x value in function $name is ${params.x}")
May you add the example: instantiate a class from a Map
case class Foo(a: Int, c: String)
val params: Map[String, String] = Map("a" -> "1", "c" -> "hi")
fromParams[Foo](params) // Right(Foo(1, "hi")))
Hi,
I think this defaultParamsInference is a great example I'd like to extend further to include the type of each case class field.
What amazes me is I didn't realize you can cast a Tree
as you do here:
https://github.com/lampepfl/dotty-macro-examples/blob/main/defaultParamsInference/src/macro.scala#L18
I thought I would need to use the Symbol's signature
to get the type but I don't see a lot of documentation for signature
or how to access type information (such as individually selecting types from higher orders, such as List[Int]
, as enabled in scala 2 by typeSignature
or scala.reflect.macros.Context.typeCheck
).
So can someone please clarify how tree
or signature
can be used to get detailed type information for each case class field?
Thanks!
Could it be possible with Dotty to write some macro for ternary operator that would replace
A ? B : C
by
if (A)
B
else
C
without adding an overhead in runtime?
Seems quite a lot staff changed in 3.0.0-M3
I try to update the version to 3.0.0 in build.sc:
def scalaVersion = "3.0.0"
When try to run mill abstractTypeclassBody.run
I see:
[20/38] abstractTypeclassBody.resolvedIvyDeps | Downloading [2/2] artifacts (~0/0 bytes)
1 targets failed
abstractTypeclassBody.resolvedIvyDeps
Resolution failed for 1 modules:
--------------------------------------------
org.scala-lang:scala3-library_3.0:3.0.0
not found: /home/shapeless-cat/.ivy2/local/org.scala-lang/scala3-library_3.0/3.0.0/ivys/ivy.xml
not found: https://repo1.maven.org/maven2/org/scala-lang/scala3-library_3.0/3.0.0/scala3-library_3.0-3.0.0.pom
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.