Skip to content

Port Debug from purescript-debugged to Prelude #273

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 93 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
ee1e3ef
Initial commit
hdgarrood Dec 13, 2017
15d7320
Fix shadowing warning
hdgarrood Dec 16, 2017
d180e48
Use a custom PSCI support module for easy experimenting
hdgarrood Dec 16, 2017
a06dbde
tweak
hdgarrood Dec 17, 2017
b3012c2
Progress
hdgarrood Dec 17, 2017
5eac352
List, lazy list, Eff, records
hdgarrood Dec 17, 2017
ea697a2
Tweaks
hdgarrood Dec 17, 2017
948ad4f
Debug {Set, Debugged}
hdgarrood Dec 17, 2017
a78a043
Tweak Debugged data definition
hdgarrood Dec 18, 2017
20459bd
Split into multiple modules
hdgarrood Dec 18, 2017
70ef617
Cleanup comments
hdgarrood Dec 18, 2017
7f46732
Update for 0.12
hdgarrood Dec 4, 2018
149e663
Further updates for 0.12
hdgarrood Dec 6, 2018
d95c6d0
Overhaul data types
hdgarrood Dec 6, 2018
544c056
Fix tests
hdgarrood Dec 6, 2018
7aef26d
Fix parenthesising of negative numbers
hdgarrood Dec 6, 2018
3ab0023
Refactor/add Tree operations
hdgarrood Dec 6, 2018
57ace7a
Diffing
hdgarrood Dec 6, 2018
efade84
Add isSmall and isReallySmall
hdgarrood Dec 6, 2018
4d78518
Minor refactoring
hdgarrood Dec 6, 2018
4ae0360
Add prettyPrint function
hdgarrood Dec 7, 2018
9d807e4
Update PSCI support module to support eval-ing Effect
hdgarrood Dec 7, 2018
5dc1a44
Add Debug Repr instance
hdgarrood Dec 7, 2018
7edb9aa
Fix some missing punctuation
hdgarrood Dec 7, 2018
5f32e92
Add generic deriving and tests for it
hdgarrood Dec 7, 2018
970ec7d
Remove prettyPrintOneLine
hdgarrood Dec 7, 2018
060bcb3
Fix whitespace issues
hdgarrood Dec 7, 2018
1e19d84
Add some instances
hdgarrood Dec 7, 2018
d35586a
Rearrange
hdgarrood Dec 7, 2018
f46cda8
Add ReprDelta
hdgarrood Dec 8, 2018
107c43c
Major refactoring of pretty-printer
hdgarrood Dec 8, 2018
73cb535
Pretty-printing deltas now works!
hdgarrood Dec 9, 2018
ae2a51f
Some small tweaks
hdgarrood Dec 9, 2018
d261772
Rename debugged => debug
hdgarrood Dec 10, 2018
6bf3b14
Rename directory structure
hdgarrood Dec 10, 2018
8b73083
Remove unused functions withProp and withAssocProp
hdgarrood Dec 11, 2018
6a90dd6
Update docs
hdgarrood Dec 11, 2018
ba3826d
Improve size calculation for compacting
hdgarrood Dec 11, 2018
85d2546
Further compacting tweaks for pretty-printing
hdgarrood Dec 11, 2018
ad21f32
Fix parenthesising of nullary constructors
hdgarrood Dec 11, 2018
7468ebd
Expand docs
hdgarrood Dec 12, 2018
654e992
Use `diff` for the more convenient variant of the function
hdgarrood Dec 12, 2018
7661f23
Add Debug ReprDelta instance
hdgarrood Dec 12, 2018
04a458d
Remove unused import
hdgarrood Dec 12, 2018
51b6705
Add missing export of DebugRowList + document it
hdgarrood Dec 12, 2018
2aba092
Add Omitted constructor + scrap Sized class
hdgarrood Dec 12, 2018
aa096bd
Implement pruning trees during pretty-printing
hdgarrood Dec 12, 2018
d4fea78
Make compact threshold configurable
hdgarrood Dec 12, 2018
0bda8f0
Make Number relative error configurable when diffing
hdgarrood Dec 12, 2018
2685974
Provide Eval (Effect Unit) instance
hdgarrood Dec 12, 2018
031e108
Add warning re: PSCI.Support hack
hdgarrood Dec 12, 2018
85be060
Quote record labels where necessary, fixes #1
hdgarrood Dec 14, 2018
cc60ae2
Remove the psci-support hack
hdgarrood Feb 2, 2019
5f01b0b
Provide more flexibility with `opaque` constructors
hdgarrood Feb 2, 2019
52dc3be
Remove Collection ctor + pretty-printing opaque tweaks
hdgarrood Feb 2, 2019
c4baf77
Add Debug Date instance
hdgarrood Feb 2, 2019
2b5527c
Improve diffing for Assoc labels
hdgarrood Feb 3, 2019
70b12a2
Update to purescript 0.13.0
May 30, 2019
2e9c38a
Merge pull request #4 from dn3010/purs-0.13.0
hdgarrood May 30, 2019
7112c1b
Fix warnings
hdgarrood May 30, 2019
fbcbeb6
Get code to compile again
JordanMartinez Sep 23, 2021
4d1d3a4
Replace all kind-specific proxies with Proxy
JordanMartinez Sep 23, 2021
5772d79
Replace Tuple usage with Record
JordanMartinez Sep 23, 2021
f9c6353
Remove unused import
JordanMartinez Sep 24, 2021
2c3ffbc
Reuse Show FFI `cons` function to create Array
JordanMartinez Sep 24, 2021
53b24f9
Drop non-Prelude/Prim Debug instances
JordanMartinez Sep 24, 2021
b0f2871
Rename Tree to InternalRoseTree
JordanMartinez Sep 24, 2021
1f17631
Move InternalRoseTree into separate file
JordanMartinez Sep 24, 2021
bccefb9
Replace Prelude import with module imports
JordanMartinez Sep 24, 2021
42e4dc0
Move PrettyPrinter to inner module
JordanMartinez Sep 24, 2021
f6be82b
Update module name to match file path
JordanMartinez Sep 24, 2021
6c6e82c
Port PrettyPrinter code into PrettyPrinter module
JordanMartinez Sep 24, 2021
c420bad
Update docs of modules
JordanMartinez Sep 24, 2021
f89fe53
Replace Prelude import with modular imports
JordanMartinez Sep 24, 2021
59f943e
Replace safe get/delete with unsafe ones
JordanMartinez Sep 24, 2021
05b87ba
Replace Prelude import with modular imports
JordanMartinez Sep 24, 2021
01dfffd
Generic: replace prelude import with modular imports
JordanMartinez Sep 24, 2021
05fd7f1
Sort order of imports
JordanMartinez Sep 24, 2021
2ba0f8f
Drop blank line separating imports
JordanMartinez Sep 24, 2021
6360aac
Delete Data.Debug module
JordanMartinez Sep 24, 2021
6256007
Rename module: Data.Debug.Class to Data.Debug
JordanMartinez Sep 24, 2021
d178d25
Keep only source code intended for prelude merge
JordanMartinez Sep 24, 2021
9a7417c
Merge remote-tracking branch 'prelude/master' into prepare-for-prelud…
JordanMartinez Sep 24, 2021
a097919
Add Debug instances for newtypes and Proxy
JordanMartinez Sep 24, 2021
5670410
Update changelog
JordanMartinez Sep 24, 2021
78ad6cf
Add use strict to FFI file
JordanMartinez Sep 24, 2021
7499409
Add missing import for `D` module alias
JordanMartinez Sep 24, 2021
6114b33
Fix Endo Debug instance
JordanMartinez Sep 24, 2021
ba52a4d
Merge remote-tracking branch 'origin/master' into prepare-for-prelude…
JordanMartinez Sep 15, 2022
768a228
Migrate FFI to ES syntax
JordanMartinez Sep 15, 2022
4d6963f
Add missing blank line
JordanMartinez Sep 15, 2022
15ce45f
Fix linting error
JordanMartinez Sep 15, 2022
0a41095
Add Debug instance for Repr
JordanMartinez Sep 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Ported the `Debug` type class from `purescript-debugged` into `purescript-prelude` (#273 by @JordanMartinez)

Bugfixes:

Expand Down
10 changes: 10 additions & 0 deletions src/Data/Debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const cons = function (head) {
return function (tail) {
const arr = new Array(tail.length + 1);
arr[0] = head;
for (let i = 0; i++; i < tail.length) {
arr[i + 1] = tail[i];
}
return arr;
};
};
114 changes: 114 additions & 0 deletions src/Data/Debug.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
-- | This module provides the `Debug` type class, for converting values into
-- | their `Debug` representations.
module Data.Debug
( class Debug
, debug
, class DebugRowList
, debugRowList
) where

import Control.Semigroupoid ((<<<))
import Data.Functor (map)
import Data.Debug.Type as D
import Data.Ordering (Ordering(..))
import Data.Symbol (class IsSymbol, reflectSymbol)
import Data.Unit (Unit)
import Data.Void (Void, absurd)
import Prim.Row as Row
import Prim.RowList (class RowToList, RowList, Nil, Cons)
import Record.Unsafe (unsafeDelete, unsafeGet)
import Type.Proxy (Proxy(..))

-- | Ideally, all types of kind `Type` should have an instance of this class.
-- | If you are defining a type where it's difficult/impossible to do anything
-- | useful here (e.g. `Ref` or `(->)`) then you should use the `opaque`
-- | constructor.
-- |
-- | If a type has an `Eq` instance, then the `debug` function in its `Debug`
-- | instance should be *injective*, that is:
-- |
-- | ```purescript
-- | x /= y `implies` debug x /= debug y
-- | ```
class Debug :: Type -> Constraint
class Debug a where
debug :: a -> D.Repr

-------------------------------------------------------------------------------
-- Prim

instance debugInt :: Debug Int where
debug = D.int

instance debugNumber :: Debug Number where
debug = D.number

instance debugBoolean :: Debug Boolean where
debug = D.boolean

instance debugString :: Debug String where
debug = D.string

instance debugChar :: Debug Char where
debug = D.char

instance debugArray :: Debug a => Debug (Array a) where
debug = D.array <<< map debug

instance debugFunction :: Debug (a -> b) where
debug _ = D.opaque_ "function"

-- | This class is part of the machinery for the `Debug (Record r)` instance;
-- | it is not intended to be used directly.
class DebugRowList :: RowList Type -> Row Type -> Constraint
class DebugRowList list row | list -> row where
debugRowList :: Proxy list -> Record row -> Array { key :: String, value :: D.Repr }

instance debugRowListNil :: DebugRowList Nil () where
debugRowList _ _ = []

instance debugRowListCons ::
( Debug a
, DebugRowList listRest rowRest
, Row.Cons key a rowRest rowFull
, Row.Lacks key rowRest
, RowToList rowFull (Cons key a listRest)
, IsSymbol key
) => DebugRowList (Cons key a listRest) rowFull where
debugRowList _ rec =
cons { key, value: debug val } rest
where
key = reflectSymbol (Proxy :: Proxy key)
val = unsafeGet key rec :: a
rest = debugRowList (Proxy :: Proxy listRest) (unsafeDelete key rec)

instance debugRecord ::
( RowToList row list
, DebugRowList list row
) => Debug (Record row) where
debug r =
D.record (debugRowList prx r)
where
prx = Proxy :: Proxy list

-------------------------------------------------------------------------------
-- Prelude

instance debugOrdering :: Debug Ordering where
debug LT = D.constructor "LT" []
debug EQ = D.constructor "EQ" []
debug GT = D.constructor "GT" []

instance debugUnit :: Debug Unit where
debug _ = D.constructor "unit" []

instance debugVoid :: Debug Void where
debug = absurd

instance debugProxy :: Debug (Proxy a) where
debug _ = D.opaque_ "Proxy"

foreign import cons :: forall a. a -> Array a -> Array a

instance debugRepr :: Debug D.Repr where
debug r = D.opaque "Repr" r
69 changes: 69 additions & 0 deletions src/Data/Debug/Generic.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- | This module provides a mechanism for deriving `Debug` instances for types
-- | which export their constructors. To use it, simply derive a `Generic`
-- | instance and then use `genericDebug` in the `Debug` instance. For example:
-- |
-- | ```
-- | data MyType = [...]
-- | derive instance genericMyType :: Generic MyType _
-- | instance debugMyType :: Debug MyType where
-- | debug genericDebug
-- | ```
-- |
-- | Note that the resulting `Debug` instance will expose details of the
-- | constructors. Therefore, this mechanism is not suitable for types which
-- | hide their constructors.
module Data.Debug.Generic
( genericDebug
, class GenericDebug
, genericDebug'
, class GenericDebugArgs
, genericDebugArgs
) where

import Control.Semigroupoid ((<<<))
import Data.Semigroup ((<>))
import Data.Debug (class Debug, debug)
import Data.Debug.Type as D
import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments(..), NoConstructors, Product(..), Sum(..), from)
import Data.Symbol (class IsSymbol, reflectSymbol)
import Type.Proxy (Proxy(..))

-- | A generic implementation of the `Debug` type class.
genericDebug :: forall a rep.
Generic a rep =>
GenericDebug rep =>
a -> D.Repr
genericDebug = genericDebug' <<< from

-- | This class is part of the machinery for deriving `Debug` instances; it is
-- | not intended to be used directly.
class GenericDebug rep where
genericDebug' :: rep -> D.Repr

instance genericDebugNoConstructors :: GenericDebug NoConstructors where
genericDebug' x = genericDebug' x

instance genericDebugConstructor
:: (GenericDebugArgs a, IsSymbol name) => GenericDebug (Constructor name a) where
genericDebug' (Constructor a) =
D.constructor
(reflectSymbol (Proxy :: Proxy name))
(genericDebugArgs a)

instance genericDebugSum :: (GenericDebug a, GenericDebug b) => GenericDebug (Sum a b) where
genericDebug' (Inl a) = genericDebug' a
genericDebug' (Inr b) = genericDebug' b

-- | This class is part of the machinery for deriving `Debug` instances; it is
-- | not intended to be used directly.
class GenericDebugArgs rep where
genericDebugArgs :: rep -> Array D.Repr

instance genericDebugArgsArgument :: Debug a => GenericDebugArgs (Argument a) where
genericDebugArgs (Argument a) = [debug a]

instance genericDebugArgsProduct :: (GenericDebugArgs a, GenericDebugArgs b) => GenericDebugArgs (Product a b) where
genericDebugArgs (Product a b) = genericDebugArgs a <> genericDebugArgs b

instance genericDebugArgsNoArguments :: GenericDebugArgs NoArguments where
genericDebugArgs NoArguments = []
Loading