From d4e0cbb8d32515db7a815cdd55e7a8b1e9a43fd2 Mon Sep 17 00:00:00 2001 From: Ian Grant Jeffries Date: Sun, 3 Nov 2019 19:40:38 -0500 Subject: [PATCH] Include Id in prelude. --- bowtie-blueprint/src/Bowtie/Blueprint.hs | 1 - bowtie-js/src/Bowtie/JS/AST.hs | 1 - bowtie-js/src/Bowtie/JS/Imperativize.hs | 1 - bowtie-js/src/Bowtie/JS/Serialize.hs | 1 - .../src/Bowtie/Visualize/GraphConstraints.hs | 1 - bowtie/bowtie.cabal | 3 +-- bowtie/src/Bowtie/Core/Expr.hs | 1 - bowtie/src/Bowtie/Infer/Assumptions.hs | 1 - bowtie/src/Bowtie/Infer/BottomUp.hs | 1 - bowtie/src/Bowtie/Infer/Constraints.hs | 1 - bowtie/src/Bowtie/Infer/Elaborate.hs | 1 - bowtie/src/Bowtie/Infer/Generalize.hs | 1 - bowtie/src/Bowtie/Infer/Infer.hs | 1 - bowtie/src/Bowtie/Infer/Substitution.hs | 1 - bowtie/src/Bowtie/Infer/Unify.hs | 1 - bowtie/src/Bowtie/Lib/Builtin.hs | 2 +- bowtie/src/Bowtie/Lib/Environment.hs | 1 - bowtie/src/Bowtie/Lib/FreeVars.hs | 1 - bowtie/src/Bowtie/Lib/Id.hs | 20 ------------------- bowtie/src/Bowtie/Lib/Prelude.hs | 17 ++++++++++++++++ bowtie/src/Bowtie/Lib/TypeScheme.hs | 1 - bowtie/src/Bowtie/Surface/AST.hs | 1 - bowtie/src/Bowtie/Surface/Desugar.hs | 1 - bowtie/src/Bowtie/Surface/Parse.hs | 1 - bowtie/src/Bowtie/Type/AST.hs | 1 - bowtie/src/Bowtie/Type/Kindcheck.hs | 1 - bowtie/src/Bowtie/Type/Parse.hs | 1 - bowtie/src/Bowtie/Untyped/Erase.hs | 1 - bowtie/src/Bowtie/Untyped/Eval.hs | 1 - bowtie/src/Bowtie/Untyped/Expr.hs | 1 - bowtie/test/Bowtie/Surface/InferSpec.hs | 1 - bowtie/test/Test/Quoted/AST.hs | 8 ++++---- bowtie/test/Test/Quoted/Expr.hs | 9 ++++----- 33 files changed, 27 insertions(+), 59 deletions(-) delete mode 100644 bowtie/src/Bowtie/Lib/Id.hs diff --git a/bowtie-blueprint/src/Bowtie/Blueprint.hs b/bowtie-blueprint/src/Bowtie/Blueprint.hs index 193e19b..0fe7a49 100644 --- a/bowtie-blueprint/src/Bowtie/Blueprint.hs +++ b/bowtie-blueprint/src/Bowtie/Blueprint.hs @@ -1,6 +1,5 @@ module Bowtie.Blueprint where -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import qualified Bowtie.Type.AST as Type.AST diff --git a/bowtie-js/src/Bowtie/JS/AST.hs b/bowtie-js/src/Bowtie/JS/AST.hs index cf59619..1f45eac 100644 --- a/bowtie-js/src/Bowtie/JS/AST.hs +++ b/bowtie-js/src/Bowtie/JS/AST.hs @@ -1,6 +1,5 @@ module Bowtie.JS.AST where -import Bowtie.Lib.Id import Bowtie.Lib.Prelude -- h/t PureScript diff --git a/bowtie-js/src/Bowtie/JS/Imperativize.hs b/bowtie-js/src/Bowtie/JS/Imperativize.hs index 3cd2a91..2fdc734 100644 --- a/bowtie-js/src/Bowtie/JS/Imperativize.hs +++ b/bowtie-js/src/Bowtie/JS/Imperativize.hs @@ -2,7 +2,6 @@ module Bowtie.JS.Imperativize where import Bowtie.JS.AST import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme diff --git a/bowtie-js/src/Bowtie/JS/Serialize.hs b/bowtie-js/src/Bowtie/JS/Serialize.hs index e1ea782..90f4011 100644 --- a/bowtie-js/src/Bowtie/JS/Serialize.hs +++ b/bowtie-js/src/Bowtie/JS/Serialize.hs @@ -6,7 +6,6 @@ module Bowtie.JS.Serialize ) where import Bowtie.JS.AST -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import qualified Data.Text as Text diff --git a/bowtie-visualize/src/Bowtie/Visualize/GraphConstraints.hs b/bowtie-visualize/src/Bowtie/Visualize/GraphConstraints.hs index e92a90a..4dcad17 100644 --- a/bowtie-visualize/src/Bowtie/Visualize/GraphConstraints.hs +++ b/bowtie-visualize/src/Bowtie/Visualize/GraphConstraints.hs @@ -3,7 +3,6 @@ module Bowtie.Visualize.GraphConstraints where import Bowtie.Infer.Constraints -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme import Bowtie.Type.AST diff --git a/bowtie/bowtie.cabal b/bowtie/bowtie.cabal index eba99db..707e01b 100644 --- a/bowtie/bowtie.cabal +++ b/bowtie/bowtie.cabal @@ -4,7 +4,7 @@ cabal-version: 1.18 -- -- see: https://github.com/sol/hpack -- --- hash: e7bc26b76c7c6decea4f8480aaf9046bf3bc39db02244bad3baad02ce95c1190 +-- hash: 06e4c7b376d5a49b162fc81cf1e96b8f72f6dea96f0d13be1c83b7a4ec6aaa40 name: bowtie version: 0.0.0 @@ -28,7 +28,6 @@ library Bowtie.Lib.Builtin Bowtie.Lib.Environment Bowtie.Lib.FreeVars - Bowtie.Lib.Id Bowtie.Lib.OrderedMap Bowtie.Lib.Prelude Bowtie.Lib.TypeScheme diff --git a/bowtie/src/Bowtie/Core/Expr.hs b/bowtie/src/Bowtie/Core/Expr.hs index 0f9d362..44c059d 100644 --- a/bowtie/src/Bowtie/Core/Expr.hs +++ b/bowtie/src/Bowtie/Core/Expr.hs @@ -1,7 +1,6 @@ module Bowtie.Core.Expr where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Type.AST diff --git a/bowtie/src/Bowtie/Infer/Assumptions.hs b/bowtie/src/Bowtie/Infer/Assumptions.hs index 4b8e6fa..66c5aa6 100644 --- a/bowtie/src/Bowtie/Infer/Assumptions.hs +++ b/bowtie/src/Bowtie/Infer/Assumptions.hs @@ -1,6 +1,5 @@ module Bowtie.Infer.Assumptions where -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Type.AST diff --git a/bowtie/src/Bowtie/Infer/BottomUp.hs b/bowtie/src/Bowtie/Infer/BottomUp.hs index c9a35b1..53118bb 100644 --- a/bowtie/src/Bowtie/Infer/BottomUp.hs +++ b/bowtie/src/Bowtie/Infer/BottomUp.hs @@ -3,7 +3,6 @@ module Bowtie.Infer.BottomUp where import Bowtie.Infer.Assumptions import Bowtie.Infer.Constraints import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme diff --git a/bowtie/src/Bowtie/Infer/Constraints.hs b/bowtie/src/Bowtie/Infer/Constraints.hs index 938de88..0bf882c 100644 --- a/bowtie/src/Bowtie/Infer/Constraints.hs +++ b/bowtie/src/Bowtie/Infer/Constraints.hs @@ -1,7 +1,6 @@ module Bowtie.Infer.Constraints where import Bowtie.Infer.Substitution -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme import Bowtie.Type.AST diff --git a/bowtie/src/Bowtie/Infer/Elaborate.hs b/bowtie/src/Bowtie/Infer/Elaborate.hs index b1884c7..ca03794 100644 --- a/bowtie/src/Bowtie/Infer/Elaborate.hs +++ b/bowtie/src/Bowtie/Infer/Elaborate.hs @@ -3,7 +3,6 @@ module Bowtie.Infer.Elaborate where import Bowtie.Infer.Infer import Bowtie.Infer.Substitution import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Surface.AST import Control.Monad.State.Class diff --git a/bowtie/src/Bowtie/Infer/Generalize.hs b/bowtie/src/Bowtie/Infer/Generalize.hs index 697fb18..1a5ee17 100644 --- a/bowtie/src/Bowtie/Infer/Generalize.hs +++ b/bowtie/src/Bowtie/Infer/Generalize.hs @@ -2,7 +2,6 @@ module Bowtie.Infer.Generalize where import Bowtie.Infer.Substitution import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme import Bowtie.Type.AST diff --git a/bowtie/src/Bowtie/Infer/Infer.hs b/bowtie/src/Bowtie/Infer/Infer.hs index 0c781b0..0bda99c 100644 --- a/bowtie/src/Bowtie/Infer/Infer.hs +++ b/bowtie/src/Bowtie/Infer/Infer.hs @@ -7,7 +7,6 @@ import Bowtie.Infer.Constraints import Bowtie.Infer.Solve import Bowtie.Infer.Substitution import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Surface.AST import Control.Monad.Except diff --git a/bowtie/src/Bowtie/Infer/Substitution.hs b/bowtie/src/Bowtie/Infer/Substitution.hs index 7734800..4be6a54 100644 --- a/bowtie/src/Bowtie/Infer/Substitution.hs +++ b/bowtie/src/Bowtie/Infer/Substitution.hs @@ -1,7 +1,6 @@ module Bowtie.Infer.Substitution where import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme import Bowtie.Surface.AST diff --git a/bowtie/src/Bowtie/Infer/Unify.hs b/bowtie/src/Bowtie/Infer/Unify.hs index e297eb5..8dc6c4b 100644 --- a/bowtie/src/Bowtie/Infer/Unify.hs +++ b/bowtie/src/Bowtie/Infer/Unify.hs @@ -2,7 +2,6 @@ module Bowtie.Infer.Unify where import Bowtie.Infer.Substitution import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Surface.AST diff --git a/bowtie/src/Bowtie/Lib/Builtin.hs b/bowtie/src/Bowtie/Lib/Builtin.hs index 47fb6c2..75b23f0 100644 --- a/bowtie/src/Bowtie/Lib/Builtin.hs +++ b/bowtie/src/Bowtie/Lib/Builtin.hs @@ -1,6 +1,6 @@ module Bowtie.Lib.Builtin where -import Bowtie.Lib.Id +import Bowtie.Lib.Prelude int :: Id int = diff --git a/bowtie/src/Bowtie/Lib/Environment.hs b/bowtie/src/Bowtie/Lib/Environment.hs index bbc9fa6..5f5b692 100644 --- a/bowtie/src/Bowtie/Lib/Environment.hs +++ b/bowtie/src/Bowtie/Lib/Environment.hs @@ -3,7 +3,6 @@ module Bowtie.Lib.Environment where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme diff --git a/bowtie/src/Bowtie/Lib/FreeVars.hs b/bowtie/src/Bowtie/Lib/FreeVars.hs index 8ae9c35..96db5e0 100644 --- a/bowtie/src/Bowtie/Lib/FreeVars.hs +++ b/bowtie/src/Bowtie/Lib/FreeVars.hs @@ -1,6 +1,5 @@ module Bowtie.Lib.FreeVars where -import Bowtie.Lib.Id import Bowtie.Lib.Prelude class FreeVars a where diff --git a/bowtie/src/Bowtie/Lib/Id.hs b/bowtie/src/Bowtie/Lib/Id.hs deleted file mode 100644 index bb779da..0000000 --- a/bowtie/src/Bowtie/Lib/Id.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Bowtie.Lib.Id where - -import Bowtie.Lib.Prelude -import Control.Monad.State.Class - -newtype Id - = Id Text - deriving stock (Eq, Ord, Show, Generic) - deriving newtype (Hashable) - deriving anyclass (NFData) - --- | Note making this a field of @id@ since then it would --- be printed every time an @Id@ is shown. -unId :: Id -> Text -unId (Id t) = - t - -genVar :: MonadState Int m => m Id -genVar = - state (\n -> (Id (show n), n + 1)) diff --git a/bowtie/src/Bowtie/Lib/Prelude.hs b/bowtie/src/Bowtie/Lib/Prelude.hs index c40239e..40be751 100644 --- a/bowtie/src/Bowtie/Lib/Prelude.hs +++ b/bowtie/src/Bowtie/Lib/Prelude.hs @@ -34,6 +34,7 @@ import Numeric.Natural as X (Natural) -- Local stuff: import Control.Monad.Except +import Control.Monad.State.Class import GHC.Stack.Types (HasCallStack) import System.Directory (listDirectory) import System.Exit (exitFailure) @@ -48,6 +49,22 @@ import qualified Data.Text as Text import qualified Data.Text.IO as TIO import qualified Prelude +newtype Id + = Id Text + deriving stock (Eq, Ord, Show, Generic) + deriving newtype (Hashable) + deriving anyclass (NFData) + +-- | Note making this a field of @id@ since then it would +-- be printed every time an @Id@ is shown. +unId :: Id -> Text +unId (Id t) = + t + +genVar :: MonadState Int m => m Id +genVar = + state (\n -> (Id (show n), n + 1)) + {-# WARNING error "'error' remains in code" #-} error :: HasCallStack => [Char] -> a error = diff --git a/bowtie/src/Bowtie/Lib/TypeScheme.hs b/bowtie/src/Bowtie/Lib/TypeScheme.hs index 48fb7a5..7778f2d 100644 --- a/bowtie/src/Bowtie/Lib/TypeScheme.hs +++ b/bowtie/src/Bowtie/Lib/TypeScheme.hs @@ -1,7 +1,6 @@ module Bowtie.Lib.TypeScheme where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Surface.AST diff --git a/bowtie/src/Bowtie/Surface/AST.hs b/bowtie/src/Bowtie/Surface/AST.hs index dd07b17..e14a6e5 100644 --- a/bowtie/src/Bowtie/Surface/AST.hs +++ b/bowtie/src/Bowtie/Surface/AST.hs @@ -4,7 +4,6 @@ module Bowtie.Surface.AST ) where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap import Bowtie.Lib.Prelude import Bowtie.Type.AST diff --git a/bowtie/src/Bowtie/Surface/Desugar.hs b/bowtie/src/Bowtie/Surface/Desugar.hs index 4a66a87..a488647 100644 --- a/bowtie/src/Bowtie/Surface/Desugar.hs +++ b/bowtie/src/Bowtie/Surface/Desugar.hs @@ -5,7 +5,6 @@ module Bowtie.Surface.Desugar ) where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude hiding (all, rem) import Bowtie.Surface.AST diff --git a/bowtie/src/Bowtie/Surface/Parse.hs b/bowtie/src/Bowtie/Surface/Parse.hs index 7606ac0..b2f1161 100644 --- a/bowtie/src/Bowtie/Surface/Parse.hs +++ b/bowtie/src/Bowtie/Surface/Parse.hs @@ -10,7 +10,6 @@ module Bowtie.Surface.Parse , dirtyParseAST ) where -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude hiding (many, some) import Bowtie.Surface.AST diff --git a/bowtie/src/Bowtie/Type/AST.hs b/bowtie/src/Bowtie/Type/AST.hs index 389ebf2..839c235 100644 --- a/bowtie/src/Bowtie/Type/AST.hs +++ b/bowtie/src/Bowtie/Type/AST.hs @@ -1,7 +1,6 @@ module Bowtie.Type.AST where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import qualified Data.Set as Set diff --git a/bowtie/src/Bowtie/Type/Kindcheck.hs b/bowtie/src/Bowtie/Type/Kindcheck.hs index b277e22..e533349 100644 --- a/bowtie/src/Bowtie/Type/Kindcheck.hs +++ b/bowtie/src/Bowtie/Type/Kindcheck.hs @@ -1,7 +1,6 @@ module Bowtie.Type.Kindcheck where import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme diff --git a/bowtie/src/Bowtie/Type/Parse.hs b/bowtie/src/Bowtie/Type/Parse.hs index a328692..0ae2b1b 100644 --- a/bowtie/src/Bowtie/Type/Parse.hs +++ b/bowtie/src/Bowtie/Type/Parse.hs @@ -16,7 +16,6 @@ module Bowtie.Type.Parse , parseTest ) where -import Bowtie.Lib.Id import Bowtie.Lib.Prelude hiding (many, some) import Bowtie.Type.AST import Control.Applicative.Combinators.NonEmpty diff --git a/bowtie/src/Bowtie/Untyped/Erase.hs b/bowtie/src/Bowtie/Untyped/Erase.hs index 5e148f9..fdfba95 100644 --- a/bowtie/src/Bowtie/Untyped/Erase.hs +++ b/bowtie/src/Bowtie/Untyped/Erase.hs @@ -1,7 +1,6 @@ module Bowtie.Untyped.Erase where import Bowtie.Core.Expr -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import qualified Bowtie.Untyped.Expr as U diff --git a/bowtie/src/Bowtie/Untyped/Eval.hs b/bowtie/src/Bowtie/Untyped/Eval.hs index a88e9bc..e5f5b00 100644 --- a/bowtie/src/Bowtie/Untyped/Eval.hs +++ b/bowtie/src/Bowtie/Untyped/Eval.hs @@ -1,7 +1,6 @@ module Bowtie.Untyped.Eval where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Bowtie.Untyped.Expr import Safe.Exact (zipExactMay) diff --git a/bowtie/src/Bowtie/Untyped/Expr.hs b/bowtie/src/Bowtie/Untyped/Expr.hs index 524580f..feb9b18 100644 --- a/bowtie/src/Bowtie/Untyped/Expr.hs +++ b/bowtie/src/Bowtie/Untyped/Expr.hs @@ -1,7 +1,6 @@ module Bowtie.Untyped.Expr where import Bowtie.Lib.FreeVars -import Bowtie.Lib.Id import Bowtie.Lib.Prelude import Data.HashMap.Strict (HashMap) diff --git a/bowtie/test/Bowtie/Surface/InferSpec.hs b/bowtie/test/Bowtie/Surface/InferSpec.hs index c61d5cb..cf7a73f 100644 --- a/bowtie/test/Bowtie/Surface/InferSpec.hs +++ b/bowtie/test/Bowtie/Surface/InferSpec.hs @@ -5,7 +5,6 @@ module Bowtie.Surface.InferSpec where import Bowtie.Infer.Elaborate import Bowtie.Infer.Substitution import Bowtie.Lib.Environment -import Bowtie.Lib.Id import Bowtie.Infer.Infer import Bowtie.Lib.Prelude import Bowtie.Lib.TypeScheme diff --git a/bowtie/test/Test/Quoted/AST.hs b/bowtie/test/Test/Quoted/AST.hs index 041f77e..1560142 100644 --- a/bowtie/test/Test/Quoted/AST.hs +++ b/bowtie/test/Test/Quoted/AST.hs @@ -3,11 +3,11 @@ module Test.Quoted.AST (quotedAST) where +import Bowtie.Lib.Prelude import Bowtie.Surface.AST import Bowtie.Surface.Parse import Data.Data import Language.Haskell.TH.Quote -import Prelude import Test.Quoted.Expr (liftDataWithText, trimLeadingNewline) import qualified Data.Text as Text @@ -21,7 +21,7 @@ quotedAST = { quoteExp = liftDataWithText . dirtyParseAST . Text.pack . trimLeadingNewline - , quotePat = \_ -> error "quotedAST: quotePat not defined" - , quoteType = \_ -> error "quotedAST: quoteType not defined" - , quoteDec = \_ -> error "quotedAST: quoteDec not defined" + , quotePat = \_ -> panic "quotedAST: quotePat not defined" + , quoteType = \_ -> panic "quotedAST: quoteType not defined" + , quoteDec = \_ -> panic "quotedAST: quoteDec not defined" } diff --git a/bowtie/test/Test/Quoted/Expr.hs b/bowtie/test/Test/Quoted/Expr.hs index d9d08ab..96d35d2 100644 --- a/bowtie/test/Test/Quoted/Expr.hs +++ b/bowtie/test/Test/Quoted/Expr.hs @@ -11,7 +11,7 @@ module Test.Quoted.Expr , trimLeadingNewline ) where -import Bowtie.Lib.Id +import Bowtie.Lib.Prelude import Bowtie.Surface.AST import Bowtie.Surface.Parse import Data.Data @@ -19,7 +19,6 @@ import Data.Text (Text) import Language.Haskell.TH import Language.Haskell.TH.Quote import Language.Haskell.TH.Syntax (lift) -import Prelude import qualified Bowtie.Type.AST as TYP import qualified Data.Text as Text @@ -35,9 +34,9 @@ quotedExpr = { quoteExp = liftDataWithText . dirtyParseExpr . Text.pack . trimLeadingNewline - , quotePat = \_ -> error "quotedExpr: quotePat not defined" - , quoteType = \_ -> error "quotedExpr: quoteType not defined" - , quoteDec = \_ -> error "quotedExpr: quoteDec not defined" + , quotePat = \_ -> panic "quotedExpr: quotePat not defined" + , quoteType = \_ -> panic "quotedExpr: quoteType not defined" + , quoteDec = \_ -> panic "quotedExpr: quoteDec not defined" } -- This and liftText from: https://stackoverflow.com/a/38182444