[Template-haskell] RE: Another question regarding Template Haskell

Simon Peyton-Jones simonpj@microsoft.com
Mon, 13 Jan 2003 11:38:46 -0000


| Would it be possible to write a function "showFun"  such that one
could
| write a program
|=20
| f x y =3D x +y -- say
|=20
| main =3D putStrLn (show $(showFun f))
|=20
| and the result of this program would be
|=20
| "f"
|=20
| I don't think it's possible at the moment because one can't reify
| expressions.

That's right.  In an earlier posting I explained why I have been slow
about implementing expression reification (enclosed).   Feedback on
exactly what expression reification should do would help to un-glue me.

Simon

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

| Why is it that one can't reify top level function declarations? At the

| moment it only seems that we can reify type declarations.  No
immediate
| reason for this seems to spring to mind, but there may be one.

[I'm interested to know something about your application, incidentally.]

Several reasons conspire. =20

a) Inconvenience (it's a little tiresome to implement)

b) It would be particularly difficult to get the definition of a
function defined in another module (because we'd have to read that
entire module too).  This is not true of data type declarations, which
travel in interface files, so there is no ugly cross-module issue to
worry about. =20

c) I'm not quite clear what you'd expect to get.  If we have

	f =3D ...f...

it's easy enough.  If you have mutual recursion

	f =3D ...g...
	g =3D ...f...

do you get just f's definition, or g's too?  If it's a pattern binding

	(f,g) =3D ...

you can't avoid getting both. =20

And even if it's a simple, non-recursive defn

	f =3D ....g....

(where g is defined earlier), I wonder whether there should be some way
to get at g's definition too.=20