I think a way to do this would be to define a small lambda calculus of DSL in Haskell (or use an existing implementation). Thus, instead of using the native Haskell wording, you should write something like
k = Lam "x" (Lam "y" (App (Var "x") (Var "y"))) s = Lam "x" (Lam "y" (Lam "z" (App (App (Var "x") (Var "z") (App (Var "y") (Var "z"))))
and similarly for s and i . Then you have to write / use a rating function so you can write
debug e = eval e debug (App sk)
which will provide you with the final form in your own syntax. Also, to convert your DSL syntax to Haskell, you'll need a kind of interpreter so that you can actually use the functions in your code.
Implementing this seems like a pretty complicated job, and it's probably not exactly what you had in mind (especially if you need an assessment for typed syntax), but I'm sure it will be a great learning experience. A good reference would be chapter 6, "Write to you Haskell . " Using an existing implementation would be a lot easier (but less fun :)).
If this is just for debugging purposes, it might be useful for you to look at the syntax of the main ghc syntax. See Haskell chapter 25 of the real world , the ghc flag to use is -ddump-simple. But that would mean looking for the generated code, not creating a view inside your program. I'm also not sure how easily you could identify certain functions in the base code (I have no experience with this, so YMMV).
Of course, it would be great if the show on functions function would give the kind of output you are describing, but there are probably very good reasons that the functions are not an instance of Show (I could not tell you).
source share