On 02-May-2000, Jan Brosius <[EMAIL PROTECTED]> wrote:
>
>
> > On 29-Apr-2000, Jan Brosius <[EMAIL PROTECTED]> wrote:
> > >
> > > Is it possible to interrogate the typechecker
> > > from within a Haskell program
> >
> > You can of course invoke a Haskell typechecker (e.g. Hugs) as a separate
> > process.
> >
> > Why do you ask? What kind of questions do you want to ask the type
> > checker?
>
> Suppose in some function definition some variable is of type A s a and I
> want to do something like this : if the type variable of the first parameter
> in A s a is s then do this if not then do something else.
That particular example seems nonsensical: you're asking if `s' is `s'?
The answer would always be "yes".
More generally, you can use the `Dynamic' module (a Hugs/ghc extension)
to perform dynamic type tests, so long as the type that you are testing
is an instance of the `Typeable' type class.
> It should be some sort of program flow during compilation before the code is
> generated.
If you're worried about efficiency, with a little bit of partial
evaluation, a good compiler should be able to optimize away dynamic
type checks in cases where the type is known at compile time.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.