Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings to ghc's Debug.Trace #541

Closed
gallais opened this issue Nov 23, 2018 · 2 comments
Closed

Add bindings to ghc's Debug.Trace #541

gallais opened this issue Nov 23, 2018 · 2 comments
Milestone

Comments

@gallais
Copy link
Member

gallais commented Nov 23, 2018

Turned out to be pretty convenient in agda/agda/issues/3410

@gallais gallais added this to the v0.18 milestone Nov 23, 2018
@jmchapman
Copy link
Contributor

It would be nice if it didn't prevent running stuff in Agda. I tried defining trace to be
trace _ x = x and asking Agda not to inline it but it still did.

@gallais
Copy link
Member Author

gallais commented Nov 23, 2018

Hmm. Good point, I didn't think of that. This seems to work:

{-# OPTIONS --rewriting #-}

module Main where

open import Agda.Builtin.String
open import Agda.Builtin.Equality

postulate
  trace :  {a} {A : Set a}  String  A  A
  trace-eq :  a (A : Set a) (a : A) str  trace str a ≡ a

{-# FOREIGN GHC import qualified Debug.Trace as Debug #-}
{-# FOREIGN GHC import qualified Data.Text as Text #-}
{-# COMPILE GHC trace = const (const (Debug.trace . Text.unpack)) #-}

{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE trace-eq #-}

a : String
a = trace "The Traced" "The Value"

open import IO.Primitive
open import Codata.Musical.Costring

main = putStrLn (toCostring a)

C-c C-n on a yields "The Value"
./Main after compilation yields The Traced\nThe Value

gallais added a commit that referenced this issue Jan 4, 2019
@MatthewDaggitt MatthewDaggitt modified the milestones: v0.18, v1.0 Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants