about summary refs log tree commit diff
path: root/users/Profpatsch/my-prelude
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/my-prelude')
-rw-r--r--users/Profpatsch/my-prelude/Data/Error/Tree.hs113
-rw-r--r--users/Profpatsch/my-prelude/default.nix2
-rw-r--r--users/Profpatsch/my-prelude/my-prelude.cabal4
3 files changed, 3 insertions, 116 deletions
diff --git a/users/Profpatsch/my-prelude/Data/Error/Tree.hs b/users/Profpatsch/my-prelude/Data/Error/Tree.hs
deleted file mode 100644
index e8e45e704882..000000000000
--- a/users/Profpatsch/my-prelude/Data/Error/Tree.hs
+++ /dev/null
@@ -1,113 +0,0 @@
-{-# LANGUAGE DerivingStrategies #-}
-{-# LANGUAGE GHC2021 #-}
-{-# LANGUAGE OverloadedRecordDot #-}
-
-module Data.Error.Tree where
-
-import Data.String (IsString (..))
-import Data.Tree qualified as Tree
-import MyPrelude
-
--- | A tree of 'Error's, with a single root 'Error' and 0..n nested 'ErrorTree's.
---
--- @@
--- top error
--- |
--- |-- error 1
--- | |
--- |  -- error 1.1
--- |
--- |-- error 2
--- @@
-newtype ErrorTree = ErrorTree {unErrorTree :: (Tree.Tree Error)}
-  deriving stock (Show)
-
-instance IsString ErrorTree where
-  fromString = singleError . fromString
-
--- deriving newtype (Ord) -- TODO: Add this instance with containers-0.6.5
-
--- | Turn a single 'Error' into an 'ErrorTree', a leaf.
-singleError :: Error -> ErrorTree
-singleError e = ErrorTree $ Tree.Node e []
-
--- | Take a list of errors & create a new 'ErrorTree' with the given 'Error' as the root.
-errorTree :: Error -> NonEmpty Error -> ErrorTree
-errorTree topLevelErr nestedErrs =
-  ErrorTree
-    ( Tree.Node
-        topLevelErr
-        (nestedErrs <&> (\e -> Tree.Node e []) & toList)
-    )
-
--- | Attach more context to the root 'Error' of the 'ErrorTree', via 'errorContext'.
-errorTreeContext :: Text -> ErrorTree -> ErrorTree
-errorTreeContext context (ErrorTree tree) =
-  ErrorTree $
-    tree
-      { Tree.rootLabel = tree.rootLabel & errorContext context
-      }
-
--- | Nest the given 'Error' around the ErrorTree
---
--- @@
--- top level error
--- |
--- -- nestedError
---   |
---   -- error 1
---   |
---   -- error 2
--- @@
-nestedError ::
-  Error -> -- top level
-  ErrorTree -> -- nested
-  ErrorTree
-nestedError topLevelErr nestedErr =
-  ErrorTree $
-    Tree.Node
-      { Tree.rootLabel = topLevelErr,
-        Tree.subForest = [nestedErr.unErrorTree]
-      }
-
--- | Nest the given 'Error' around the list of 'ErrorTree's.
---
--- @@
--- top level error
--- |
--- |- nestedError1
--- | |
--- | -- error 1
--- | |
--- | -- error 2
--- |
--- |- nestedError 2
--- @@
-nestedMultiError ::
-  Error -> -- top level
-  NonEmpty ErrorTree -> -- nested
-  ErrorTree
-nestedMultiError topLevelErr nestedErrs =
-  ErrorTree $
-    Tree.Node
-      { Tree.rootLabel = topLevelErr,
-        Tree.subForest = nestedErrs & toList <&> (.unErrorTree)
-      }
-
-prettyErrorTree :: ErrorTree -> Text
-prettyErrorTree (ErrorTree tree) =
-  tree
-    <&> prettyError
-    <&> textToString
-    & Tree.drawTree
-    & stringToText
-
-prettyErrorTrees :: NonEmpty ErrorTree -> Text
-prettyErrorTrees forest =
-  forest
-    <&> (.unErrorTree)
-    <&> fmap prettyError
-    <&> fmap textToString
-    & toList
-    & Tree.drawForest
-    & stringToText
diff --git a/users/Profpatsch/my-prelude/default.nix b/users/Profpatsch/my-prelude/default.nix
index 1fa8075c523c..0c582c9585ca 100644
--- a/users/Profpatsch/my-prelude/default.nix
+++ b/users/Profpatsch/my-prelude/default.nix
@@ -8,7 +8,6 @@ pkgs.haskellPackages.mkDerivation {
     ./my-prelude.cabal
     ./MyPrelude.hs
     ./Pretty.hs
-    ./Data/Error/Tree.hs
     ./Aeson.hs
     ./RunCommand.hs
     ./Test.hs
@@ -18,6 +17,7 @@ pkgs.haskellPackages.mkDerivation {
 
   libraryHaskellDepends = [
     pkgs.haskellPackages.pa-label
+    pkgs.haskellPackages.pa-error-tree
     pkgs.haskellPackages.aeson
     pkgs.haskellPackages.aeson-better-errors
     pkgs.haskellPackages.PyF
diff --git a/users/Profpatsch/my-prelude/my-prelude.cabal b/users/Profpatsch/my-prelude/my-prelude.cabal
index 283f9f71375f..fad13300a29a 100644
--- a/users/Profpatsch/my-prelude/my-prelude.cabal
+++ b/users/Profpatsch/my-prelude/my-prelude.cabal
@@ -1,4 +1,4 @@
-cabal-version:      2.4
+cabal-version:      3.0
 name:               my-prelude
 version:            0.0.1.0
 author:             Profpatsch
@@ -8,7 +8,6 @@ library
     exposed-modules:
       MyPrelude
       Pretty
-      Data.Error.Tree
       Aeson
       RunCommand
       Test
@@ -21,6 +20,7 @@ library
     build-depends:
        base >=4.15 && <5
      , pa-label
+     , pa-error-tree
      , aeson
      , aeson-better-errors
      , PyF