[Haskell-cafe] Questions about haskell CPP macros

Malcolm Wallace malcolm.wallace at cs.york.ac.uk
Mon Jul 13 13:34:36 EDT 2009


> {-# LANGUAGE CPP #-}
> main = putStrLn (__FILE__ ++ ":" ++ show __LINE__)
>
> This outputs:
> test.hs:2

> if I had a module Foo.Bar.Car.MyModule, I would like to be able to  
> output something like this on error:
> Foo.Bar.Car.MyModule:2

It works for me.  If you place that text in Try/Me.hs and call
     ghc -E Try/Me.hs
you get
     Try/Me.hs:2

If you just want to turn slashes into dots, and remove the suffix,  
that is a simple exercise in Haskell itself

main = putStrLn (mangle __FILE__)
   where mangle ('/':cs) = '.': mangle cs
         mangle .....

Regards,
     Malcolm



More information about the Haskell-Cafe mailing list