1

Related to a question asked in #haskell, where all the answers flowed but basically none was really right, i post the question here.

Is there any function f (possibly without involving TemplateHaskell) such as:

f (+)      == "+"
f f        == "f"
f putStrLn == "putStrLn"

ie, a function that, given a function in the scope as an input, retrieves the name of that function.

In Text.Show.Functions, there is:

instance Show (a -> b)

But here's the only thing it does:

λ show (+)
"<function>"
λ show show
"<function>"
λ show putStrLn
"<function>"
qleguennec
  • 544
  • 4
  • 12
  • 3
    What should be the output of `f (g . h)`? Or `f $ \x -> x`? – Bakuriu Sep 02 '14 at 18:38
  • Also [this](http://stackoverflow.com/questions/15272231/function-to-output-function-name), or [this](http://stackoverflow.com/questions/10962069/how-can-i-have-show-display-the-name-of-a-function). – bheklilr Sep 02 '14 at 18:38
  • @Bakuriu If this approach would ever be taken, I'd say functions would `Show` just their signature (doesn't F# interactive take this approach?), and as a bonus maybe the identifier too if it's bound to any symbol. Although I don't think `Show` is appropriate for functions, even though I must agree it could be (even very) convenient. – MasterMastic Sep 03 '14 at 05:03
  • @Masterastic Actually, there is **Typeable** who does show the functions signatures. Reading the previous questions on the same project, i don't think there is any _real_ solution which doesn't involve metaprogramming. – qleguennec Sep 04 '14 at 16:19

0 Answers0