Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Accessing type parameters in Macros
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Julian Schrittwieser  
View profile  
 More options Nov 18 2012, 11:59 am
From: Julian Schrittwieser <j.schrittwie...@gmail.com>
Date: Sun, 18 Nov 2012 08:59:45 -0800 (PST)
Local: Sun, Nov 18 2012 11:59 am
Subject: Accessing type parameters in Macros

I'm trying to create a System of Measurements with Scala Macros. As such,
each number is represented by the actual value and it's unit:

case class Number[T](n: Int)

eg val a = Number[Meter](10)

If I add and multiply those numbers, I want to correctly handle the units
(= the type parameter T). Normally, those wouldn't be accessible because of
erasure, but I found TypeTags (
http://www.scala-lang.org/archives/downloads/distrib/files/nightly/do...),
which are supposed to solve this problem.

At first, this seems to work - directly creating a number and the printing
it gives me the correct type parameter: http://pastebin.com/Yxxw7zN7

However, once I perform some arithmetic one those values with a macro, I
don't get any concrete value for T, just T itself. (for a complete example
see https://github.com/Mononofu/Units-of-Measure/)

I get the following output:

type of 2 has type arguments List(Meter)
type of 7 has type arguments List(T)
type of 12 has type arguments List(Times[T,U])
type of 17 has type arguments List(T)

I suspect this is because of the way I create expressions with reify - the multiplication_impl
macro (used for the third line of output) returns an expression of type Number[Times[T,
U]] in the last line, and this is exactly the type it shows to me. Do I
need to resolve the type parameters somehow before creating the new
expressions? (see
https://github.com/Mononofu/Units-of-Measure/blob/master/macros/macro...
)

all the best, Julian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Julian Schrittwieser  
View profile  
 More options Nov 18 2012, 2:43 pm
From: Julian Schrittwieser <j.schrittwie...@gmail.com>
Date: Sun, 18 Nov 2012 11:43:28 -0800 (PST)
Local: Sun, Nov 18 2012 2:43 pm
Subject: Re: Accessing type parameters in Macros

Thanks to Paul for pointing out what I was doing wrong - I hadn't added the
"T: WeakTypeTag" annotation everywhere I declared T, so the type was erased
when I multiplied or added two numbers.

However, I still have a problem - the types are printed fine at run time,
but I haven't yet managed to get at them during compile time (ie when the
macro runs)

Adding an implicit parameter for the TypeTag ("(implicit tag:
WeakTypeTag[Number[T]])") just makes it fail because the macro has an
unexpected form, and getting the tag with "weakTypeTag[T]" doesn't work
either.

Are there any other options?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Nov 19 2012, 9:11 am
From: Eugene Burmako <xeno...@gmail.com>
Date: Mon, 19 Nov 2012 06:11:45 -0800 (PST)
Local: Mon, Nov 19 2012 9:11 am
Subject: Re: Accessing type parameters in Macros
In a macro use c.weakTypeTag, not just weakTypeTag

On Nov 18, 8:43 pm, Julian Schrittwieser <j.schrittwie...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »