HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerelude-1.2.0.0Haskell2010

Relude.Extra.CallStack

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Contains useful functions to work with GHC callstack.

  • 2 values
  • Packagerelude-1.2.0.0
  • Exports2
  • LanguageHaskell2010
  • LicenceMIT
  • SourceCallStack.hs
valueownName :: HasCallStack => String
#

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

Example4 expressions
foo :: HasCallStack => String; foo = ownNamefoo"foo"bar :: HasCallStack => String; bar = foobar"foo"

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:

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