-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Description
Moving discussion from JordanMartinez/purescript-cookbook#161 (comment)
Should this debug API be expanded? I was thinking of something like:
-- Uses JS console.log to print contents
spy :: a -> a
-- Uses Show instance to convert contents to string
spyShow :: Show a => a -> a
-- Prepends a tag (current spy behavior)
spyTag :: String -> a -> a
spyTagShow :: Show a => String -> a -> a
-- Wait to evaluate expression
-- Not sure if this only makes sense with `Tag`
spyThunk :: (Unit -> a) -> a
-- ... other combinations with Tag and Show
-- Monodic version
-- Wondering if this could be relaxed to Applicative (like haskell's traceM).
spyM :: Monad m => a -> m Unit
-- ... other combinations with Thunk, Tag, and Show
-- Stack dump
-- Uses JS console.trace() to log stack
-- Similar to Haskell's traceStack
spyStack :: a -> a
-- ... other combinations with M, Thunk, Tag, and Show
-- Reflecting version
-- Uses reflected expression as tag
-- Not sure if this is possible
spyReflect :: a -> a
-- ... other combinations with Stack, M, Thunk, Tag, and Show
-- This would be great to include
todo :: aAdditional details on spyReflect
Imagine writing:
fact :: Int -> Int -> Int
fact 0 acc = spyReflect acc
fact n acc = fact (spyReflect $ n - 1) (spyReflect $ acc * n)To get this behavior:
fact :: Int -> Int -> Int
fact 0 acc = spy "acc" acc
fact n acc = fact (spy "n - 1" $ n - 1) (spy "acc * n" $ acc * n)This is really convenient for debugging in other languages:
julia> x = 5
5
julia> @show (x + 3)
x + 3 = 8
8
julia> @info "tag" (x + 3)
┌ Info: tag
└ x + 3 = 8Other questions:
- Thoughts on
spyvstracenaming? - Is reflect behavior possible?
- Are there other ways to gain all these behaviors without writing 2^n functions? Looks like 64 would be needed.
MonadvsApplicativefortraceM/spyM?- Any other inspiration to gain from Haskell or Elm debug logging?
- Which
todoimplementation to use? This PR or this snippet?
Metadata
Metadata
Assignees
Labels
No labels