[Haskell-cafe] Questions about haskell CPP macros
Stephan Friedrichs
deduktionstheorem at web.de
Mon Jul 13 13:27:31 EDT 2009
Matthew Elder wrote:
> {-# LANGUAGE CPP #-}
> main = putStrLn (__FILE__ ++ ":" ++ show __LINE__)
>
> This outputs:
> test.hs:2
>
> Unfortunately, if your file is in a hierarchy of folders, this flat file
> name doesn't give much context. Is there a macro to find out the current
> module? IE 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
As mentioned by Claus, template-haskell offers a solution. But in some
cases, this is an overkill; consider using Control.Exception.assert, it
will provide module and line information without having to use CPP:
myHead :: [a] -> a
myHead (x:_) = x
myHead [] = assert False undefined
>
> [...]
//Stephan
--
Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.
- Dieter Nuhr
More information about the Haskell-Cafe
mailing list