RE: [Haskell] reflection/metadata in Haskell?
I would rather argue that: - Template Haskell approx. *compile-time* reflection - Scrap your boilerplate II (ICFP 2004) approx. *run-time* reflection - Generic Haskell is effectively a Haskell generator Ralf P.S.: Another way to get *compile-time* reflection in Haskell is of course type-level programming as pioneered by McBride and Hallgreen ...
-----Original Message----- From: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] On Behalf Of Mads Lindstrøm Sent: Wednesday, September 21, 2005 11:40 AM To: haskell@haskell.org Subject: Re: [Haskell] reflection/metadata in Haskell? ... I do not know of any Java-like reflection capabilities in Haskell. However, "Scrap Your Boilerplate" (search google) and Generic Haskell can do a lot of the same stuff reflection can do in Java. Think of it as compile-time reflection.
Ralf, On Sep 22, 2005, at 1:52 AM, Ralf Lammel wrote:
I would rather argue that: - Template Haskell approx. *compile-time* reflection - Scrap your boilerplate II (ICFP 2004) approx. *run-time* reflection - Generic Haskell is effectively a Haskell generator
I think, Generic Haskell is a Haskell generator in the sense that it's currently implemented like that, i.e., as a preprocessing compiler. I assume that's what you mean by 'effectively'. Conceptually, it's a Haskell extension: indeed, one that gives you a certain form of reflection capabilities. Regards, Stefan
hello Ralf, thanks for your reply. I took a look at the Scrap Your Biolerplate paper and plan to try it out. Meanwhile there's one little piece in that paper I didn't quite follow, and thats the definition of mkT mkT :: (Typeable a, Typeable b) => (b -> b) -> a -> a mkT f = case cast f of Just g -> g Nothing -> id From the definition of cast and the examples given earlier it looks like cast needs to be told what the target type (a here) is in order to know what its trying to cast to - hence the example was "(cast 'a')::Maybe Char" - which makes sense. So I dont quite understand the usage of cast presented here inside mkT. How does the case proceed without knowing what its trying to cast f to? thanks "Ralf Lammel" <ralfla@microsoft.com> wrote in message news:1152E22EE8996742A7E36BBBA7768FEE07203433@RED-MSG-50.redmond.corp.micros oft.com... I would rather argue that: - Template Haskell approx. *compile-time* reflection - Scrap your boilerplate II (ICFP 2004) approx. *run-time* reflection - Generic Haskell is effectively a Haskell generator Ralf P.S.: Another way to get *compile-time* reflection in Haskell is of course type-level programming as pioneered by McBride and Hallgreen ...
-----Original Message----- From: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] On Behalf Of Mads Lindstrøm Sent: Wednesday, September 21, 2005 11:40 AM To: haskell@haskell.org Subject: Re: [Haskell] reflection/metadata in Haskell? ... I do not know of any Java-like reflection capabilities in Haskell. However, "Scrap Your Boilerplate" (search google) and Generic Haskell can do a lot of the same stuff reflection can do in Java. Think of it as compile-time reflection.
Srinivas,
mkT :: (Typeable a, Typeable b) => (b -> b) -> a -> a mkT f = case cast f of Just g -> g Nothing -> id
From the definition of cast and the examples given earlier it looks like cast needs to be told what the target type (a here) is in order to know what its trying to cast to - hence the example was "(cast 'a')::Maybe Char" - which makes sense. So I dont quite understand the usage of cast presented here inside mkT. How does the case proceed without knowing what its trying to cast f to?
Well, it can proceed because all type information it really needs is available. Just consider: The explicit signature reveals that mkT has type (b -> b) -> a -> a (for any a and b that are instances of Typeable). Using this information we derive that f in mkT f = ... is a function of type b -> b, right? Then the right-hand side: that one should give us a function of type a -> a. Just skip the first part of the case statement for a while and proceed to its body: mkT f = case ... of Just g -> g ... Since, g has to have type a -> a and Just has type t -> Maybe t for all t, it follows that Just g has type Maybe (a -> a). Therefore the case statement should perform pattern matching on a value of type Maybe (a -> a). So, from mkT f = case cast f of Just g -> g ... it can be inferred that cast f has type Maybe (a -> a) and, hence, that cast should try to case f to a function of type a -> a. HTH, Stefan
Hi
I would rather argue that: - Template Haskell approx. *compile-time* reflection - Scrap your boilerplate II (ICFP 2004) approx. *run-time* reflection After given the Scrap Your Boilerplate (SYB) issue further thought, I am afraid I must say that you are right. What I should have said was that SYB, opposed to Java-type reflection, has compile-time type checking. Well, most of its constructs are checked at compile-time.
/Mads Lindstrøm
- Generic Haskell is effectively a Haskell generator Ralf P.S.: Another way to get *compile-time* reflection in Haskell is of course type-level programming as pioneered by McBride and Hallgreen ...
-----Original Message----- From: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] On Behalf Of Mads Lindstrøm Sent: Wednesday, September 21, 2005 11:40 AM To: haskell@haskell.org Subject: Re: [Haskell] reflection/metadata in Haskell? ... I do not know of any Java-like reflection capabilities in Haskell. However, "Scrap Your Boilerplate" (search google) and Generic Haskell can do a lot of the same stuff reflection can do in Java. Think of it as compile-time reflection.
participants (4)
-
Mads Lindstrøm -
Ralf Lammel -
Srinivas Nedunuri -
Stefan Holdermans