relude-0.7.0.0: Safe, performant, user-friendly and lightweight Haskell Standard Library
Copyright(c) 2018-2020 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityExperimental
PortabilityPortable
Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.CallStack

Description

Contains useful functions to work with GHC callstack.

Since: 0.2.0

Synopsis

Documentation

ownName :: HasCallStack => String Source #

This function returns the name of its caller function, but it requires that the caller function has HasCallStack constraint. Otherwise, it returns "unknown".

>>> foo :: HasCallStack => String; foo = ownName
>>> foo
"foo"
>>> bar :: HasCallStack => String; bar = foo
>>> bar
"foo"

Since: 0.2.0

callerName :: HasCallStack => String Source #

This function returns the name of its caller of the caller function, but it requires that the caller function and caller of the caller function have HasCallStack constraint. Otherwise, it returns "unknown". It's useful for logging:

>>> log :: HasCallStack => String -> IO (); log s = putStrLn $ callerName ++ ":" ++ s
>>> greeting :: HasCallStack => IO (); greeting = log "Starting..." >> putStrLn "Hello!" >> log "Ending..."
>>> greeting
greeting:Starting...
Hello!
greeting:Ending...

Since: 0.2.0