Debian Codegraph @

src/Debug/Trace.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Printing Strings During Evaluation
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --rewriting #-}
8
9 -- see README.Debug.Trace for a use-case
10
11 module Debug.Trace where
12
13 open import Agda.Builtin.String using (String)
14 open import Agda.Builtin.Equality using (_≡_)
15
16 -- Postulating the `trace` function and explaining how to compile it
17
18 postulate
19 trace : ∀ {a} {A : Set a} → String → A → A
20
21 {-# FOREIGN GHC import qualified Debug.Trace as Debug #-}
22 {-# FOREIGN GHC import qualified Data.Text as Text #-}
23 {-# COMPILE GHC trace = const (const (Debug.trace . Text.unpack)) #-}
24
25 -- Because expressions involving postulates get stuck during evaluation,
26 -- we also postulate an equality characterising `trace`'s behaviour. By
27 -- declaring it as a rewrite rule we internalise that evaluation rule.
28
29 postulate
30 trace-eq : ∀ {a} {A : Set a} (a : A) str → trace str a ≡ a
31
32 {-# BUILTIN REWRITE _≡_ #-}
33 {-# REWRITE trace-eq #-}
34
35 -- Specialised version of `trace` returning the traced message.
36
37 traceId : String → String
38 traceId str = trace str str