[Haskell-beginners] How to print the name of a variable

John Velman velman at cox.net
Fri Mar 19 18:23:28 EDT 2010

I have a number of variables (whose values are computed in my program) of
the same type, and in ghci I want to be able to call a function to print
something computed from the value of one or more of these to a file.  I
want the file name to reflect the name of the variable.  This is probably
not clear, but conceptually the function to do the output would look
something like this:

  someFunction :: MyTypeVariable -> String
  writeFileFor :: MyTypeVariable -> IO ()
  writeFileFor v =
        nameOfV <- someFunction v
        outh <- openFile nameOfV ++ ".txt" WriteMode

        outputstring = calculationsFrom v

        hPutStr outh outputstring

        hClose outh

Is there any such "someFunction", or is there a way to build one?


John Velman

More information about the Beginners mailing list