[racket] Determining type from a syntax object
On Jun 16, 2014, at 2:53 PM, Sam Tobin-Hochstadt <samth at cs.indiana.edu> wrote:
> This is exactly what predicates are for, in general. However, you
> can't have predicates that check things about functions -- there's no
> information there at runtime to look at.
I was kind of wondering if there was anything that could make the type checker put something there for runtime to look at.
> Typed Racket functions are
> just plain Racket functions. We could add some extra metadata to every
> value that held its type,
It wouldn’t have to be every value, it could just put that information in for :has-type expressions, right?
Would that still require fundamental changes to Racket?
> and then implement this operation, but that
> would require fundamental changes to Racket.
>
> Even if we wanted to do that, what if `f` came in from untyped Racket?
If f comes from untyped Racket, then the type checker says to use require/typed to import it.
>
> Sam
>
> On Mon, Jun 16, 2014 at 2:49 PM, Alexander D. Knauth
> <alexander at knauth.org> wrote:
>> Would there be a way to test the type for making decisions at run-time (not
>> just with predicates)?
>>
>> For example:
>> (cond [(:has-type? f (Number -> Any))
>> (f 1)]
>> [(:has-type? f (String -> Any))
>> (f "1")])
>>
>> On Jun 16, 2014, at 6:54 AM, Matthias Felleisen <matthias at ccs.neu.edu>
>> wrote:
>>
>>
>> That's what I thought you wanted it for so my answer stands -- Matthias
>>
>>
>>
>> On Jun 15, 2014, at 12:55 AM, Spencer Florence wrote:
>>
>> This is about making decisions at compile time. Specifically I have a
>> sequence of expressions I want to partition into expressions of some type T
>> and expressions of other types.
>>
>>
>> On Sat, Jun 14, 2014 at 7:34 PM, Robby Findler <robby at eecs.northwestern.edu>
>> wrote:
>>>
>>> Would it be enough to expand into an 'ann' expression? Or do you need
>>> to make decisions at compile time based on whether or not the types
>>> worked?
>>>
>>> Robby
>>>
>>> On Sat, Jun 14, 2014 at 2:04 PM, Matthias Felleisen
>>> <matthias at ccs.neu.edu> wrote:
>>>>
>>>> No, TR expands first, then checks. -- Matthias
>>>>
>>>>
>>>>
>>>>
>>>> On Jun 14, 2014, at 2:59 PM, Spencer Florence wrote:
>>>>
>>>>> Hey All,
>>>>>
>>>>> I'm trying to take advantage of typed/racket in a few macros. Is there
>>>>> any way to check the type of an expression from its syntax object? something
>>>>> like:
>>>>>
>>>>> (:has-type? (-> Void) #'expression)
>>>>>
>>>>>
>>>>> --Spencer
>>>>> ____________________
>>>>> Racket Users list:
>>>>> http://lists.racket-lang.org/users
>>>>
>>>>
>>>> ____________________
>>>> Racket Users list:
>>>> http://lists.racket-lang.org/users
>>
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>