diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
 ![LiquidHaskell](/resources/logo.png)
 
 
-
 [![Hackage](https://img.shields.io/hackage/v/liquidhaskell.svg)](https://hackage.haskell.org/package/liquidhaskell) [![Hackage-Deps](https://img.shields.io/hackage-deps/v/liquidhaskell.svg)](http://packdeps.haskellers.com/feed?needle=liquidhaskell) [![Build Status](https://img.shields.io/circleci/project/ucsd-progsys/liquidhaskell/master.svg)](https://circleci.com/gh/ucsd-progsys/liquidhaskell)
 [![Windows build status](https://ci.appveyor.com/api/projects/status/78y7uusjcgor5p16/branch/develop?svg=true)](https://ci.appveyor.com/project/varosi/liquidhaskell-nlhra/branch/develop)
 
@@ -35,13 +34,13 @@
 * Please be sure to include test cases that illustrate the effect of the PR
     - e.g. show new features that that are supported or how it fixes some previous issue
 * If you're making user-visible changes, please also add documentation
-    - e.g. [options.md](options.md), [specifications.md](specifications.md), the [main tutorial](https:///github.com/ucsd-progsys/intro-refinement-types) (as relevant)
+    - e.g. [options.md](docs/mkDocs/docs/options.md), [specifications.md](docs/mkDocs/docs/specifications.md), the [main tutorial](https:///github.com/ucsd-progsys/intro-refinement-types) (as relevant)
 
 Pull requests don't just have to be about code: documentation can often be improved too!
 
 ## Ask for Help
 
-If you have further questions or you just need help, you can always reach out on our [slack channel](https://join.slack.com/t/liquidhaskell/shared_invite/enQtMjY4MTk3NDkwODE3LTFmZGFkNGEzYWRkNDJmZDQ0ZGU1MzBiZWZiZDhhNmY3YTJiMjUzYTRlNjMyZDk1NDU3ZGIxYzhlOTIzN2UxNWE), [google groups mailing list](https://groups.google.com/forum/#!forum/liquidhaskell), [GitHub issue tracker](https://github.com/ucsd-progsys/liquidhaskell/issues), or by emailing one of our star developers: [Ranjit Jhala](https://github.com/ranjitjhala), [Niki Vazou](https://github.com/nikivazou).
+If you have further questions or you just need help, you can always reach out on our [slack channel](https://join.slack.com/t/liquidhaskell/shared_invite/enQtMjY4MTk3NDkwODE3LTFmZGFkNGEzYWRkNDJmZDQ0ZGU1MzBiZWZiZDhhNmY3YTJiMjUzYTRlNjMyZDk1NDU3ZGIxYzhlOTIzN2UxNWE), [google groups mailing list](https://groups.google.com/forum/#!forum/liquidhaskell), [GitHub issue tracker](https://github.com/ucsd-progsys/liquidhaskell/issues), or by emailing [Ranjit Jhala](https://github.com/ranjitjhala), [Niki Vazou](https://github.com/nikivazou).
 
 # General Development Guide
 
@@ -78,9 +77,18 @@
 #### Stack
 
 ```
-env LIQUID_DEV_MODE=true stack build
+LIQUID_DEV_MODE=true stack build
 ```
 
+If on NixOS
+
+```
+LIQUID_DEV_MODE=true stack --no-nix-pure build
+```
+
+With the above, `stack` will unregister and re-register the libraries,
+but hopefully it won't rebuild any modules.
+
 #### Cabal
 
 ```
@@ -96,43 +104,75 @@
 
 ## How To Run Regression Tests
 
+For documentation on the `test-driver` executable itself, please refer to the
+`README.md` in `tests/` or run `cabal run tests:test-driver -- --help` or `stack
+run test-driver -- --help`
+
 _For a way of running the test suite for multiple GHC versions, consult the General Development FAQs. below_
 
 There are particular scripts for running LH in the different modes, e.g. for different 
-compiler versions and in plugin mode or as standalone. These scripts are in:
+compiler versions. These scripts are in:
 
     $ ./scripts/test
 
 So you can run *all* the tests for say the ghc-8.10 version by
 
-    $ ./scripts/test/test_810.sh
+    $ ./scripts/test/test_810_plugin.sh
 
-You can run a particular test instead by
+You can run a bunch of particular test-groups instead by
 
-    $ LIQUID_DEV_MODE=true ./scripts/test/test_810.sh BadDataDeclTyVars.hs
+    $ LIQUID_DEV_MODE=true ./scripts/test/test_810_plugin.sh <test-group-name1> <test-group-name2> ...
 
-Note that the script uses the `BadDataDeclTyVars.hs` as a pattern so will run *all* tests that match.
-So, for example,
+and you can list all the possible test options with 
 
-    $ LIQUID_DEV_MODE=true ./scripts/test/test_810.sh Error-Messages
+    $ LIQUID_DEV_MODE=true ./scripts/test/test_810_plugin.sh --help
 
-will run all the tests in the `Error-Messages` group.
+or get a list of just the test groups, one per line, with
 
-To pass in specific parameters and run a subset of the tests  **FIXME**
+    $ LIQUID_DEV_MODE=true ./scripts/test/test_810_plugin.sh --show-all
 
-    $ stack test liquidhaskell --fast  --test-arguments "--liquid-opts --no-termination -p Unit
+To pass in specific parameters and run a subset of the tests, you can invoke cabal directly with
 
+    $ LIQUID_DEV_MODE=true cabal build tests:<test-group-name> --ghc-options=-fplugin-opt=LiquidHaskell:--no-termination MySpecificTest
+
+For example:
+
+    $ LIQUID_DEV_MODE=true cabal build tests:unit-neg --ghc-options=--fplugin-opt=LiquidHaskell:--no-termination AbsApp
+
 Or your favorite number of threads, depending on cores etc.
 
-You can directly extend and run the tests by modifying
+You can directly extend and run the tests by modifying the files in
 
-    tests/test.hs
+    tests/harness/
 
+### Parallelism in Tests
+
+Most tests run in parallel, with a few module dependencies built sequentially in
+advance. Benchmarks are run sequentially after all other tests have finished.
+For details on adding tests, see note [Parallel_Tests] in `tests/test.hs`.
+
 ## How to create performance comparison charts
 
-Everytime `liquidhaskell` tests are run, a report of the time taken by
-each test is written to a file `tests/logs/<host>-<time>/summary.csv`.
+When `liquidhaskell` tests run, we can collect timing information with
 
+    $ ./scripts/test/test_810_plugin.sh --measure-timings
+
+Measures will be collected in `.dump-timings` files. These can be converted to json
+data with
+
+```bash
+cabal v2-build ghc-timings
+cabal v2-exec ghc-timings dist-newstyle
+```
+
+which will produce `tmp/*.json` files.
+
+Then a csv report can be generated from this json files with
+```
+cabal v2-run benchmark-timings -- tmp/*.json --phase LiquidHaskell -o summary.csv
+```
+On each line, the report will contain the time taken by each test.
+
 There is a script `scripts/plot-performance/chart_perf.sh` that can be
 used to generate comparison charts in `svg` and `png` formats. It
 requires [gnuplot](http://www.gnuplot.info/) to run. The following
@@ -141,10 +181,17 @@
 
     $ scripts/plot-performance/chart_perf.sh path_to_before_summary.csv path_to_after_summary.csv
 
-The current formatting is optmized for comparing the outputs of running
+The current formatting is optimized for comparing the outputs of running
 the benchmarks alone.
 
-    $ scripts/test/test_810.sh Benchmarks
+    $ scripts/test/test_810_plugin.sh \
+        benchmark-stitch-lh \
+        benchmark-bytestring \
+        benchmark-vector-algorithms \
+        benchmark-cse230 \
+        benchmark-esop2013 \
+        benchmark-icfp15-pos \
+        benchmark-icfp15-neg
 
 ## How to Profile
 
@@ -253,10 +300,22 @@
 to upload by scanning the `$PWD` for packages named appropriately. It will ask the user for confirmation
 before proceeding, and `stack upload` will be used under the hood.
 
+## GHC support policy
+
+LH supports only one version of GHC at any given time. This is because LH depends heavily on the `ghc` library
+and there is currently no distinction between public API's and API's internal to GHC. There are currently no
+release notes for the `ghc` library and breaking changes happen without notice and without deprecation
+periods. Supporting only one GHC version saves developer time because it obviates the need for `#ifdef`'s
+throughout the codebase, or for an compatibility layer that becomes increasingly difficult to write as we
+attempt to support more GHC versions. Porting to newer GHC versions takes less time, the code is easier to
+read and there is less code duplication.
+
+Users of older versions of GHC can still use older versions of LH.
+
 ## The GHC.API module
 
-In order to allow LH to work with multiple GHC versions, we need a way to abstract over all the breaking
-changes of the `ghc` library, which might change substantially with every major GHC release. This is
+In order to minimize the effort in porting LH to new releases of GHC, we need a way to abstract over breaking
+changes in the `ghc` library, which might change substantially with every major GHC release. This is
 accomplished by the [GHC.API][] module. The idea is that **rather than importing multiple `ghc` modules,
 LH developers must import this single module in order to write future-proof code**. This is especially
 important for versions of the compiler greater than 9, where the module hierarchy changed substantially,
diff --git a/devel/Paths_liquidhaskell.hs b/devel/Paths_liquidhaskell.hs
--- a/devel/Paths_liquidhaskell.hs
+++ b/devel/Paths_liquidhaskell.hs
@@ -8,10 +8,10 @@
 import Data.Version (Version, makeVersion)
 
 getDataFileName :: FilePath -> IO FilePath
-getDataFileName f = do
-  let loc = $(do { loc <- location; f <- runIO (canonicalizePath (loc_filename loc)); litE (stringL f); })
-  let root = takeDirectory (takeDirectory loc)
-  return (root </> f)
+getDataFileName fp = do
+  let loc' = $(do { loc <- location; f <- runIO (canonicalizePath (loc_filename loc)); litE (stringL f); })
+  let root = takeDirectory (takeDirectory loc')
+  return (root </> fp)
 
 -- | dummy version (devel only)
 version :: Version
diff --git a/include/CoreToLogic.lg b/include/CoreToLogic.lg
--- a/include/CoreToLogic.lg
+++ b/include/CoreToLogic.lg
@@ -23,6 +23,7 @@
 define GHC.Types.True                 = (true)
 define GHC.Real.div x y               = (x / y)
 define GHC.Real.mod x y               = (x mod y)
+define GHC.Classes.not x              = (~ x)
 define GHC.Base.$ f x                 = (f x)
 
 define Language.Haskell.Liquid.Bag.get k m   = (Map_select m k)
@@ -38,6 +39,7 @@
 define String.stringEmp  = (stringEmp)
 define Main.mempty       = (mempty)
 define Language.Haskell.Liquid.ProofCombinators.cast x y = (y)
+define Language.Haskell.Liquid.ProofCombinators.withProof x y = (x)
 define ProofCombinators.cast x y = (y)
 define Liquid.ProofCombinators.cast x y = (y)
 define Control.Parallel.Strategies.withStrategy s x = (x)
diff --git a/include/GHC/Num.spec b/include/GHC/Num.spec
--- a/include/GHC/Num.spec
+++ b/include/GHC/Num.spec
@@ -1,8 +1,8 @@
 module spec GHC.Num where
 
-embed GHC.Integer.Type.Integer as int 
+// embed GHC.Integer.Type.Integer as int 
 
-GHC.Num.fromInteger :: (GHC.Num.Num a) => x:GHC.Integer.Type.Integer -> {v:a | v = x }
+GHC.Num.fromInteger :: (GHC.Num.Num a) => x:_ -> {v:a | v = x }
 
 GHC.Num.negate :: (GHC.Num.Num a)
                => x:a
diff --git a/include/Language/Haskell/Liquid/RTick/Combinators.hs b/include/Language/Haskell/Liquid/RTick/Combinators.hs
deleted file mode 100644
--- a/include/Language/Haskell/Liquid/RTick/Combinators.hs
+++ /dev/null
@@ -1,366 +0,0 @@
-
---
--- Liquidate your assets: reasoning about resource usage in Liquid Haskell.
---
-
-{-@ LIQUID "--reflection" @-}
-
-module Language.Haskell.Liquid.RTick.Combinators
-  (
-
-  -- Basic:
-    Proof         -- Simply the unit type.
-  , QED(..)       -- 'ASS': Signify the end of an /unfinished/ proof.
-                  -- 'QED': Signify the end of a /complete/ proof.
-  , (&&&)         -- Combine proofs.
-  , (***)         -- Discard final result at the end of a proof.
-  , (?)           -- Appeal to an external theorem.
-  , isAss         -- Check whether a proof is complete.
-  , toProof       -- Cast to proof.
-  , trivial       -- Trivial proof.
-  , withTheorem   -- Appeal to an external theorem.
-  -- Equational:
-  , (==.)         -- Equality.
-  , (==?)         -- Equality (assumption).
-  , eq            -- Equality. Note: 'eq' is inlined in the logic.
-  -- Inequational:
-  , (<.)          -- Less than.
-  , (<?)          -- Less than (assumption).
-  , (<=.)         -- Less than or equal.
-  , (<=?)         -- Less than or equal (assumption).
-  , (>.)          -- Greater than.
-  , (>?)          -- Greater than (assumption).
-  , (>=.)         -- Greater than or equal.
-  , (>=?)         -- Greater than or equal (assumption).
-  , (<=>.)        -- Cost equivalence.
-  , (<=>?)        -- Cost equivalence (assumption)
-  , (>~>.)        -- Improvement.
-  , (>~>?)        -- Improvement (assumption).
-  , (.>==)        -- Quantified improvement.
-  , (?>==)        -- Quantified improvement (assumption).
-  , (<~<.)        -- Diminishment.
-  , (<~<?)        -- Diminishment (assumption).
-  , (.<==)        -- Quantified diminishment.
-  , (?<==)        -- Quantified diminishment (assumption).
-  -- Cost separators:
-  , (==>.)        -- Quantified improvement.
-  , (==>?)        -- Quantified improvement (assumption).
-  , (==<.)        -- Quantified diminishment.
-  , (==<?)        -- Quantified diminishment (assumption).
-  , (==!)
-  , assert
-  ) where
-
-import Language.Haskell.Liquid.RTick ( Tick(..) )
-
---
--- Proof combinators for extrinsic cost analysis.
---
-
--------------------------------------------------------------------------------
--- | Basic:
--------------------------------------------------------------------------------
-
-{-@ assert :: b:{Bool | b} -> {b} @-}
-assert :: Bool -> Proof
-assert _ = ()
-
--- unchecked
-(==!) :: a -> a -> a
-_ ==! x = x
-
-
-type Proof = ()
-data QED   = QED | ASS
-
-{-@ toProof :: a -> Proof @-}
-toProof :: a -> Proof
-toProof _ = ()
-{-# INLINE toProof #-}
-
-{-@ trivial :: Proof @-}
-trivial :: Proof
-trivial = ()
-{-# INLINE trivial #-}
-
-{-@ measure isAss @-}
-isAss :: QED -> Bool
-isAss ASS = True
-isAss QED = False
-
-{-@ assume (***) :: a -> qed:QED -> { if (isAss qed) then false else true } @-}
-infixl 1 ***
-(***) :: a -> QED -> Proof
-_ *** _ = ()
-{-# INLINE (***) #-}
-
-{-@ (?) :: x:a -> Proof -> { v:a | x == v } @-}
-infixl 3 ?
-(?) :: a -> Proof -> a
-x ? _ = x
-{-# INLINE (?) #-}
-
-{-@ (&&&) :: Proof -> Proof -> Proof @-}
-infixl 3 &&&
-(&&&) :: Proof -> Proof -> Proof
-x &&& _ = x
-{-# INLINE (&&&) #-}
-
-{-@ withTheorem :: x:a -> Proof -> { v:a | x == v } @-}
-withTheorem :: a -> Proof -> a
-withTheorem x _ = x
-{-# INLINE withTheorem #-}
-
--------------------------------------------------------------------------------
--- | Equational:
--------------------------------------------------------------------------------
-
---
--- Equality.
---
-{-@ (==.) :: x:a -> { y:a | x == y } -> { v:a | x == v && y == v } @-}
-infixl 3 ==.
-(==.) :: a -> a -> a
-_ ==. x = x
-{-# INLINE (==.) #-}
-
-{-@ assume (==?) :: x:a -> y:a -> { v:a | x == v && y == v } @-}
-infixl 3 ==?
-(==?) :: a -> a -> a
-_ ==? x = x
-{-# INLINE (==?) #-}
-
---
--- Equality. Note: 'eq' is inlined in the logic, so can be used in
--- reflected functions.
---
-{-@ eq :: x:a -> { y:a | x == y } -> { v:a | x == v && y == v } @-}
-eq :: a -> a -> a
-_ `eq` x = x
-{-# INLINE eq #-}
-
--------------------------------------------------------------------------------
--- | Inequational:
--------------------------------------------------------------------------------
-
---
--- Less than.
---
-{-@ (<.) :: m:a -> { n:a | m < n } -> { o:a | o == n } @-}
-infixl 3 <.
-(<.) :: a -> a -> a
-_ <. n = n
-{-# INLINE (<.) #-}
-
-{-@ assume (<?) :: m:a -> n:a -> { o:a | o == n && m < n } @-}
-infixl 3 <?
-(<?) :: a -> a -> a
-_ <? n = n
-{-# INLINE (<?) #-}
-
---
--- Less than or equal.
---
-{-@ (<=.) :: m:a -> { n:a | m <= n } -> { o:a | o == n } @-}
-infixl 3 <=.
-(<=.) :: a -> a -> a
-_ <=. n = n
-{-# INLINE (<=.) #-}
-
-{-@ assume (<=?) :: m:a -> n:a -> { o:a | o == n && m <= n } @-}
-infixl 3 <=?
-(<=?) :: a -> a -> a
-_ <=? n = n
-{-# INLINE (<=?) #-}
-
---
--- Greater than.
---
-{-@ (>.) :: m:a -> { n:a | m > n } -> { o:a | o == n } @-}
-infixl 3 >.
-(>.) :: a -> a -> a
-_ >. y = y
-{-# INLINE (>.) #-}
-
-{-@ assume (>?) :: m:a -> n:a -> { o:a | o == n && m > n } @-}
-infixl 3 >?
-(>?) :: a -> a -> a
-_ >? y = y
-{-# INLINE (>?) #-}
-
---
--- Greater than or equal.
---
-{-@ (>=.) :: m:a -> { n:a | m >= n } -> { o:a | o == n } @-}
-infixl 3 >=.
-(>=.) :: a -> a -> a
-_ >=. n = n
-{-# INLINE (>=.) #-}
-
-{-@ assume (>=?) :: m:a -> n:a -> { o:a | o == n && m >= n } @-}
-infixl 3 >=?
-(>=?) :: a -> a -> a
-_ >=? n = n
-{-# INLINE (>=?) #-}
-
---
--- Cost equivalence.
---
-{-@ predicate COSTEQ T1 T2 = tval T1 == tval T2 && tcost T1 == tcost T2 @-}
-
-{-@ (<=>.)
-  :: t1:Tick a
-  -> { t2:Tick a | COSTEQ t1 t2 }
-  -> { t3:Tick a | COSTEQ t1 t2 && COSTEQ t1 t3 && COSTEQ t2 t3 }
-@-}
-infixl 3 <=>.
-(<=>.) :: Tick a -> Tick a -> Tick a
-(<=>.) _ t2 = t2
-{-# INLINE (<=>.) #-}
-
-{-@ assume (<=>?)
-  :: t1:Tick a -> t2:Tick a
-  -> { t3:Tick a | COSTEQ t1 t2 && COSTEQ t1 t3 && t2 == t3 }
-@-}
-infixl 3 <=>?
-(<=>?) :: Tick a -> Tick a -> Tick a
-(<=>?) _ t2 = t2
-{-# INLINE (<=>?) #-}
-
---
--- Improvement.
---
-{-@ predicate IMP T1 T2 = tval T1 == tval T2 && tcost T1 >= tcost T2 @-}
-
-{-@ (>~>.)
-  :: t1:Tick a
-  -> { t2:Tick a | IMP t1 t2 }
-  -> { t3:Tick a | IMP t1 t2 && IMP t1 t3 && t2 == t3 }
-@-}
-infixl 3 >~>.
-(>~>.) :: Tick a -> Tick a -> Tick a
-(>~>.) _ t2 = t2
-{-# INLINE (>~>.) #-}
-
-{-@ assume (>~>?)
-  :: t1:Tick a -> t2:Tick a
-  -> { t3:Tick a | IMP t1 t2 && IMP t1 t3 && t2 == t3 }
-@-}
-infixl 3 >~>?
-(>~>?) :: Tick a -> Tick a -> Tick a
-(>~>?) _ t2 = t2
-{-# INLINE (>~>?) #-}
-
---
--- Quantified improvement.
---
-{-@ predicate QIMP T1 N T2 = tval T1 == tval T2 && tcost T1 == tcost T2 + N @-}
-
-{-@ (.>==)
-  :: t1:Tick a
-  -> n:Int
-  -> { t2:Tick a | QIMP t1 n t2 }
-  -> { t3:Tick a | QIMP t1 n t2 && QIMP t1 n t3 && t2 == t3 }
-@-}
-infixl 3 .>==
-(.>==) :: Tick a -> Int -> Tick a -> Tick a
-(.>==) _ _ t2 = t2
-{-# INLINE (.>==) #-}
-
-{-@ assume (?>==)
-  :: t1:Tick a -> n:Nat -> t2:Tick a
-  -> { t3:Tick a | QIMP t1 n t2 && QIMP t1 n t3 && t2 == t3 }
-@-}
-infixl 3 ?>==
-(?>==) :: Tick a -> Int -> Tick a -> Tick a
-(?>==) _ _ t2 = t2
-{-# INLINE (?>==) #-}
-
---
--- Diminishment.
---
-{-@ predicate DIM T1 T2 = tval T1 == tval T2 && tcost T1 <= tcost T2 @-}
-
-{-@ (<~<.)
-  :: t1:Tick a
-  -> { t2:Tick a | DIM t1 t2 }
-  -> { t3:Tick a | DIM t1 t2 && DIM t1 t3 && t2 == t3 }
-@-}
-infixl 3 <~<.
-(<~<.) :: Tick a -> Tick a -> Tick a
-(<~<.) _ t2 = t2
-{-# INLINE (<~<.) #-}
-
-{-@ assume (<~<?)
-  :: t1:Tick a -> t2:Tick a
-  -> { t3:Tick a | DIM t1 t2 && DIM t1 t3 && t2 == t3 }
-@-}
-infixl 3 <~<?
-(<~<?) :: Tick a -> Tick a -> Tick a
-(<~<?) _ t2 = t2
-{-# INLINE (<~<?) #-}
-
---
--- Quantified diminishment.
---
-{-@ predicate QDIM T1 N T2 = tval T1 == tval T2 && tcost T1 + N == tcost T2 @-}
-
-{-@ (.<==)
-  :: t1:Tick a
-  -> n:Nat
-  -> { t2:Tick a | QDIM t1 n t2 }
-  -> { t3:Tick a | QDIM t1 n t2 && QDIM t1 n t3 && t2 == t3 }
-@-}
-infixl 3 .<==
-(.<==) :: Tick a -> Int -> Tick a -> Tick a
-(.<==) _ _ t2 = t2
-{-# INLINE (.<==) #-}
-
-{-@ assume (?<==)
-  :: t1:Tick a -> n:Nat -> t2:Tick a
-  -> { t3:Tick a | QDIM t1 n t2 && QDIM t1 n t3 && t2 == t3 }
-@-}
-infixl 3 ?<==
-(?<==) :: Tick a -> Int -> Tick a -> Tick a
-(?<==) _ _ t2 = t2
-{-# INLINE (?<==) #-}
-
--------------------------------------------------------------------------------
--- | Cost separators:
--------------------------------------------------------------------------------
-
---
--- Quantified improvement.
---
-{-@ (==>.) :: (a -> b) -> a -> b @-}
-infixl 3 ==>.
-(==>.) :: (a -> b) -> a -> b
-f ==>. a = f a
-{-# INLINE (==>.) #-}
-
---
--- Quantified improvement (assumption).
---
-{-@ (==>?) :: (a -> b) -> a -> b @-}
-infixl 3 ==>?
-(==>?) :: (a -> b) -> a -> b
-f ==>? a = f a
-{-# INLINE (==>?) #-}
-
---
--- Quantified diminishment.
---
-{-@ (==<.) :: (a -> b) -> a -> b @-}
-infixl 3 ==<.
-(==<.) :: (a -> b) -> a -> b
-f ==<. a = f a
-{-# INLINE (==<.) #-}
-
---
--- Quantified diminishment (assumption).
---
-{-@ (==<?) :: (a -> b) -> a -> b @-}
-infixl 3 ==<?
-(==<?) :: (a -> b) -> a -> b
-f ==<? a = f a
-{-# INLINE (==<?) #-}
diff --git a/liquidhaskell.cabal b/liquidhaskell.cabal
--- a/liquidhaskell.cabal
+++ b/liquidhaskell.cabal
@@ -1,6 +1,6 @@
 cabal-version:      2.4
 name:               liquidhaskell
-version:            0.8.10.7.1
+version:            0.9.0.2.1
 synopsis:           Liquid Types for Haskell
 description:        Liquid Types for Haskell.
 license:            BSD-3-Clause
@@ -11,7 +11,7 @@
 category:           Language
 homepage:           https://github.com/ucsd-progsys/liquidhaskell
 build-type:         Simple
-tested-with:        GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.1,  GHC == 8.10.7, GHC == 9.0.1
+tested-with:        GHC == 9.0.2
 extra-source-files: CHANGES.md
                     README.md
                     devel/Paths_liquidhaskell.hs
@@ -65,6 +65,12 @@
   type:     git
   location: https://github.com/ucsd-progsys/liquidhaskell/
 
+flag devel
+  default:     False
+  manual:      True
+  description: Enable more warnings and fail compilation when warnings occur.
+               Turn this flag on in CI.
+
 flag include
   default:     False
   description: use in-tree include directory
@@ -113,17 +119,20 @@
                       Language.Haskell.Liquid.Constraint.Split
                       Language.Haskell.Liquid.Constraint.ToFixpoint
                       Language.Haskell.Liquid.Constraint.Types
-                      Language.Haskell.Liquid.GHC.API
-                      Language.Haskell.Liquid.GHC.API.StableModule
-                      Language.Haskell.Liquid.GHC.GhcMonadLike
-                      Language.Haskell.Liquid.GHC.Interface
-                      Language.Haskell.Liquid.GHC.Logging
-                      Language.Haskell.Liquid.GHC.Misc
-                      Language.Haskell.Liquid.GHC.Play
-                      Language.Haskell.Liquid.GHC.Resugar
-                      Language.Haskell.Liquid.GHC.SpanStack
-                      Language.Haskell.Liquid.GHC.Types
-                      Language.Haskell.Liquid.GHC.TypeRep
+                      Language.Haskell.Liquid.Constraint.Relational
+                      Liquid.GHC.API
+                      Liquid.GHC.API.StableModule
+                      Liquid.GHC.GhcMonadLike
+                      Liquid.GHC.Interface
+                      Liquid.GHC.Logging
+                      Liquid.GHC.Misc
+                      Liquid.GHC.Play
+                      Liquid.GHC.Resugar
+                      Liquid.GHC.SpanStack
+                      Liquid.GHC.Types
+                      Liquid.GHC.TypeRep
+                      Language.Haskell.Liquid.GHC.Plugin
+                      Language.Haskell.Liquid.GHC.Plugin.Tutorial
                       Language.Haskell.Liquid.Interactive.Handler
                       Language.Haskell.Liquid.Interactive.Types
                       Language.Haskell.Liquid.LawInstances
@@ -172,36 +181,15 @@
                       Language.Haskell.Liquid.UX.DiffCheck
                       Language.Haskell.Liquid.UX.Errors
                       Language.Haskell.Liquid.UX.QuasiQuoter
+                      Language.Haskell.Liquid.UX.SimpleVersion
                       Language.Haskell.Liquid.UX.Tidy
                       Language.Haskell.Liquid.WiredIn
                       LiquidHaskell
                       Paths_liquidhaskell
-
-  -- FIXME: Temporary measure to ensure that if the source plugin is available, then:
-  --   1. we compile it;
-  --   2. We don't rely on the \"liquid-prelude\" Haskell files previously shipped as part of LH itself.
-  -- Once the source plugin is out, we should also removed the duplicate \"liquid-prelude\" files from
-  -- the \"include\" directory.
-
-  if impl(ghc >= 8.10)
-      exposed-modules:    Language.Haskell.Liquid.GHC.Plugin
-                          Language.Haskell.Liquid.GHC.Plugin.Tutorial
-      other-modules:      Language.Haskell.Liquid.GHC.Plugin.SpecFinder
-                          Language.Haskell.Liquid.GHC.Plugin.Types
-                          Language.Haskell.Liquid.GHC.Plugin.Util
-      hs-source-dirs:     src
-  else
-      hs-source-dirs:     src include
-      exposed-modules:    Language.Haskell.Liquid.RTick
-                          Language.Haskell.Liquid.Prelude
-                          Language.Haskell.Liquid.Foreign
-                          Language.Haskell.Liquid.RTick.Combinators
-                          Language.Haskell.Liquid.String
-                          Language.Haskell.Liquid.List
-                          Language.Haskell.Liquid.Equational
-                          Language.Haskell.Liquid.Bag
-                          Language.Haskell.Liquid.ProofCombinators
-                          KMeansHelper
+  other-modules:      Language.Haskell.Liquid.GHC.Plugin.SpecFinder
+                      Language.Haskell.Liquid.GHC.Plugin.Types
+                      Language.Haskell.Liquid.GHC.Plugin.Util
+  hs-source-dirs:     src src-ghc
 
   build-depends:      base                 >= 4.11.1.0 && < 5
                     , Diff                 >= 0.3 && < 0.5
@@ -218,19 +206,17 @@
                     , filepath             >= 1.3
                     , fingertree           >= 0.1
                     , exceptions           < 0.11
-                    , ghc
+                    , ghc                  ^>= 9
                     , ghc-boot
                     , ghc-paths            >= 0.1
                     , ghc-prim
                     , gitrev
-                    , hashable             >= 1.3 && < 1.3.4
+                    , hashable             >= 1.3 && < 1.4
                     , hscolour             >= 1.22
                     , liquid-fixpoint      >= 0.8.10.2.1 && < 0.9
                     , mtl                  >= 2.1
                     , optics               >= 0.2
-                    , optparse-applicative < 0.16.0.0
-                    , optparse-simple
-                    , optparse-applicative < 0.16.0.0
+                    , optparse-applicative < 0.17
                     , githash
                     , megaparsec           >= 8
                     , pretty               >= 1.1
@@ -241,25 +227,27 @@
                     , temporary            >= 1.2
                     , text                 >= 1.2
                     , time                 >= 1.4
-                    , time
                     , transformers         >= 0.3
                     , unordered-containers >= 0.2.11
                     , vector               >= 0.10
                     , free
-                    , recursion-schemes    <= 5.2.2
+                    , recursion-schemes    < 5.3
                     , data-fix
-                    , extra 
+                    , extra
   default-language:   Haskell98
   default-extensions: PatternGuards, RecordWildCards, DoAndIfThenElse
   ghc-options:        -W -fwarn-missing-signatures
 
+  if flag(devel)
+    ghc-options:      -Wall -Werror
+
   if flag(include)
     hs-source-dirs: devel
 
   if flag(deterministic-profiling)
     cpp-options: -DDETERMINISTIC_PROFILING
 
-  if impl(ghc < 8.10) || flag(no-plugin)
+  if flag(no-plugin)
     cpp-options: -DLIQUID_NO_PLUGIN
 
 -- This is the (legacy) 'liquid' executable which uses the old GHC Interface.
@@ -268,35 +256,10 @@
   build-depends:      base >= 4.9.1.0 && < 5, liquidhaskell
   default-language:   Haskell98
   default-extensions: PatternGuards
-  ghc-options:        -W -threaded -fdefer-typed-holes
-
+  ghc-options:        -W -threaded
 
-test-suite test
-  type:             exitcode-stdio-1.0
-  main-is:          test.hs
-  other-modules:    Paths_liquidhaskell
-  hs-source-dirs:   tests
-  build-depends:    base                 >= 4.8.1.0 && < 5
-                  , containers           >= 0.5
-                  , directory            >= 1.2
-                  , filepath             >= 1.3
-                  , mtl                  >= 2.1
-                  , optparse-applicative >= 0.11
-                  , process              >= 1.2
-                  , stm                  >= 2.4
-                  , string-conv          >= 0.1
-                  , tagged               >= 0.7.3
-                  , tasty                >= 1.4.2 && < 1.5
-                  , tasty-ant-xml
-                  , tasty-golden         >= 2.0.0
-                  , tasty-hunit          >= 0.9
-                  , tasty-rerun          >= 1.1
-                  , text
-                  , transformers         >= 0.3
-  default-language: Haskell98
-  ghc-options:      -W -threaded
-  if !flag(no-plugin)
-    cpp-options: -DUSE_NEW_EXECUTABLE
+  if flag(devel)
+    ghc-options:      -Wall -Wno-name-shadowing -Werror
 
 test-suite liquidhaskell-parser
   type:             exitcode-stdio-1.0
@@ -316,6 +279,9 @@
   default-language: Haskell2010
   ghc-options:      -W
 
+  if flag(devel)
+    ghc-options:    -Wall -Wno-name-shadowing -Werror
+
 test-suite synthesis
   type:             exitcode-stdio-1.0
   main-is:          Synthesis.hs
@@ -335,6 +301,8 @@
   default-language: Haskell2010
   ghc-options:      -W
 
+  if flag(devel)
+    ghc-options:    -Wall -Wno-name-shadowing -Werror
 
 -- This executable can be used to generate modules for mirror-packages.
 executable mirror-modules
@@ -351,7 +319,7 @@
                  , filepath < 1.5
                  , containers < 0.7
                  , mustache < 2.4
-                 , optparse-applicative < 0.16.1.0
+                 , optparse-applicative < 0.17
     buildable: True
   else
     buildable: False
@@ -363,3 +331,7 @@
     MultiWayIf
     LambdaCase
   ghc-options:        -W -threaded
+
+  if flag(devel)
+    ghc-options:      -Wall -Wno-name-shadowing -Werror
+
diff --git a/src-ghc/Liquid/GHC/API.hs b/src-ghc/Liquid/GHC/API.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/API.hs
@@ -0,0 +1,179 @@
+{-| This module re-exports a bunch of the GHC API.
+
+The intended use of this module is to shelter LiquidHaskell from changes to the GHC API, so this is the
+/only/ module LiquidHaskell should import when trying to access any ghc-specific functionality.
+
+--}
+
+{-# LANGUAGE DeriveTraversable #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE PatternSynonyms #-}
+{-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE ViewPatterns #-}
+{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE BangPatterns #-}
+
+module Liquid.GHC.API (
+    module Ghc
+  , module StableModule
+  , tyConRealArity
+  , dataConExTyVars
+  , fsToUnitId
+  , moduleUnitId
+  , thisPackage
+  , renderWithStyle
+  , mkUserStyle
+  , pattern LitNumber
+  , dataConSig
+  , getDependenciesModuleNames
+  , gcatch
+  ) where
+
+import           Liquid.GHC.API.StableModule      as StableModule
+import           GHC                                               as Ghc hiding ( Warning
+                                                                                 , SrcSpan(RealSrcSpan, UnhelpfulSpan)
+                                                                                 , exprType
+                                                                                 )
+
+import Optics
+import qualified Control.Monad.Catch as Ex
+
+import Data.Foldable                  (asum)
+import GHC.Builtin.Names              as Ghc
+import GHC.Builtin.Types              as Ghc
+import GHC.Builtin.Types.Prim         as Ghc
+import GHC.Builtin.Utils              as Ghc
+import GHC.Core                       as Ghc hiding (AnnExpr, AnnExpr' (..), AnnRec, AnnCase)
+import GHC.Core.Class                 as Ghc
+import GHC.Core.Coercion              as Ghc
+import GHC.Core.Coercion.Axiom        as Ghc
+import GHC.Core.ConLike               as Ghc
+import GHC.Core.DataCon               as Ghc
+import GHC.Core.FamInstEnv            as Ghc hiding (pprFamInst)
+import GHC.Core.InstEnv               as Ghc
+import GHC.Core.Lint                  as Ghc hiding (dumpIfSet)
+import GHC.Core.Make                  as Ghc
+import GHC.Core.Opt.Monad             as Ghc (CoreToDo(..))
+import GHC.Core.Opt.WorkWrap.Utils    as Ghc
+import GHC.Core.Predicate             as Ghc (getClassPredTys_maybe, getClassPredTys, isEvVarType, isEqPrimPred, isEqPred, isClassPred, isDictId, mkClassPred)
+import GHC.Core.Subst                 as Ghc (deShadowBinds, emptySubst, extendCvSubst)
+import GHC.Core.TyCo.Rep              as Ghc
+import GHC.Core.TyCon                 as Ghc
+import GHC.Core.Type                  as Ghc hiding (typeKind , isPredTy, extendCvSubst, linear)
+import GHC.Core.Unify                 as Ghc
+import GHC.Core.Utils                 as Ghc (exprType)
+import GHC.Data.Bag                   as Ghc
+import GHC.Data.FastString            as Ghc
+import GHC.Data.Graph.Directed        as Ghc
+import GHC.Data.Pair                  as Ghc
+import GHC.Driver.Finder              as Ghc
+import GHC.Driver.Main                as Ghc
+import GHC.Driver.Phases              as Ghc (Phase(StopLn))
+import GHC.Driver.Pipeline            as Ghc (compileFile)
+import GHC.Driver.Session             as Ghc hiding (isHomeModule)
+import GHC.Driver.Types               as Ghc
+import GHC.Driver.Monad               as Ghc (withSession)
+import GHC.HsToCore.Monad             as Ghc
+import GHC.Iface.Syntax               as Ghc
+import GHC.Plugins                    as Ghc ( deserializeWithData
+                                             , fromSerialized
+                                             , toSerialized
+                                             , defaultPlugin
+                                             , Plugin(..)
+                                             , CommandLineOption
+                                             , purePlugin
+                                             , extendIdSubst
+                                             , substExpr
+                                             )
+import GHC.Tc.Instance.Family         as Ghc
+import GHC.Tc.Module                  as Ghc
+import GHC.Tc.Types                   as Ghc
+import GHC.Tc.Utils.Monad             as Ghc hiding (getGHCiMonad)
+import GHC.Tc.Utils.TcType            as Ghc (tcSplitDFunTy, tcSplitMethodTy)
+import GHC.Types.Annotations          as Ghc
+import GHC.Types.Avail                as Ghc
+import GHC.Types.Basic                as Ghc
+import GHC.Types.CostCentre           as Ghc
+import GHC.Types.Id                   as Ghc hiding (lazySetIdInfo, setIdExported, setIdNotExported)
+import GHC.Types.Id.Info              as Ghc
+import GHC.Types.Literal              as Ghc hiding (LitNumber)
+import GHC.Types.Name                 as Ghc hiding (varName, isWiredIn)
+import GHC.Types.Name.Reader          as Ghc
+import GHC.Types.Name.Set             as Ghc
+import GHC.Types.SrcLoc               as Ghc
+import GHC.Types.Unique               as Ghc
+import GHC.Types.Unique.DFM           as Ghc
+import GHC.Types.Unique.FM            as Ghc
+import GHC.Types.Unique.Set           as Ghc
+import GHC.Types.Unique.Supply        as Ghc
+import GHC.Types.Var                  as Ghc
+import GHC.Types.Var.Env              as Ghc
+import GHC.Types.Var.Set              as Ghc
+import GHC.Unit.Module                as Ghc
+import GHC.Utils.Error                as Ghc
+import GHC.Utils.Outputable           as Ghc hiding ((<>), integer, renderWithStyle, mkUserStyle)
+import GHC.Utils.Panic                as Ghc
+import qualified GHC.Types.Literal    as Ghc
+import qualified GHC.Utils.Outputable as Ghc
+import GHC.Tc.Types.Origin            as Ghc (lexprCtOrigin)
+import GHC.Rename.Expr                as Ghc (rnLExpr)
+import GHC.Tc.Gen.Expr                as Ghc (tcInferSigma, tcInferRho)
+import GHC.Tc.Gen.Bind                as Ghc (tcValBinds)
+import GHC.Tc.Solver                  as Ghc
+import GHC.Tc.Utils.Zonk              as Ghc
+import GHC.Core.FVs                   as Ghc (exprFreeVarsList)
+import GHC.Tc.Types.Evidence          as Ghc
+import GHC.HsToCore.Expr              as Ghc
+import GHC.Core.Opt.OccurAnal         as Ghc
+
+-- 'fsToUnitId' is gone in GHC 9, but we can bring code it in terms of 'fsToUnit' and 'toUnitId'.
+fsToUnitId :: FastString -> UnitId
+fsToUnitId = toUnitId . fsToUnit
+
+moduleUnitId :: Module -> UnitId
+moduleUnitId = toUnitId . moduleUnit
+
+thisPackage :: DynFlags -> UnitId
+thisPackage = toUnitId . homeUnit
+
+-- See NOTE [tyConRealArity].
+tyConRealArity :: TyCon -> Int
+tyConRealArity tc = go 0 (tyConKind tc)
+  where
+    go :: Int -> Kind -> Int
+    go !acc k =
+      case asum [fmap (view _3) (splitFunTy_maybe k), fmap snd (splitForAllTy_maybe k)] of
+        Nothing -> acc
+        Just ks -> go (acc + 1) ks
+
+dataConExTyVars :: DataCon -> [TyVar]
+dataConExTyVars = dataConExTyCoVars
+
+getDependenciesModuleNames :: Dependencies -> [ModuleNameWithIsBoot]
+getDependenciesModuleNames = dep_mods
+
+renderWithStyle :: DynFlags -> SDoc -> PprStyle -> String
+renderWithStyle dynflags sdoc style = Ghc.renderWithStyle (Ghc.initSDocContext dynflags style) sdoc
+
+mkUserStyle :: DynFlags -> PrintUnqualified -> Depth -> PprStyle
+mkUserStyle _ = Ghc.mkUserStyle
+
+--
+-- Literal
+--
+
+-- In GHC 9 'LitNumber' doesn't have the extra 3rd argument, so we simply ignore it in the construction.
+
+pattern LitNumber :: Ghc.LitNumType -> Integer -> Ghc.Type -> Ghc.Literal
+pattern LitNumber numType integer ty <- ((intPrimTy,) -> (ty, Ghc.LitNumber numType integer))
+  where
+    LitNumber numType integer _ = Ghc.LitNumber numType integer
+
+-- This function is gone in GHC 9.
+dataConSig :: DataCon -> ([TyCoVar], ThetaType, [Type], Type)
+dataConSig dc
+  = (dataConUnivAndExTyCoVars dc, dataConTheta dc, map irrelevantMult $ dataConOrigArgTys dc, dataConOrigResTy dc)
+
+gcatch :: (Ex.MonadCatch m, Exception e) => m a -> (e -> m a) -> m a
+gcatch = Ex.catch
diff --git a/src-ghc/Liquid/GHC/API/StableModule.hs b/src-ghc/Liquid/GHC/API/StableModule.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/API/StableModule.hs
@@ -0,0 +1,81 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+module Liquid.GHC.API.StableModule (
+    StableModule
+  -- * Constructing a 'StableModule'
+  , mkStableModule
+  -- * Converting a 'StableModule' into a standard 'Module'
+  , unStableModule
+  -- * Utility functions
+  , toStableModule
+  , renderModule
+  ) where
+
+import qualified GHC
+import qualified GHC.Unit.Types as GHC
+import qualified GHC.Unit.Module as GHC
+import           Data.Hashable
+import           GHC.Generics            hiding (to, moduleName)
+import           Data.Binary
+
+-- | A newtype wrapper around a 'Module' which:
+--
+-- * Allows a 'Module' to be serialised (i.e. it has a 'Binary' instance)
+-- * It tries to use stable comparison and equality under the hood.
+--
+newtype StableModule =
+  StableModule { unStableModule :: GHC.Module }
+  deriving Generic
+
+-- | Converts a 'Module' into a 'StableModule'.
+toStableModule :: GHC.Module -> StableModule
+toStableModule = StableModule
+
+moduleUnitId :: GHC.Module -> GHC.UnitId
+moduleUnitId = GHC.toUnitId . GHC.moduleUnit
+
+renderModule :: GHC.Module -> String
+renderModule m =    "Module { unitId = " <> (GHC.unitIdString . moduleUnitId $ m)
+                 <> ", name = " <> show (GHC.moduleName m)
+                 <> " }"
+
+-- These two orphans originally lived inside module 'Language.Haskell.Liquid.Types.Types'.
+instance Hashable GHC.ModuleName where
+  hashWithSalt i = hashWithSalt i . show
+
+instance Show GHC.ModuleName where
+  show = GHC.moduleNameString
+
+instance Hashable StableModule where
+  hashWithSalt s (StableModule mdl) = hashWithSalt s (GHC.moduleStableString mdl)
+
+instance Ord StableModule where
+  (StableModule m1) `compare` (StableModule m2) = GHC.stableModuleCmp m1 m2
+
+instance Eq StableModule where
+  (StableModule m1) == (StableModule m2) = (m1 `GHC.stableModuleCmp` m2) == EQ
+
+instance Show StableModule where
+    show (StableModule mdl) = "Stable" ++ renderModule mdl
+
+instance Binary StableModule where
+
+    put (StableModule mdl) = do
+      put (GHC.unitIdString . moduleUnitId $ mdl)
+      put (GHC.moduleNameString . GHC.moduleName $ mdl)
+
+    get = do
+      uidStr <- get
+      mkStableModule (GHC.stringToUnitId uidStr) . GHC.mkModuleName <$> get
+
+--
+-- Compat shim layer
+--
+
+-- | Creates a new 'StableModule' out of a 'ModuleName' and a 'UnitId'.
+mkStableModule :: GHC.UnitId -> GHC.ModuleName -> StableModule
+mkStableModule uid modName =
+  let realUnit = GHC.RealUnit $ GHC.Definite uid
+  in StableModule (GHC.Module realUnit modName)
diff --git a/src-ghc/Liquid/GHC/GhcMonadLike.hs b/src-ghc/Liquid/GHC/GhcMonadLike.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/GhcMonadLike.hs
@@ -0,0 +1,307 @@
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
+-- | This module introduces a \"lighter\" "GhcMonad" typeclass which doesn't require an instance of
+-- 'ExceptionMonad', and can therefore be used for both 'CoreM' and 'Ghc'.
+--
+
+module Liquid.GHC.GhcMonadLike (
+  -- * Types and type classes
+    HasHscEnv
+  , GhcMonadLike
+  , ModuleInfo
+  , TypecheckedModule(..)
+
+  -- * Functions and typeclass methods
+
+  , askHscEnv
+  , getModuleGraph
+  , getModSummary
+  , lookupModSummary
+  , lookupGlobalName
+  , lookupName
+  , modInfoLookupName
+  , moduleInfoTc
+  , parseModule
+  , typecheckModule
+  , desugarModule
+  , findModule
+  , lookupModule
+  , isBootInterface
+  , apiComments
+  ) where
+
+import Control.Monad.IO.Class
+import Control.Exception (throwIO)
+
+import Data.IORef (readIORef)
+
+import qualified Liquid.GHC.API   as Ghc
+import           Liquid.GHC.API   hiding ( ModuleInfo
+                                                          , findModule
+                                                          , desugarModule
+                                                          , typecheckModule
+                                                          , parseModule
+                                                          , lookupName
+                                                          , lookupGlobalName
+                                                          , getModSummary
+                                                          , getModuleGraph
+                                                          , modInfoLookupName
+                                                          , lookupModule
+                                                          , TypecheckedModule
+                                                          , tm_parsed_module
+                                                          , tm_renamed_source
+                                                          )
+
+import GHC.Data.Maybe
+import GHC.Driver.Make
+import GHC.Utils.Exception (ExceptionMonad)
+import qualified GHC.Core.Opt.Monad as CoreMonad
+import qualified GHC.Data.EnumSet as EnumSet
+
+import qualified Data.Map.Strict as M
+import Optics
+
+class HasHscEnv m where
+  askHscEnv :: m HscEnv
+
+instance HasHscEnv CoreMonad.CoreM where
+  askHscEnv = CoreMonad.getHscEnv
+
+instance HasHscEnv Ghc where
+  askHscEnv = getSession
+
+instance HasHscEnv (IfM lcl) where
+  askHscEnv = getTopEnv
+
+instance HasHscEnv TcM where
+  askHscEnv = env_top <$> getEnv
+
+instance HasHscEnv Hsc where
+  askHscEnv = Hsc $ curry pure
+
+instance (ExceptionMonad m, HasHscEnv m) => HasHscEnv (GhcT m) where
+  askHscEnv = getSession
+
+-- | A typeclass which is /very/ similar to the existing 'GhcMonad', but it doesn't impose a
+-- 'ExceptionMonad' constraint.
+class (Functor m, MonadIO m, HasHscEnv m, HasDynFlags m) => GhcMonadLike m
+
+instance GhcMonadLike CoreMonad.CoreM
+instance GhcMonadLike Ghc
+instance GhcMonadLike (IfM lcl)
+instance GhcMonadLike TcM
+instance GhcMonadLike Hsc
+instance (ExceptionMonad m, GhcMonadLike m) => GhcMonadLike (GhcT m)
+
+-- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
+getModuleGraph :: GhcMonadLike m => m ModuleGraph
+getModuleGraph = fmap hsc_mod_graph askHscEnv
+
+-- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
+getModSummary :: GhcMonadLike m => ModuleName -> m ModSummary
+getModSummary mdl = do
+   mg <- fmap hsc_mod_graph askHscEnv
+   let mods_by_name = [ ms | ms <- mgModSummaries mg
+                      , ms_mod_name ms == mdl
+                      , not (isBootInterface . isBootSummary $ ms) ]
+   case mods_by_name of
+     [] -> do dflags <- getDynFlags
+              liftIO $ throwIO $ mkApiErr dflags (text "Module not part of module graph")
+     [ms] -> return ms
+     multiple -> do dflags <- getDynFlags
+                    liftIO $ throwIO $ mkApiErr dflags (text "getModSummary is ambiguous: " <+> ppr multiple)
+
+
+-- Converts a 'IsBootInterface' into a 'Bool'.
+isBootInterface :: IsBootInterface -> Bool
+isBootInterface IsBoot  = True
+isBootInterface NotBoot = False
+
+lookupModSummary :: GhcMonadLike m => ModuleName -> m (Maybe ModSummary)
+lookupModSummary mdl = do
+   mg <- fmap hsc_mod_graph askHscEnv
+   let mods_by_name = [ ms | ms <- mgModSummaries mg
+                      , ms_mod_name ms == mdl
+                      , not (isBootInterface . isBootSummary $ ms) ]
+   case mods_by_name of
+     [ms] -> pure (Just ms)
+     _    -> pure Nothing
+
+-- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
+lookupGlobalName :: GhcMonadLike m => Name -> m (Maybe TyThing)
+lookupGlobalName name = do
+  hsc_env <- askHscEnv
+  liftIO $ lookupTypeHscEnv hsc_env name
+
+-- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
+lookupName :: GhcMonadLike m => Name -> m (Maybe TyThing)
+lookupName name = do
+  hsc_env <- askHscEnv
+  liftIO $ hscTcRcLookupName hsc_env name
+
+-- | Our own simplified version of 'ModuleInfo' to overcome the fact we cannot construct the \"original\"
+-- one as the constructor is not exported, and 'getHomeModuleInfo' and 'getPackageModuleInfo' are not
+-- exported either, so we had to backport them as well.
+newtype ModuleInfo = ModuleInfo { minf_type_env :: UniqFM Name TyThing }
+
+modInfoLookupName :: GhcMonadLike m
+                  => ModuleInfo
+                  -> Name
+                  -> m (Maybe TyThing)
+modInfoLookupName minf name = do
+  hsc_env <- askHscEnv
+  case lookupTypeEnv (minf_type_env minf) name of
+    Just tyThing -> return (Just tyThing)
+    Nothing      -> do
+      eps   <- liftIO $ readIORef (hsc_EPS hsc_env)
+      return $! lookupType (hsc_dflags hsc_env) (hsc_HPT hsc_env) (eps_PTE eps) name
+
+moduleInfoTc :: GhcMonadLike m => ModSummary -> TcGblEnv -> m ModuleInfo
+moduleInfoTc ms tcGblEnv = do
+  hsc_env <- askHscEnv
+  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
+  details <- md_types <$> liftIO (makeSimpleDetails hsc_env_tmp tcGblEnv)
+  pure ModuleInfo { minf_type_env = details }
+
+--
+-- Parsing, typechecking and desugaring a module
+--
+parseModule :: GhcMonadLike m => ModSummary -> m ParsedModule
+parseModule ms = do
+  hsc_env <- askHscEnv
+  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
+  hpm <- liftIO $ hscParse hsc_env_tmp ms
+  return (ParsedModule ms (hpm_module hpm) (hpm_src_files hpm)
+                           (hpm_annotations hpm))
+
+-- | Our own simplified version of 'TypecheckedModule'.
+data TypecheckedModule = TypecheckedModule { 
+    tm_parsed_module  :: ParsedModule
+  , tm_renamed_source :: Maybe RenamedSource
+  , tm_mod_summary    :: ModSummary
+  , tm_gbl_env        :: TcGblEnv
+  }
+
+typecheckModule :: GhcMonadLike m => ParsedModule -> m TypecheckedModule
+typecheckModule pmod = do
+  -- Suppress all the warnings, so that they won't be printed (which would result in them being
+  -- printed twice, one by GHC and once here).
+  let ms = pm_mod_summary pmod
+  hsc_env <- askHscEnv
+  let dynFlags' = ms_hspp_opts ms
+  let hsc_env_tmp = hsc_env { hsc_dflags = dynFlags' { warningFlags = EnumSet.empty } }
+  (tc_gbl_env, rn_info)
+        <- liftIO $ hscTypecheckRename hsc_env_tmp ms $
+                       HsParsedModule { hpm_module = parsedSource pmod,
+                                        hpm_src_files = pm_extra_src_files pmod,
+                                        hpm_annotations = pm_annotations pmod }
+  return TypecheckedModule {
+      tm_parsed_module  = pmod
+    , tm_renamed_source = rn_info
+    , tm_mod_summary    = ms
+    , tm_gbl_env        = tc_gbl_env
+    }
+
+{- | [NOTE:ghc810]
+Something changed in the GHC bowels such that the 'hscTarget' that the 'ModSummary' was inheriting
+was /not/ the one we were setting in 'configureDynFlags'. This is important, because if the 'hscTarget'
+is not 'HscInterpreted' or 'HscNothing', the call to 'targetRetainsAllBindings' will yield 'False'. This
+function is used internally by GHC to do dead-code-elimination and to mark functions as "exported" or not.
+Therefore, the 'CoreBind's passed to LiquidHaskell would be different between GHC 8.6.5 and GHC 8.10.
+-}
+
+class IsTypecheckedModule t where
+  tmParsedModule :: Lens'  t ParsedModule
+  tmModSummary   :: Lens'  t ModSummary
+  tmGblEnv       :: Getter t TcGblEnv
+
+instance IsTypecheckedModule TypecheckedModule where
+  tmParsedModule = lens tm_parsed_module (\s x -> s { tm_parsed_module = x })
+  tmModSummary   = lens tm_mod_summary   (\s x -> s { tm_mod_summary = x })
+  tmGblEnv       = to tm_gbl_env
+
+instance IsTypecheckedModule Ghc.TypecheckedModule where
+  tmParsedModule = lens Ghc.tm_parsed_module (\s x -> s { Ghc.tm_parsed_module = x })
+  tmModSummary   = lens (pm_mod_summary . Ghc.tm_parsed_module)
+                        (\s x -> over tmParsedModule (\pm -> pm { Ghc.pm_mod_summary = x }) s )
+  tmGblEnv       = to (fst . Ghc.tm_internals_)
+
+-- | Desugar a typechecked module.
+desugarModule :: (GhcMonadLike m, IsTypecheckedModule t) => ModSummary -> t -> m ModGuts
+desugarModule originalModSum typechecked = do
+  -- See [NOTE:ghc810] on why we override the dynFlags here before calling 'desugarModule'.
+  dynFlags          <- getDynFlags
+  let modSum         = originalModSum { ms_hspp_opts = dynFlags }
+  let parsedMod'     = (view tmParsedModule typechecked) { pm_mod_summary = modSum }
+  let typechecked'   = set tmParsedModule parsedMod' typechecked
+
+  hsc_env <- askHscEnv
+  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts (view tmModSummary typechecked') }
+  liftIO $ hscDesugar hsc_env_tmp (view tmModSummary typechecked') (view tmGblEnv typechecked')
+
+-- | Takes a 'ModuleName' and possibly a 'UnitId', and consults the
+-- filesystem and package database to find the corresponding 'Module',
+-- using the algorithm that is used for an @import@ declaration.
+findModule :: GhcMonadLike m => ModuleName -> Maybe FastString -> m Module
+findModule mod_name maybe_pkg = do
+  hsc_env <- askHscEnv
+  let
+    dflags   = hsc_dflags hsc_env
+    this_pkg = thisPackage dflags
+  --
+  case maybe_pkg of
+    Just pkg | fsToUnitId pkg /= this_pkg && pkg /= fsLit "this" -> liftIO $ do
+      res <- findImportedModule hsc_env mod_name maybe_pkg
+      case res of
+        Found _ m -> return m
+        err       -> throwOneError $ noModError dflags noSrcSpan mod_name err
+    _otherwise -> do
+      home <- lookupLoadedHomeModule mod_name
+      case home of
+        Just m  -> return m
+        Nothing -> liftIO $ do
+           res <- findImportedModule hsc_env mod_name maybe_pkg
+           case res of
+             Found loc m | moduleUnitId m /= this_pkg -> return m
+                         | otherwise -> modNotLoadedError dflags m loc
+             err -> throwOneError $ noModError dflags noSrcSpan mod_name err
+
+
+lookupLoadedHomeModule :: GhcMonadLike m => ModuleName -> m (Maybe Module)
+lookupLoadedHomeModule mod_name = do
+  hsc_env <- askHscEnv
+  case lookupHpt (hsc_HPT hsc_env) mod_name of
+    Just mod_info      -> return (Just (mi_module (hm_iface mod_info)))
+    _not_a_home_module -> return Nothing
+
+
+modNotLoadedError :: DynFlags -> Module -> ModLocation -> IO a
+modNotLoadedError dflags m loc = throwGhcExceptionIO $ CmdLineError $ showSDoc dflags $
+   text "module is not loaded:" <+>
+   quotes (ppr (moduleName m)) <+>
+   parens (text (expectJust "modNotLoadedError" (ml_hs_file loc)))
+
+
+lookupModule :: GhcMonadLike m => ModuleName -> Maybe FastString -> m Module
+lookupModule mod_name (Just pkg) = findModule mod_name (Just pkg)
+lookupModule mod_name Nothing = do
+  hsc_env <- askHscEnv
+  home <- lookupLoadedHomeModule mod_name
+  case home of
+    Just m  -> return m
+    Nothing -> liftIO $ do
+      res <- findExposedPackageModule hsc_env mod_name Nothing
+      case res of
+        Found _ m -> return m
+        err       -> throwOneError $ noModError (hsc_dflags hsc_env) noSrcSpan mod_name err
+
+-- Compatibility shim to extract the comments out of an 'ApiAnns', as modern GHCs now puts the
+-- comments (i.e. Haskell comments) in a different field ('apiAnnRogueComments').
+apiComments :: ApiAnns -> [Ghc.Located AnnotationComment]
+apiComments apiAnns =
+  let comments = concat . M.elems . apiAnnComments $ apiAnns
+  in
+     map toRealSrc $ mappend comments (apiAnnRogueComments apiAnns)
+  where
+    toRealSrc (L x e) = L (RealSrcSpan x Nothing) e
diff --git a/src-ghc/Liquid/GHC/Interface.hs b/src-ghc/Liquid/GHC/Interface.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Interface.hs
@@ -0,0 +1,1048 @@
+{-# LANGUAGE NoMonomorphismRestriction  #-}
+{-# LANGUAGE LambdaCase                 #-}
+{-# LANGUAGE TypeSynonymInstances       #-}
+{-# LANGUAGE FlexibleContexts           #-}
+{-# LANGUAGE FlexibleInstances          #-}
+{-# LANGUAGE TupleSections              #-}
+{-# LANGUAGE ScopedTypeVariables        #-}
+{-# LANGUAGE OverloadedStrings          #-}
+{-# LANGUAGE PartialTypeSignatures      #-}
+{-# LANGUAGE TypeFamilies               #-}
+{-# LANGUAGE ViewPatterns               #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wwarn=deprecations #-}
+
+module Liquid.GHC.Interface (
+
+  -- * Determine the build-order for target files
+   realTargets
+
+  , getInterfaceDynFlags
+
+  -- * Extract all information needed for verification
+  , getTargetInfos
+  , runLiquidGhc
+
+  -- * Printer
+  , pprintCBs
+
+  -- * predicates
+  -- , isExportedVar
+  -- , exportedVars
+
+  -- * Internal exports (provisional)
+  , extractSpecComments
+  , extractSpecQuotes'
+  , makeLogicMap
+  , classCons
+  , derivedVars
+  , importVars
+  , makeGhcSrc
+  , allImports
+  , qualifiedImports
+  , modSummaryHsFile
+  , makeFamInstEnv
+  , findAndParseSpecFiles
+  , parseSpecFile
+  , noTerm
+  , clearSpec
+  , checkFilePragmas
+  , keepRawTokenStream
+  , ignoreInline
+  , lookupTyThings
+  , availableTyCons
+  , availableVars
+  , updLiftedSpec
+  , loadDependenciesOf
+  ) where
+
+import Prelude hiding (error)
+
+import GHC.Paths (libdir)
+
+import           Liquid.GHC.API as Ghc hiding ( text
+                                                               , (<+>)
+                                                               , panic
+                                                               , vcat
+                                                               , showPpr
+                                                               , mkStableModule
+                                                               , Target
+                                                               , Located
+                                                               )
+import qualified Liquid.GHC.API as Ghc
+import qualified Liquid.GHC.API as O
+import GHC.LanguageExtensions
+
+import Control.Exception
+import Control.Monad
+
+import Data.Bifunctor
+import Data.Data
+import Data.List hiding (intersperse)
+import Data.Maybe
+
+import Data.Generics.Aliases (mkT)
+import Data.Generics.Schemes (everywhere)
+
+import qualified Data.HashSet        as S
+import qualified Data.HashMap.Strict as HM
+
+import System.Console.CmdArgs.Verbosity hiding (Loud)
+import System.Directory
+import System.FilePath
+import System.IO
+import System.IO.Temp
+import Text.Megaparsec.Error
+import Text.PrettyPrint.HughesPJ        hiding (first, (<>))
+import Language.Fixpoint.Types          hiding (err, panic, Error, Result, Expr)
+import qualified Language.Fixpoint.Misc as Misc
+import Language.Haskell.Liquid.Bare
+import Liquid.GHC.Misc
+import Liquid.GHC.Types (MGIModGuts(..), miModGuts)
+import Liquid.GHC.Play
+import qualified Liquid.GHC.GhcMonadLike as GhcMonadLike
+import Liquid.GHC.GhcMonadLike (GhcMonadLike, isBootInterface, askHscEnv)
+import Language.Haskell.Liquid.WiredIn (isDerivedInstance)
+import qualified Language.Haskell.Liquid.Measure  as Ms
+import qualified Language.Haskell.Liquid.Misc     as Misc
+import Language.Haskell.Liquid.Parse
+import Language.Haskell.Liquid.Transforms.ANF
+import Language.Haskell.Liquid.Types hiding (Spec)
+-- import Language.Haskell.Liquid.Types.PrettyPrint
+-- import Language.Haskell.Liquid.Types.Visitors
+import Language.Haskell.Liquid.UX.CmdLine
+import Language.Haskell.Liquid.UX.QuasiQuoter
+import Language.Haskell.Liquid.UX.Tidy
+import Language.Fixpoint.Utils.Files
+
+import Optics hiding (ix)
+
+import qualified Debug.Trace as Debug
+
+
+--------------------------------------------------------------------------------
+{- | @realTargets mE cfg targets@ uses `Interface.configureGhcTargets` to
+     return a list of files
+
+       [i1, i2, ... ] ++ [f1, f2, ...]
+
+     1. Where each file only (transitively imports) PRECEDIING ones;
+     2. `f1..` are a permutation of the original `targets`;
+     3. `i1..` either don't have "fresh" .bspec files.
+
+ -}
+--------------------------------------------------------------------------------
+realTargets :: Maybe HscEnv -> Config -> [FilePath] -> IO [FilePath]
+realTargets  mbEnv cfg tgtFs
+  | noCheckImports cfg = return tgtFs
+  | otherwise          = do
+    incDir   <- Misc.getIncludeDir
+    allFs    <- orderTargets mbEnv cfg tgtFs
+    let srcFs = filter (not . Misc.isIncludeFile incDir) allFs
+    realFs   <- filterM check srcFs
+    dir      <- getCurrentDirectory
+    return      (makeRelative dir <$> realFs)
+  where
+    check f    = not <$> skipTarget tgts f
+    tgts       = S.fromList tgtFs
+
+getInterfaceDynFlags :: Maybe HscEnv -> Config -> IO DynFlags
+getInterfaceDynFlags mbEnv cfg = runLiquidGhc mbEnv cfg getSessionDynFlags
+
+orderTargets :: Maybe HscEnv -> Config -> [FilePath] -> IO [FilePath]
+orderTargets mbEnv cfg tgtFiles = runLiquidGhc mbEnv cfg $ do
+  homeModules <- configureGhcTargets tgtFiles
+  return         (modSummaryHsFile <$> mgModSummaries homeModules)
+
+
+skipTarget :: S.HashSet FilePath -> FilePath -> IO Bool
+skipTarget tgts f
+  | S.member f tgts = return False          -- Always check target file
+  | otherwise       = hasFreshBinSpec f     -- But skip an import with fresh .bspec
+
+hasFreshBinSpec :: FilePath -> IO Bool
+hasFreshBinSpec srcF = do
+  let specF = extFileName BinSpec srcF
+  srcMb    <- Misc.lastModified srcF
+  specMb   <- Misc.lastModified specF
+  case (srcMb, specMb) of
+    (Just srcT, Just specT) -> return (srcT < specT)
+    _                       -> return False
+
+
+
+--------------------------------------------------------------------------------
+-- | GHC Interface Pipeline ----------------------------------------------------
+--------------------------------------------------------------------------------
+
+getTargetInfos :: Maybe HscEnv -> Config -> [FilePath] -> IO ([TargetInfo], HscEnv)
+getTargetInfos hscEnv cfg tgtFiles' = do
+  tgtFiles <- mapM canonicalizePath tgtFiles'
+  mapM_ checkFilePresent tgtFiles
+  mapM_ createTempDirectoryIfMissing tgtFiles
+  logicMap <- liftIO makeLogicMap
+  runLiquidGhc hscEnv cfg (getTargetInfos' cfg logicMap tgtFiles)
+
+checkFilePresent :: FilePath -> IO ()
+checkFilePresent f = do
+  b <- doesFileExist f
+  unless b $ panic Nothing ("Cannot find file: " ++ f)
+
+getTargetInfos' :: Config -> LogicMap -> [FilePath] -> Ghc ([TargetInfo], HscEnv)
+getTargetInfos' cfg logicMap tgtFiles = do
+  _           <- compileCFiles cfg
+  homeModules <- configureGhcTargets tgtFiles
+  depGraph    <- buildDepGraph homeModules
+  ghcInfos    <- processModules cfg logicMap tgtFiles depGraph homeModules
+  hscEnv      <- getSession
+  return (ghcInfos, hscEnv)
+
+createTempDirectoryIfMissing :: FilePath -> IO ()
+createTempDirectoryIfMissing tgtFile = Misc.tryIgnore "create temp directory" $
+  createDirectoryIfMissing False $ tempDirectory tgtFile
+
+--------------------------------------------------------------------------------
+-- | GHC Configuration & Setup -------------------------------------------------
+--------------------------------------------------------------------------------
+runLiquidGhc :: Maybe HscEnv -> Config -> Ghc a -> IO a
+runLiquidGhc hscEnv cfg act =
+  withSystemTempDirectory "liquid" $ \tmp ->
+    runGhc (Just libdir) $ do
+      maybe (return ()) setSession hscEnv
+      df <- configureDynFlags cfg tmp
+      prettyPrintGhcErrors df act
+
+updateIncludePaths :: DynFlags -> [FilePath] -> IncludeSpecs
+updateIncludePaths df ps = addGlobalInclude (includePaths df) ps
+
+configureDynFlags :: Config -> FilePath -> Ghc DynFlags
+configureDynFlags cfg tmp = do
+  df <- getSessionDynFlags
+  (df',_,_) <- parseDynamicFlags df $ map noLoc $ ghcOptions cfg
+  loud <- liftIO isLoud
+  let df'' = df' { importPaths  = nub $ idirs cfg ++ importPaths df'
+                 , libraryPaths = nub $ idirs cfg ++ libraryPaths df'
+                 , includePaths = updateIncludePaths df' (idirs cfg) -- addGlobalInclude (includePaths df') (idirs cfg)
+                 , packageFlags = ExposePackage ""
+                                                (PackageArg "ghc-prim")
+                                                (ModRenaming True [])
+                                : packageFlags df'
+
+                 , debugLevel   = 1               -- insert SourceNotes
+                 -- , profAuto     = ProfAutoCalls
+                 , ghcLink      = LinkInMemory
+                 , hscTarget    = HscInterpreted
+                 , ghcMode      = CompManager
+                 -- prevent GHC from printing anything, unless in Loud mode
+                 , log_action   = if loud
+                                    then defaultLogAction
+                                    else \_ _ _ _ _   -> return ()
+                 -- redirect .hi/.o/etc files to temp directory
+                 , objectDir    = Just tmp
+                 , hiDir        = Just tmp
+                 , stubDir      = Just tmp
+                 } `gopt_set` Opt_ImplicitImportQualified
+                   `gopt_set` Opt_PIC
+                   `gopt_set` Opt_DeferTypedHoles
+                   `xopt_set` MagicHash
+                   `xopt_set` DeriveGeneric
+                   `xopt_set` StandaloneDeriving
+  _ <- setSessionDynFlags df''
+  return df''
+
+configureGhcTargets :: [FilePath] -> Ghc ModuleGraph
+configureGhcTargets tgtFiles = do
+  targets         <- mapM (`guessTarget` Nothing) tgtFiles
+  _               <- setTargets targets
+  moduleGraph     <- depanal [] False -- see [NOTE:DROP-BOOT-FILES]
+
+  let homeModules  = filter (not . isBootInterface . isBootSummary) $
+                     flattenSCCs $ topSortModuleGraph False moduleGraph Nothing
+  let homeNames    = moduleName . ms_mod <$> homeModules
+  _               <- setTargetModules homeNames
+  liftIO $ whenLoud $ print ("Module Dependencies" :: String, homeNames)
+  return $ mkModuleGraph homeModules
+
+setTargetModules :: [ModuleName] -> Ghc ()
+setTargetModules modNames = setTargets $ mkTarget <$> modNames
+  where
+    mkTarget modName = Ghc.Target (TargetModule modName) True Nothing
+
+compileCFiles :: Config -> Ghc ()
+compileCFiles cfg = do
+  df  <- getSessionDynFlags
+  _   <- setSessionDynFlags $
+           df { includePaths = updateIncludePaths df (idirs cfg)
+              , importPaths  = nub $ idirs cfg ++ importPaths df
+              , libraryPaths = nub $ idirs cfg ++ libraryPaths df }
+  hsc <- getSession
+  os  <- mapM (\x -> liftIO $ compileFile hsc StopLn (x,Nothing)) (nub $ cFiles cfg)
+  df'  <- getSessionDynFlags
+  void $ setSessionDynFlags $ df' { ldInputs = nub $ map (FileOption "") os ++ ldInputs df' }
+
+{- | [NOTE:DROP-BOOT-FILES] Drop hs-boot files from the graph.
+      We do it manually rather than using the flag to topSortModuleGraph
+      because otherwise the order of mutually recursive modules depends
+      on the modulename, e.g. given
+
+      Bar.hs --> Foo.hs --> Bar.hs-boot
+
+      we'll get
+
+      [Bar.hs, Foo.hs]
+
+      which is backwards..
+ -}
+--------------------------------------------------------------------------------
+-- Home Module Dependency Graph ------------------------------------------------
+--------------------------------------------------------------------------------
+
+type DepGraph = Graph DepGraphNode
+type DepGraphNode = Node Module ()
+
+reachableModules :: DepGraph -> Module -> [Module]
+reachableModules depGraph mod' =
+  node_key <$> tail (reachableG depGraph (DigraphNode () mod' []))
+
+buildDepGraph :: ModuleGraph -> Ghc DepGraph
+buildDepGraph homeModules =
+  graphFromEdgedVerticesOrd <$> mapM mkDepGraphNode (mgModSummaries homeModules)
+
+mkDepGraphNode :: ModSummary -> Ghc DepGraphNode
+mkDepGraphNode modSummary =
+  DigraphNode () (ms_mod modSummary) <$> (filterM isHomeModule =<< modSummaryImports modSummary)
+
+isHomeModule :: GhcMonadLike m => Module -> m Bool
+isHomeModule mod' = do
+  homePkg <- thisPackage <$> getDynFlags
+  return   $ moduleUnitId mod' == homePkg
+
+modSummaryImports :: GhcMonadLike m => ModSummary -> m [Module]
+modSummaryImports modSummary =
+  mapM (importDeclModule (ms_mod modSummary))
+       (ms_textual_imps modSummary)
+
+importDeclModule :: GhcMonadLike m => Module -> (Maybe FastString,  Ghc.Located ModuleName) -> m Module
+importDeclModule fromMod (mpkgQual, locModName) = do
+  hscEnv <- askHscEnv
+  let modName = unLoc locModName
+  res <- liftIO $ findImportedModule hscEnv modName mpkgQual
+  case res of
+    Ghc.Found _ mod' -> return mod'
+    _ -> do
+      dflags <- getDynFlags
+      liftIO $ throwGhcExceptionIO $ ProgramError $
+        O.showPpr dflags (moduleName fromMod) ++ ": " ++
+        O.showSDoc dflags (cannotFindModule dflags modName res)
+
+--------------------------------------------------------------------------------
+-- | Extract Ids ---------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+classCons :: Maybe [ClsInst] -> [Id]
+classCons Nothing   = []
+classCons (Just cs) = concatMap (dataConImplicitIds . head . tyConDataCons . classTyCon . is_cls) cs
+
+derivedVars :: Config -> MGIModGuts -> [Var]
+derivedVars cfg mg  = concatMap (dFunIdVars cbs . is_dfun) derInsts
+  where
+    derInsts
+      | checkDer    = insts
+      | otherwise   = filter isDerivedInstance insts
+    insts           = mgClsInstances mg
+    checkDer        = checkDerived cfg
+    cbs             = mgi_binds mg
+
+
+mgClsInstances :: MGIModGuts -> [ClsInst]
+mgClsInstances = fromMaybe [] . mgi_cls_inst
+
+dFunIdVars :: CoreProgram -> DFunId -> [Id]
+dFunIdVars cbs fd  = notracepp msg $ concatMap bindersOf cbs' ++ deps
+  where
+    msg            = "DERIVED-VARS-OF: " ++ showpp fd
+    cbs'           = filter f cbs
+    f (NonRec x _) = eqFd x
+    f (Rec xes)    = any eqFd (fst <$> xes)
+    eqFd x         = varName x == varName fd
+    deps           = concatMap unfoldDep unfolds
+    unfolds        = unfoldingInfo . idInfo <$> concatMap bindersOf cbs'
+
+unfoldDep :: Unfolding -> [Id]
+unfoldDep (DFunUnfolding _ _ e)       = concatMap exprDep e
+unfoldDep CoreUnfolding {uf_tmpl = e} = exprDep e
+unfoldDep _                           = []
+
+exprDep :: CoreExpr -> [Id]
+exprDep = freeVars S.empty
+
+importVars :: CoreProgram -> [Id]
+importVars = freeVars S.empty
+
+_definedVars :: CoreProgram -> [Id]
+_definedVars = concatMap defs
+  where
+    defs (NonRec x _) = [x]
+    defs (Rec xes)    = map fst xes
+
+--------------------------------------------------------------------------------
+-- | Per-Module Pipeline -------------------------------------------------------
+--------------------------------------------------------------------------------
+
+type SpecEnv = ModuleEnv (ModName, Ms.BareSpec)
+
+processModules :: Config -> LogicMap -> [FilePath] -> DepGraph -> ModuleGraph -> Ghc [TargetInfo]
+processModules cfg logicMap tgtFiles depGraph homeModules = do
+  -- DO NOT DELETE: liftIO $ putStrLn $ "Process Modules: TargetFiles = " ++ show tgtFiles
+  catMaybes . snd <$> Misc.mapAccumM go emptyModuleEnv (mgModSummaries homeModules)
+  where
+    go = processModule cfg logicMap (S.fromList tgtFiles) depGraph
+
+processModule :: Config -> LogicMap -> S.HashSet FilePath -> DepGraph -> SpecEnv -> ModSummary
+              -> Ghc (SpecEnv, Maybe TargetInfo)
+processModule cfg logicMap tgtFiles depGraph specEnv modSummary = do
+  let mod'             = ms_mod modSummary
+  -- DO-NOT-DELETE _                <- liftIO $ whenLoud $ putStrLn $ "Process Module: " ++ showPpr (moduleName mod)
+  file                <- liftIO $ canonicalizePath $ modSummaryHsFile modSummary
+  let isTarget'        = file `S.member` tgtFiles
+  _                   <- loadDependenciesOf $ moduleName mod'
+  parsed              <- parseModule $ keepRawTokenStream modSummary
+  let specComments     = extractSpecComments (pm_annotations parsed)
+  typechecked         <- typecheckModule $ ignoreInline parsed
+  let specQuotes       = extractSpecQuotes typechecked
+  _                   <- loadModule' typechecked
+  (modName, commSpec) <- either throw return $ hsSpecificationP (moduleName mod') specComments specQuotes
+
+  liftedSpec          <- liftIO $ if isTarget' || null specComments then return Nothing else loadLiftedSpec cfg file
+  let bareSpec         = updLiftedSpec commSpec liftedSpec
+  _                   <- checkFilePragmas $ Ms.pragmas bareSpec
+  let specEnv'         = extendModuleEnv specEnv mod' (modName, noTerm bareSpec)
+  (specEnv', ) <$> if isTarget'
+                     then Just <$> processTargetModule cfg logicMap depGraph specEnv file typechecked bareSpec
+                     else return Nothing
+
+updLiftedSpec :: Ms.BareSpec -> Maybe Ms.BareSpec -> Ms.BareSpec
+updLiftedSpec s1 Nothing   = s1
+updLiftedSpec s1 (Just s2) = clearSpec s1 `mappend` s2
+
+clearSpec :: Ms.BareSpec -> Ms.BareSpec
+clearSpec s = s { sigs = [], asmSigs = [], aliases = [], ealiases = [], qualifiers = [], dataDecls = [] }
+
+keepRawTokenStream :: ModSummary -> ModSummary
+keepRawTokenStream modSummary = modSummary
+  { ms_hspp_opts = ms_hspp_opts modSummary `gopt_set` Opt_KeepRawTokenStream }
+
+loadDependenciesOf :: GhcMonad m => ModuleName -> m ()
+loadDependenciesOf modName = do
+  loadResult <- load $ LoadDependenciesOf modName
+  when (failed loadResult) $ liftIO $ throwGhcExceptionIO $ ProgramError $
+   "Failed to load dependencies of module " ++ showPpr modName
+
+loadModule' :: TypecheckedModule -> Ghc TypecheckedModule
+loadModule' tm = loadModule tm'
+  where
+    pm   = tm_parsed_module tm
+    ms   = pm_mod_summary pm
+    df   = ms_hspp_opts ms
+    df'  = df { hscTarget = HscNothing, ghcLink = NoLink }
+    ms'  = ms { ms_hspp_opts = df' }
+    pm'  = pm { pm_mod_summary = ms' }
+    tm'  = tm { tm_parsed_module = pm' }
+
+
+
+
+      -- -- we should be able to setContext regardless of whether
+      -- -- we use the ghc api. However, ghc will complain
+      -- -- if the filename does not match the module name
+      -- when (typeclass cfg) $ do
+      --   Ghc.setContext [iimport |(modName, _) <- allSpecs legacyBareSpec,
+      --                   let iimport = if isTarget modName
+      --                                 then Ghc.IIModule (getModName modName)
+      --                                 else Ghc.IIDecl (Ghc.simpleImportDecl (getModName modName))]
+      --   void $ Ghc.execStmt
+      --     "let {infixr 1 ==>; True ==> False = False; _ ==> _ = True}"
+      --     Ghc.execOptions
+      --   void $ Ghc.execStmt
+      --     "let {infixr 1 <=>; True <=> False = False; _ <=> _ = True}"
+      --     Ghc.execOptions
+      --   void $ Ghc.execStmt
+      --     "let {infix 4 ==; (==) :: a -> a -> Bool; _ == _ = undefined}"
+      --     Ghc.execOptions
+      --   void $ Ghc.execStmt
+      --     "let {infix 4 /=; (/=) :: a -> a -> Bool; _ /= _ = undefined}"
+      --     Ghc.execOptions
+      --   void $ Ghc.execStmt
+      --     "let {infixl 7 /; (/) :: Num a => a -> a -> a; _ / _ = undefined}"
+      --     Ghc.execOptions
+      --   void $ Ghc.execStmt
+      --     "let {len :: [a] -> Int; len _ = undefined}"
+      --     Ghc.execOptions
+processTargetModule :: Config -> LogicMap -> DepGraph -> SpecEnv -> FilePath -> TypecheckedModule -> Ms.BareSpec
+                    -> Ghc TargetInfo
+processTargetModule cfg0 logicMap depGraph specEnv file typechecked bareSpec = do
+  withPragmas cfg0 file (Ms.pragmas bareSpec) $ \cfg -> do
+    let modSum    = pm_mod_summary (tm_parsed_module typechecked)
+    ghcSrc       <- makeGhcSrc    cfg file     typechecked modSum
+    dependencies <- makeDependencies cfg depGraph specEnv modSum bareSpec
+
+    let targetSrc = view targetSrcIso ghcSrc
+    dynFlags <- getDynFlags
+  -- set up the interactive context
+    when (typeclass cfg) $
+      loadContext (view bareSpecIso bareSpec) dependencies targetSrc
+    (msgs, specM) <- Ghc.withSession $ \hsc_env -> liftIO $ runTcInteractive hsc_env
+      (makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies)
+    case specM of
+      Nothing -> panic Nothing  $ O.showSDoc dynFlags $ O.sep (Ghc.pprErrMsgBagWithLoc (snd msgs))
+      Just spec ->
+        case spec of
+          Left diagnostics -> do
+            mapM_ (liftIO . printWarning dynFlags) (allWarnings diagnostics)
+            throw (allErrors diagnostics)
+          Right (warns, targetSpec, liftedSpec) -> do
+            mapM_ (liftIO . printWarning dynFlags) warns
+            -- The call below is temporary, we should really load & save directly 'LiftedSpec's.
+            _          <- liftIO $ saveLiftedSpec (_giTarget ghcSrc) (unsafeFromLiftedSpec liftedSpec)
+            return      $ TargetInfo targetSrc targetSpec
+
+  -- cfg          <- liftIO $ withPragmas cfg0 file (Ms.pragmas bareSpec)
+  -- let modSum    = pm_mod_summary (tm_parsed_module typechecked)
+  -- ghcSrc       <- makeGhcSrc    cfg file     typechecked modSum
+  -- dependencies <- makeDependencies cfg depGraph specEnv modSum bareSpec
+
+  -- let targetSrc = view targetSrcIso ghcSrc
+  -- dynFlags <- getDynFlags
+  -- -- set up the interactive context
+  -- when (typeclass cfg) $
+  --   loadContext (view bareSpecIso bareSpec) dependencies targetSrc
+  -- (msgs, specM) <- Ghc.withSession $ \hsc_env -> liftIO $ runTcInteractive hsc_env
+  --   (makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies)
+  -- case specM of
+  --   Nothing -> panic Nothing  $ O.showSDoc dynFlags $ O.sep (Ghc.pprErrMsgBagWithLoc (snd msgs))
+  --   Just spec ->
+  --     case spec of
+  --       Left diagnostics -> do
+  --         mapM_ (liftIO . printWarning dynFlags) (allWarnings diagnostics)
+  --         throw (allErrors diagnostics)
+  --       Right (warns, targetSpec, liftedSpec) -> do
+  --         mapM_ (liftIO . printWarning dynFlags) warns
+
+  --     -- makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies >>= \case
+  --     --   Left  validationErrors -> Bare.checkThrow (Left validationErrors)
+  --     --   Right (targetSpec, liftedSpec) -> do
+
+  --     -- The call below is temporary, we should really load & save directly 'LiftedSpec's.
+  --         _          <- liftIO $ saveLiftedSpec (_giTarget ghcSrc) (unsafeFromLiftedSpec liftedSpec)
+  --         return      $ TargetInfo targetSrc targetSpec
+
+
+loadContext :: BareSpec -> TargetDependencies -> TargetSrc -> Ghc ()
+loadContext bareSpec dependencies targetSrc = do
+  Ghc.setContext $ [Ghc.IIModule (getModName modName) |(modName, _) <- allSpecs legacyBareSpec,
+                    isTarget modName]
+
+  where
+    toLegacyDep :: (StableModule, LiftedSpec) -> (ModName, Ms.BareSpec)
+    toLegacyDep (sm, ls) = (ModName SrcImport (Ghc.moduleName . unStableModule $ sm), unsafeFromLiftedSpec ls)
+
+    toLegacyTarget :: Ms.BareSpec -> (ModName, Ms.BareSpec)
+    toLegacyTarget validatedSpec = (giTargetMod targetSrc, validatedSpec)
+
+    legacyDependencies :: [(ModName, Ms.BareSpec)]
+    legacyDependencies = map toLegacyDep . HM.toList . getDependencies $ dependencies
+
+    allSpecs :: Ms.BareSpec -> [(ModName, Ms.BareSpec)]
+    allSpecs validSpec = toLegacyTarget validSpec : legacyDependencies
+
+    -- legacyBareSpec :: Spec LocBareType F.LocSymbol
+    legacyBareSpec = review bareSpecIso bareSpec
+
+---------------------------------------------------------------------------------------
+-- | @makeGhcSrc@ builds all the source-related information needed for consgen
+---------------------------------------------------------------------------------------
+
+makeGhcSrc :: Config -> FilePath -> TypecheckedModule -> ModSummary -> Ghc GhcSrc
+makeGhcSrc cfg file typechecked modSum = do
+  modGuts'          <- GhcMonadLike.desugarModule modSum typechecked
+
+  let modGuts        = makeMGIModGuts modGuts'
+  hscEnv            <- getSession
+  coreBinds         <- liftIO $ anormalize cfg hscEnv modGuts'
+  _                 <- liftIO $ whenNormal $ Misc.donePhase Misc.Loud "A-Normalization"
+  let dataCons       = concatMap (map dataConWorkId . tyConDataCons) (mgi_tcs modGuts)
+  (fiTcs, fiDcs)    <- makeFamInstEnv <$> liftIO (getFamInstances hscEnv)
+  things            <- lookupTyThings hscEnv modSum (fst $ tm_internals_ typechecked)
+
+  availableTcs      <- availableTyCons hscEnv modSum (fst $ tm_internals_ typechecked) (mg_exports modGuts')
+
+  let impVars        = importVars coreBinds ++ classCons (mgi_cls_inst modGuts)
+  incDir            <- liftIO Misc.getIncludeDir
+
+  --liftIO $ do
+  --  print $ "_gsTcs   => " ++ show (nub $ (mgi_tcs      modGuts) ++ availableTcs)
+  --  print $ "_gsFiTcs => " ++ show fiTcs
+  --  print $ "_gsFiDcs => " ++ show fiDcs
+  --  print $ "dataCons => " ++ show dataCons
+  --  print $ "defVars  => " ++ show (dataCons ++ (letVars coreBinds))
+
+  return $ Src
+    { _giIncDir    = incDir
+    , _giTarget    = file
+    , _giTargetMod = ModName Target (moduleName (ms_mod modSum))
+    , _giCbs       = coreBinds
+    , _giImpVars   = impVars
+    , _giDefVars   = dataCons ++ letVars coreBinds
+    , _giUseVars   = readVars coreBinds
+    , _giDerVars   = S.fromList (derivedVars cfg modGuts)
+    , _gsExports   = mgi_exports  modGuts
+    , _gsTcs       = nub $ mgi_tcs modGuts ++ availableTcs
+    , _gsCls       = mgi_cls_inst modGuts
+    , _gsFiTcs     = fiTcs
+    , _gsFiDcs     = fiDcs
+    , _gsPrimTcs   = Ghc.primTyCons
+    , _gsQualImps  = qualifiedImports (maybe mempty (view _2) (tm_renamed_source typechecked))
+    , _gsAllImps   = allImports       (maybe mempty (view _2) (tm_renamed_source typechecked))
+    , _gsTyThings  = [ t | (_, Just t) <- things ]
+    }
+
+_impThings :: [Var] -> [TyThing] -> [TyThing]
+_impThings vars  = filter ok
+  where
+    vs          = S.fromList vars
+    ok (AnId x) = S.member x vs
+    ok _        = True
+
+allImports :: [LImportDecl GhcRn] -> S.HashSet Symbol
+allImports = \case
+  []-> Debug.trace "WARNING: Missing RenamedSource" mempty
+  imps -> S.fromList (symbol . unLoc . ideclName . unLoc <$> imps)
+
+qualifiedImports :: [LImportDecl GhcRn] -> QImports
+qualifiedImports = \case
+  []   -> Debug.trace "WARNING: Missing RenamedSource" (qImports mempty)
+  imps -> qImports [ (qn, n) | i         <- imps
+                                          , let decl   = unLoc i
+                                          , let m      = unLoc (ideclName decl)
+                                          , qm        <- maybeToList (unLoc <$> ideclAs decl)
+                                          , let [n,qn] = symbol <$> [m, qm]
+                                          ]
+
+qImports :: [(Symbol, Symbol)] -> QImports
+qImports qns  = QImports
+  { qiNames   = Misc.group qns
+  , qiModules = S.fromList (snd <$> qns)
+  }
+
+
+---------------------------------------------------------------------------------------
+-- | @lookupTyThings@ grabs all the @Name@s and associated @TyThing@ known to GHC
+--   for this module; we will use this to create our name-resolution environment
+--   (see `Bare.Resolve`)
+---------------------------------------------------------------------------------------
+lookupTyThings :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> m [(Name, Maybe TyThing)]
+lookupTyThings hscEnv modSum tcGblEnv = forM names (lookupTyThing hscEnv modSum tcGblEnv)
+  where
+    names :: [Ghc.Name]
+    names  = liftM2 (++)
+             (fmap Ghc.gre_name . Ghc.globalRdrEnvElts . tcg_rdr_env)
+             (fmap is_dfun_name . tcg_insts) tcGblEnv
+-- | Lookup a single 'Name' in the GHC environment, yielding back the 'Name' alongside the 'TyThing',
+-- if one is found.
+lookupTyThing :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> Name -> m (Name, Maybe TyThing)
+lookupTyThing hscEnv modSum tcGblEnv n = do
+  mi  <- GhcMonadLike.moduleInfoTc modSum tcGblEnv
+  tt1 <-          GhcMonadLike.lookupName      n
+  tt2 <- liftIO $ Ghc.hscTcRcLookupName hscEnv n
+  tt3 <-          GhcMonadLike.modInfoLookupName mi n
+  tt4 <-          GhcMonadLike.lookupGlobalName n
+  return (n, Misc.firstMaybes [tt1, tt2, tt3, tt4])
+
+availableTyThings :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [TyThing]
+availableTyThings hscEnv modSum tcGblEnv avails = fmap (catMaybes . mconcat) $ forM avails $ \a -> do
+  results <- case a of
+    Avail n        -> pure <$> lookupTyThing hscEnv modSum tcGblEnv n
+    AvailTC n ns _ -> forM (n : ns) $ lookupTyThing hscEnv modSum tcGblEnv
+  pure . map snd $ results
+
+-- | Returns all the available (i.e. exported) 'TyCon's (type constructors) for the input 'Module'.
+availableTyCons :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [Ghc.TyCon]
+availableTyCons hscEnv modSum tcGblEnv avails =
+  fmap (\things -> [tyCon | (ATyCon tyCon) <- things]) (availableTyThings hscEnv modSum tcGblEnv avails)
+
+-- | Returns all the available (i.e. exported) 'Var's for the input 'Module'.
+availableVars :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [Ghc.Var]
+availableVars hscEnv modSum tcGblEnv avails =
+  fmap (\things -> [var | (AnId var) <- things]) (availableTyThings hscEnv modSum tcGblEnv avails)
+
+-- lookupTyThings :: HscEnv -> TypecheckedModule -> MGIModGuts -> Ghc [(Name, Maybe TyThing)]
+-- lookupTyThings hscEnv tcm mg =
+--   forM (mgNames mg ++ instNames mg) $ \n -> do
+--     tt1 <-          lookupName                   n
+--     tt2 <- liftIO $ Ghc.hscTcRcLookupName hscEnv n
+--     tt3 <-          modInfoLookupName mi         n
+--     tt4 <-          lookupGlobalName             n
+--     return (n, Misc.firstMaybes [tt1, tt2, tt3, tt4])
+--     where
+--       mi = tm_checked_module_info tcm
+
+
+-- lookupName        :: GhcMonad m => Name -> m (Maybe TyThing)
+-- hscTcRcLookupName :: HscEnv -> Name -> IO (Maybe TyThing)
+-- modInfoLookupName :: GhcMonad m => ModuleInfo -> Name -> m (Maybe TyThing)
+-- lookupGlobalName  :: GhcMonad m => Name -> m (Maybe TyThing)
+
+_dumpTypeEnv :: TypecheckedModule -> IO ()
+_dumpTypeEnv tm = do
+  print ("DUMP-TYPE-ENV" :: String)
+  print (showpp <$> tcmTyThings tm)
+
+tcmTyThings :: TypecheckedModule -> Maybe [Name]
+tcmTyThings
+  =
+  -- typeEnvElts
+  -- . tcg_type_env . fst
+  -- . md_types . snd
+  -- . tm_internals_
+  modInfoTopLevelScope
+  . tm_checked_module_info
+
+
+_dumpRdrEnv :: HscEnv -> MGIModGuts -> IO ()
+_dumpRdrEnv _hscEnv modGuts = do
+  print ("DUMP-RDR-ENV" :: String)
+  print (mgNames modGuts)
+  -- print (hscNames hscEnv)
+  -- print (mgDeps modGuts)
+  where
+    _mgDeps   = Ghc.dep_mods . mgi_deps
+    _hscNames = fmap showPpr . Ghc.ic_tythings . Ghc.hsc_IC
+
+mgNames :: MGIModGuts -> [Ghc.Name]
+mgNames  = fmap Ghc.gre_name . Ghc.globalRdrEnvElts .  mgi_rdr_env
+
+---------------------------------------------------------------------------------------
+-- | @makeDependencies@ loads BareSpec for target and imported modules
+-- /IMPORTANT(adn)/: We \"cheat\" a bit by creating a 'Module' out the 'ModuleName' we
+-- parse from the spec, and convert the former into a 'StableModule' for the purpose
+-- of dependency tracking. This means, in practice, that all the \"wired-in-prelude\"
+-- specs will share the same `UnitId`, which for the sake of the executable is an
+-- acceptable compromise, as long as we don't create duplicates.
+---------------------------------------------------------------------------------------
+makeDependencies :: Config -> DepGraph -> SpecEnv -> ModSummary -> Ms.BareSpec
+                 -> Ghc TargetDependencies
+makeDependencies cfg depGraph specEnv modSum _ = do
+  let paths     = S.fromList $ idirs cfg ++ importPaths (ms_hspp_opts modSum)
+  _            <- liftIO $ whenLoud $ putStrLn $ "paths = " ++ show paths
+  let reachable = reachableModules depGraph (ms_mod modSum)
+  specSpecs    <- findAndParseSpecFiles cfg paths modSum reachable
+  let homeSpecs = cachedBareSpecs specEnv reachable
+
+  -- NOTE:(adn) Unfortunately for the executable we might have 3 different 'Prelude' specs
+  -- (one for the Prelude functions, one for the Real/NonReal and one for the PatErr, so we
+  -- cannot really assume all the module names will be disjointed. As a result we have to
+  -- hack our way around this by replacing the 'UnitId' with some unique enumeration, at
+  -- least unique in this local scope.
+
+  let combine' ix (mn, sp) = ((mn, ix), sp)
+  let impSpecs  = map (bimap mkStableModule (view liftedSpecGetter)) (zipWith combine' [0..] (specSpecs ++ homeSpecs))
+
+  return        $ TargetDependencies $ HM.fromList impSpecs
+  where
+    mkStableModule :: (ModName, Int) -> StableModule
+    mkStableModule (modName, ix) =
+      Ghc.mkStableModule (fakeUnitId (moduleUnitId targetModule) ix) (getModName modName)
+
+    fakeUnitId :: UnitId -> Int -> UnitId
+    fakeUnitId uid ix = stringToUnitId $ unitIdString uid ++ show ix
+
+    targetModule :: Module
+    targetModule = ms_mod modSum
+
+modSummaryHsFile :: ModSummary -> FilePath
+modSummaryHsFile modSummary =
+  fromMaybe
+    (panic Nothing $
+      "modSummaryHsFile: missing .hs file for " ++
+      showPpr (ms_mod modSummary))
+    (ml_hs_file $ ms_location modSummary)
+
+cachedBareSpecs :: SpecEnv -> [Module] -> [(ModName, Ms.BareSpec)]
+cachedBareSpecs specEnv mods = lookupBareSpec <$> mods
+  where
+    lookupBareSpec m         = fromMaybe (err m) (lookupModuleEnv specEnv m)
+    err m                    = impossible Nothing ("lookupBareSpec: missing module " ++ showPpr m)
+
+checkFilePragmas :: GhcMonadLike m => [Located String] -> m ()
+checkFilePragmas = Misc.applyNonNull (return ()) throw . mapMaybe err
+  where
+    err pragma
+      | check (val pragma) = Just (ErrFilePragma $ fSrcSpan pragma :: Error)
+      | otherwise          = Nothing
+    check pragma           = any (`isPrefixOf` pragma) bad
+    bad =
+      [ "-i", "--idirs"
+      , "-g", "--ghc-option"
+      , "--c-files", "--cfiles"
+      ]
+
+--------------------------------------------------------------------------------
+-- | Family instance information
+--------------------------------------------------------------------------------
+makeFamInstEnv :: [FamInst] -> ([Ghc.TyCon], [(Symbol, DataCon)])
+makeFamInstEnv famInsts =
+  let fiTcs = [ tc            | FamInst { fi_flavor = DataFamilyInst tc } <- famInsts ]
+      fiDcs = [ (symbol d, d) | tc <- fiTcs, d <- tyConDataCons tc ]
+  in (fiTcs, fiDcs)
+
+getFamInstances :: HscEnv -> IO [FamInst]
+getFamInstances env = do
+  (_, Just (pkg_fie, home_fie)) <- runTcInteractive env tcGetFamInstEnvs
+  return $ famInstEnvElts home_fie ++ famInstEnvElts pkg_fie
+
+--------------------------------------------------------------------------------
+-- | Extract Specifications from GHC -------------------------------------------
+--------------------------------------------------------------------------------
+extractSpecComments :: ApiAnns -> [(SourcePos, String)]
+extractSpecComments = mapMaybe extractSpecComment . GhcMonadLike.apiComments
+
+-- | 'extractSpecComment' pulls out the specification part from a full comment
+--   string, i.e. if the string is of the form:
+--   1. '{-@ S @-}' then it returns the substring 'S',
+--   2. '{-@ ... -}' then it throws a malformed SPECIFICATION ERROR, and
+--   3. Otherwise it is just treated as a plain comment so we return Nothing.
+
+extractSpecComment :: Ghc.Located AnnotationComment -> Maybe (SourcePos, String)
+extractSpecComment (Ghc.L sp (AnnBlockComment txt))
+  | isPrefixOf "{-@" txt && isSuffixOf "@-}" txt          -- valid   specification
+  = Just (offsetPos, take (length txt - 6) $ drop 3 txt)
+  | isPrefixOf "{-@" txt                                   -- invalid specification
+  = uError $ ErrParseAnn sp "A valid specification must have a closing '@-}'."
+  where
+    offsetPos = case srcSpanSourcePos sp of
+      SourcePos file line col -> safeSourcePos file (unPos line) (unPos col + 3)
+extractSpecComment _ = Nothing
+
+extractSpecQuotes :: TypecheckedModule -> [BPspec]
+extractSpecQuotes =
+  extractSpecQuotes' (ms_mod . pm_mod_summary . tm_parsed_module)
+                     (tcg_anns . fst . tm_internals_)
+
+extractSpecQuotes' :: (a -> Module) -> (a -> [Annotation]) -> a -> [BPspec]
+extractSpecQuotes' thisModule getAnns a = mapMaybe extractSpecQuote anns
+  where
+    anns = map ann_value $
+           filter (isOurModTarget . ann_target) $
+           getAnns a
+
+    isOurModTarget (ModuleTarget mod1) = mod1 == thisModule a
+    isOurModTarget _ = False
+
+extractSpecQuote :: AnnPayload -> Maybe BPspec
+extractSpecQuote payload =
+  case Ghc.fromSerialized Ghc.deserializeWithData payload of
+    Nothing -> Nothing
+    Just qt -> Just $ refreshSymbols $ liquidQuoteSpec qt
+
+refreshSymbols :: Data a => a -> a
+refreshSymbols = everywhere (mkT refreshSymbol)
+
+refreshSymbol :: Symbol -> Symbol
+refreshSymbol = symbol . symbolText
+
+--------------------------------------------------------------------------------
+-- | Finding & Parsing Files ---------------------------------------------------
+--------------------------------------------------------------------------------
+
+-- | Handle Spec Files ---------------------------------------------------------
+
+findAndParseSpecFiles :: GhcMonadLike m
+                      => Config
+                      -> S.HashSet FilePath
+                      -> ModSummary
+                      -> [Module]
+                      -> m [(ModName, Ms.BareSpec)]
+findAndParseSpecFiles cfg paths modSummary reachable = do
+  modGraph <- GhcMonadLike.getModuleGraph
+  impSumms <- mapM GhcMonadLike.getModSummary (moduleName <$> reachable)
+  imps''   <- nub . concat <$> mapM modSummaryImports (modSummary : impSumms)
+  imps'    <- filterM ((not <$>) . isHomeModule) imps''
+  let imps  = m2s <$> imps'
+  fs'      <- liftIO $ moduleFiles modGraph Spec paths imps
+  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps'': "  ++ show (m2s <$> imps''))
+  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps' : "  ++ show (m2s <$> imps'))
+  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps  : "  ++ show imps)
+  -- liftIO  $ whenLoud  $ print ("moduleFiles-Paths : "  ++ show paths)
+  -- liftIO  $ whenLoud  $ print ("moduleFiles-Specs : "  ++ show fs')
+  patSpec  <- liftIO $ getPatSpec  modGraph paths $ totalityCheck cfg
+  rlSpec   <- liftIO $ getRealSpec modGraph paths $ not (linear cfg)
+  let fs    = patSpec ++ rlSpec ++ fs'
+  liftIO $ transParseSpecs modGraph paths mempty mempty fs
+  where
+    m2s = moduleNameString . moduleName
+
+getPatSpec :: ModuleGraph -> S.HashSet FilePath -> Bool -> IO [FilePath]
+getPatSpec modGraph paths totalitycheck
+ | totalitycheck = moduleFiles modGraph Spec paths [patErrorName]
+ | otherwise     = return []
+ where
+  patErrorName   = "PatErr"
+
+getRealSpec :: ModuleGraph -> S.HashSet FilePath -> Bool -> IO [FilePath]
+getRealSpec modGraph paths freal
+  | freal     = moduleFiles modGraph Spec paths [realSpecName]
+  | otherwise = moduleFiles modGraph Spec paths [notRealSpecName]
+  where
+    realSpecName    = "Real"
+    notRealSpecName = "NotReal"
+
+transParseSpecs :: ModuleGraph
+                -> S.HashSet FilePath
+                -> S.HashSet FilePath
+                -> [(ModName, Ms.BareSpec)]
+                -> [FilePath]
+                -> IO [(ModName, Ms.BareSpec)]
+transParseSpecs _ _ _ specs [] = return specs
+transParseSpecs modGraph paths seenFiles specs newFiles = do
+  -- liftIO $ print ("TRANS-PARSE-SPECS", seenFiles, newFiles)
+  newSpecs      <- liftIO $ mapM parseSpecFile newFiles
+  impFiles      <- moduleFiles modGraph Spec paths $ specsImports newSpecs
+  let seenFiles' = seenFiles `S.union` S.fromList newFiles
+  let specs'     = specs ++ map (second noTerm) newSpecs
+  let newFiles'  = filter (not . (`S.member` seenFiles')) impFiles
+  transParseSpecs modGraph paths seenFiles' specs' newFiles'
+  where
+    specsImports ss = nub $ concatMap (map symbolString . Ms.imports . snd) ss
+
+noTerm :: Ms.BareSpec -> Ms.BareSpec
+noTerm spec = spec { Ms.decr = mempty, Ms.lazy = mempty, Ms.termexprs = mempty }
+
+-- | Parse a spec file by path.
+--
+-- On a parse error, we fail.
+--
+-- TODO, Andres: It would be better to fail more systematically, but currently we
+-- seem to have an option between throwing an error which will be reported badly,
+-- or printing the error ourselves.
+--
+parseSpecFile :: FilePath -> IO (ModName, Ms.BareSpec)
+parseSpecFile file = do
+  contents <- Misc.sayReadFile file
+  case specSpecificationP file contents of
+    Left peb -> do
+      hPutStrLn stderr (errorBundlePretty peb)
+      panic Nothing "parsing spec file failed"
+    Right x  -> pure x
+
+-- Find Hquals Files -----------------------------------------------------------
+
+-- _moduleHquals :: MGIModGuts
+--              -> [FilePath]
+--              -> FilePath
+--              -> [String]
+--              -> [FilePath]
+--              -> Ghc [FilePath]
+-- _moduleHquals mgi paths target imps incs = do
+--   hqs   <- specIncludes Hquals paths incs
+--   hqs'  <- moduleFiles Hquals paths (mgi_namestring mgi : imps)
+--   hqs'' <- liftIO $ filterM doesFileExist [extFileName Hquals target]
+--   return $ Misc.sortNub $ hqs'' ++ hqs ++ hqs'
+
+-- Find Files for Modules ------------------------------------------------------
+
+moduleFiles :: ModuleGraph -> Ext -> S.HashSet FilePath -> [String] -> IO [FilePath]
+moduleFiles modGraph ext paths names = catMaybes <$> mapM (moduleFile modGraph ext paths) names
+
+moduleFile :: ModuleGraph -> Ext -> S.HashSet FilePath -> String -> IO (Maybe FilePath)
+moduleFile modGraph ext (S.toList -> paths) name
+  | ext `elem` [Hs, LHs] = do
+    let graph = mgModSummaries modGraph
+    case find (\m -> not (isBootInterface . isBootSummary $ m) &&
+                     name == moduleNameString (ms_mod_name m)) graph of
+      Nothing -> getFileInDirs (extModuleName name ext) paths
+      Just ms -> return $ normalise <$> ml_hs_file (ms_location ms)
+  | otherwise = getFileInDirs (extModuleName name ext) paths
+
+
+--------------------------------------------------------------------------------
+-- Assemble Information for Spec Extraction ------------------------------------
+--------------------------------------------------------------------------------
+
+makeMGIModGuts :: ModGuts -> MGIModGuts
+makeMGIModGuts modGuts = miModGuts deriv modGuts
+  where
+    deriv   = Just $ instEnvElts $ mg_inst_env modGuts
+
+makeLogicMap :: IO LogicMap
+makeLogicMap = do
+  lg    <- Misc.getCoreToLogicPath
+  lspec <- Misc.sayReadFile lg
+  case parseSymbolToLogic lg lspec of
+    Left peb -> do
+      hPutStrLn stderr (errorBundlePretty peb)
+      panic Nothing "makeLogicMap failed"
+    Right lm -> return (lm <> listLMap)
+
+listLMap :: LogicMap -- TODO-REBARE: move to wiredIn
+listLMap  = toLogicMap [ (dummyLoc nilName , []     , hNil)
+                       , (dummyLoc consName, [x, xs], hCons (EVar <$> [x, xs])) ]
+  where
+    x     = "x"
+    xs    = "xs"
+    hNil  = mkEApp (dcSym Ghc.nilDataCon ) []
+    hCons = mkEApp (dcSym Ghc.consDataCon)
+    dcSym = dummyLoc . dropModuleUnique . symbol
+
+
+
+--------------------------------------------------------------------------------
+-- | Pretty Printing -----------------------------------------------------------
+--------------------------------------------------------------------------------
+
+instance PPrint TargetSpec where
+  pprintTidy k spec = vcat
+    [ "******* Target Variables ********************"
+    , pprintTidy k $ gsTgtVars (gsVars spec)
+    , "******* Type Signatures *********************"
+    , pprintLongList k (gsTySigs (gsSig spec))
+    , "******* Assumed Type Signatures *************"
+    , pprintLongList k (gsAsmSigs (gsSig spec))
+    , "******* DataCon Specifications (Measure) ****"
+    , pprintLongList k (gsCtors (gsData spec))
+    , "******* Measure Specifications **************"
+    , pprintLongList k (gsMeas (gsData spec))       ]
+
+instance PPrint TargetInfo where
+  pprintTidy k info = vcat
+    [ -- "*************** Imports *********************"
+      -- , intersperse comma $ text <$> imports info
+      -- , "*************** Includes ********************"
+      -- , intersperse comma $ text <$> includes info
+      "*************** Imported Variables **********"
+    , pprDoc $ _giImpVars (review targetSrcIso $ giSrc info)
+    , "*************** Defined Variables ***********"
+    , pprDoc $ _giDefVars (review targetSrcIso $ giSrc info)
+    , "*************** Specification ***************"
+    , pprintTidy k $ giSpec info
+    , "*************** Core Bindings ***************"
+    , pprintCBs $ _giCbs (review targetSrcIso $ giSrc info) ]
+
+pprintCBs :: [CoreBind] -> Doc
+pprintCBs = pprDoc . tidyCBs
+    -- To print verbosely
+    --    = text . O.showSDocDebug unsafeGlobalDynFlags . O.ppr . tidyCBs
+
+instance Show TargetInfo where
+  show = showpp
+
+instance PPrint TargetVars where
+  pprintTidy _ AllVars   = text "All Variables"
+  pprintTidy k (Only vs) = text "Only Variables: " <+> pprintTidy k vs
+
+------------------------------------------------------------------------
+-- Dealing with Errors ---------------------------------------------------
+------------------------------------------------------------------------
+
+instance Result SourceError where
+  result e = Crash ((, Nothing) <$> sourceErrors "" e) "Invalid Source"
diff --git a/src-ghc/Liquid/GHC/Logging.hs b/src-ghc/Liquid/GHC/Logging.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Logging.hs
@@ -0,0 +1,52 @@
+{- | This module exposes variations over the standard GHC's logging functions to work with the 'Doc'
+     type from the \"pretty\" package. We would like LiquidHaskell to emit diagnostic messages using the very
+     same GHC machinery, so that IDE-like programs (e.g. \"ghcid\", \"ghcide\" etc) would be able to
+     correctly show errors and warnings to the users, in ther editors.
+
+     Unfortunately, this is not possible to do out of the box because LiquidHaskell uses the 'Doc' type from
+     the \"pretty\" package but GHC uses (for historical reasons) its own version. Due to the fact none of
+     the constructors are exported, we simply cannot convert between the two types effortlessly, but we have
+     to pay the price of a pretty-printing \"roundtrip\".
+-}
+
+module Liquid.GHC.Logging (
+    fromPJDoc
+  , putWarnMsg
+  , putErrMsg
+  , mkLongErrAt
+  ) where
+
+import qualified Liquid.GHC.API as GHC
+import qualified Text.PrettyPrint.HughesPJ as PJ
+
+-- Unfortunately we need the import below to bring in scope 'PPrint' instances.
+import Language.Haskell.Liquid.Types.Errors ()
+
+fromPJDoc :: PJ.Doc -> GHC.SDoc
+fromPJDoc = GHC.text . PJ.render
+
+-- | Like the original 'putLogMsg', but internally converts the input 'Doc' (from the \"pretty\" library)
+-- into GHC's internal 'SDoc'.
+putLogMsg :: GHC.DynFlags
+          -> GHC.WarnReason
+          -> GHC.Severity
+          -> GHC.SrcSpan
+          -> Maybe GHC.PprStyle
+          -> PJ.Doc
+          -> IO ()
+putLogMsg dynFlags reason sev srcSpan _mbStyle =
+  GHC.putLogMsg dynFlags reason sev srcSpan . GHC.text . PJ.render
+
+defaultErrStyle :: GHC.DynFlags -> GHC.PprStyle
+defaultErrStyle _dynFlags = GHC.defaultErrStyle
+
+putWarnMsg :: GHC.DynFlags -> GHC.SrcSpan -> PJ.Doc -> IO ()
+putWarnMsg dynFlags srcSpan doc =
+  putLogMsg dynFlags GHC.NoReason GHC.SevWarning srcSpan (Just $ defaultErrStyle dynFlags) doc
+
+putErrMsg :: GHC.DynFlags -> GHC.SrcSpan -> PJ.Doc -> IO ()
+putErrMsg dynFlags srcSpan doc = putLogMsg dynFlags GHC.NoReason GHC.SevError srcSpan Nothing doc
+
+-- | Like GHC's 'mkLongErrAt', but it builds the final 'ErrMsg' out of two \"HughesPJ\"'s 'Doc's.
+mkLongErrAt :: GHC.SrcSpan -> PJ.Doc -> PJ.Doc -> GHC.TcRn GHC.ErrMsg
+mkLongErrAt srcSpan msg extra = GHC.mkLongErrAt srcSpan (fromPJDoc msg) (fromPJDoc extra)
diff --git a/src-ghc/Liquid/GHC/Misc.hs b/src-ghc/Liquid/GHC/Misc.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Misc.hs
@@ -0,0 +1,1097 @@
+{-# LANGUAGE CPP                       #-}
+{-# LANGUAGE OverloadedStrings         #-}
+{-# LANGUAGE FlexibleInstances         #-}
+{-# LANGUAGE FlexibleContexts          #-}
+{-# LANGUAGE GADTs                     #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
+{-# LANGUAGE RankNTypes                #-}
+{-# LANGUAGE TupleSections             #-}
+{-# LANGUAGE TypeSynonymInstances      #-}
+{-# LANGUAGE UndecidableInstances      #-}
+{-# LANGUAGE ViewPatterns              #-}
+{-# LANGUAGE PatternSynonyms           #-}
+
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+-- | This module contains a wrappers and utility functions for
+-- accessing GHC module information. It should NEVER depend on
+-- ANY module inside the Language.Haskell.Liquid.* tree.
+
+module Liquid.GHC.Misc where
+
+import           Data.String
+import qualified Data.List as L
+import           Debug.Trace
+
+import           Prelude                                    hiding (error)
+import           Liquid.GHC.API            as Ghc hiding ( L
+                                                                          , sourceName
+                                                                          , showPpr
+                                                                          , showSDocDump
+                                                                          , panic
+                                                                          , showSDoc
+                                                                          )
+import qualified Liquid.GHC.API            as Ghc (GenLocated (L), showSDoc, panic, showSDocDump)
+
+
+import           Data.Char                                  (isLower, isSpace, isUpper)
+import           Data.Maybe                                 (isJust, fromMaybe, fromJust, maybeToList)
+import           Data.Hashable
+import qualified Data.HashSet                               as S
+import qualified Data.Map.Strict                            as OM
+import           Control.Monad.State                        (evalState, get, modify)
+
+import qualified Data.Text.Encoding.Error                   as TE
+import qualified Data.Text.Encoding                         as T
+import qualified Data.Text                                  as T
+import           Control.Arrow                              (second)
+import           Control.Monad                              ((>=>), foldM)
+import qualified Text.PrettyPrint.HughesPJ                  as PJ
+import           Language.Fixpoint.Types                    hiding (L, panic, Loc (..), SrcSpan, Constant, SESearch (..))
+import qualified Language.Fixpoint.Types                    as F
+import           Language.Fixpoint.Misc                     (safeHead, safeLast, errorstar) -- , safeLast, safeInit)
+import           Language.Haskell.Liquid.Misc               (keyDiff)
+import           Control.DeepSeq
+import           Language.Haskell.Liquid.Types.Errors
+
+
+isAnonBinder :: Ghc.TyConBinder -> Bool
+isAnonBinder (Bndr _ (AnonTCB _)) = True
+isAnonBinder (Bndr _ _)           = False
+
+mkAlive :: Var -> Id
+mkAlive x
+  | isId x && isDeadOcc (idOccInfo x)
+  = setIdInfo x (setOccInfo (idInfo x) noOccInfo)
+  | otherwise
+  = x
+
+
+--------------------------------------------------------------------------------
+-- | Encoding and Decoding Location --------------------------------------------
+--------------------------------------------------------------------------------
+srcSpanTick :: Module -> SrcSpan -> Tickish a
+srcSpanTick m sp = ProfNote (AllCafsCC m sp) False True
+
+tickSrcSpan ::  Outputable a => Tickish a -> SrcSpan
+tickSrcSpan (ProfNote cc _ _) = cc_loc cc
+tickSrcSpan (SourceNote ss _) = RealSrcSpan ss Nothing
+tickSrcSpan _                 = noSrcSpan
+
+--------------------------------------------------------------------------------
+-- | Generic Helpers for Accessing GHC Innards ---------------------------------
+--------------------------------------------------------------------------------
+
+-- FIXME: reusing uniques like this is really dangerous
+stringTyVar :: String -> TyVar
+stringTyVar s = mkTyVar name liftedTypeKind
+  where
+    name      = mkInternalName (mkUnique 'x' 24)  occ noSrcSpan
+    occ       = mkTyVarOcc s
+
+-- FIXME: reusing uniques like this is really dangerous
+stringVar :: String -> Type -> Var
+stringVar s t = mkLocalVar VanillaId name Many t vanillaIdInfo
+   where
+      name = mkInternalName (mkUnique 'x' 25) occ noSrcSpan
+      occ  = mkVarOcc s
+
+-- FIXME: plugging in dummy type like this is really dangerous
+maybeAuxVar :: Symbol -> Maybe Var
+maybeAuxVar s
+  | isMethod sym = Just sv
+  | otherwise = Nothing
+  where (_, uid) = splitModuleUnique s
+        sym = dropModuleNames s
+        sv = mkExportedLocalId VanillaId name anyTy
+        -- 'x' is chosen for no particular reason..
+        name = mkInternalName (mkUnique 'x' uid) occ noSrcSpan
+        occ = mkVarOcc (T.unpack (symbolText sym))
+
+stringTyCon :: Char -> Int -> String -> TyCon
+stringTyCon = stringTyConWithKind anyTy
+
+-- FIXME: reusing uniques like this is really dangerous
+stringTyConWithKind :: Kind -> Char -> Int -> String -> TyCon
+stringTyConWithKind k c n s = Ghc.mkKindTyCon name [] k [] name
+  where
+    name          = mkInternalName (mkUnique c n) occ noSrcSpan
+    occ           = mkTcOcc s
+
+hasBaseTypeVar :: Var -> Bool
+hasBaseTypeVar = isBaseType . varType
+
+-- same as Constraint isBase
+isBaseType :: Type -> Bool
+isBaseType (ForAllTy _ _)  = False
+isBaseType (FunTy { ft_arg = t1, ft_res = t2}) = isBaseType t1 && isBaseType t2
+isBaseType (TyVarTy _)     = True
+isBaseType (TyConApp _ ts) = all isBaseType ts
+isBaseType (AppTy t1 t2)   = isBaseType t1 && isBaseType t2
+isBaseType _               = False
+
+isTmpVar :: Var -> Bool
+isTmpVar = isTmpSymbol . dropModuleNamesAndUnique . symbol
+
+isTmpSymbol    :: Symbol -> Bool
+isTmpSymbol x  = any (`isPrefixOfSym` x) [anfPrefix, tempPrefix, "ds_"]
+
+validTyVar :: String -> Bool
+validTyVar s@(c:_) = isLower c && not (any isSpace s)
+validTyVar _       = False
+
+tvId :: TyVar -> String
+tvId α = {- traceShow ("tvId: α = " ++ show α) $ -} showPpr α ++ show (varUnique α)
+
+tidyCBs :: [CoreBind] -> [CoreBind]
+tidyCBs = map unTick
+
+unTick :: CoreBind -> CoreBind
+unTick (NonRec b e) = NonRec b (unTickExpr e)
+unTick (Rec bs)     = Rec $ map (second unTickExpr) bs
+
+unTickExpr :: CoreExpr -> CoreExpr
+unTickExpr (App e a)          = App (unTickExpr e) (unTickExpr a)
+unTickExpr (Lam b e)          = Lam b (unTickExpr e)
+unTickExpr (Let b e)          = Let (unTick b) (unTickExpr e)
+unTickExpr (Case e b t as)    = Case (unTickExpr e) b t (map unTickAlt as)
+    where unTickAlt (a, b', e') = (a, b', unTickExpr e')
+unTickExpr (Cast e c)         = Cast (unTickExpr e) c
+unTickExpr (Tick _ e)         = unTickExpr e
+unTickExpr x                  = x
+
+isFractionalClass :: Class -> Bool
+isFractionalClass clas = classKey clas `elem` fractionalClassKeys
+
+isOrdClass :: Class -> Bool
+isOrdClass clas = classKey clas == ordClassKey
+
+--------------------------------------------------------------------------------
+-- | Pretty Printers -----------------------------------------------------------
+--------------------------------------------------------------------------------
+notracePpr :: Outputable a => String -> a -> a
+notracePpr _ x = x
+
+tracePpr :: Outputable a => String -> a -> a
+tracePpr s x = trace ("\nTrace: [" ++ s ++ "] : " ++ showPpr x) x
+
+pprShow :: Show a => a -> Ghc.SDoc
+pprShow = text . show
+
+
+toFixSDoc :: Fixpoint a => a -> PJ.Doc
+toFixSDoc = PJ.text . PJ.render . toFix
+
+sDocDoc :: Ghc.SDoc -> PJ.Doc
+sDocDoc   = PJ.text . showSDoc
+
+pprDoc :: Outputable a => a -> PJ.Doc
+pprDoc    = sDocDoc . ppr
+
+-- Overriding Outputable functions because they now require DynFlags!
+showPpr :: Outputable a => a -> String
+showPpr       = showSDoc . ppr
+
+-- FIXME: somewhere we depend on this printing out all GHC entities with
+-- fully-qualified names...
+showSDoc :: Ghc.SDoc -> String
+showSDoc sdoc = Ghc.renderWithStyle unsafeGlobalDynFlags sdoc (Ghc.mkUserStyle unsafeGlobalDynFlags myQualify {- Ghc.alwaysQualify -} Ghc.AllTheWay)
+
+myQualify :: Ghc.PrintUnqualified
+myQualify = Ghc.neverQualify { Ghc.queryQualifyName = Ghc.alwaysQualifyNames }
+-- { Ghc.queryQualifyName = \_ _ -> Ghc.NameNotInScope1 }
+
+showSDocDump :: Ghc.SDoc -> String
+showSDocDump  = Ghc.showSDocDump unsafeGlobalDynFlags
+
+instance Outputable a => Outputable (S.HashSet a) where
+  ppr = ppr . S.toList
+
+typeUniqueString :: Outputable a => a -> String
+typeUniqueString = {- ("sort_" ++) . -} showSDocDump . ppr
+
+
+--------------------------------------------------------------------------------
+-- | Manipulating Source Spans -------------------------------------------------
+--------------------------------------------------------------------------------
+
+newtype Loc    = L (Int, Int) deriving (Eq, Ord, Show)
+
+instance Hashable Loc where
+  hashWithSalt i (L z) = hashWithSalt i z
+
+--instance (Uniquable a) => Hashable a where
+
+instance Hashable SrcSpan where
+  hashWithSalt i (UnhelpfulSpan reason) = case reason of
+    UnhelpfulNoLocationInfo -> hashWithSalt i (uniq $ fsLit "UnhelpfulNoLocationInfo")
+    UnhelpfulWiredIn        -> hashWithSalt i (uniq $ fsLit "UnhelpfulWiredIn")
+    UnhelpfulInteractive    -> hashWithSalt i (uniq $ fsLit "UnhelpfulInteractive")
+    UnhelpfulGenerated      -> hashWithSalt i (uniq $ fsLit "UnhelpfulGenerated")
+    UnhelpfulOther fs       -> hashWithSalt i (uniq fs)
+  hashWithSalt i (RealSrcSpan s _)      = hashWithSalt i (srcSpanStartLine s, srcSpanStartCol s, srcSpanEndCol s)
+
+fSrcSpan :: (F.Loc a) => a -> SrcSpan
+fSrcSpan = fSrcSpanSrcSpan . F.srcSpan
+
+fSourcePos :: (F.Loc a) => a -> F.SourcePos
+fSourcePos = F.sp_start . F.srcSpan
+
+fSrcSpanSrcSpan :: F.SrcSpan -> SrcSpan
+fSrcSpanSrcSpan (F.SS p p') = sourcePos2SrcSpan p p'
+
+srcSpanFSrcSpan :: SrcSpan -> F.SrcSpan
+srcSpanFSrcSpan sp = F.SS p p'
+  where
+    p              = srcSpanSourcePos sp
+    p'             = srcSpanSourcePosE sp
+
+sourcePos2SrcSpan :: SourcePos -> SourcePos -> SrcSpan
+sourcePos2SrcSpan p p' = RealSrcSpan (realSrcSpan f (unPos l) (unPos c) (unPos l') (unPos c')) Nothing
+  where
+    (f, l,  c)         = F.sourcePosElts p
+    (_, l', c')        = F.sourcePosElts p'
+
+sourcePosSrcSpan   :: SourcePos -> SrcSpan
+sourcePosSrcSpan p@(SourcePos file line col) = sourcePos2SrcSpan p (SourcePos file line (succPos col))
+
+sourcePosSrcLoc    :: SourcePos -> SrcLoc
+sourcePosSrcLoc (SourcePos file line col) = mkSrcLoc (fsLit file) (unPos line) (unPos col)
+
+srcSpanSourcePos :: SrcSpan -> SourcePos
+srcSpanSourcePos (UnhelpfulSpan _) = dummyPos "<no source information>"
+srcSpanSourcePos (RealSrcSpan s _) = realSrcSpanSourcePos s
+
+srcSpanSourcePosE :: SrcSpan -> SourcePos
+srcSpanSourcePosE (UnhelpfulSpan _) = dummyPos "<no source information>"
+srcSpanSourcePosE (RealSrcSpan s _) = realSrcSpanSourcePosE s
+
+srcSpanFilename :: SrcSpan -> String
+srcSpanFilename    = maybe "" unpackFS . srcSpanFileName_maybe
+
+srcSpanStartLoc :: RealSrcSpan -> Loc
+srcSpanStartLoc l  = L (srcSpanStartLine l, srcSpanStartCol l)
+
+srcSpanEndLoc :: RealSrcSpan -> Loc
+srcSpanEndLoc l    = L (srcSpanEndLine l, srcSpanEndCol l)
+
+
+oneLine :: RealSrcSpan -> Bool
+oneLine l          = srcSpanStartLine l == srcSpanEndLine l
+
+lineCol :: RealSrcSpan -> (Int, Int)
+lineCol l          = (srcSpanStartLine l, srcSpanStartCol l)
+
+realSrcSpanSourcePos :: RealSrcSpan -> SourcePos
+realSrcSpanSourcePos s = safeSourcePos file line col
+  where
+    file               = unpackFS $ srcSpanFile s
+    line               = srcSpanStartLine       s
+    col                = srcSpanStartCol        s
+
+
+realSrcSpanSourcePosE :: RealSrcSpan -> SourcePos
+realSrcSpanSourcePosE s = safeSourcePos file line col
+  where
+    file                = unpackFS $ srcSpanFile s
+    line                = srcSpanEndLine       s
+    col                 = srcSpanEndCol        s
+
+getSourcePos :: NamedThing a => a -> SourcePos
+getSourcePos = srcSpanSourcePos  . getSrcSpan
+
+getSourcePosE :: NamedThing a => a -> SourcePos
+getSourcePosE = srcSpanSourcePosE . getSrcSpan
+
+locNamedThing :: NamedThing a => a -> F.Located a
+locNamedThing x = F.Loc l lE x
+  where
+    l          = getSourcePos  x
+    lE         = getSourcePosE x
+
+instance F.Loc Var where
+  srcSpan v = SS (getSourcePos v) (getSourcePosE v)
+
+namedLocSymbol :: (F.Symbolic a, NamedThing a) => a -> F.Located F.Symbol
+namedLocSymbol d = F.symbol <$> locNamedThing d
+
+varLocInfo :: (Type -> a) -> Var -> F.Located a
+varLocInfo f x = f . varType <$> locNamedThing x
+
+namedPanic :: (NamedThing a) => a -> String -> b
+namedPanic x msg = panic (Just (getSrcSpan x)) msg
+
+--------------------------------------------------------------------------------
+-- | Manipulating CoreExpr -----------------------------------------------------
+--------------------------------------------------------------------------------
+
+collectArguments :: Int -> CoreExpr -> [Var]
+collectArguments n e = if length xs > n then take n xs else xs
+  where
+    (vs', e')        = collectValBinders' $ snd $ collectTyBinders e
+    vs               = fst $ collectBinders $ ignoreLetBinds e'
+    xs               = vs' ++ vs
+
+{-
+collectTyBinders :: CoreExpr -> ([Var], CoreExpr)
+collectTyBinders expr
+  = go [] expr
+  where
+    go tvs (Lam b e) | isTyVar b = go (b:tvs) e
+    go tvs e                     = (reverse tvs, e)
+-}
+
+collectValBinders' :: Ghc.Expr Var -> ([Var], Ghc.Expr Var)
+collectValBinders' = go []
+  where
+    go tvs (Lam b e) | isTyVar b = go tvs     e
+    go tvs (Lam b e) | isId    b = go (b:tvs) e
+    go tvs (Tick _ e)            = go tvs e
+    go tvs e                     = (reverse tvs, e)
+
+ignoreLetBinds :: Ghc.Expr t -> Ghc.Expr t
+ignoreLetBinds (Let (NonRec _ _) e')
+  = ignoreLetBinds e'
+ignoreLetBinds e
+  = e
+
+--------------------------------------------------------------------------------
+-- | Predicates on CoreExpr and DataCons ---------------------------------------
+--------------------------------------------------------------------------------
+
+isExternalId :: Id -> Bool
+isExternalId = isExternalName . getName
+
+isTupleId :: Id -> Bool
+isTupleId = maybe False Ghc.isTupleDataCon . idDataConM
+
+idDataConM :: Id -> Maybe DataCon
+idDataConM x = case idDetails x of
+  DataConWorkId d -> Just d
+  DataConWrapId d -> Just d
+  _               -> Nothing
+
+isDataConId :: Id -> Bool
+isDataConId = isJust . idDataConM
+
+getDataConVarUnique :: Var -> Unique
+getDataConVarUnique v
+  | isId v && isDataConId v = getUnique (idDataCon v)
+  | otherwise               = getUnique v
+
+isDictionaryExpression :: Ghc.Expr Id -> Maybe Id
+isDictionaryExpression (Tick _ e) = isDictionaryExpression e
+isDictionaryExpression (Var x)    | isDictionary x = Just x
+isDictionaryExpression _          = Nothing
+
+realTcArity :: TyCon -> Arity
+realTcArity = tyConArity
+
+{-
+  tracePpr ("realTcArity of " ++ showPpr c
+     ++ "\n tyConKind = " ++ showPpr (tyConKind c)
+     ++ "\n kindArity = " ++ show (kindArity (tyConKind c))
+     ++ "\n kindArity' = " ++ show (kindArity' (tyConKind c)) -- this works for TypeAlias
+     ) $ kindArity' (tyConKind c)
+-}
+
+kindTCArity :: TyCon -> Arity
+kindTCArity = go . tyConKind
+  where
+    go (FunTy { ft_res = res}) = 1 + go res
+    go _               = 0
+
+
+kindArity :: Kind -> Arity
+kindArity (ForAllTy _ res)
+  = 1 + kindArity res
+kindArity _
+  = 0
+
+uniqueHash :: Uniquable a => Int -> a -> Int
+uniqueHash i = hashWithSalt i . getKey . getUnique
+
+-- slightly modified version of DynamicLoading.lookupRdrNameInModule
+lookupRdrName :: HscEnv -> ModuleName -> RdrName -> IO (Maybe Name)
+lookupRdrName hsc_env mod_name rdr_name = do
+    -- First find the package the module resides in by searching exposed packages and home modules
+    found_module <- findImportedModule hsc_env mod_name Nothing
+    case found_module of
+        Found _ mod' -> do
+            -- Find the exports of the module
+            (_, mb_iface) <- getModuleInterface hsc_env mod'
+            case mb_iface of
+                Just iface -> do
+                    -- Try and find the required name in the exports
+                    let decl_spec = ImpDeclSpec { is_mod = mod_name, is_as = mod_name
+                                                , is_qual = False, is_dloc = noSrcSpan }
+                        provenance = Just $ ImpSpec decl_spec ImpAll
+                        env = case mi_globals iface of
+                                Nothing -> mkGlobalRdrEnv (gresFromAvails provenance (mi_exports iface))
+                                Just e -> e
+                    case lookupGRE_RdrName rdr_name env of
+                        [gre] -> return (Just (gre_name gre))
+                        []    -> return Nothing
+                        _     -> Ghc.panic "lookupRdrNameInModule"
+                Nothing -> throwCmdLineErrorS dflags $ Ghc.hsep [Ghc.ptext (sLit "Could not determine the exports of the module"), ppr mod_name]
+        err' -> throwCmdLineErrorS dflags $ cannotFindModule dflags mod_name err'
+  where dflags = hsc_dflags hsc_env
+        throwCmdLineErrorS dflags' = throwCmdLineError . Ghc.showSDoc dflags'
+        throwCmdLineError = throwGhcException . CmdLineError
+
+-- qualImportDecl :: ModuleName -> ImportDecl name
+-- qualImportDecl mn = (simpleImportDecl mn) { ideclQualified = True }
+
+ignoreInline :: ParsedModule -> ParsedModule
+ignoreInline x = x {pm_parsed_source = go <$> pm_parsed_source x}
+  where
+    go  y      = y {hsmodDecls = filter go' (hsmodDecls y) }
+    go' :: LHsDecl GhcPs -> Bool
+    go' z
+      | SigD _ (InlineSig {}) <-  unLoc z = False
+      | otherwise                         = True
+
+--------------------------------------------------------------------------------
+-- | Symbol Conversions --------------------------------------------------------
+--------------------------------------------------------------------------------
+
+symbolTyConWithKind :: Kind -> Char -> Int -> Symbol -> TyCon
+symbolTyConWithKind k x i n = stringTyConWithKind k x i (symbolString n)
+
+symbolTyCon :: Char -> Int -> Symbol -> TyCon
+symbolTyCon x i n = stringTyCon x i (symbolString n)
+
+symbolTyVar :: Symbol -> TyVar
+symbolTyVar = stringTyVar . symbolString
+
+localVarSymbol ::  Var -> Symbol
+localVarSymbol v
+  | us `isSuffixOfSym` vs = vs
+  | otherwise             = suffixSymbol vs us
+  where
+    us                    = symbol $ showPpr $ getDataConVarUnique v
+    vs                    = exportedVarSymbol v
+
+exportedVarSymbol :: Var -> Symbol
+exportedVarSymbol x = notracepp msg . symbol . getName $ x
+  where
+    msg = "exportedVarSymbol: " ++ showPpr x
+
+qualifiedNameSymbol :: Name -> Symbol
+qualifiedNameSymbol n = symbol $ concatFS [modFS, occFS, uniqFS]
+  where
+  _msg   = showSDoc (ppr n) -- getOccString n
+  modFS = case nameModule_maybe n of
+            Nothing -> fsLit ""
+            Just m  -> concatFS [moduleNameFS (moduleName m), fsLit "."]
+
+  occFS = occNameFS (getOccName n)
+  uniqFS
+    | isSystemName n
+    = concatFS [fsLit "_",  fsLit (showPpr (getUnique n))]
+    | otherwise
+    = fsLit ""
+
+instance Symbolic FastString where
+  symbol = symbol . fastStringText
+
+fastStringText :: FastString -> T.Text
+fastStringText = T.decodeUtf8With TE.lenientDecode . bytesFS
+
+tyConTyVarsDef :: TyCon -> [TyVar]
+tyConTyVarsDef c
+  | noTyVars c = []
+  | otherwise  = Ghc.tyConTyVars c
+  --where
+  --  none         = tracepp ("tyConTyVarsDef: " ++ show c) (noTyVars c)
+
+noTyVars :: TyCon -> Bool
+noTyVars c =  Ghc.isPrimTyCon c || isFunTyCon c || Ghc.isPromotedDataCon c
+
+--------------------------------------------------------------------------------
+-- | Symbol Instances
+--------------------------------------------------------------------------------
+
+instance Symbolic TyCon where
+  symbol = symbol . getName
+
+instance Symbolic Class where
+  symbol = symbol . getName
+
+instance Symbolic Name where
+  symbol = symbol . qualifiedNameSymbol
+
+-- | [NOTE:REFLECT-IMPORTS] we **eschew** the `unique` suffix for exported vars,
+-- to make it possible to lookup names from symbols _across_ modules;
+-- anyways exported names are top-level and you shouldn't have local binders
+-- that shadow them. However, we **keep** the `unique` suffix for local variables,
+-- as otherwise there are spurious, but extremely problematic, name collisions
+-- in the fixpoint environment.
+
+instance Symbolic Var where   -- TODO:reflect-datacons varSymbol
+  symbol v
+    | isExternalId v = exportedVarSymbol v
+    | otherwise      = localVarSymbol    v
+
+
+instance Hashable Var where
+  hashWithSalt = uniqueHash
+
+instance Hashable TyCon where
+  hashWithSalt = uniqueHash
+
+instance Hashable Class where
+  hashWithSalt = uniqueHash
+
+instance Hashable DataCon where
+  hashWithSalt = uniqueHash
+
+instance Fixpoint Var where
+  toFix = pprDoc
+
+instance Fixpoint Name where
+  toFix = pprDoc
+
+instance Fixpoint Type where
+  toFix = pprDoc
+
+instance Show Name where
+  show = symbolString . symbol
+
+instance Show Var where
+  show = show . getName
+
+instance Show Class where
+  show = show . getName
+
+instance Show TyCon where
+  show = show . getName
+
+instance NFData Class where
+  rnf t = seq t ()
+
+instance NFData TyCon where
+  rnf t = seq t ()
+
+instance NFData Type where
+  rnf t = seq t ()
+
+instance NFData Var where
+  rnf t = seq t ()
+
+--------------------------------------------------------------------------------
+-- | Manipulating Symbols ------------------------------------------------------
+--------------------------------------------------------------------------------
+
+takeModuleUnique :: Symbol -> Symbol
+takeModuleUnique = mungeNames tailName sepUnique   "takeModuleUnique: "
+  where
+    tailName msg = symbol . safeLast msg
+
+splitModuleUnique :: Symbol -> (Symbol, Int)
+splitModuleUnique x = (dropModuleNamesAndUnique x, base62ToI (takeModuleUnique x))
+
+base62ToI :: Symbol -> Int
+base62ToI s =  fromMaybe (errorstar "base62ToI Out Of Range") $ go (F.symbolText s)
+  where
+    digitToI :: OM.Map Char Int
+    digitToI = OM.fromList $ zip (['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z']) [0..]
+    f acc (flip OM.lookup digitToI -> x) = (acc * 62 +) <$> x
+    go = foldM f 0 . T.unpack
+
+
+splitModuleName :: Symbol -> (Symbol, Symbol)
+splitModuleName x = (takeModuleNames x, dropModuleNamesAndUnique x)
+
+dropModuleNamesAndUnique :: Symbol -> Symbol
+dropModuleNamesAndUnique = dropModuleUnique . dropModuleNames
+
+dropModuleNames  :: Symbol -> Symbol
+dropModuleNames = dropModuleNamesCorrect
+{- 
+dropModuleNames = mungeNames lastName sepModNames "dropModuleNames: "
+ where
+   lastName msg = symbol . safeLast msg
+-}
+
+dropModuleNamesCorrect  :: Symbol -> Symbol
+dropModuleNamesCorrect = F.symbol . go . F.symbolText
+  where
+    go s = case T.uncons s of
+             Just (c,tl) -> if isUpper c  && T.any (== '.') tl
+                              then go $ snd $ fromJust $ T.uncons $ T.dropWhile (/= '.') s
+                              else s
+             Nothing -> s
+
+takeModuleNames  :: Symbol -> Symbol
+takeModuleNames  = F.symbol . go [] . F.symbolText
+  where
+    go acc s = case T.uncons s of
+                Just (c,tl) -> if isUpper c && T.any (== '.') tl
+                                 then go (getModule' s:acc) $ snd $ fromJust $ T.uncons $ T.dropWhile (/= '.') s
+                                 else T.intercalate "." (reverse acc)
+                Nothing -> T.intercalate "." (reverse acc)
+    getModule' = T.takeWhile (/= '.')
+
+{- 
+takeModuleNamesOld  = mungeNames initName sepModNames "takeModuleNames: "
+  where
+    initName msg = symbol . T.intercalate "." . safeInit msg
+-}
+dropModuleUnique :: Symbol -> Symbol
+dropModuleUnique = mungeNames headName sepUnique   "dropModuleUnique: "
+  where
+    headName msg = symbol . safeHead msg
+
+cmpSymbol :: Symbol -> Symbol -> Bool
+cmpSymbol coreSym logicSym
+  =  (dropModuleUnique coreSym == dropModuleNamesAndUnique logicSym)
+  || (dropModuleUnique coreSym == dropModuleUnique         logicSym)
+
+sepModNames :: T.Text
+sepModNames = "."
+
+sepUnique :: T.Text
+sepUnique = "#"
+
+mungeNames :: (String -> [T.Text] -> Symbol) -> T.Text -> String -> Symbol -> Symbol
+mungeNames _ _ _ ""  = ""
+mungeNames f d msg s'@(symbolText -> s)
+  | s' == tupConName = tupConName
+  | otherwise        = f (msg ++ T.unpack s) $ T.splitOn d $ stripParens s
+
+qualifySymbol :: Symbol -> Symbol -> Symbol
+qualifySymbol (symbolText -> m) x'@(symbolText -> x)
+  | isQualified x  = x'
+  | isParened x    = symbol (wrapParens (m `mappend` "." `mappend` stripParens x))
+  | otherwise      = symbol (m `mappend` "." `mappend` x)
+
+isQualifiedSym :: Symbol -> Bool
+isQualifiedSym (symbolText -> x) = isQualified x
+
+isQualified :: T.Text -> Bool
+isQualified y = "." `T.isInfixOf` y
+
+wrapParens :: (IsString a, Monoid a) => a -> a
+wrapParens x  = "(" `mappend` x `mappend` ")"
+
+isParened :: T.Text -> Bool
+isParened xs  = xs /= stripParens xs
+
+isDictionary :: Symbolic a => a -> Bool
+isDictionary = isPrefixOfSym "$f" . dropModuleNames . symbol
+
+isMethod :: Symbolic a => a -> Bool
+isMethod = isPrefixOfSym "$c" . dropModuleNames . symbol
+
+isInternal :: Symbolic a => a -> Bool
+isInternal   = isPrefixOfSym "$"  . dropModuleNames . symbol
+
+isWorker :: Symbolic a => a -> Bool
+isWorker s = notracepp ("isWorkerSym: s = " ++ ss) $ "$W" `L.isInfixOf` ss
+  where
+    ss     = symbolString (symbol s)
+
+isSCSel :: Symbolic a => a -> Bool
+isSCSel  = isPrefixOfSym "$p" . dropModuleNames . symbol
+
+stripParens :: T.Text -> T.Text
+stripParens t = fromMaybe t (strip t)
+  where
+    strip = T.stripPrefix "(" >=> T.stripSuffix ")"
+
+stripParensSym :: Symbol -> Symbol
+stripParensSym (symbolText -> t) = symbol (stripParens t)
+
+desugarModule :: TypecheckedModule -> Ghc DesugaredModule
+desugarModule tcm = do
+  let ms = pm_mod_summary $ tm_parsed_module tcm
+  -- let ms = modSummary tcm
+  let (tcg, _) = tm_internals_ tcm
+  hsc_env <- getSession
+  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
+  guts <- liftIO $ hscDesugar{- WithLoc -} hsc_env_tmp ms tcg
+  return DesugaredModule { dm_typechecked_module = tcm, dm_core_module = guts }
+
+--------------------------------------------------------------------------------
+-- | GHC Compatibility Layer ---------------------------------------------------
+--------------------------------------------------------------------------------
+
+gHC_VERSION :: String
+gHC_VERSION = show (__GLASGOW_HASKELL__ :: Int)
+
+symbolFastString :: Symbol -> FastString
+symbolFastString = mkFastStringByteString . T.encodeUtf8 . symbolText
+
+lintCoreBindings :: [Var] -> CoreProgram -> (Bag MsgDoc, Bag MsgDoc)
+lintCoreBindings = Ghc.lintCoreBindings (defaultDynFlags undefined (undefined ("LlvmTargets" :: String))) CoreDoNothing
+
+synTyConRhs_maybe :: TyCon -> Maybe Type
+synTyConRhs_maybe = Ghc.synTyConRhs_maybe
+
+tcRnLookupRdrName :: HscEnv -> Ghc.Located RdrName -> IO (Messages, Maybe [Name])
+tcRnLookupRdrName = Ghc.tcRnLookupRdrName
+
+showCBs :: Bool -> [CoreBind] -> String
+showCBs untidy
+  | untidy    = Ghc.showSDocDebug unsafeGlobalDynFlags . ppr . tidyCBs
+  | otherwise = showPpr
+
+
+ignoreCoreBinds :: S.HashSet Var -> [CoreBind] -> [CoreBind]
+ignoreCoreBinds vs cbs
+  | S.null vs         = cbs
+  | otherwise         = concatMap go cbs
+  where
+    go :: CoreBind -> [CoreBind]
+    go b@(NonRec x _)
+      | S.member x vs = []
+      | otherwise     = [b]
+    go (Rec xes)      = [Rec (filter ((`notElem` vs) . fst) xes)]
+
+
+findVarDef :: Symbol -> [CoreBind] -> Maybe (Var, CoreExpr)
+findVarDef sym cbs = case xCbs of
+                     (NonRec v def   : _ ) -> Just (v, def)
+                     (Rec [(v, def)] : _ ) -> Just (v, def)
+                     _                     -> Nothing
+  where
+    xCbs            = [ cb | cb <- concatMap unRec cbs, sym `elem` coreBindSymbols cb ]
+    unRec (Rec xes) = [NonRec x es | (x,es) <- xes]
+    unRec nonRec    = [nonRec]
+
+
+findVarDefMethod :: Symbol -> [CoreBind] -> Maybe (Var, CoreExpr)
+findVarDefMethod sym cbs =
+  case rcbs  of
+                     (NonRec v def   : _ ) -> Just (v, def)
+                     (Rec [(v, def)] : _ ) -> Just (v, def)
+                     _                     -> Nothing
+  where
+    rcbs | isMethod sym = mCbs
+         | isDictionary (dropModuleNames sym) = dCbs
+         | otherwise  = xCbs
+    xCbs            = [ cb | cb <- concatMap unRec cbs, sym `elem` coreBindSymbols cb
+                           ]
+    mCbs            = [ cb | cb <- concatMap unRec cbs, sym `elem` methodSymbols cb]
+    dCbs            = [ cb | cb <- concatMap unRec cbs, sym `elem` dictionarySymbols cb]
+    unRec (Rec xes) = [NonRec x es | (x,es) <- xes]
+    unRec nonRec    = [nonRec]
+
+dictionarySymbols :: CoreBind -> [Symbol]
+dictionarySymbols = filter isDictionary . map (dropModuleNames . symbol) . binders
+
+
+methodSymbols :: CoreBind -> [Symbol]
+methodSymbols = filter isMethod . map (dropModuleNames . symbol) . binders
+
+
+
+coreBindSymbols :: CoreBind -> [Symbol]
+coreBindSymbols = map (dropModuleNames . simplesymbol) . binders
+
+simplesymbol :: (NamedThing t) => t -> Symbol
+simplesymbol = symbol . getName
+
+binders :: Bind a -> [a]
+binders (NonRec z _) = [z]
+binders (Rec xes)    = fst <$> xes
+
+expandVarType :: Var -> Type
+expandVarType = expandTypeSynonyms . varType
+
+--------------------------------------------------------------------------------
+-- | The following functions test if a `CoreExpr` or `CoreVar` can be
+--   embedded in logic. With type-class support, we can no longer erase
+--   such expressions arbitrarily.
+--------------------------------------------------------------------------------
+isEmbeddedDictExpr :: CoreExpr -> Bool
+isEmbeddedDictExpr = isEmbeddedDictType . exprType
+
+isEmbeddedDictVar :: Var -> Bool
+isEmbeddedDictVar v = F.notracepp msg . isEmbeddedDictType . varType $ v
+  where
+    msg     =  "isGoodCaseBind v = " ++ show v
+
+isEmbeddedDictType :: Type -> Bool
+isEmbeddedDictType = anyF [isOrdPred, isNumericPred, isEqPred, isPrelEqPred]
+
+-- unlike isNumCls, isFracCls, these two don't check if the argument's
+-- superclass is Ord or Num. I believe this is the more predictable behavior
+
+isPrelEqPred :: Type -> Bool
+isPrelEqPred ty = case tyConAppTyCon_maybe ty of
+  Just tyCon -> isPrelEqTyCon tyCon
+  _          -> False
+
+
+isPrelEqTyCon :: TyCon -> Bool
+isPrelEqTyCon tc = tc `hasKey` eqClassKey
+
+isOrdPred :: Type -> Bool
+isOrdPred ty = case tyConAppTyCon_maybe ty of
+  Just tyCon -> tyCon `hasKey` ordClassKey
+  _          -> False
+
+-- Not just Num, but Fractional, Integral as well
+isNumericPred :: Type -> Bool
+isNumericPred ty = case tyConAppTyCon_maybe ty of
+  Just tyCon -> getUnique tyCon `elem` numericClassKeys
+  _          -> False
+
+
+
+--------------------------------------------------------------------------------
+-- | The following functions test if a `CoreExpr` or `CoreVar` are just types
+--   in disguise, e.g. have `PredType` (in the GHC sense of the word), and so
+--   shouldn't appear in refinements.
+--------------------------------------------------------------------------------
+isPredExpr :: CoreExpr -> Bool
+isPredExpr = isPredType . Ghc.exprType
+
+isPredVar :: Var -> Bool
+isPredVar v = F.notracepp msg . isPredType . varType $ v
+  where
+    msg     =  "isGoodCaseBind v = " ++ show v
+
+isPredType :: Type -> Bool
+isPredType = anyF [ isClassPred, isEqPred, isEqPrimPred ]
+
+anyF :: [a -> Bool] -> a -> Bool
+anyF ps x = or [ p x | p <- ps ]
+
+
+-- | 'defaultDataCons t ds' returns the list of '(dc, types)' pairs,
+--   corresponding to the _missing_ cases, i.e. _other_ than those in 'ds',
+--   that are being handled by DEFAULT.
+defaultDataCons :: Type -> [AltCon] -> Maybe [(DataCon, [TyVar], [Type])]
+defaultDataCons (TyConApp tc argτs) ds = do
+  allDs     <- Ghc.tyConDataCons_maybe tc
+  let seenDs = [d | DataAlt d <- ds ]
+  let defDs  = keyDiff showPpr allDs seenDs
+  return [ (d, Ghc.dataConExTyVars d, map irrelevantMult $ Ghc.dataConInstArgTys d argτs) | d <- defDs ]
+
+defaultDataCons _ _ =
+  Nothing
+
+
+
+isEvVar :: Id -> Bool
+isEvVar x = isPredVar x || isTyVar x || isCoVar x
+
+
+--------------------------------------------------------------------------------
+-- | Elaboration
+--------------------------------------------------------------------------------
+
+-- FIXME: the handling of exceptions seems to be broken
+
+-- partially stolen from GHC'sa exprType
+
+-- elaborateHsExprInst
+--   :: GhcMonad m => LHsExpr GhcPs -> m (Messages, Maybe CoreExpr)
+-- elaborateHsExprInst expr = elaborateHsExpr TM_Inst expr
+
+
+-- elaborateHsExpr
+--   :: GhcMonad m => TcRnExprMode -> LHsExpr GhcPs -> m (Messages, Maybe CoreExpr)
+-- elaborateHsExpr mode expr =
+--   withSession $ \hsc_env -> liftIO $ hscElabHsExpr hsc_env mode expr
+
+-- hscElabHsExpr :: HscEnv -> TcRnExprMode -> LHsExpr GhcPs -> IO (Messages, Maybe CoreExpr)
+-- hscElabHsExpr hsc_env0 mode expr = runInteractiveHsc hsc_env0 $ do
+--   hsc_env <- Ghc.getHscEnv
+--   liftIO $ elabRnExpr hsc_env mode expr
+
+elabRnExpr
+  :: TcRnExprMode -> LHsExpr GhcPs -> TcRn CoreExpr
+elabRnExpr mode rdr_expr = do
+    (rn_expr, _fvs) <- rnLExpr rdr_expr
+    failIfErrsM
+
+        -- Now typecheck the expression, and generalise its type
+        -- it might have a rank-2 type (e.g. :t runST)
+    uniq <- newUnique ;
+    let fresh_it  = itName uniq (getLoc rdr_expr) 
+    ((tclvl, (tc_expr, res_ty)), lie)
+          <- captureTopConstraints $
+             pushTcLevelM          $
+             tc_infer rn_expr
+
+    -- Generalise
+    (_qtvs, _dicts, evbs, residual, _)
+         <- simplifyInfer tclvl infer_mode
+                          []    {- No sig vars -}
+                          [(fresh_it, res_ty)]
+                          lie
+
+    -- Ignore the dictionary bindings
+    evbs' <- perhaps_disable_default_warnings $
+         simplifyInteractive residual
+    full_expr <- zonkTopLExpr (mkHsDictLet (EvBinds evbs') (mkHsDictLet evbs tc_expr))
+    initDsTc $ dsLExpr full_expr
+  where
+    tc_infer expr' | inst      = tcInferRho expr'
+                   | otherwise = tcInferSigma expr'
+                  -- tcInferSigma: see Note [Implementing :type]
+
+    -- See Note [TcRnExprMode]
+    (inst, infer_mode, perhaps_disable_default_warnings) = case mode of
+      TM_Inst    -> (True,  NoRestrictions, id)
+      TM_NoInst  -> (False, NoRestrictions, id)
+      TM_Default -> (True,  EagerDefaulting, unsetWOptM Opt_WarnTypeDefaults)
+
+newtype HashableType = HashableType {getHType :: Type}
+
+instance Eq HashableType where
+  x == y = eqType (getHType x) (getHType y)
+
+instance Ord HashableType where
+  compare x y = nonDetCmpType (getHType x) (getHType y)
+
+instance Outputable HashableType where
+  ppr = ppr . getHType
+
+
+--------------------------------------------------------------------------------
+-- | Superclass coherence
+--------------------------------------------------------------------------------
+
+canonSelectorChains :: PredType -> OM.Map HashableType [Id]
+canonSelectorChains t = foldr (OM.unionWith const) mempty (zs : xs)
+ where
+  (cls, ts) = Ghc.getClassPredTys t
+  scIdTys   = classSCSelIds cls
+  ys        = fmap (\d -> (d, piResultTys (idType d) (ts ++ [t]))) scIdTys
+  zs        = OM.fromList $ fmap (\(x, y) -> (HashableType y, [x])) ys
+  xs        = fmap (\(d, t') -> fmap (d :) (canonSelectorChains t')) ys
+
+buildCoherenceOblig :: Class -> [[([Id], [Id])]]
+buildCoherenceOblig cls = evalState (mapM f xs) OM.empty
+ where
+  (ts, _, selIds, _) = classBigSig cls
+  tts                = mkTyVarTy <$> ts
+  t                  = mkClassPred cls tts
+  ys = fmap (\d -> (d, piResultTys (idType d) (tts ++ [t]))) selIds
+  xs                 = fmap (\(d, t') -> fmap (d:) (canonSelectorChains t')) ys
+  f tid = do
+    ctid' <- get
+    modify (flip (OM.unionWith const) tid)
+    pure . OM.elems $ OM.intersectionWith (,) ctid' (fmap tail tid)
+
+
+-- to be zipped onto the super class selectors
+coherenceObligToRef :: (F.Symbolic s) => s -> [Id] -> [Id] -> F.Reft
+coherenceObligToRef d = coherenceObligToRefE (F.eVar $ F.symbol d)
+
+coherenceObligToRefE :: F.Expr -> [Id] -> [Id] -> F.Reft
+coherenceObligToRefE e rps0 rps1 = F.Reft (F.vv_, F.PAtom F.Eq lhs rhs)
+  where lhs = L.foldr EApp e ps0
+        rhs = L.foldr EApp (F.eVar F.vv_) ps1
+        ps0 = F.eVar . F.symbol <$> L.reverse rps0
+        ps1 = F.eVar . F.symbol <$> L.reverse rps1
+
+data TcWiredIn = TcWiredIn {
+    tcWiredInName :: Name
+  , tcWiredInFixity :: Maybe (Int, FixityDirection)
+  , tcWiredInType :: LHsType GhcRn
+  }
+
+-- | Run a computation in GHC's typechecking monad with wired in values locally bound in the typechecking environment.
+withWiredIn :: TcM a -> TcM a
+withWiredIn m = discardConstraints $ do
+  -- undef <- lookupUndef
+  wiredIns <- mkWiredIns
+  -- snd <$> tcValBinds Ghc.NotTopLevel (binds undef wiredIns) (sigs wiredIns) m
+  snd <$> tcValBinds Ghc.NotTopLevel [] (sigs wiredIns) m
+
+ where
+  -- lookupUndef = do
+  --   lookupOrig gHC_ERR (Ghc.mkVarOcc "undefined")
+  --   -- tcLookupGlobal undefName
+
+  -- binds :: Name -> [TcWiredIn] -> [(Ghc.RecFlag, LHsBinds GhcRn)]
+  -- binds undef wiredIns = map (\w -> 
+  --     let ext = Ghc.unitNameSet undef in -- $ varName $ tyThingId undef in
+  --     let co_fn = idHsWrapper in
+  --     let matches = 
+  --           let ctxt = LambdaExpr in
+  --           let grhss = GRHSs Ghc.noExtField [Ghc.L locSpan (GRHS Ghc.noExtField [] (Ghc.L locSpan (HsVar Ghc.noExtField (Ghc.L locSpan undef))))] (Ghc.L locSpan emptyLocalBinds) in
+  --           MG Ghc.noExtField (Ghc.L locSpan [Ghc.L locSpan (Match Ghc.noExtField ctxt [] grhss)]) Ghc.Generated 
+  --     in
+  --     let b = FunBind ext (Ghc.L locSpan $ tcWiredInName w) matches co_fn [] in
+  --     (Ghc.NonRecursive, unitBag (Ghc.L locSpan b))
+  --   ) wiredIns
+
+  sigsExt ext wiredIns = concatMap (\w ->
+      let inf = maybeToList $ (\(fPrec, fDir) -> Ghc.L locSpan $ FixSig Ghc.noExtField $ FixitySig Ghc.noExtField [Ghc.L locSpan (tcWiredInName w)] $ Ghc.Fixity Ghc.NoSourceText fPrec fDir) <$> tcWiredInFixity w in
+      let t =
+            let ext' = [] in
+            [Ghc.L locSpan $ TypeSig Ghc.noExtField [Ghc.L locSpan (tcWiredInName w)] $ HsWC ext' $ HsIB ext $ tcWiredInType w]
+      in
+      inf <> t
+    ) wiredIns
+
+  sigs = sigsExt cppExt
+
+  cppExt = []
+
+  locSpan = UnhelpfulSpan (UnhelpfulOther "Liquid.GHC.Misc: WiredIn")
+
+  mkHsFunTy :: LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
+  mkHsFunTy a b = nlHsFunTy a b
+
+  mkWiredIns = sequence [impl, dimpl, eq, len]
+
+  toName s = do
+    u <- getUniqueM
+    return $ Ghc.mkInternalName u (Ghc.mkVarOcc s) locSpan
+
+  toLoc = Ghc.L locSpan
+  nameToTy = Ghc.L locSpan . HsTyVar Ghc.noExtField Ghc.NotPromoted
+
+  boolTy' :: LHsType GhcRn
+  boolTy' = nameToTy $ toLoc boolTyConName
+    -- boolName <- lookupOrig (Module (stringToUnitId "Data.Bool") (mkModuleName "Data.Bool")) (Ghc.mkVarOcc "Bool")
+    -- return $ Ghc.L locSpan $ HsTyVar Ghc.noExtField Ghc.NotPromoted $ Ghc.L locSpan boolName
+  intTy' = nameToTy $ toLoc intTyConName
+  listTy lt = toLoc $ HsAppTy Ghc.noExtField (nameToTy $ toLoc listTyConName) lt
+
+  -- infixr 1 ==> :: Bool -> Bool -> Bool
+  impl = do
+    n <- toName "==>"
+    let ty = mkHsFunTy boolTy' (mkHsFunTy boolTy' boolTy')
+    return $ TcWiredIn n (Just (1, Ghc.InfixR)) ty
+
+  -- infixr 1 <=> :: Bool -> Bool -> Bool
+  dimpl = do
+    n <- toName "<=>"
+    let ty = mkHsFunTy boolTy' (mkHsFunTy boolTy' boolTy')
+    return $ TcWiredIn n (Just (1, Ghc.InfixR)) ty
+
+  -- infix 4 == :: forall a . a -> a -> Bool
+  eq = do
+    n <- toName "=="
+    aName <- Ghc.L locSpan <$> toName "a"
+    let aTy = nameToTy aName
+    let ty = noLoc $ HsForAllTy Ghc.noExtField
+             (mkHsForAllInvisTele [Ghc.L locSpan $ UserTyVar Ghc.noExtField SpecifiedSpec aName]) $ mkHsFunTy aTy (mkHsFunTy aTy boolTy')
+    return $ TcWiredIn n (Just (4, Ghc.InfixN)) ty
+
+  -- TODO: This is defined as a measure in liquid-base GHC.Base. We probably want to insert all measures to the environment.
+  -- len :: forall a. [a] -> Int
+  len = do
+    n <- toName "len"
+    aName <- Ghc.L locSpan <$> toName "a"
+    let aTy = nameToTy aName
+    let ty =
+          noLoc $ HsForAllTy Ghc.noExtField
+               (mkHsForAllInvisTele [Ghc.L locSpan $ UserTyVar Ghc.noExtField SpecifiedSpec aName]) $ mkHsFunTy (listTy aTy) intTy'
+    return $ TcWiredIn n Nothing ty
+
+prependGHCRealQual :: FastString -> RdrName
+prependGHCRealQual = varQual_RDR gHC_REAL
+
+isFromGHCReal :: NamedThing a => a -> Bool
+isFromGHCReal x = Ghc.nameModule (Ghc.getName x) == gHC_REAL
diff --git a/src-ghc/Liquid/GHC/Play.hs b/src-ghc/Liquid/GHC/Play.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Play.hs
@@ -0,0 +1,259 @@
+{-# LANGUAGE NoMonomorphismRestriction #-}
+{-# LANGUAGE FlexibleInstances         #-}
+
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+
+module Liquid.GHC.Play where
+
+import Prelude hiding (error)
+
+import           Control.Arrow       ((***))
+import qualified Data.HashMap.Strict as M
+import qualified Data.List           as L
+import qualified Data.Maybe          as Mb
+
+import Liquid.GHC.API as Ghc hiding (substTysWith, panic,showPpr)
+import Liquid.GHC.Misc ()
+import Language.Haskell.Liquid.Types.Errors
+import Language.Haskell.Liquid.Types.Variance
+
+-------------------------------------------------------------------------------
+-- | Positivity Checker -------------------------------------------------------
+-------------------------------------------------------------------------------
+
+-- If the type constructor T is in the input list and its data constructors Di, Dj
+-- use T in non strictly positive positions, 
+-- then (T,(Di, Dj)) will appear in the result list.  
+
+getNonPositivesTyCon :: [TyCon] -> [(TyCon, [DataCon])]
+getNonPositivesTyCon tcs = Mb.mapMaybe go (M.toList $ makeOccurrences tcs)
+  where
+    go (tc,dcocs) = case filter (\(_,occ) -> elem tc (negOcc occ)) dcocs of
+                      [] -> Nothing
+                      xs -> Just (tc, fst <$> xs)
+
+
+-- OccurrenceMap maps type constructors to their TyConOccurrence. 
+-- for each of their data constructor. For example, for the below data definition
+-- data T a = P (T a) | N (T a -> Int) | Both (T a -> T a) | None 
+-- the entry below should get generated
+--  OccurrenceMap 
+-- = T |-> [(P, [
+--          (P,    TyConOcc [T] [])
+--          (N,    TyConOcc [Int] [T])
+--          (Both, TyConOcc [T] [T])
+--          (None, TyConOcc [] [])
+--         ])] 
+-- For positivity check, ultimately we only care about self occurences, 
+-- but we keep track of all the TyCons for the mutually inductive data types. 
+-- We separate the occurences per data constructor only to provide better error messages. 
+type OccurrenceMap = M.HashMap TyCon [(DataCon, TyConOccurrence)]
+
+data TyConOccurrence
+    = TyConOcc { posOcc :: [TyCon] -- TyCons that occur in positive positions
+               , negOcc :: [TyCon] -- TyCons that occur in negative positions
+               }
+  deriving Eq
+
+instance Monoid TyConOccurrence where
+  mempty = TyConOcc mempty mempty
+instance Semigroup TyConOccurrence where
+  TyConOcc p1 n1 <> TyConOcc p2 n2 = TyConOcc (L.nub (p1 <> p2)) (L.nub (n1 <> n2))
+instance Outputable TyConOccurrence where
+  ppr (TyConOcc pos neg) = text "pos" <+> ppr pos <+>  text "neg" <+> ppr neg
+
+
+instance Outputable OccurrenceMap where
+  ppr m = ppr (M.toList m)
+
+
+makeOccurrences :: [TyCon] -> OccurrenceMap
+makeOccurrences tycons
+  = let m0 = M.fromList [(tc, map (\dc -> (dc, makeOccurrence tcInfo (dctypes dc))) (tyConDataCons tc))
+                        | tc <- tycons']
+    -- fixpoint to find occurrences of mutually recursive data definitons
+    in fix (\m -> foldl merge m tycons') m0
+  where
+    fix f x = let x' = f x in if x == x' then x else fix f x'
+    tcInfo = M.fromList $ zip tycons' (makeTyConVariance <$> tycons')
+    merge m tc = M.update (mergeList m) tc m
+    mergeList m xs = Just [(dc, mergeApp m am) | (dc,am) <- xs]
+    mergeApp m (TyConOcc pos neg) =
+        let TyConOcc pospos posneg = mconcat (findOccurrence m <$> pos)
+            TyConOcc negpos negneg = mconcat (findOccurrence m <$> neg)
+        -- Keep positive, flip negative 
+        in TyConOcc (L.nub (pos <> pospos <> negneg)) (L.nub (neg <> negpos <> posneg))
+
+
+    tycontypes tc = concatMap dctypes $ tyConDataCons tc
+    dctypes    dc = irrelevantMult <$> dataConOrigArgTys dc
+
+    -- Construct the map for all TyCons that appear in the definitions 
+    tycons' = L.nub (concatMap tcs (concatMap tycontypes tycons) ++ tycons)
+
+    tcs (TyConApp tc' ts) = tc': concatMap tcs ts
+    tcs (AppTy t1 t2)     = tcs t1 ++ tcs t2
+    tcs (ForAllTy _ t)    = tcs t
+    tcs (FunTy _ _ t1 t2) = tcs t1 ++ tcs t2
+    tcs (TyVarTy _ )      = []
+    tcs (LitTy _)         = []
+    tcs (CastTy _ _)      = []
+    tcs (CoercionTy _)    = []
+
+makeOccurrence :: M.HashMap TyCon VarianceInfo -> [Type] -> TyConOccurrence
+makeOccurrence tcInfo = foldl (go Covariant) mempty
+  where
+    go :: Variance -> TyConOccurrence -> Type -> TyConOccurrence
+    go p m (TyConApp tc ts)  = addOccurrence p tc
+                             $ foldl (\m' (t, v) -> go (v <> p) m' t) m
+                                (zip ts (M.lookupDefault (repeat Bivariant) tc tcInfo))
+    go _ m (TyVarTy _ )      = m
+    go _ m (AppTy t1 t2)     = go Bivariant (go Bivariant m t1) t2
+    go p m (ForAllTy _ t)    = go p m t
+    go p m (FunTy _ _ t1 t2) = go p (go (flipVariance p) m t1) t2
+    go _ m (LitTy _)         = m
+    go _ m (CastTy _ _)      = m
+    go _ m (CoercionTy _)    = m
+
+    addOccurrence p tc (TyConOcc pos neg)
+      = case p of
+         Covariant     -> TyConOcc (L.nub (tc:pos)) neg
+         Contravariant -> TyConOcc pos (L.nub (tc:neg))
+         Bivariant     -> TyConOcc (L.nub (tc:pos)) (L.nub (tc:neg))
+         Invariant     -> TyConOcc pos neg
+
+findOccurrence :: OccurrenceMap -> TyCon -> TyConOccurrence
+findOccurrence m tc = mconcat (snd <$> M.lookupDefault mempty tc m)
+
+
+
+
+isRecursivenewTyCon :: TyCon -> Bool
+isRecursivenewTyCon c
+  | not (isNewTyCon c)
+  = False
+isRecursivenewTyCon c
+  = go t
+  where
+    t = snd $ newTyConRhs c
+    go (AppTy t1 t2)      = go t1 || go t2
+    go (TyConApp c' ts)   = c == c' || any go ts
+    go (ForAllTy _ t1)    = go t1
+    go (FunTy _ _ t1 t2)  = go t1 || go t2
+    go (CastTy t1 _)      = go t1
+    go _                  = False
+
+
+isHoleVar :: Var -> Bool
+isHoleVar x = L.isPrefixOf "_" (show x)
+
+dataConImplicitIds :: DataCon -> [Id]
+dataConImplicitIds dc = [ x | AnId x <- dataConImplicitTyThings dc]
+
+class Subable a where
+  sub   :: M.HashMap CoreBndr CoreExpr -> a -> a
+  subTy :: M.HashMap TyVar Type -> a -> a
+
+instance Subable CoreExpr where
+  sub s (Var v)        = M.lookupDefault (Var v) v s
+  sub _ (Lit l)        = Lit l
+  sub s (App e1 e2)    = App (sub s e1) (sub s e2)
+  sub s (Lam b e)      = Lam b (sub s e)
+  sub s (Let b e)      = Let (sub s b) (sub s e)
+  sub s (Case e b t a) = Case (sub s e) (sub s b) t (map (sub s) a)
+  sub s (Cast e c)     = Cast (sub s e) c
+  sub s (Tick t e)     = Tick t (sub s e)
+  sub _ (Type t)       = Type t
+  sub _ (Coercion c)   = Coercion c
+
+  subTy s (Var v)      = Var (subTy s v)
+  subTy _ (Lit l)      = Lit l
+  subTy s (App e1 e2)  = App (subTy s e1) (subTy s e2)
+  subTy s (Lam b e)    | isTyVar b = Lam v' (subTy s e)
+   where v' = case M.lookup b s of
+               Just (TyVarTy v) -> v
+               _                -> b
+
+  subTy s (Lam b e)      = Lam (subTy s b) (subTy s e)
+  subTy s (Let b e)      = Let (subTy s b) (subTy s e)
+  subTy s (Case e b t a) = Case (subTy s e) (subTy s b) (subTy s t) (map (subTy s) a)
+  subTy s (Cast e c)     = Cast (subTy s e) (subTy s c)
+  subTy s (Tick t e)     = Tick t (subTy s e)
+  subTy s (Type t)       = Type (subTy s t)
+  subTy s (Coercion c)   = Coercion (subTy s c)
+
+instance Subable Coercion where
+  sub _ c                = c
+  subTy _ _              = panic Nothing "subTy Coercion"
+
+instance Subable (Alt Var) where
+ sub s (a, b, e)   = (a, map (sub s) b,   sub s e)
+ subTy s (a, b, e) = (a, map (subTy s) b, subTy s e)
+
+instance Subable Var where
+ sub s v   | M.member v s = subVar $ s M.! v
+           | otherwise    = v
+ subTy s v = setVarType v (subTy s (varType v))
+
+subVar :: Expr t -> Id
+subVar (Var x) = x
+subVar  _      = panic Nothing "sub Var"
+
+instance Subable (Bind Var) where
+ sub s (NonRec x e)   = NonRec (sub s x) (sub s e)
+ sub s (Rec xes)      = Rec ((sub s *** sub s) <$> xes)
+
+ subTy s (NonRec x e) = NonRec (subTy s x) (subTy s e)
+ subTy s (Rec xes)    = Rec ((subTy s  *** subTy s) <$> xes)
+
+instance Subable Type where
+ sub _ e   = e
+ subTy     = substTysWith
+
+substTysWith :: M.HashMap Var Type -> Type -> Type
+substTysWith s tv@(TyVarTy v)      = M.lookupDefault tv v s
+substTysWith s (FunTy aaf m t1 t2) = FunTy aaf m (substTysWith s t1) (substTysWith s t2)
+substTysWith s (ForAllTy v t)      = ForAllTy v (substTysWith (M.delete (binderVar v) s) t)
+substTysWith s (TyConApp c ts)     = TyConApp c (map (substTysWith s) ts)
+substTysWith s (AppTy t1 t2)       = AppTy (substTysWith s t1) (substTysWith s t2)
+substTysWith _ (LitTy t)           = LitTy t
+substTysWith s (CastTy t c)        = CastTy (substTysWith s t) c
+substTysWith _ (CoercionTy c)      = CoercionTy c
+
+substExpr :: M.HashMap Var Var -> CoreExpr -> CoreExpr
+substExpr s = go
+  where
+    subsVar v                = M.lookupDefault v v s
+    go (Var v)               = Var $ subsVar v
+    go (Lit l)               = Lit l
+    go (App e1 e2)           = App (go e1) (go e2)
+    go (Lam x e)             = Lam (subsVar x) (go e)
+    go (Let (NonRec x ex) e) = Let (NonRec (subsVar x) (go ex)) (go e)
+    go (Let (Rec xes) e)     = Let (Rec [(subsVar x', go e') | (x',e') <- xes]) (go e)
+    go (Case e b t alts)     = Case (go e) (subsVar b) t [(c, subsVar <$> xs, go e') | (c, xs, e') <- alts]
+    go (Cast e c)            = Cast (go e) c
+    go (Tick t e)            = Tick t (go e)
+    go (Type t)              = Type t
+    go (Coercion c)          = Coercion c
+
+mapType :: (Type -> Type) -> Type -> Type
+mapType f = go
+  where
+    go t@(TyVarTy _)        = f t
+    go (AppTy t1 t2)        = f $ AppTy (go t1) (go t2)
+    go (TyConApp c ts)      = f $ TyConApp c (go <$> ts)
+    go (FunTy aaf m t1 t2)  = f $ FunTy aaf m (go t1) (go t2)
+    go (ForAllTy v t)       = f $ ForAllTy v (go t)
+    go t@(LitTy _)          = f t
+    go (CastTy t c)         = CastTy (go t) c
+    go (CoercionTy c)       = f $ CoercionTy c
+
+
+stringClassArg :: Type -> Maybe Type
+stringClassArg t | isFunTy t
+  = Nothing
+stringClassArg t
+  = case (tyConAppTyCon_maybe t, tyConAppArgs_maybe t) of
+      (Just c, Just [t']) | isStringClassName == tyConName c
+           -> Just t'
+      _    -> Nothing
diff --git a/src-ghc/Liquid/GHC/Resugar.hs b/src-ghc/Liquid/GHC/Resugar.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Resugar.hs
@@ -0,0 +1,162 @@
+{-# LANGUAGE OverloadedStrings         #-}
+{-# LANGUAGE FlexibleInstances         #-}
+{-# LANGUAGE GADTs                     #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
+{-# LANGUAGE RankNTypes                #-}
+{-# LANGUAGE UndecidableInstances      #-}
+
+-- | This module contains functions for "resugaring" low-level GHC `CoreExpr`
+--   into high-level patterns, that can receive special case handling in
+--   different phases (e.g. ANF, Constraint Generation, etc.)
+
+module Liquid.GHC.Resugar (
+  -- * High-level Source Patterns
+    Pattern (..)
+
+  -- * Lift a CoreExpr into a Pattern
+  , lift
+
+  -- * Lower a pattern back into a CoreExpr
+  , lower
+  ) where
+
+import qualified Data.List as L
+import           Liquid.GHC.API  as Ghc hiding (PatBind)
+import qualified Liquid.GHC.Misc as GM
+import qualified Language.Fixpoint.Types          as F 
+import qualified Text.PrettyPrint.HughesPJ        as PJ 
+-- import           Debug.Trace
+
+--------------------------------------------------------------------------------
+-- | Data type for high-level patterns -----------------------------------------
+--------------------------------------------------------------------------------
+
+data Pattern
+  = PatBind
+      { patE1  :: !CoreExpr
+      , patX   :: !Var
+      , patE2  :: !CoreExpr
+      , patM   :: !Type
+      , patDct :: !CoreExpr
+      , patTyA :: !Type
+      , patTyB :: !Type
+      , patFF  :: !Var
+      }                      -- ^ e1 >>= \x -> e2
+
+  | PatReturn                -- return @ m @ t @ $dT @ e
+     { patE    :: !CoreExpr  -- ^ e
+     , patM    :: !Type      -- ^ m
+     , patDct  :: !CoreExpr  -- ^ $dT
+     , patTy   :: !Type      -- ^ t
+     , patRet  :: !Var       -- ^ "return"
+     }
+
+  | PatProject               -- (case xe as x of C [x1,...,xn] -> xi) : ty
+    { patXE    :: !Var       -- ^ xe
+    , patX     :: !Var       -- ^ x
+    , patTy    :: !Type      -- ^ ty
+    , patCtor  :: !DataCon   -- ^ C
+    , patBinds :: ![Var]     -- ^ [x1,...,xn]
+    , patIdx   :: !Int       -- ^ i :: NatLT {len patBinds}
+    }
+
+  | PatSelfBind              -- let x = e in x
+    { patX     :: !Var       -- ^ x
+    , patE     :: !CoreExpr  -- ^ e
+    }
+
+  | PatSelfRecBind           -- letrec x = e in x
+    { patX     :: !Var       -- ^ x
+    , patE     :: !CoreExpr  -- ^ e
+    }
+
+instance F.PPrint Pattern where 
+  pprintTidy  = ppPat
+
+ppPat :: F.Tidy -> Pattern -> PJ.Doc 
+ppPat k (PatReturn e m d t rv) = 
+  "PatReturn: " 
+  PJ.$+$ 
+  F.pprintKVs k
+    [ ("rv" :: PJ.Doc, GM.pprDoc rv) 
+    , ("e " :: PJ.Doc, GM.pprDoc e) 
+    , ("m " :: PJ.Doc, GM.pprDoc m) 
+    , ("$d" :: PJ.Doc, GM.pprDoc d) 
+    , ("t " :: PJ.Doc, GM.pprDoc t) 
+    ] 
+ppPat _ _  = "TODO: PATTERN" 
+    
+
+_mbId :: CoreExpr -> Maybe Var
+_mbId (Var x)    = Just x
+_mbId (Tick _ e) = _mbId e
+_mbId _          = Nothing
+
+--------------------------------------------------------------------------------
+-- | Lift expressions into High-level patterns ---------------------------------
+--------------------------------------------------------------------------------
+lift :: CoreExpr -> Maybe Pattern
+--------------------------------------------------------------------------------
+lift e = exprArgs e (collectArgs e)
+
+exprArgs :: CoreExpr -> (CoreExpr, [CoreExpr]) -> Maybe Pattern
+exprArgs _e (Var op, [Type m, d, Type a, Type b, e1, Lam x e2])
+  | op `is` Ghc.bindMName
+  = Just (PatBind e1 x e2 m d a b op)
+
+exprArgs (Case (Var xe) x t [(DataAlt c, ys, Var y)]) _
+  | Just i <- y `L.elemIndex` ys
+  = Just (PatProject xe x t c ys i)
+
+
+{- TEMPORARILY DISABLED: TODO-REBARE; in reality it hasn't been working AT ALL 
+   since at least the GHC 8.2.1 port (?) because the TICKs get in the way 
+   of recognizing the pattern? Anyways, messes up 
+
+     tests/pattern/pos/Return00.hs  
+
+   because we treat _all_ types of the form `m a` as "invariant" in the parameter `a`.
+   Looks like the above tests only pass in earlier LH versions because this pattern 
+   was NOT getting tickled!
+
+exprArgs _e (Var op, [Type m, d, Type t, e])
+  | op `is` PN.returnMName
+  = Just (PatReturn e m d t op)
+-}
+
+{- TEMPORARILY DISBLED
+
+exprArgs (Let (NonRec x e) e') _
+  | Just y <- _mbId e', x == y
+  = Just (PatSelfBind x e)
+
+exprArgs (Let (Rec [(x, e)]) e') _
+  | Just y <- _mbId e', x == y
+  = Just (PatSelfRecBind x e)
+
+-}
+exprArgs _ _
+  = Nothing
+
+is :: Var -> Name -> Bool
+is v n = n == getName v
+
+--------------------------------------------------------------------------------
+-- | Lower patterns back into expressions --------------------------------------
+--------------------------------------------------------------------------------
+lower :: Pattern -> CoreExpr
+--------------------------------------------------------------------------------
+lower (PatBind e1 x e2 m d a b op)
+  = Ghc.mkCoreApps (Var op) [Type m, d, Type a, Type b, e1, Lam x e2]
+
+lower (PatReturn e m d t op)
+  = Ghc.mkCoreApps (Var op) [Type m, d, Type t, e]
+
+lower (PatProject xe x t c ys i)
+  = Case (Var xe) x t [(DataAlt c, ys, Var yi)] where yi = ys !! i
+
+lower (PatSelfBind x e)
+  = Let (NonRec x e) (Var x)
+
+lower (PatSelfRecBind x e)
+  = Let (Rec [(x, e)]) (Var x)
diff --git a/src-ghc/Liquid/GHC/SpanStack.hs b/src-ghc/Liquid/GHC/SpanStack.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/SpanStack.hs
@@ -0,0 +1,80 @@
+{-# LANGUAGE BangPatterns #-}
+
+module Liquid.GHC.SpanStack
+   ( -- * Stack of positions
+     Span (..)
+   , SpanStack
+
+     -- * Creating Stacks
+   , empty, push
+
+     -- * Using Stacks
+   , srcSpan
+
+     -- * Creating general spans
+   , showSpan
+   ) where
+
+import           Prelude                   hiding (error)
+import           Data.Maybe                       (listToMaybe, fromMaybe)
+import           Liquid.GHC.Misc (tickSrcSpan, showPpr)
+import qualified Liquid.GHC.API  as Ghc
+import           Liquid.GHC.API  ( SrcSpan
+                                                  , fsLit
+                                                  , getSrcSpan
+                                                  , isGoodSrcSpan
+                                                  , mkGeneralSrcSpan
+                                                  )
+
+-- | Opaque type for a stack of spans
+newtype SpanStack = SpanStack { unStack :: [(Span, SrcSpan)] }
+
+--------------------------------------------------------------------------------
+empty :: SpanStack
+--------------------------------------------------------------------------------
+empty = SpanStack []
+
+--------------------------------------------------------------------------------
+push :: Span -> SpanStack -> SpanStack
+--------------------------------------------------------------------------------
+push !s stk -- @(SpanStack stk)
+  | Just sp <- spanSrcSpan s = SpanStack ((s, sp) : unStack stk)
+  | otherwise                = stk
+
+-- | A single span
+data Span
+  = Var  !Ghc.Var               -- ^ binder for whom we are generating constraint
+  | Tick !(Ghc.Tickish Ghc.Var) -- ^ nearest known Source Span
+  | Span SrcSpan
+
+instance Show Span where
+  show (Var x)   = show x
+  show (Tick tt) = showPpr tt
+  show (Span s)  = show s 
+
+--------------------------------------------------------------------------------
+srcSpan :: SpanStack -> SrcSpan
+--------------------------------------------------------------------------------
+srcSpan s  = fromMaybe noSpan (mbSrcSpan s)
+  where
+    noSpan = showSpan "Yikes! No source information"
+
+mbSrcSpan :: SpanStack -> Maybe SrcSpan
+mbSrcSpan = fmap snd . listToMaybe  . unStack
+
+spanSrcSpan :: Span -> Maybe SrcSpan
+spanSrcSpan      = maybeSpan Nothing . go
+  where
+    go (Var x)   = getSrcSpan x
+    go (Tick tt) = tickSrcSpan tt
+    go (Span s)  = s 
+
+maybeSpan :: Maybe SrcSpan -> SrcSpan -> Maybe SrcSpan
+maybeSpan d sp
+  | isGoodSrcSpan sp = Just sp
+  | otherwise        = d
+
+--------------------------------------------------------------------------------
+showSpan :: (Show a) => a -> SrcSpan
+--------------------------------------------------------------------------------
+showSpan = mkGeneralSrcSpan . fsLit . show
diff --git a/src-ghc/Liquid/GHC/TypeRep.hs b/src-ghc/Liquid/GHC/TypeRep.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/TypeRep.hs
@@ -0,0 +1,164 @@
+{-# LANGUAGE OverloadedStrings         #-}
+{-# LANGUAGE FlexibleInstances         #-}
+{-# LANGUAGE GADTs                     #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
+{-# LANGUAGE RankNTypes                #-}
+{-# LANGUAGE UndecidableInstances      #-}
+{-# LANGUAGE StandaloneDeriving        #-}
+
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+module Liquid.GHC.TypeRep (
+  mkTyArg, 
+
+  showTy
+  ) where
+
+import           Liquid.GHC.Misc (showPpr)
+import           Liquid.GHC.API as Ghc hiding (mkTyArg, showPpr, panic)
+import           Language.Fixpoint.Types (symbol)
+
+-- e368f3265b80aeb337fbac3f6a70ee54ab14edfd
+
+mkTyArg :: TyVar -> TyVarBinder
+mkTyArg v = Bndr v Required
+
+instance Eq Type where
+  t1 == t2 = eqType' t1 t2
+
+eqType' :: Type -> Type -> Bool 
+eqType' (LitTy l1) (LitTy l2) 
+  = l1 == l2  
+eqType' (CoercionTy c1) (CoercionTy c2) 
+  = c1 == c2  
+eqType'(CastTy t1 c1) (CastTy t2 c2) 
+  = eqType' t1 t2 && c1 == c2 
+eqType' (FunTy a1 m1 t11 t12) (FunTy a2 m2 t21 t22)
+  = a1 == a2 && m1 == m2 && eqType' t11 t21 && eqType' t12 t22  
+eqType' (ForAllTy (Bndr v1 _) t1) (ForAllTy (Bndr v2 _) t2) 
+  = eqType' t1 (subst v2 (TyVarTy v1) t2) 
+eqType' (TyVarTy v1) (TyVarTy v2) 
+  = v1 == v2 
+eqType' (AppTy t11 t12) (AppTy t21 t22) 
+  = eqType' t11 t21 && eqType' t12 t22  
+eqType' (TyConApp c1 ts1) (TyConApp c2 ts2) 
+  = c1 == c2 && and (zipWith eqType' ts1 ts2) 
+eqType' _ _ 
+  = False 
+
+
+deriving instance (Eq tyvar, Eq argf) => Eq (VarBndr tyvar argf)
+
+instance Eq Coercion where
+  _ == _ = True 
+
+
+showTy :: Type -> String 
+showTy (TyConApp c ts) = "(RApp   " ++ showPpr c ++ " " ++ sep' ", " (showTy <$> ts) ++ ")"
+showTy (AppTy t1 t2)   = "(TAppTy " ++ (showTy t1 ++ " " ++ showTy t2) ++ ")" 
+showTy (TyVarTy v)   = "(RVar " ++ show (symbol v)  ++ ")" 
+showTy (ForAllTy (Bndr v _) t)  = "ForAllTy " ++ show (symbol v) ++ ". (" ++  showTy t ++ ")"
+showTy (FunTy af _m1 t1 t2) = "FunTy " ++ showPpr af ++ " " ++ showTy t1 ++ ". (" ++  showTy t2 ++ ")"
+showTy (CastTy _ _)    = "CastTy"
+showTy (CoercionTy _)  = "CoercionTy"
+showTy (LitTy _)       = "LitTy"
+
+sep' :: String -> [String] -> String
+sep' _ [x] = x
+sep' _ []  = []
+sep' s (x:xs) = x ++ s ++ sep' s xs 
+
+
+
+-------------------------------------------------------------------------------
+-- | GHC Type Substitutions ---------------------------------------------------
+-------------------------------------------------------------------------------
+
+class SubstTy a where
+  subst :: TyVar -> Type -> a -> a
+  subst _ _ = id  
+
+instance SubstTy Type where
+  subst = substType
+
+substType :: TyVar -> Type -> Type -> Type
+substType x tx (TyConApp c ts) 
+  = TyConApp c (subst x tx <$> ts)
+substType x tx (AppTy t1 t2)   
+  = AppTy (subst x tx t1) (subst x tx t2) 
+substType x tx (TyVarTy y)   
+  | symbol x == symbol y
+  = tx 
+  | otherwise
+  = TyVarTy y 
+substType x tx (FunTy aaf m t1 t2)
+  = FunTy aaf m (subst x tx t1) (subst x tx t2)
+substType x tx f@(ForAllTy b@(Bndr y _) t)  
+  | symbol x == symbol y 
+  = f
+  | otherwise 
+  = ForAllTy b (subst x tx t)
+substType x tx (CastTy t c)    
+  = CastTy (subst x tx t) (subst x tx c)
+substType x tx (CoercionTy c)  
+  = CoercionTy $ subst x tx c 
+substType _ _  (LitTy l)
+  = LitTy l  
+
+
+instance SubstTy Coercion where
+  subst = substCoercion
+
+substCoercion :: TyVar -> Type -> Coercion -> Coercion
+substCoercion x tx (TyConAppCo r c cs)
+  = TyConAppCo (subst x tx r) c (subst x tx <$> cs)
+substCoercion x tx (AppCo c1 c2)
+  = AppCo (subst x tx c1) (subst x tx c2)
+substCoercion x tx (FunCo r cN c1 c2)
+  = FunCo r cN (subst x tx c1) (subst x tx c2) -- TODO(adinapoli) Is this the correct substitution?
+substCoercion x tx (ForAllCo y c1 c2)
+  | symbol x == symbol y 
+  = ForAllCo y c1 c2
+  | otherwise 
+  = ForAllCo y (subst x tx c1) (subst x tx c2)
+substCoercion _ _ (CoVarCo y)
+  = CoVarCo y 
+substCoercion x tx (AxiomInstCo co bi cs)
+  = AxiomInstCo (subst x tx co) bi (subst x tx <$> cs)  
+substCoercion x tx (UnivCo y r t1 t2)
+  = UnivCo (subst x tx y) (subst x tx r) (subst x tx t1) (subst x tx t2)
+substCoercion x tx (SymCo c)
+  = SymCo (subst x tx c)
+substCoercion x tx (TransCo c1 c2)
+  = TransCo (subst x tx c1) (subst x tx c2)
+substCoercion x tx (AxiomRuleCo ca cs)
+  = AxiomRuleCo (subst x tx ca)  (subst x tx <$> cs)  
+substCoercion x tx (NthCo r i c)
+  = NthCo r i (subst x tx c)
+substCoercion x tx (LRCo i c)
+  = LRCo i (subst x tx c)
+substCoercion x tx (InstCo c1 c2)
+  = InstCo (subst x tx c1) (subst x tx c2)
+substCoercion x tx (KindCo c)
+  = KindCo (subst x tx c)
+substCoercion x tx (SubCo c)
+  = SubCo (subst x tx c)
+
+instance SubstTy Role where
+instance SubstTy (CoAxiom Branched) where
+
+instance SubstTy UnivCoProvenance where
+  subst x tx (PhantomProv c)
+    = PhantomProv $ subst x tx c 
+  subst x tx (ProofIrrelProv c)
+    = ProofIrrelProv $ subst x tx c 
+  subst _ _ ch 
+    = ch 
+
+instance SubstTy CoAxiomRule where
+  subst x tx (CoAxiomRule n rs r ps) 
+    = CoAxiomRule n (subst x tx <$> rs) (subst x tx r) (\eq -> subst x tx (ps (subst x tx eq)))
+
+instance (SubstTy a, Functor m) => SubstTy (m a) where
+  subst x tx xs = subst x tx <$> xs
diff --git a/src-ghc/Liquid/GHC/Types.hs b/src-ghc/Liquid/GHC/Types.hs
new file mode 100644
--- /dev/null
+++ b/src-ghc/Liquid/GHC/Types.hs
@@ -0,0 +1,79 @@
+{-# LANGUAGE DeriveGeneric #-}
+module Liquid.GHC.Types where
+
+import           Data.HashSet (HashSet, fromList)
+import           Data.Hashable
+import           GHC.Generics hiding (moduleName)
+import           Liquid.GHC.API
+
+-- | A 'StableName' is virtually isomorphic to a GHC's 'Name' but crucially we don't use
+-- the 'Eq' instance defined on a 'Name' because it's 'Unique'-based. In particular, GHC
+-- doesn't guarantee that if we load an interface multiple times we would get the same 'Unique' for the
+-- same 'Name', and this is a problem when we rely on 'Name's to be the same when we call 'isExportedVar',
+-- which used to use a 'NameSet' derived from the '[AvailInfo]'. As the name implies, a 'NameSet' uses a
+-- 'Name's 'Unique' for duplicate detection and indexing, and this would lead to 'Var's being resolved to
+-- a 'Name' which is basically the same, but it has a /different/ 'Unique', and that would cause the lookup
+-- inside the 'NameSet' to fail.
+newtype StableName =
+  MkStableName { unStableName :: Name }
+  deriving Generic
+
+instance Show StableName where
+  show (MkStableName n) = nameStableString n
+
+instance Hashable StableName where
+  hashWithSalt s (MkStableName n) = hashWithSalt s (nameStableString n)
+
+instance Eq StableName where
+  (MkStableName n1) == (MkStableName n2) = -- n1 `stableNameCmp` n2 == EQ
+    let sameOccName = occNameString (nameOccName n1) == occNameString (nameOccName n2)
+        sameModule  = nameModule  n1 == nameModule  n2
+        sameSrcLoc  = nameSrcLoc  n1 == nameSrcLoc  n2
+        sameSrcSpan = nameSrcSpan n1 == nameSrcSpan n2
+    in sameOccName && sameModule && sameSrcLoc  && sameSrcSpan
+
+-- | Creates a new 'StableName' out of a 'Name'.
+mkStableName :: Name -> StableName
+mkStableName = MkStableName
+
+-- | Converts a list of 'AvailInfo' into a \"StableNameSet\", similarly to what 'availsToNameSet' would do.
+availsToStableNameSet :: [AvailInfo] -> HashSet StableName
+availsToStableNameSet avails = foldr add mempty avails
+      where add av acc = acc <> fromList (map mkStableName (availNames av))
+
+--------------------------------------------------------------------------------
+-- | Datatype For Holding GHC ModGuts ------------------------------------------
+--------------------------------------------------------------------------------
+data MGIModGuts = MI
+  { mgi_binds     :: !CoreProgram
+  , mgi_module    :: !Module
+  , mgi_deps      :: !Dependencies
+  , mgi_dir_imps  :: ![ModuleName]
+  , mgi_rdr_env   :: !GlobalRdrEnv
+  , mgi_tcs       :: ![TyCon]
+  , mgi_fam_insts :: ![FamInst]
+  , mgi_exports   :: !(HashSet StableName)
+  , mgi_cls_inst  :: !(Maybe [ClsInst])
+  }
+
+miModGuts :: Maybe [ClsInst] -> ModGuts -> MGIModGuts
+miModGuts cls mg  = MI
+  { mgi_binds     = mg_binds mg
+  , mgi_module    = mg_module mg
+  , mgi_deps      = mg_deps mg
+  , mgi_dir_imps  = mgDirImps mg
+  , mgi_rdr_env   = mg_rdr_env mg
+  , mgi_tcs       = mg_tcs mg
+  , mgi_fam_insts = mg_fam_insts mg
+  , mgi_exports   = availsToStableNameSet $ mg_exports mg
+  , mgi_cls_inst  = cls
+  }
+
+nameSetToStableNameSet :: NameSet -> HashSet StableName
+nameSetToStableNameSet = fromList . map mkStableName . nameSetElemsStable
+
+mgDirImps :: ModGuts -> [ModuleName]
+mgDirImps = map gwib_mod . getDependenciesModuleNames . mg_deps
+
+mgiNamestring :: MGIModGuts -> String
+mgiNamestring = moduleNameString . moduleName . mgi_module
diff --git a/src/Language/Haskell/Liquid/Bare.hs b/src/Language/Haskell/Liquid/Bare.hs
--- a/src/Language/Haskell/Liquid/Bare.hs
+++ b/src/Language/Haskell/Liquid/Bare.hs
@@ -2,8 +2,6 @@
 {-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE ScopedTypeVariables       #-}
 {-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE RecordWildCards           #-}
-{-# LANGUAGE ViewPatterns              #-}
 {-# LANGUAGE PartialTypeSignatures     #-}
 {-# LANGUAGE OverloadedStrings         #-}
 
@@ -25,7 +23,7 @@
 
 import           Prelude                                    hiding (error)
 import           Optics
-import           Control.Monad                              (unless, forM)
+import           Control.Monad                              (forM)
 import           Control.Applicative                        ((<|>))
 import qualified Control.Exception                          as Ex
 import qualified Data.Binary                                as B
@@ -38,30 +36,30 @@
 import           System.Directory                           (doesFileExist)
 import           System.Console.CmdArgs.Verbosity           (whenLoud)
 import           Language.Fixpoint.Utils.Files              as Files
-import           Language.Fixpoint.Misc                     as Misc 
+import           Language.Fixpoint.Misc                     as Misc
 import           Language.Fixpoint.Types                    hiding (dcFields, DataDecl, Error, panic)
 import qualified Language.Fixpoint.Types                    as F
 import qualified Language.Haskell.Liquid.Misc               as Misc -- (nubHashOn)
-import qualified Language.Haskell.Liquid.GHC.Misc           as GM
-import qualified Language.Haskell.Liquid.GHC.API            as Ghc 
-import           Language.Haskell.Liquid.GHC.Types          (StableName)
+import qualified Liquid.GHC.Misc           as GM
+import qualified Liquid.GHC.API            as Ghc
+import           Liquid.GHC.Types          (StableName)
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.WiredIn
 import qualified Language.Haskell.Liquid.Measure            as Ms
-import qualified Language.Haskell.Liquid.Bare.Types         as Bare 
-import qualified Language.Haskell.Liquid.Bare.Resolve       as Bare 
+import qualified Language.Haskell.Liquid.Bare.Types         as Bare
+import qualified Language.Haskell.Liquid.Bare.Resolve       as Bare
 import qualified Language.Haskell.Liquid.Bare.DataType      as Bare
 import           Language.Haskell.Liquid.Bare.Elaborate
-import qualified Language.Haskell.Liquid.Bare.Expand        as Bare 
-import qualified Language.Haskell.Liquid.Bare.Measure       as Bare 
-import qualified Language.Haskell.Liquid.Bare.Plugged       as Bare 
-import qualified Language.Haskell.Liquid.Bare.Axiom         as Bare 
-import qualified Language.Haskell.Liquid.Bare.ToBare        as Bare 
-import qualified Language.Haskell.Liquid.Bare.Class         as Bare 
-import qualified Language.Haskell.Liquid.Bare.Check         as Bare 
+import qualified Language.Haskell.Liquid.Bare.Expand        as Bare
+import qualified Language.Haskell.Liquid.Bare.Measure       as Bare
+import qualified Language.Haskell.Liquid.Bare.Plugged       as Bare
+import qualified Language.Haskell.Liquid.Bare.Axiom         as Bare
+import qualified Language.Haskell.Liquid.Bare.ToBare        as Bare
+import qualified Language.Haskell.Liquid.Bare.Class         as Bare
+import qualified Language.Haskell.Liquid.Bare.Check         as Bare
 import qualified Language.Haskell.Liquid.Bare.Laws          as Bare
-import qualified Language.Haskell.Liquid.Bare.Typeclass     as Bare 
-import qualified Language.Haskell.Liquid.Transforms.CoreToLogic as CoreToLogic 
+import qualified Language.Haskell.Liquid.Bare.Typeclass     as Bare
+import qualified Language.Haskell.Liquid.Transforms.CoreToLogic as CoreToLogic
 import           Control.Arrow                    (second)
 import Data.Hashable (Hashable)
 import qualified Language.Haskell.Liquid.Bare.Slice as Dg
@@ -72,13 +70,13 @@
 
 loadLiftedSpec :: Config -> FilePath -> IO (Maybe Ms.BareSpec)
 loadLiftedSpec cfg srcF
-  | noLiftedImport cfg = putStrLn "No LIFTED Import" >> return Nothing 
+  | noLiftedImport cfg = putStrLn "No LIFTED Import" >> return Nothing
   | otherwise          = do
       let specF = extFileName BinSpec srcF
       ex  <- doesFileExist specF
       whenLoud $ putStrLn $ "Loading Binary Lifted Spec: " ++ specF ++ " " ++ "for source-file: " ++ show srcF ++ " " ++ show ex
-      lSp <- if ex 
-               then Just <$> B.decodeFile specF 
+      lSp <- if ex
+               then Just <$> B.decodeFile specF
                else {- warnMissingLiftedSpec srcF specF >> -} return Nothing
       Ex.evaluate lSp
 
@@ -88,10 +86,7 @@
 --   unless (Misc.isIncludeFile incDir srcF)
 --     $ Ex.throw (errMissingSpec srcF specF) 
 
-errMissingSpec :: FilePath -> FilePath -> UserError 
-errMissingSpec srcF specF = ErrNoSpec Ghc.noSrcSpan (text srcF) (text specF)
-
-saveLiftedSpec :: FilePath -> Ms.BareSpec -> IO () 
+saveLiftedSpec :: FilePath -> Ms.BareSpec -> IO ()
 saveLiftedSpec srcF lspec = do
   ensurePath specF
   B.encodeFile specF lspec
@@ -123,9 +118,10 @@
                -> TargetDependencies
                -> Ghc.TcRn (Either Diagnostics ([Warning], TargetSpec, LiftedSpec))
 makeTargetSpec cfg lmap targetSrc bareSpec dependencies = do
+  let targDiagnostics     = Bare.checkTargetSrc cfg targetSrc
   let depsDiagnostics     = mapM (uncurry Bare.checkBareSpec) legacyDependencies
   let bareSpecDiagnostics = Bare.checkBareSpec (giTargetMod targetSrc) legacyBareSpec
-  case depsDiagnostics >> bareSpecDiagnostics of
+  case targDiagnostics >> depsDiagnostics >> bareSpecDiagnostics of
    Left d | noErrors d -> secondPhase (allWarnings d)
    Left d              -> return $ Left d
    Right ()            -> secondPhase mempty
@@ -198,9 +194,9 @@
                                          (ghcSpecEnv sp)
                                          (_giCbs src)
                                          (fst . view targetSpecGetter $ sp)
-  pure $ if not (noErrors dg0) then Left dg0 else 
+  pure $ if not (noErrors dg0) then Left dg0 else
            case diagnostics of
-             Left dg1 
+             Left dg1
                | noErrors dg1 -> pure (allWarnings dg1, sp)
                | otherwise    -> Left dg1
              Right ()         -> pure (mempty, sp)
@@ -210,7 +206,7 @@
 ghcSpecEnv sp = F.notracepp "RENV" $ fromListSEnv binds
   where
     emb       = gsTcEmbeds (_gsName sp)
-    binds     = F.notracepp "binds" $ concat 
+    binds     = F.notracepp "binds" $ concat
                  [ [(x,        rSort t) | (x, Loc _ _ t)  <- gsMeas     (_gsData sp)]
                  , [(symbol v, rSort t) | (v, Loc _ _ t)  <- gsCtors    (_gsData sp)]
                  , [(symbol v, vSort v) | v               <- gsReflects (_gsRefl sp)]
@@ -230,48 +226,48 @@
 --   essentially, to get to the `BareRTEnv` as soon as possible, as thats what
 --   lets us use aliases inside data-constructor definitions.
 -------------------------------------------------------------------------------------
-makeGhcSpec0 :: Config -> GhcSrc ->  LogicMap -> [(ModName, Ms.BareSpec)] -> 
+makeGhcSpec0 :: Config -> GhcSrc ->  LogicMap -> [(ModName, Ms.BareSpec)] ->
                 Ghc.TcRn (Diagnostics, GhcSpec)
 makeGhcSpec0 cfg src lmap mspecsNoCls = do
   -- build up environments
-  tycEnv <- makeTycEnv1 cfg name env (tycEnv0, datacons) coreToLg simplifier
-  let tyi      = Bare.tcTyConMap   tycEnv 
-  let sigEnv   = makeSigEnv  embs tyi (_gsExports src) rtEnv 
-  let lSpec1   = lSpec0 <> makeLiftedSpec1 cfg src tycEnv lmap mySpec1 
-  let mySpec   = mySpec2 <> lSpec1 
+  tycEnv <- makeTycEnv1 name env (tycEnv0, datacons) coreToLg simplifier
+  let tyi      = Bare.tcTyConMap   tycEnv
+  let sigEnv   = makeSigEnv  embs tyi (_gsExports src) rtEnv
+  let lSpec1   = lSpec0 <> makeLiftedSpec1 cfg src tycEnv lmap mySpec1
+  let mySpec   = mySpec2 <> lSpec1
   let specs    = M.insert name mySpec iSpecs2
-  let myRTE    = myRTEnv       src env sigEnv rtEnv  
-  let (dg5, measEnv) = withDiagnostics $ makeMeasEnv      env tycEnv sigEnv       specs 
+  let myRTE    = myRTEnv       src env sigEnv rtEnv
+  let (dg5, measEnv) = withDiagnostics $ makeMeasEnv      env tycEnv sigEnv       specs
   let (dg4, sig) = withDiagnostics $ makeSpecSig cfg name specs env sigEnv   tycEnv measEnv (_giCbs src)
   elaboratedSig <-
     if allowTC then Bare.makeClassAuxTypes (elaborateSpecType coreToLg simplifier) datacons instMethods
                               >>= elaborateSig sig
                else pure sig
-  let qual     = makeSpecQual cfg env tycEnv measEnv rtEnv specs 
-  let sData    = makeSpecData  src env sigEnv measEnv elaboratedSig specs 
+  let qual     = makeSpecQual cfg env tycEnv measEnv rtEnv specs
+  let sData    = makeSpecData  src env sigEnv measEnv elaboratedSig specs
   let (dg1, spcVars) = withDiagnostics $ makeSpecVars cfg src mySpec env measEnv
-  let (dg2, spcTerm) = withDiagnostics $ makeSpecTerm cfg     mySpec env       name    
-  let (dg3, refl)    = withDiagnostics $ makeSpecRefl cfg src measEnv specs env name elaboratedSig tycEnv 
-  let laws     = makeSpecLaws env sigEnv (gsTySigs elaboratedSig ++ gsAsmSigs elaboratedSig) measEnv specs 
+  let (dg2, spcTerm) = withDiagnostics $ makeSpecTerm cfg     mySpec env       name
+  let (dg3, refl)    = withDiagnostics $ makeSpecRefl cfg src measEnv specs env name elaboratedSig tycEnv
+  let laws     = makeSpecLaws env sigEnv (gsTySigs elaboratedSig ++ gsAsmSigs elaboratedSig) measEnv specs
   let finalLiftedSpec = makeLiftedSpec name src env refl sData elaboratedSig qual myRTE lSpec1
   let diags    = mconcat [dg0, dg1, dg2, dg3, dg4, dg5]
 
-  pure (diags, SP 
-    { _gsConfig = cfg 
+  pure (diags, SP
+    { _gsConfig = cfg
     , _gsImps   = makeImports mspecs
     , _gsSig    = addReflSigs env name rtEnv refl elaboratedSig
-    , _gsRefl   = refl 
-    , _gsLaws   = laws 
-    , _gsData   = sData 
-    , _gsQual   = qual 
-    , _gsName   = makeSpecName env     tycEnv measEnv   name 
+    , _gsRefl   = refl
+    , _gsLaws   = laws
+    , _gsData   = sData
+    , _gsQual   = qual
+    , _gsName   = makeSpecName env     tycEnv measEnv   name
     , _gsVars   = spcVars
     , _gsTerm   = spcTerm
 
     , _gsLSpec  = finalLiftedSpec
                 { impSigs   = makeImports mspecs
                 , expSigs   = [ (F.symbol v, F.sr_sort $ Bare.varSortedReft embs v) | v <- gsReflects refl ]
-                , dataDecls = dataDecls mySpec2 
+                , dataDecls = Bare.dataDeclSize mySpec $ dataDecls mySpec
                 , measures  = Ms.measures mySpec
                   -- We want to export measures in a 'LiftedSpec', especially if they are
                   -- required to check termination of some 'liftedSigs' we export. Due to the fact
@@ -286,20 +282,20 @@
                   -- Preserve user-defined 'dvariance'.
                 , rinstance = Ms.rinstance finalLiftedSpec ++ Ms.rinstance mySpec
                   -- Preserve rinstances.
-                } 
+                }
     })
   where
     -- typeclass elaboration
 
-    coreToLg e =
+    coreToLg ce =
       case CoreToLogic.runToLogic
              embs
              lmap
              dm
              (\x -> todo Nothing ("coreToLogic not working " ++ x))
-             (CoreToLogic.coreToLogic allowTC e) of
+             (CoreToLogic.coreToLogic allowTC ce) of
         Left msg -> panic Nothing (F.showpp msg)
-        Right e -> e    
+        Right e -> e
     elaborateSig si auxsig = do
       tySigs <-
         forM (gsTySigs si) $ \(x, t) ->
@@ -321,30 +317,30 @@
     allowTC  = typeclass cfg
     mySpec2  = Bare.qualifyExpand env name rtEnv l [] mySpec1    where l = F.dummyPos "expand-mySpec2"
     iSpecs2  = Bare.qualifyExpand env name rtEnv l [] iSpecs0    where l = F.dummyPos "expand-iSpecs2"
-    rtEnv    = Bare.makeRTEnv env name mySpec1 iSpecs0 lmap  
+    rtEnv    = Bare.makeRTEnv env name mySpec1 iSpecs0 lmap
     mspecs   = if allowTC then M.toList $ M.insert name mySpec0 iSpecs0 else mspecsNoCls
     (mySpec0, instMethods)  = if allowTC
                               then Bare.compileClasses src env (name, mySpec0NoCls) (M.toList iSpecs0)
                               else (mySpec0NoCls, [])
-    mySpec1  = mySpec0 <> lSpec0    
-    lSpec0   = makeLiftedSpec0 cfg src embs lmap mySpec0 
+    mySpec1  = mySpec0 <> lSpec0
+    lSpec0   = makeLiftedSpec0 cfg src embs lmap mySpec0
     embs     = makeEmbeds          src env ((name, mySpec0) : M.toList iSpecs0)
     dm       = Bare.tcDataConMap tycEnv0
-    (dg0, datacons, tycEnv0) = makeTycEnv0   cfg name env embs mySpec2 iSpecs2 
+    (dg0, datacons, tycEnv0) = makeTycEnv0   cfg name env embs mySpec2 iSpecs2
     -- extract name and specs
     env      = Bare.makeEnv cfg src lmap mspecsNoCls
     (mySpec0NoCls, iSpecs0) = splitSpecs name src mspecsNoCls
     -- check barespecs 
-    name     = F.notracepp ("ALL-SPECS" ++ zzz) $ _giTargetMod  src 
+    name     = F.notracepp ("ALL-SPECS" ++ zzz) $ _giTargetMod  src
     zzz      = F.showpp (fst <$> mspecs)
 
-splitSpecs :: ModName -> GhcSrc -> [(ModName, Ms.BareSpec)] -> (Ms.BareSpec, Bare.ModSpecs) 
-splitSpecs name src specs = (mySpec, iSpecm) 
-  where 
+splitSpecs :: ModName -> GhcSrc -> [(ModName, Ms.BareSpec)] -> (Ms.BareSpec, Bare.ModSpecs)
+splitSpecs name src specs = (mySpec, iSpecm)
+  where
     iSpecm             = fmap mconcat . Misc.group $ iSpecs
     iSpecs             = Dg.sliceSpecs src mySpec iSpecs'
     mySpec             = mconcat (snd <$> mySpecs)
-    (mySpecs, iSpecs') = L.partition ((name ==) . fst) specs 
+    (mySpecs, iSpecs') = L.partition ((name ==) . fst) specs
 
 
 makeImports :: [(ModName, Ms.BareSpec)] -> [(F.Symbol, F.Sort)]
@@ -352,17 +348,17 @@
   where specs' = filter (isSrcImport . fst) specs
 
 
-makeEmbeds :: GhcSrc -> Bare.Env -> [(ModName, Ms.BareSpec)] -> F.TCEmb Ghc.TyCon 
-makeEmbeds src env 
-  = Bare.addClassEmbeds (_gsCls src) (_gsFiTcs src) 
-  . mconcat 
+makeEmbeds :: GhcSrc -> Bare.Env -> [(ModName, Ms.BareSpec)] -> F.TCEmb Ghc.TyCon
+makeEmbeds src env
+  = Bare.addClassEmbeds (_gsCls src) (_gsFiTcs src)
+  . mconcat
   . map (makeTyConEmbeds env)
 
 makeTyConEmbeds :: Bare.Env -> (ModName, Ms.BareSpec) -> F.TCEmb Ghc.TyCon
-makeTyConEmbeds env (name, spec) 
+makeTyConEmbeds env (name, spec)
   = F.tceFromList [ (tc, t) | (c,t) <- F.tceToList (Ms.embeds spec), tc <- symTc c ]
     where
-      symTc = Mb.maybeToList . Bare.maybeResolveSym env name "embed-tycon" 
+      symTc = Mb.maybeToList . Bare.maybeResolveSym env name "embed-tycon"
 
 --------------------------------------------------------------------------------
 -- | [NOTE]: REFLECT-IMPORTS
@@ -375,7 +371,7 @@
 --   we compute the `SpecType` for (all, including the reflected binders),
 --   as we need the inlines and aliases to properly `expand` the SpecTypes.
 --------------------------------------------------------------------------------
-makeLiftedSpec1 :: Config -> GhcSrc -> Bare.TycEnv -> LogicMap -> Ms.BareSpec 
+makeLiftedSpec1 :: Config -> GhcSrc -> Bare.TycEnv -> LogicMap -> Ms.BareSpec
                 -> Ms.BareSpec
 makeLiftedSpec1 config src tycEnv lmap mySpec = mempty
   { Ms.measures  = Bare.makeHaskellMeasures (typeclass config) src tycEnv lmap mySpec }
@@ -392,12 +388,12 @@
 -- i.e. the refined datatypes and their associate selectors, projectors etc,
 -- that are needed for subsequent stages of the lifting.
 --------------------------------------------------------------------------------
-makeLiftedSpec0 :: Config -> GhcSrc -> F.TCEmb Ghc.TyCon -> LogicMap -> Ms.BareSpec 
+makeLiftedSpec0 :: Config -> GhcSrc -> F.TCEmb Ghc.TyCon -> LogicMap -> Ms.BareSpec
                 -> Ms.BareSpec
 makeLiftedSpec0 cfg src embs lmap mySpec = mempty
-  { Ms.ealiases  = lmapEAlias . snd <$> Bare.makeHaskellInlines (typeclass cfg) src embs lmap mySpec 
-  , Ms.reflects  = Ms.reflects mySpec <> (if reflection cfg then Ms.hmeas mySpec else mempty)
-  , Ms.dataDecls = Bare.makeHaskellDataDecls cfg name mySpec tcs  
+  { Ms.ealiases  = lmapEAlias . snd <$> Bare.makeHaskellInlines (typeclass cfg) src embs lmap mySpec
+  , Ms.reflects  = Ms.reflects mySpec
+  , Ms.dataDecls = Bare.makeHaskellDataDecls cfg name mySpec tcs
   , Ms.embeds    = Ms.embeds mySpec
   -- We do want 'embeds' to survive and to be present into the final 'LiftedSpec'. The
   -- caveat is to decide which format is more appropriate. We obviously cannot store
@@ -407,7 +403,7 @@
   -- We do want 'cmeasures' to survive and to be present into the final 'LiftedSpec'. The
   -- caveat is to decide which format is more appropriate. This needs more thinking.
   }
-  where 
+  where
     tcs          = uniqNub (_gsTcs src ++ refTcs)
     refTcs       = reflectedTyCons cfg embs cbs  mySpec
     cbs          = _giCbs       src
@@ -426,7 +422,7 @@
 reflectedTyCons cfg embs cbs spec
   | exactDCFlag cfg = filter (not . isEmbedded embs)
                     $ concatMap varTyCons
-                    $ reflectedVars cfg spec cbs
+                    $ reflectedVars spec cbs ++ measureVars spec cbs
   | otherwise       = []
 
 -- | We cannot reflect embedded tycons (e.g. Bool) as that gives you a sort
@@ -444,66 +440,72 @@
     tc acc t@RApp {} = rtc_tc (rt_tycon t) : acc
     tc acc _         = acc
 
-reflectedVars :: Config -> Ms.BareSpec -> [Ghc.CoreBind] -> [Ghc.Var]
-reflectedVars cfg spec cbs = fst <$> xDefs
+reflectedVars :: Ms.BareSpec -> [Ghc.CoreBind] -> [Ghc.Var]
+reflectedVars spec cbs = fst <$> xDefs
   where
     xDefs              = Mb.mapMaybe (`GM.findVarDef` cbs) reflSyms
-    reflSyms           = fmap val $ S.toList (Ms.reflects spec <> if reflection cfg then Ms.hmeas spec else mempty)
+    reflSyms           = val <$> S.toList (Ms.reflects spec)
 
+measureVars :: Ms.BareSpec -> [Ghc.CoreBind] -> [Ghc.Var]
+measureVars spec cbs = fst <$> xDefs
+  where
+    xDefs              = Mb.mapMaybe (`GM.findVarDef` cbs) measureSyms
+    measureSyms        = val <$> S.toList (Ms.hmeas spec)
+
 ------------------------------------------------------------------------------------------
-makeSpecVars :: Config -> GhcSrc -> Ms.BareSpec -> Bare.Env -> Bare.MeasEnv 
+makeSpecVars :: Config -> GhcSrc -> Ms.BareSpec -> Bare.Env -> Bare.MeasEnv
              -> Bare.Lookup GhcSpecVars
 ------------------------------------------------------------------------------------------
-makeSpecVars cfg src mySpec env measEnv = do 
-  tgtVars     <-   mapM (resolveStringVar  env name)              (checks     cfg) 
-  igVars      <-  sMapM (Bare.lookupGhcVar env name "gs-ignores") (Ms.ignores mySpec) 
+makeSpecVars cfg src mySpec env measEnv = do
+  tgtVars     <-   mapM (resolveStringVar  env name)              (checks     cfg)
+  igVars      <-  sMapM (Bare.lookupGhcVar env name "gs-ignores") (Ms.ignores mySpec)
   lVars       <-  sMapM (Bare.lookupGhcVar env name "gs-lvars"  ) (Ms.lvars   mySpec)
   return (SpVar tgtVars igVars lVars cMethods)
-  where 
-    name       = _giTargetMod src 
-    cMethods   = snd3 <$> Bare.meMethods measEnv 
+  where
+    name       = _giTargetMod src
+    cMethods   = snd3 <$> Bare.meMethods measEnv
 
 sMapM :: (Monad m, Eq b, Hashable b) => (a -> m b) -> S.HashSet a -> m (S.HashSet b)
-sMapM f xSet = do 
- ys <- mapM f (S.toList xSet) 
+sMapM f xSet = do
+ ys <- mapM f (S.toList xSet)
  return (S.fromList ys)
 
 sForM :: (Monad m, Eq b, Hashable b) =>S.HashSet a -> (a -> m b) -> m (S.HashSet b)
 sForM xs f = sMapM f xs
 
-qualifySymbolic :: (F.Symbolic a) => ModName -> a -> F.Symbol 
+qualifySymbolic :: (F.Symbolic a) => ModName -> a -> F.Symbol
 qualifySymbolic name s = GM.qualifySymbol (F.symbol name) (F.symbol s)
 
 resolveStringVar :: Bare.Env -> ModName -> String -> Bare.Lookup Ghc.Var
 resolveStringVar env name s = Bare.lookupGhcVar env name "resolve-string-var" lx
-  where 
+  where
     lx                      = dummyLoc (qualifySymbolic name s)
 
 
 
 ------------------------------------------------------------------------------------------
-makeSpecQual :: Config -> Bare.Env -> Bare.TycEnv -> Bare.MeasEnv -> BareRTEnv -> Bare.ModSpecs 
-             -> GhcSpecQual 
+makeSpecQual :: Config -> Bare.Env -> Bare.TycEnv -> Bare.MeasEnv -> BareRTEnv -> Bare.ModSpecs
+             -> GhcSpecQual
 ------------------------------------------------------------------------------------------
-makeSpecQual _cfg env tycEnv measEnv _rtEnv specs = SpQual 
-  { gsQualifiers = filter okQual quals 
+makeSpecQual _cfg env tycEnv measEnv _rtEnv specs = SpQual
+  { gsQualifiers = filter okQual quals
   , gsRTAliases  = [] -- makeSpecRTAliases env rtEnv -- TODO-REBARE
-  } 
-  where 
-    quals        = concatMap (makeQualifiers env tycEnv) (M.toList specs) 
+  }
+  where
+    quals        = concatMap (makeQualifiers env tycEnv) (M.toList specs)
     -- mSyms        = F.tracepp "MSYMS" $ M.fromList (Bare.meSyms measEnv ++ Bare.meClassSyms measEnv)
-    okQual q     = F.notracepp ("okQual: " ++ F.showpp q) 
+    okQual q     = F.notracepp ("okQual: " ++ F.showpp q)
                    $ all (`S.member` mSyms) (F.syms q)
-    mSyms        = F.notracepp "MSYMS" . S.fromList 
-                   $  (fst <$> wiredSortedSyms) 
-                   ++ (fst <$> Bare.meSyms measEnv) 
+    mSyms        = F.notracepp "MSYMS" . S.fromList
+                   $  (fst <$> wiredSortedSyms)
+                   ++ (fst <$> Bare.meSyms measEnv)
                    ++ (fst <$> Bare.meClassSyms measEnv)
 
 makeQualifiers :: Bare.Env -> Bare.TycEnv -> (ModName, Ms.Spec ty bndr) -> [F.Qualifier]
-makeQualifiers env tycEnv (mod, spec) 
-  = fmap        (Bare.qualifyTopDummy env        mod) 
-  . Mb.mapMaybe (resolveQParams       env tycEnv mod)
-  $ Ms.qualifiers spec 
+makeQualifiers env tycEnv (modn, spec)
+  = fmap        (Bare.qualifyTopDummy env        modn)
+  . Mb.mapMaybe (resolveQParams       env tycEnv modn)
+  $ Ms.qualifiers spec
 
 
 -- | @resolveQualParams@ converts the sorts of parameters from, e.g. 
@@ -512,85 +514,102 @@
 --   It would not be required if _all_ qualifiers are scraped from 
 --   function specs, but we're keeping it around for backwards compatibility.
 
-resolveQParams :: Bare.Env -> Bare.TycEnv -> ModName -> F.Qualifier -> Maybe F.Qualifier 
-resolveQParams env tycEnv name q = do 
-     qps   <- mapM goQP (F.qParams q) 
-     return $ q { F.qParams = qps } 
-  where 
-    goQP qp          = do { s <- go (F.qpSort qp) ; return qp { F.qpSort = s } } 
-    go               :: F.Sort -> Maybe F.Sort   
+resolveQParams :: Bare.Env -> Bare.TycEnv -> ModName -> F.Qualifier -> Maybe F.Qualifier
+resolveQParams env tycEnv name q = do
+     qps   <- mapM goQP (F.qParams q)
+     return $ q { F.qParams = qps }
+  where
+    goQP qp          = do { s <- go (F.qpSort qp) ; return qp { F.qpSort = s } }
+    go               :: F.Sort -> Maybe F.Sort
     go (FAbs i s)    = FAbs i <$> go s
     go (FFunc s1 s2) = FFunc  <$> go s1 <*> go s2
     go (FApp  s1 s2) = FApp   <$> go s1 <*> go s2
-    go (FTC c)       = qualifyFTycon env tycEnv name c 
-    go s             = Just s 
+    go (FTC c)       = qualifyFTycon env tycEnv name c
+    go s             = Just s
 
-qualifyFTycon :: Bare.Env -> Bare.TycEnv -> ModName -> F.FTycon -> Maybe F.Sort 
-qualifyFTycon env tycEnv name c 
-  | isPrimFTC           = Just (FTC c) 
-  | otherwise           = tyConSort embs . F.atLoc tcs <$> ty 
-  where       
-    ty                  = Bare.maybeResolveSym env name "qualify-FTycon" tcs                
-    isPrimFTC           = F.val tcs `elem` F.prims 
+qualifyFTycon :: Bare.Env -> Bare.TycEnv -> ModName -> F.FTycon -> Maybe F.Sort
+qualifyFTycon env tycEnv name c
+  | isPrimFTC           = Just (FTC c)
+  | otherwise           = tyConSort embs . F.atLoc tcs <$> ty
+  where
+    ty                  = Bare.maybeResolveSym env name "qualify-FTycon" tcs
+    isPrimFTC           = F.val tcs `elem` F.prims
     tcs                 = F.fTyconSymbol c
-    embs                = Bare.tcEmbs tycEnv 
+    embs                = Bare.tcEmbs tycEnv
 
-tyConSort :: F.TCEmb Ghc.TyCon -> F.Located Ghc.TyCon -> F.Sort 
+tyConSort :: F.TCEmb Ghc.TyCon -> F.Located Ghc.TyCon -> F.Sort
 tyConSort embs lc = Mb.maybe s0 fst (F.tceLookup c embs)
-  where 
+  where
     c             = F.val lc
     s0            = tyConSortRaw lc
 
-tyConSortRaw :: F.Located Ghc.TyCon -> F.Sort 
-tyConSortRaw = FTC . F.symbolFTycon . fmap F.symbol 
+tyConSortRaw :: F.Located Ghc.TyCon -> F.Sort
+tyConSortRaw = FTC . F.symbolFTycon . fmap F.symbol
 
 ------------------------------------------------------------------------------------------
-makeSpecTerm :: Config -> Ms.BareSpec -> Bare.Env -> ModName -> 
-                Bare.Lookup GhcSpecTerm 
+makeSpecTerm :: Config -> Ms.BareSpec -> Bare.Env -> ModName ->
+                Bare.Lookup GhcSpecTerm
 ------------------------------------------------------------------------------------------
-makeSpecTerm cfg mySpec env name = do 
+makeSpecTerm cfg mySpec env name = do
   sizes  <- if structuralTerm cfg then pure mempty else makeSize env name mySpec
   lazies <- makeLazy     env name mySpec
   autos  <- makeAutoSize env name mySpec
   decr   <- makeDecrs env name mySpec
-  fail   <- makeFail env name mySpec 
-  return  $ SpTerm 
+  gfail  <- makeFail env name mySpec
+  return  $ SpTerm
     { gsLazy       = S.insert dictionaryVar (lazies `mappend` sizes)
-    , gsFail       = fail
+    , gsFail       = gfail
     , gsStTerm     = sizes
-    , gsAutosize   = autos 
-    , gsDecr       = decr 
-    , gsNonStTerm  = mempty 
+    , gsAutosize   = autos
+    , gsDecr       = decr
+    , gsNonStTerm  = mempty
     }
 
 -- formerly, makeHints
-makeDecrs :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup [(Ghc.Var, [Int])] 
+makeDecrs :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup [(Ghc.Var, [Int])]
 makeDecrs env name mySpec =
-  forM (Ms.decr mySpec) $ \(lx, z) -> do 
+  forM (Ms.decr mySpec) $ \(lx, z) -> do
     v <- Bare.lookupGhcVar env name "decreasing" lx
     return (v, z)
 
+makeRelation :: Bare.Env -> ModName -> Bare.SigEnv ->
+  [(LocSymbol, LocSymbol, LocBareType, LocBareType, RelExpr, RelExpr)] -> Bare.Lookup [(Ghc.Var, Ghc.Var, LocSpecType, LocSpecType, RelExpr, RelExpr)]
+makeRelation env name sigEnv = mapM go
+ where
+  go (x, y, tx, ty, a, e) = do
+    vx <- Bare.lookupGhcVar env name "Var" x
+    vy <- Bare.lookupGhcVar env name "Var" y
+    return  
+        ( vx
+        , vy
+        , Bare.cookSpecType env sigEnv name (Bare.HsTV vx) tx
+        , Bare.cookSpecType env sigEnv name (Bare.HsTV vy) ty
+        , a
+        , e
+        )
+
+
 makeLazy :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (S.HashSet Ghc.Var)
 makeLazy env name spec =
   sMapM (Bare.lookupGhcVar env name "Var") (Ms.lazy spec)
 
 makeFail :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (S.HashSet (Located Ghc.Var))
-makeFail env name spec = 
-  sForM (Ms.fails spec) $ \x -> do 
-    vx <- Bare.lookupGhcVar env name "Var" x 
+makeFail env name spec =
+  sForM (Ms.fails spec) $ \x -> do
+    vx <- Bare.lookupGhcVar env name "Var" x
     return x { val = vx }
 
 makeRewrite :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (S.HashSet (Located Ghc.Var))
-makeRewrite env name spec = 
+makeRewrite env name spec =
   sForM (Ms.rewrites spec) $ \x -> do
-    vx <-  Bare.lookupGhcVar env name "Var" x 
+    vx <-  Bare.lookupGhcVar env name "Var" x
     return x { val = vx }
 
 makeRewriteWith :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (M.HashMap Ghc.Var [Ghc.Var])
 makeRewriteWith env name spec = M.fromList <$> makeRewriteWith' env name spec
 
 makeRewriteWith' :: Bare.Env -> ModName -> Spec ty bndr -> Bare.Lookup [(Ghc.Var, [Ghc.Var])]
-makeRewriteWith' env name spec = 
+makeRewriteWith' env name spec =
   forM (M.toList $ Ms.rewriteWith spec) $ \(x, xs) -> do
     xv  <- Bare.lookupGhcVar env name "Var1" x
     xvs <- mapM (Bare.lookupGhcVar env name "Var2") xs
@@ -598,17 +617,17 @@
 
 makeAutoSize :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (S.HashSet Ghc.TyCon)
 makeAutoSize env name
-  = fmap S.fromList 
-  . mapM (Bare.lookupGhcTyCon env name "TyCon") 
-  . S.toList 
-  . Ms.autosize 
+  = fmap S.fromList
+  . mapM (Bare.lookupGhcTyCon env name "TyCon")
+  . S.toList
+  . Ms.autosize
 
 makeSize :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup (S.HashSet Ghc.Var)
 makeSize env name
   = fmap S.fromList
-  . mapM (Bare.lookupGhcVar env name "Var") 
+  . mapM (Bare.lookupGhcVar env name "Var")
   . Mb.mapMaybe getSizeFuns
-  . Ms.dataDecls 
+  . Ms.dataDecls
 
 getSizeFuns :: DataDecl -> Maybe LocSymbol
 getSizeFuns decl
@@ -620,46 +639,54 @@
 
 
 ------------------------------------------------------------------------------------------
-makeSpecLaws :: Bare.Env -> Bare.SigEnv -> [(Ghc.Var,LocSpecType)] -> Bare.MeasEnv -> Bare.ModSpecs 
-             -> GhcSpecLaws 
+makeSpecLaws :: Bare.Env -> Bare.SigEnv -> [(Ghc.Var,LocSpecType)] -> Bare.MeasEnv -> Bare.ModSpecs
+             -> GhcSpecLaws
 ------------------------------------------------------------------------------------------
-makeSpecLaws env sigEnv sigs menv specs = SpLaws 
-  { gsLawDefs = second (map (\(_,x,y) -> (x,y))) <$> Bare.meCLaws menv  
+makeSpecLaws env sigEnv sigs menv specs = SpLaws
+  { gsLawDefs = second (map (\(_,x,y) -> (x,y))) <$> Bare.meCLaws menv
   , gsLawInst = Bare.makeInstanceLaws env sigEnv sigs specs
   }
 
 ------------------------------------------------------------------------------------------
-makeSpecRefl :: Config -> GhcSrc -> Bare.MeasEnv -> Bare.ModSpecs -> Bare.Env -> ModName -> GhcSpecSig -> Bare.TycEnv 
-             -> Bare.Lookup GhcSpecRefl 
+makeSpecRefl :: Config -> GhcSrc -> Bare.MeasEnv -> Bare.ModSpecs -> Bare.Env -> ModName -> GhcSpecSig -> Bare.TycEnv
+             -> Bare.Lookup GhcSpecRefl
 ------------------------------------------------------------------------------------------
-makeSpecRefl cfg src menv specs env name sig tycEnv = do 
-  autoInst <- makeAutoInst env name mySpec 
+makeSpecRefl cfg src menv specs env name sig tycEnv = do
+  autoInst <- makeAutoInst env name mySpec
   rwr      <- makeRewrite env name mySpec
   rwrWith  <- makeRewriteWith env name mySpec
   wRefls   <- Bare.wiredReflects cfg env name sig
   xtes     <- Bare.makeHaskellAxioms cfg src env tycEnv name lmap sig mySpec
-  let myAxioms = [ Bare.qualifyTop env name (F.loc lt) (e {eqName = symbol x}) | (x, lt, e) <- xtes]  
+  let myAxioms =
+        [ Bare.qualifyTop
+            env
+            name
+            (F.loc lt)
+            e {eqName = s, eqRec = S.member s (exprSymbolsSet (eqBody e))}
+        | (x, lt, e) <- xtes
+        , let s = symbol x
+        ]
   let sigVars  = F.notracepp "SIGVARS" $ (fst3 <$> xtes)            -- reflects
                                       ++ (fst  <$> gsAsmSigs sig)   -- assumes
                                       ++ (fst  <$> gsRefSigs sig)
-  return SpRefl 
-    { gsLogicMap   = lmap 
-    , gsAutoInst   = autoInst 
+  return SpRefl
+    { gsLogicMap   = lmap
+    , gsAutoInst   = autoInst
     , gsImpAxioms  = concatMap (Ms.axeqs . snd) (M.toList specs)
-    , gsMyAxioms   = F.notracepp "gsMyAxioms" myAxioms 
+    , gsMyAxioms   = F.notracepp "gsMyAxioms" myAxioms
     , gsReflects   = F.notracepp "gsReflects" (lawMethods ++ filter (isReflectVar rflSyms) sigVars ++ wRefls)
-    , gsHAxioms    = F.notracepp "gsHAxioms" xtes 
+    , gsHAxioms    = F.notracepp "gsHAxioms" xtes
     , gsWiredReft  = wRefls
     , gsRewrites   = rwr
     , gsRewritesWith = rwrWith
     }
   where
-    lawMethods   = F.notracepp "Law Methods" $ concatMap Ghc.classMethods (fst <$> Bare.meCLaws menv) 
-    mySpec       = M.lookupDefault mempty name specs 
+    lawMethods   = F.notracepp "Law Methods" $ concatMap Ghc.classMethods (fst <$> Bare.meCLaws menv)
+    mySpec       = M.lookupDefault mempty name specs
     rflSyms      = S.fromList (getReflects specs)
     lmap         = Bare.reLMap env
 
-isReflectVar :: S.HashSet F.Symbol -> Ghc.Var -> Bool 
+isReflectVar :: S.HashSet F.Symbol -> Ghc.Var -> Bool
 isReflectVar reflSyms v = S.member vx reflSyms
   where
     vx                  = GM.dropModuleNames (symbol v)
@@ -668,7 +695,7 @@
 getReflects  = fmap val . S.toList . S.unions . fmap (names . snd) . M.toList
   where
     names  z = S.unions [ Ms.reflects z, Ms.inlines z, Ms.hmeas z ]
-    
+
 ------------------------------------------------------------------------------------------
 -- | @updateReflSpecSig@ uses the information about reflected functions to update the 
 --   "assumed" signatures. 
@@ -677,7 +704,7 @@
 ------------------------------------------------------------------------------------------
 addReflSigs env name rtEnv refl sig =
   sig { gsRefSigs = F.notracepp ("gsRefSigs for " ++ F.showpp name) $ map expandReflectedSignature reflSigs
-      , gsAsmSigs = F.notracepp ("gsAsmSigs for " ++ F.showpp name) $ (wreflSigs ++ filter notReflected (gsAsmSigs sig))
+      , gsAsmSigs = F.notracepp ("gsAsmSigs for " ++ F.showpp name) (wreflSigs ++ filter notReflected (gsAsmSigs sig))
       }
   where
 
@@ -690,162 +717,166 @@
     expandReflectedSignature :: (Ghc.Var, LocSpecType) -> (Ghc.Var, LocSpecType)
     expandReflectedSignature = fmap (Bare.qualifyExpand env name rtEnv (F.dummyPos "expand-refSigs") [])
 
-    (wreflSigs, reflSigs)   = L.partition ((`elem` gsWiredReft refl) . fst) 
-                                 [ (x, t) | (x, t, _) <- gsHAxioms refl ]   
+    (wreflSigs, reflSigs)   = L.partition ((`elem` gsWiredReft refl) . fst)
+                                 [ (x, t) | (x, t, _) <- gsHAxioms refl ]
     reflected       = fst <$> (wreflSigs ++ reflSigs)
     notReflected xt = fst xt `notElem` reflected
 
-makeAutoInst :: Bare.Env -> ModName -> Ms.BareSpec -> 
+makeAutoInst :: Bare.Env -> ModName -> Ms.BareSpec ->
                 Bare.Lookup (M.HashMap Ghc.Var (Maybe Int))
 makeAutoInst env name spec = M.fromList <$> kvs
-  where 
-    kvs = forM (M.toList (Ms.autois spec)) $ \(k, val) -> do 
+  where
+    kvs = forM (M.toList (Ms.autois spec)) $ \(k, val) -> do
             vk <- Bare.lookupGhcVar env name "Var" k
             return (vk, val)
 
 
 ----------------------------------------------------------------------------------------
 makeSpecSig :: Config -> ModName -> Bare.ModSpecs -> Bare.Env -> Bare.SigEnv -> Bare.TycEnv -> Bare.MeasEnv -> [Ghc.CoreBind]
-            -> Bare.Lookup GhcSpecSig 
+            -> Bare.Lookup GhcSpecSig
 ----------------------------------------------------------------------------------------
-makeSpecSig cfg name specs env sigEnv tycEnv measEnv cbs = do 
+makeSpecSig cfg name specs env sigEnv tycEnv measEnv cbs = do
   mySigs     <- makeTySigs  env sigEnv name mySpec
-  aSigs      <- F.notracepp ("makeSpecSig aSigs " ++ F.showpp name) $ makeAsmSigs env sigEnv name specs 
-  let asmSigs =  Bare.tcSelVars tycEnv 
+  aSigs      <- F.notracepp ("makeSpecSig aSigs " ++ F.showpp name) $ makeAsmSigs env sigEnv name specs
+  let asmSigs =  Bare.tcSelVars tycEnv
               ++ aSigs
               ++ [ (x,t) | (_, x, t) <- concatMap snd (Bare.meCLaws measEnv) ]
-  let tySigs  = strengthenSigs . concat $ 
+  let tySigs  = strengthenSigs . concat $
                   [ [(v, (0, t)) | (v, t,_) <- mySigs                         ]   -- NOTE: these weights are to priortize 
                   , [(v, (1, t)) | (v, t  ) <- makeMthSigs measEnv            ]   -- user defined sigs OVER auto-generated 
                   , [(v, (2, t)) | (v, t  ) <- makeInlSigs env rtEnv allSpecs ]   -- during the strengthening, i.e. to KEEP 
                   , [(v, (3, t)) | (v, t  ) <- makeMsrSigs env rtEnv allSpecs ]   -- the binders used in USER-defined sigs 
                   ]                                                               -- as they appear in termination metrics
-  newTys     <-  makeNewTypes env sigEnv allSpecs 
-  return SpSig 
-    { gsTySigs   = tySigs 
+  newTys     <-  makeNewTypes env sigEnv allSpecs
+  relation   <-  makeRelation env name sigEnv (Ms.relational mySpec)
+  asmRel     <-  makeRelation env name sigEnv (Ms.asmRel mySpec)
+  return SpSig
+    { gsTySigs   = tySigs
     , gsAsmSigs  = asmSigs
-    , gsRefSigs  = [] 
-    , gsDicts    = dicts 
+    , gsRefSigs  = []
+    , gsDicts    = dicts
     -- , gsMethods  = if noclasscheck cfg then [] else Bare.makeMethodTypes dicts (Bare.meClasses  measEnv) cbs 
-    , gsMethods  = if noclasscheck cfg then [] else Bare.makeMethodTypes (typeclass cfg) dicts (Bare.meClasses  measEnv) cbs 
+    , gsMethods  = if noclasscheck cfg then [] else Bare.makeMethodTypes (typeclass cfg) dicts (Bare.meClasses  measEnv) cbs
     , gsInSigs   = mempty
-    , gsNewTypes = newTys 
-    , gsTexprs   = [ (v, t, es) | (v, t, Just es) <- mySigs ] 
-    }
-  where 
-    dicts      = Bare.makeSpecDictionaries env sigEnv specs  
+    , gsNewTypes = newTys
+    , gsTexprs   = [ (v, t, es) | (v, t, Just es) <- mySigs ]
+    , gsRelation = relation
+    , gsAsmRel   = asmRel
+  }
+  where
+    dicts      = Bare.makeSpecDictionaries env sigEnv specs
     mySpec     = M.lookupDefault mempty name specs
-    allSpecs   = M.toList specs 
-    rtEnv      = Bare.sigRTEnv sigEnv 
+    allSpecs   = M.toList specs
+    rtEnv      = Bare.sigRTEnv sigEnv
     -- hmeas      = makeHMeas    env allSpecs 
 
 strengthenSigs :: [(Ghc.Var, (Int, LocSpecType))] ->[(Ghc.Var, LocSpecType)]
-strengthenSigs sigs = go <$> Misc.groupList sigs 
+strengthenSigs sigs = go <$> Misc.groupList sigs
   where
     go (v, ixs)     = (v,) $ L.foldl1' (flip meetLoc) (F.notracepp ("STRENGTHEN-SIGS: " ++ F.showpp v) (prio ixs))
-    prio            = fmap snd . Misc.sortOn fst 
+    prio            = fmap snd . Misc.sortOn fst
     meetLoc         :: LocSpecType -> LocSpecType -> LocSpecType
     meetLoc t1 t2   = t1 {val = val t1 `F.meet` val t2}
 
 makeMthSigs :: Bare.MeasEnv -> [(Ghc.Var, LocSpecType)]
 makeMthSigs measEnv = [ (v, t) | (_, v, t) <- Bare.meMethods measEnv ]
 
-makeInlSigs :: Bare.Env -> BareRTEnv -> [(ModName, Ms.BareSpec)] -> [(Ghc.Var, LocSpecType)] 
-makeInlSigs env rtEnv 
+makeInlSigs :: Bare.Env -> BareRTEnv -> [(ModName, Ms.BareSpec)] -> [(Ghc.Var, LocSpecType)]
+makeInlSigs env rtEnv
   = makeLiftedSigs rtEnv (CoreToLogic.inlineSpecType (typeclass (getConfig env)))
-  . makeFromSet "hinlines" Ms.inlines env 
+  . makeFromSet "hinlines" Ms.inlines env
 
-makeMsrSigs :: Bare.Env -> BareRTEnv -> [(ModName, Ms.BareSpec)] -> [(Ghc.Var, LocSpecType)] 
-makeMsrSigs env rtEnv 
+makeMsrSigs :: Bare.Env -> BareRTEnv -> [(ModName, Ms.BareSpec)] -> [(Ghc.Var, LocSpecType)]
+makeMsrSigs env rtEnv
   = makeLiftedSigs rtEnv (CoreToLogic.inlineSpecType (typeclass (getConfig env)))
-  . makeFromSet "hmeas" Ms.hmeas env 
+  . makeFromSet "hmeas" Ms.hmeas env
 
 makeLiftedSigs :: BareRTEnv -> (Ghc.Var -> SpecType) -> [Ghc.Var] -> [(Ghc.Var, LocSpecType)]
-makeLiftedSigs rtEnv f xs 
+makeLiftedSigs rtEnv f xs
   = [(x, lt) | x <- xs
              , let lx = GM.locNamedThing x
              , let lt = expand $ lx {val = f x}
     ]
   where
-    expand   = Bare.specExpandType rtEnv 
+    expand   = Bare.specExpandType rtEnv
 
-makeFromSet :: String -> (Ms.BareSpec -> S.HashSet LocSymbol) -> Bare.Env -> [(ModName, Ms.BareSpec)] 
-            -> [Ghc.Var] 
-makeFromSet msg f env specs = concat [ mk n xs | (n, s) <- specs, let xs = S.toList (f s)] 
-  where 
-    mk name                 = Mb.mapMaybe (Bare.maybeResolveSym env name msg) 
+makeFromSet :: String -> (Ms.BareSpec -> S.HashSet LocSymbol) -> Bare.Env -> [(ModName, Ms.BareSpec)]
+            -> [Ghc.Var]
+makeFromSet msg f env specs = concat [ mk n xs | (n, s) <- specs, let xs = S.toList (f s)]
+  where
+    mk name                 = Mb.mapMaybe (Bare.maybeResolveSym env name msg)
 
-makeTySigs :: Bare.Env -> Bare.SigEnv -> ModName -> Ms.BareSpec 
+makeTySigs :: Bare.Env -> Bare.SigEnv -> ModName -> Ms.BareSpec
            -> Bare.Lookup [(Ghc.Var, LocSpecType, Maybe [Located F.Expr])]
 makeTySigs env sigEnv name spec = do
-  bareSigs   <- bareTySigs env name                spec 
-  expSigs    <- makeTExpr  env name bareSigs rtEnv spec 
-  let rawSigs = Bare.resolveLocalBinds env expSigs 
+  bareSigs   <- bareTySigs env name                spec
+  expSigs    <- makeTExpr  env name bareSigs rtEnv spec
+  let rawSigs = Bare.resolveLocalBinds env expSigs
   return [ (x, cook x bt, z) | (x, bt, z) <- rawSigs ]
-  where 
-    rtEnv     = Bare.sigRTEnv sigEnv 
-    cook x bt = Bare.cookSpecType env sigEnv name (Bare.HsTV x) bt 
+  where
+    rtEnv     = Bare.sigRTEnv sigEnv
+    cook x bt = Bare.cookSpecType env sigEnv name (Bare.HsTV x) bt
 
 bareTySigs :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup [(Ghc.Var, LocBareType)]
-bareTySigs env name spec = checkDuplicateSigs <$> vts 
-  where 
-    vts = forM ( Ms.sigs spec ++ Ms.localSigs spec ) $ \ (x, t) -> do 
+bareTySigs env name spec = checkDuplicateSigs <$> vts
+  where
+    vts = forM ( Ms.sigs spec ++ Ms.localSigs spec ) $ \ (x, t) -> do
             v <- F.notracepp "LOOKUP-GHC-VAR" $ Bare.lookupGhcVar env name "rawTySigs" x
-            return (v, t) 
+            return (v, t)
 
 -- checkDuplicateSigs :: [(Ghc.Var, LocSpecType)] -> [(Ghc.Var, LocSpecType)] 
 checkDuplicateSigs :: (Symbolic x) => [(x, F.Located t)] -> [(x, F.Located t)]
 checkDuplicateSigs xts = case Misc.uniqueByKey symXs  of
   Left (k, ls) -> uError (errDupSpecs (pprint k) (GM.sourcePosSrcSpan <$> ls))
-  Right _      -> xts 
+  Right _      -> xts
   where
     symXs = [ (F.symbol x, F.loc t) | (x, t) <- xts ]
 
 
 makeAsmSigs :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.ModSpecs -> Bare.Lookup [(Ghc.Var, LocSpecType)]
-makeAsmSigs env sigEnv myName specs = do 
+makeAsmSigs env sigEnv myName specs = do
   raSigs <- rawAsmSigs env myName specs
-  return [ (x, t) | (name, x, bt) <- raSigs, let t = Bare.cookSpecType env sigEnv name (Bare.LqTV x) bt ] 
+  return [ (x, t) | (name, x, bt) <- raSigs, let t = Bare.cookSpecType env sigEnv name (Bare.LqTV x) bt ]
 
 rawAsmSigs :: Bare.Env -> ModName -> Bare.ModSpecs -> Bare.Lookup [(ModName, Ghc.Var, LocBareType)]
-rawAsmSigs env myName specs = do 
-  aSigs <- allAsmSigs env myName specs 
-  return [ (m, v, t) | (v, sigs) <- aSigs, let (m, t) = myAsmSig v sigs ] 
-    
+rawAsmSigs env myName specs = do
+  aSigs <- allAsmSigs env myName specs
+  return [ (m, v, t) | (v, sigs) <- aSigs, let (m, t) = myAsmSig v sigs ]
+
 myAsmSig :: Ghc.Var -> [(Bool, ModName, LocBareType)] -> (ModName, LocBareType)
-myAsmSig v sigs = Mb.fromMaybe errImp (Misc.firstMaybes [mbHome, mbImp]) 
-  where 
-    mbHome      = takeUnique err                  sigsHome 
-    mbImp       = takeUnique err (Misc.firstGroup sigsImp) -- see [NOTE:Prioritize-Home-Spec] 
+myAsmSig v sigs = Mb.fromMaybe errImp (Misc.firstMaybes [mbHome, mbImp])
+  where
+    mbHome      = takeUnique mkErr                  sigsHome
+    mbImp       = takeUnique mkErr (Misc.firstGroup sigsImp) -- see [NOTE:Prioritize-Home-Spec] 
     sigsHome    = [(m, t)      | (True,  m, t) <- sigs ]
     sigsImp     = F.notracepp ("SIGS-IMP: " ++ F.showpp v)
                   [(d, (m, t)) | (False, m, t) <- sigs, let d = nameDistance vName m]
-    err ts      = ErrDupSpecs (Ghc.getSrcSpan v) (F.pprint v) (GM.sourcePosSrcSpan . F.loc . snd <$> ts) :: UserError
+    mkErr ts    = ErrDupSpecs (Ghc.getSrcSpan v) (F.pprint v) (GM.sourcePosSrcSpan . F.loc . snd <$> ts) :: UserError
     errImp      = impossible Nothing "myAsmSig: cannot happen as sigs is non-null"
     vName       = GM.takeModuleNames (F.symbol v)
 
-makeTExpr :: Bare.Env -> ModName -> [(Ghc.Var, LocBareType)] -> BareRTEnv -> Ms.BareSpec 
+makeTExpr :: Bare.Env -> ModName -> [(Ghc.Var, LocBareType)] -> BareRTEnv -> Ms.BareSpec
           -> Bare.Lookup [(Ghc.Var, LocBareType, Maybe [Located F.Expr])]
-makeTExpr env name tySigs rtEnv spec = do 
+makeTExpr env name tySigs rtEnv spec = do
   vExprs       <- M.fromList <$> makeVarTExprs env name spec
-  let vSigExprs = Misc.hashMapMapWithKey (\v t -> (t, M.lookup v vExprs)) vSigs 
-  return [ (v, t, qual t <$> es) | (v, (t, es)) <- M.toList vSigExprs ] 
-  where 
+  let vSigExprs = Misc.hashMapMapWithKey (\v t -> (t, M.lookup v vExprs)) vSigs
+  return [ (v, t, qual t <$> es) | (v, (t, es)) <- M.toList vSigExprs ]
+  where
     qual t es   = qualifyTermExpr env name rtEnv t <$> es
-    vSigs       = M.fromList tySigs 
-                    
-qualifyTermExpr :: Bare.Env -> ModName -> BareRTEnv -> LocBareType -> Located F.Expr 
-                -> Located F.Expr 
-qualifyTermExpr env name rtEnv t le 
+    vSigs       = M.fromList tySigs
+
+qualifyTermExpr :: Bare.Env -> ModName -> BareRTEnv -> LocBareType -> Located F.Expr
+                -> Located F.Expr
+qualifyTermExpr env name rtEnv t le
         = F.atLoc le (Bare.qualifyExpand env name rtEnv l bs e)
-  where 
-    l   = F.loc le 
-    e   = F.val le 
-    bs  = ty_binds . toRTypeRep . val $ t 
+  where
+    l   = F.loc le
+    e   = F.val le
+    bs  = ty_binds . toRTypeRep . val $ t
 
 makeVarTExprs :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.Lookup [(Ghc.Var, [Located F.Expr])]
-makeVarTExprs env name spec = 
-  forM (Ms.termexprs spec) $ \(x, es) -> do 
+makeVarTExprs env name spec =
+  forM (Ms.termexprs spec) $ \(x, es) -> do
     vx <- Bare.lookupGhcVar env name "Var" x
     return (vx, es)
 
@@ -865,20 +896,20 @@
 -- modules and such (see `Resolve.matchMod`). However, we should pick the closer name
 -- if its available.
 ----------------------------------------------------------------------------------------
-nameDistance :: F.Symbol -> ModName -> Int 
-nameDistance vName tName 
-  | vName == F.symbol tName = 0 
+nameDistance :: F.Symbol -> ModName -> Int
+nameDistance vName tName
+  | vName == F.symbol tName = 0
   | otherwise               = 1
 
 
 takeUnique :: Ex.Exception e => ([a] -> e) -> [a] -> Maybe a
-takeUnique _ []  = Nothing 
-takeUnique _ [x] = Just x 
-takeUnique f xs  = Ex.throw (f xs) 
+takeUnique _ []  = Nothing
+takeUnique _ [x] = Just x
+takeUnique f xs  = Ex.throw (f xs)
 
-allAsmSigs :: Bare.Env -> ModName -> Bare.ModSpecs -> 
+allAsmSigs :: Bare.Env -> ModName -> Bare.ModSpecs ->
               Bare.Lookup [(Ghc.Var, [(Bool, ModName, LocBareType)])]
-allAsmSigs env myName specs = do 
+allAsmSigs env myName specs = do
   let aSigs = [ (name, must, x, t) | (name, spec) <- M.toList specs
                                    , (must, x, t) <- getAsmSigs myName name spec ]
   vSigs    <- forM aSigs $ \(name, must, x, t) -> do
@@ -891,14 +922,14 @@
 resolveAsmVar env name False lx = return $  Bare.maybeResolveSym     env name "resolveAsmVar-False" lx  <|> GM.maybeAuxVar (F.val lx)
 
 
-getAsmSigs :: ModName -> ModName -> Ms.BareSpec -> [(Bool, LocSymbol, LocBareType)]  
-getAsmSigs myName name spec 
+getAsmSigs :: ModName -> ModName -> Ms.BareSpec -> [(Bool, LocSymbol, LocBareType)]
+getAsmSigs myName name spec
   | myName == name = [ (True,  x,  t) | (x, t) <- Ms.asmSigs spec ] -- MUST    resolve, or error
-  | otherwise      = [ (False, x', t) | (x, t) <- Ms.asmSigs spec 
+  | otherwise      = [ (False, x', t) | (x, t) <- Ms.asmSigs spec
                                                   ++ Ms.sigs spec
                                       , let x' = qSym x           ]  -- MAY-NOT resolve
-  where 
-    qSym           = fmap (GM.qualifySymbol ns) 
+  where
+    qSym           = fmap (GM.qualifySymbol ns)
     ns             = F.symbol name
 
 -- TODO-REBARE: grepClassAssumes
@@ -909,52 +940,51 @@
     goOne (x, RIAssumed t) = Just (fmap (F.symbol . (".$c" ++ ) . F.symbolString) x, t)
     goOne (_, RISig _)     = Nothing
 
-makeSigEnv :: F.TCEmb Ghc.TyCon -> Bare.TyConMap -> S.HashSet StableName -> BareRTEnv -> Bare.SigEnv 
+makeSigEnv :: F.TCEmb Ghc.TyCon -> Bare.TyConMap -> S.HashSet StableName -> BareRTEnv -> Bare.SigEnv
 makeSigEnv embs tyi exports rtEnv = Bare.SigEnv
-  { sigEmbs     = embs 
-  , sigTyRTyMap = tyi 
-  , sigExports  = exports 
+  { sigEmbs     = embs
+  , sigTyRTyMap = tyi
+  , sigExports  = exports
   , sigRTEnv    = rtEnv
-  } 
+  }
 
-makeNewTypes :: Bare.Env -> Bare.SigEnv -> [(ModName, Ms.BareSpec)] -> 
+makeNewTypes :: Bare.Env -> Bare.SigEnv -> [(ModName, Ms.BareSpec)] ->
                 Bare.Lookup [(Ghc.TyCon, LocSpecType)]
-makeNewTypes env sigEnv specs = do 
-  fmap concat $ 
-    forM nameDecls $ \(name, d) -> 
-      makeNewType env sigEnv name d
+makeNewTypes env sigEnv specs = do
+  fmap concat $
+    forM nameDecls $ uncurry (makeNewType env sigEnv)
   where
-    nameDecls = [(name, d) | (name, spec) <- specs, d <- Ms.newtyDecls spec] 
+    nameDecls = [(name, d) | (name, spec) <- specs, d <- Ms.newtyDecls spec]
 
-makeNewType :: Bare.Env -> Bare.SigEnv -> ModName -> DataDecl -> 
+makeNewType :: Bare.Env -> Bare.SigEnv -> ModName -> DataDecl ->
                Bare.Lookup [(Ghc.TyCon, LocSpecType)]
-makeNewType env sigEnv name d = do 
+makeNewType env sigEnv name d = do
   tcMb <- Bare.lookupGhcDnTyCon env name "makeNewType" tcName
   case tcMb of
-    Just tc -> return [(tc, t)] 
+    Just tc -> return [(tc, lst)]
     _       -> return []
-  where 
+  where
     tcName                    = tycName d
-    t                         = Bare.cookSpecType env sigEnv name Bare.GenTV bt
+    lst                       = Bare.cookSpecType env sigEnv name Bare.GenTV bt
     bt                        = getTy tcName (tycSrcPos d) (Mb.fromMaybe [] (tycDCons d))
     getTy _ l [c]
       | [(_, t)] <- dcFields c = Loc l l t
-    getTy n l _                = Ex.throw (err n l) 
-    err n l                    = ErrOther (GM.sourcePosSrcSpan l) ("Bad new type declaration:" <+> F.pprint n) :: UserError
+    getTy n l _                = Ex.throw (mkErr n l)
+    mkErr n l                  = ErrOther (GM.sourcePosSrcSpan l) ("Bad new type declaration:" <+> F.pprint n) :: UserError
 
 ------------------------------------------------------------------------------------------
 makeSpecData :: GhcSrc -> Bare.Env -> Bare.SigEnv -> Bare.MeasEnv -> GhcSpecSig -> Bare.ModSpecs
              -> GhcSpecData
 ------------------------------------------------------------------------------------------
-makeSpecData src env sigEnv measEnv sig specs = SpData 
-  { gsCtors      = F.notracepp "GS-CTORS" 
-                   [ (x, if allowTC then t else tt) 
+makeSpecData src env sigEnv measEnv sig specs = SpData
+  { gsCtors      = F.notracepp "GS-CTORS"
+                   [ (x, if allowTC then t else tt)
                        | (x, t) <- Bare.meDataCons measEnv
-                       , let tt  = Bare.plugHoles (typeclass $ getConfig env) sigEnv name (Bare.LqTV x) t 
+                       , let tt  = Bare.plugHoles (typeclass $ getConfig env) sigEnv name (Bare.LqTV x) t
                    ]
-  , gsMeas       = [ (F.symbol x, uRType <$> t) | (x, t) <- measVars ] 
+  , gsMeas       = [ (F.symbol x, uRType <$> t) | (x, t) <- measVars ]
   , gsMeasures   = Bare.qualifyTopDummy env name <$> (ms1 ++ ms2)
-  , gsInvariants = Misc.nubHashOn (F.loc . snd) invs 
+  , gsInvariants = Misc.nubHashOn (F.loc . snd) invs
   , gsIaliases   = concatMap (makeIAliases env sigEnv) (M.toList specs)
   , gsUnsorted   = usI ++ concatMap msUnSorted (concatMap measures specs)
   }
@@ -963,39 +993,52 @@
     measVars     = Bare.meSyms      measEnv -- ms'
                 ++ Bare.meClassSyms measEnv -- cms' 
                 ++ Bare.varMeasures env
-    measuresSp   = Bare.meMeasureSpec measEnv  
+    measuresSp   = Bare.meMeasureSpec measEnv
     ms1          = M.elems (Ms.measMap measuresSp)
     ms2          = Ms.imeas   measuresSp
     mySpec       = M.lookupDefault mempty name specs
     name         = _giTargetMod      src
     (minvs,usI)  = makeMeasureInvariants env name sig mySpec
-    invs         = minvs ++ concat (makeInvariants env sigEnv <$> M.toList specs)
+    invs         = minvs ++ concatMap (makeInvariants env sigEnv) (M.toList specs)
 
 makeIAliases :: Bare.Env -> Bare.SigEnv -> (ModName, Ms.BareSpec) -> [(LocSpecType, LocSpecType)]
 makeIAliases env sigEnv (name, spec)
   = [ z | Right z <- mkIA <$> Ms.ialiases spec ]
-  where 
+  where
     -- mkIA :: (LocBareType, LocBareType) -> Either _ (LocSpecType, LocSpecType)
-    mkIA (t1, t2) = (,) <$> mkI t1 <*> mkI t2
-    mkI           = Bare.cookSpecTypeE env sigEnv name Bare.GenTV 
+    mkIA (t1, t2) = (,) <$> mkI' t1 <*> mkI' t2
+    mkI'          = Bare.cookSpecTypeE env sigEnv name Bare.GenTV
 
 makeInvariants :: Bare.Env -> Bare.SigEnv -> (ModName, Ms.BareSpec) -> [(Maybe Ghc.Var, Located SpecType)]
-makeInvariants env sigEnv (name, spec) = 
-  [ (Nothing, t) 
-    | (_, bt) <- Ms.invariants spec 
+makeInvariants env sigEnv (name, spec) =
+  [ (Nothing, t)
+    | (_, bt) <- Ms.invariants spec
     , Bare.knownGhcType env name bt
     , let t = Bare.cookSpecType env sigEnv name Bare.GenTV bt
+  ] ++
+  concat [ (Nothing,) . makeSizeInv l <$>  ts
+    | (bts, l) <- Ms.dsize spec
+    , all (Bare.knownGhcType env name) bts
+    , let ts = Bare.cookSpecType env sigEnv name Bare.GenTV <$> bts
   ]
 
-makeMeasureInvariants :: Bare.Env -> ModName -> GhcSpecSig -> Ms.BareSpec 
+makeSizeInv :: F.LocSymbol -> Located SpecType -> Located SpecType
+makeSizeInv s lst = lst{val = go (val lst)}
+  where go (RApp c ts rs r) = RApp c ts rs (r `meet` nat)
+        go (RAllT a t r)    = RAllT a (go t) r
+        go t = t
+        nat  = MkUReft (Reft (vv_, PAtom Le (ECon $ I 0) (EApp (EVar $ val s) (eVar vv_))))
+                       mempty
+
+makeMeasureInvariants :: Bare.Env -> ModName -> GhcSpecSig -> Ms.BareSpec
                       -> ([(Maybe Ghc.Var, LocSpecType)], [UnSortedExpr])
-makeMeasureInvariants env name sig mySpec 
-  = mapSnd Mb.catMaybes $ 
+makeMeasureInvariants env name sig mySpec
+  = mapSnd Mb.catMaybes $
     unzip (measureTypeToInv env name <$> [(x, (y, ty)) | x <- xs, (y, ty) <- sigs
                                          , isSymbolOfVar (val x) y ])
-  where 
-    sigs = gsTySigs sig 
-    xs   = S.toList (Ms.hmeas  mySpec) 
+  where
+    sigs = gsTySigs sig
+    xs   = S.toList (Ms.hmeas  mySpec)
 
 isSymbolOfVar :: Symbol -> Ghc.Var -> Bool
 isSymbolOfVar x v = x == symbol' v
@@ -1004,88 +1047,88 @@
     symbol' = GM.dropModuleNames . symbol . Ghc.getName
 
 measureTypeToInv :: Bare.Env -> ModName -> (LocSymbol, (Ghc.Var, LocSpecType)) -> ((Maybe Ghc.Var, LocSpecType), Maybe UnSortedExpr)
-measureTypeToInv env name (x, (v, t)) 
-  = notracepp "measureTypeToInv" $ ((Just v, t {val = Bare.qualifyTop env name (F.loc x) mtype}), usorted)
+measureTypeToInv env name (x, (v, t))
+  = notracepp "measureTypeToInv" ((Just v, t {val = Bare.qualifyTop env name (F.loc x) mtype}), usorted)
   where
     trep = toRTypeRep (val t)
-    ts   = ty_args  trep
+    rts  = ty_args  trep
     args = ty_binds trep
     res  = ty_res   trep
     z    = last args
-    tz   = last ts
-    usorted = if isSimpleADT tz then Nothing else ((mapFst (:[])) <$> mkReft (dummyLoc $ F.symbol v) z tz res)
+    tz   = last rts
+    usorted = if isSimpleADT tz then Nothing else mapFst (:[]) <$> mkReft (dummyLoc $ F.symbol v) z tz res
     mtype
-      | null ts 
+      | null rts
       = uError $ ErrHMeas (GM.sourcePosSrcSpan $ loc t) (pprint x) "Measure has no arguments!"
-      | otherwise 
-      = mkInvariant x z tz res 
-    isSimpleADT (RApp _ ts _ _) = all isRVar ts 
-    isSimpleADT _               = False 
+      | otherwise
+      = mkInvariant x z tz res
+    isSimpleADT (RApp _ ts _ _) = all isRVar ts
+    isSimpleADT _               = False
 
 mkInvariant :: LocSymbol -> Symbol -> SpecType -> SpecType -> SpecType
-mkInvariant x z t tr = strengthen (top <$> t) (MkUReft reft mempty)
+mkInvariant x z t tr = strengthen (top <$> t) (MkUReft reft' mempty)
       where
-        reft  = Mb.maybe mempty Reft mreft
-        mreft = mkReft x z t tr 
+        reft' = Mb.maybe mempty Reft mreft
+        mreft = mkReft x z t tr
 
 
 mkReft :: LocSymbol -> Symbol -> SpecType -> SpecType -> Maybe (Symbol, Expr)
-mkReft x z _t tr 
+mkReft x z _t tr
   | Just q <- stripRTypeBase tr
   = let Reft (v, p) = toReft q
         su          = mkSubst [(v, mkEApp x [EVar v]), (z,EVar v)]
         -- p'          = pAnd $ filter (\e -> z `notElem` syms e) $ conjuncts p
     in  Just (v, subst su p)
-mkReft _ _ _ _  
-  = Nothing 
+mkReft _ _ _ _
+  = Nothing
 
 
 -- REBARE: formerly, makeGhcSpec3
 -------------------------------------------------------------------------------------------
 makeSpecName :: Bare.Env -> Bare.TycEnv -> Bare.MeasEnv -> ModName -> GhcSpecNames
 -------------------------------------------------------------------------------------------
-makeSpecName env tycEnv measEnv name = SpNames 
-  { gsFreeSyms = Bare.reSyms env 
-  , gsDconsP   = [ F.atLoc dc (dcpCon dc) | dc <- datacons ++ cls ] 
-  , gsTconsP   = Bare.qualifyTopDummy env name <$> tycons                
+makeSpecName env tycEnv measEnv name = SpNames
+  { gsFreeSyms = Bare.reSyms env
+  , gsDconsP   = [ F.atLoc dc (dcpCon dc) | dc <- datacons ++ cls ]
+  , gsTconsP   = Bare.qualifyTopDummy env name <$> tycons
   -- , gsLits = mempty                                              -- TODO-REBARE, redundant with gsMeas
-  , gsTcEmbeds = Bare.tcEmbs     tycEnv   
-  , gsADTs     = Bare.tcAdts     tycEnv 
-  , gsTyconEnv = Bare.tcTyConMap tycEnv  
+  , gsTcEmbeds = Bare.tcEmbs     tycEnv
+  , gsADTs     = Bare.tcAdts     tycEnv
+  , gsTyconEnv = Bare.tcTyConMap tycEnv
   }
-  where 
+  where
     datacons, cls :: [DataConP]
-    datacons   = Bare.tcDataCons tycEnv 
-    cls        = F.notracepp "meClasses" $ Bare.meClasses measEnv 
-    tycons     = Bare.tcTyCons   tycEnv 
+    datacons   = Bare.tcDataCons tycEnv
+    cls        = F.notracepp "meClasses" $ Bare.meClasses measEnv
+    tycons     = Bare.tcTyCons   tycEnv
 
 
 -- REBARE: formerly, makeGhcCHOP1
 -- split into two to break circular dependency. we need dataconmap for core2logic
 -------------------------------------------------------------------------------------------
-makeTycEnv0 :: Config -> ModName -> Bare.Env -> TCEmb Ghc.TyCon -> Ms.BareSpec -> Bare.ModSpecs 
+makeTycEnv0 :: Config -> ModName -> Bare.Env -> TCEmb Ghc.TyCon -> Ms.BareSpec -> Bare.ModSpecs
            -> (Diagnostics,  [Located DataConP], Bare.TycEnv)
 -------------------------------------------------------------------------------------------
-makeTycEnv0 cfg myName env embs mySpec iSpecs = (diag0 <> diag1, datacons, Bare.TycEnv 
-  { tcTyCons      = tycons                  
+makeTycEnv0 cfg myName env embs mySpec iSpecs = (diag0 <> diag1, datacons, Bare.TycEnv
+  { tcTyCons      = tycons
   , tcDataCons    = mempty -- val <$> datacons 
-  , tcSelMeasures = dcSelectors             
+  , tcSelMeasures = dcSelectors
   , tcSelVars     = mempty -- recSelectors            
-  , tcTyConMap    = tyi                     
-  , tcAdts        = adts                    
+  , tcTyConMap    = tyi
+  , tcAdts        = adts
   , tcDataConMap  = dm
   , tcEmbs        = embs
   , tcName        = myName
   })
   where
     (tcDds, dcs)   = conTys
-    (diag0, conTys) = withDiagnostics $ Bare.makeConTypes myName env specs 
+    (diag0, conTys) = withDiagnostics $ Bare.makeConTypes myName env specs
     specs         = (myName, mySpec) : M.toList iSpecs
-    tcs           = Misc.snd3 <$> tcDds 
+    tcs           = Misc.snd3 <$> tcDds
     tyi           = Bare.qualifyTopDummy env myName (makeTyConInfo embs fiTcs tycons)
     -- tycons        = F.tracepp "TYCONS" $ Misc.replaceWith tcpCon tcs wiredTyCons
     -- datacons      =  Bare.makePluggedDataCons embs tyi (Misc.replaceWith (dcpCon . val) (F.tracepp "DATACONS" $ concat dcs) wiredDataCons)
-    tycons        = tcs ++ knownWiredTyCons env myName 
+    tycons        = tcs ++ knownWiredTyCons env myName
     datacons      = Bare.makePluggedDataCon (typeclass cfg) embs tyi <$> (concat dcs ++ knownWiredDataCons env myName)
     tds           = [(name, tcpCon tcp, dd) | (name, tcp, Just dd) <- tcDds]
     (diag1, adts) = Bare.makeDataDecls cfg embs myName tds       datacons
@@ -1096,14 +1139,13 @@
 
 
 makeTycEnv1 ::
-     Config 
-  -> ModName
+     ModName
   -> Bare.Env
   -> (Bare.TycEnv, [Located DataConP])
   -> (Ghc.CoreExpr -> F.Expr)
   -> (Ghc.CoreExpr -> Ghc.TcRn Ghc.CoreExpr)
   -> Ghc.TcRn Bare.TycEnv
-makeTycEnv1 cfg myName env (tycEnv, datacons) coreToLg simplifier = do
+makeTycEnv1 myName env (tycEnv, datacons) coreToLg simplifier = do
   -- fst for selector generation, snd for dataconsig generation
   lclassdcs <- forM classdcs $ traverse (Bare.elaborateClassDcp coreToLg simplifier)
   let recSelectors = Bare.makeRecordSelectorSigs env myName (dcs ++ (fmap . fmap) snd lclassdcs)
@@ -1114,27 +1156,27 @@
       L.partition
         (Ghc.isClassTyCon . Ghc.dataConTyCon . dcpCon . F.val) datacons
 
-    
-knownWiredDataCons :: Bare.Env -> ModName -> [Located DataConP] 
-knownWiredDataCons env name = filter isKnown wiredDataCons 
-  where 
+
+knownWiredDataCons :: Bare.Env -> ModName -> [Located DataConP]
+knownWiredDataCons env name = filter isKnown wiredDataCons
+  where
     isKnown                 = Bare.knownGhcDataCon env name . GM.namedLocSymbol . dcpCon . val
 
-knownWiredTyCons :: Bare.Env -> ModName -> [TyConP] 
-knownWiredTyCons env name = filter isKnown wiredTyCons 
-  where 
-    isKnown               = Bare.knownGhcTyCon env name . GM.namedLocSymbol . tcpCon 
+knownWiredTyCons :: Bare.Env -> ModName -> [TyConP]
+knownWiredTyCons env name = filter isKnown wiredTyCons
+  where
+    isKnown               = Bare.knownGhcTyCon env name . GM.namedLocSymbol . tcpCon
 
 
 -- REBARE: formerly, makeGhcCHOP2
 -------------------------------------------------------------------------------------------
-makeMeasEnv :: Bare.Env -> Bare.TycEnv -> Bare.SigEnv -> Bare.ModSpecs -> 
-               Bare.Lookup Bare.MeasEnv 
+makeMeasEnv :: Bare.Env -> Bare.TycEnv -> Bare.SigEnv -> Bare.ModSpecs ->
+               Bare.Lookup Bare.MeasEnv
 -------------------------------------------------------------------------------------------
-makeMeasEnv env tycEnv sigEnv specs = do 
+makeMeasEnv env tycEnv sigEnv specs = do
   laws        <- Bare.makeCLaws env sigEnv name specs
   (cls, mts)  <- Bare.makeClasses        env sigEnv name specs
-  let dms      = Bare.makeDefaultMethods env mts  
+  let dms      = Bare.makeDefaultMethods env mts
   measures0   <- mapM (Bare.makeMeasureSpec env sigEnv name) (M.toList specs)
   let measures = mconcat (Ms.mkMSpec' dcSelectors : measures0)
   let (cs, ms) = Bare.makeMeasureSpec'  (typeclass $ getConfig env)   measures
@@ -1143,21 +1185,21 @@
   let ms'      = [ (F.val lx, F.atLoc lx t) | (lx, t) <- ms
                                             , Mb.isNothing (lookup (val lx) cms') ]
   let cs'      = [ (v, txRefs v t) | (v, t) <- Bare.meetDataConSpec (typeclass (getConfig env)) embs cs (datacons ++ cls)]
-  return Bare.MeasEnv 
-    { meMeasureSpec = measures 
-    , meClassSyms   = cms' 
-    , meSyms        = ms' 
-    , meDataCons    = cs' 
+  return Bare.MeasEnv
+    { meMeasureSpec = measures
+    , meClassSyms   = cms'
+    , meSyms        = ms'
+    , meDataCons    = cs'
     , meClasses     = cls
-    , meMethods     = mts ++ dms 
+    , meMethods     = mts ++ dms
     , meCLaws       = laws
     }
-  where 
-    txRefs v t    = Bare.txRefSort tyi embs (t <$ GM.locNamedThing v) 
-    tyi           = Bare.tcTyConMap    tycEnv 
-    dcSelectors   = Bare.tcSelMeasures tycEnv 
-    datacons      = Bare.tcDataCons    tycEnv 
-    embs          = Bare.tcEmbs        tycEnv 
+  where
+    txRefs v t    = Bare.txRefSort tyi embs (t <$ GM.locNamedThing v)
+    tyi           = Bare.tcTyConMap    tycEnv
+    dcSelectors   = Bare.tcSelMeasures tycEnv
+    datacons      = Bare.tcDataCons    tycEnv
+    embs          = Bare.tcEmbs        tycEnv
     name          = Bare.tcName        tycEnv
 
 -----------------------------------------------------------------------------------------
@@ -1165,42 +1207,42 @@
 --   so that downstream files that import this target can access the lifted definitions, 
 --   e.g. for measures, reflected functions etc.
 -----------------------------------------------------------------------------------------
-makeLiftedSpec :: ModName -> GhcSrc -> Bare.Env 
-               -> GhcSpecRefl -> GhcSpecData -> GhcSpecSig -> GhcSpecQual -> BareRTEnv 
-               -> Ms.BareSpec -> Ms.BareSpec 
+makeLiftedSpec :: ModName -> GhcSrc -> Bare.Env
+               -> GhcSpecRefl -> GhcSpecData -> GhcSpecSig -> GhcSpecQual -> BareRTEnv
+               -> Ms.BareSpec -> Ms.BareSpec
 -----------------------------------------------------------------------------------------
-makeLiftedSpec name src _env refl sData sig qual myRTE lSpec0 = lSpec0 
-  { Ms.asmSigs    = F.notracepp   ("makeLiftedSpec : ASSUMED-SIGS " ++ F.showpp name ) $ (xbs ++ myDCs) 
+makeLiftedSpec name src _env refl sData sig qual myRTE lSpec0 = lSpec0
+  { Ms.asmSigs    = F.notracepp   ("makeLiftedSpec : ASSUMED-SIGS " ++ F.showpp name ) (xbs ++ myDCs)
   , Ms.reflSigs   = F.notracepp "REFL-SIGS"         xbs
-  , Ms.sigs       = F.notracepp   ("makeLiftedSpec : LIFTED-SIGS " ++ F.showpp name )  $ mkSigs (gsTySigs sig)  
-  , Ms.invariants = [ ((varLocSym <$> x), Bare.specToBare <$> t) 
-                       | (x, t) <- gsInvariants sData 
+  , Ms.sigs       = F.notracepp   ("makeLiftedSpec : LIFTED-SIGS " ++ F.showpp name )  $ mkSigs (gsTySigs sig)
+  , Ms.invariants = [ (varLocSym <$> x, Bare.specToBare <$> t)
+                       | (x, t) <- gsInvariants sData
                        , isLocInFile srcF t
                     ]
-  , Ms.axeqs      = gsMyAxioms refl 
+  , Ms.axeqs      = gsMyAxioms refl
   , Ms.aliases    = F.notracepp "MY-ALIASES" $ M.elems . typeAliases $ myRTE
-  , Ms.ealiases   = M.elems . exprAliases $ myRTE 
+  , Ms.ealiases   = M.elems . exprAliases $ myRTE
   , Ms.qualifiers = filter (isLocInFile srcF) (gsQualifiers qual)
   }
   where
     myDCs         = [(x,t) | (x,t) <- mkSigs (gsCtors sData)
                            , F.symbol name == fst (GM.splitModuleName $ val x)]
     mkSigs xts    = [ toBare (x, t) | (x, t) <- xts
-                    ,  S.member x sigVars && (isExportedVar (view targetSrcIso src) x) 
-                    ] 
+                    ,  S.member x sigVars && isExportedVar (view targetSrcIso src) x
+                    ]
     toBare (x, t) = (varLocSym x, Bare.specToBare <$> t)
-    xbs           = toBare <$> reflTySigs 
+    xbs           = toBare <$> reflTySigs
     sigVars       = S.difference defVars reflVars
     defVars       = S.fromList (_giDefVars src)
     reflTySigs    = [(x, t) | (x,t,_) <- gsHAxioms refl, x `notElem` gsWiredReft refl]
     reflVars      = S.fromList (fst <$> reflTySigs)
     -- myAliases fld = M.elems . fld $ myRTE 
-    srcF          = _giTarget src 
+    srcF          = _giTarget src
 
 -- | Returns 'True' if the input determines a location within the input file. Due to the fact we might have
 -- Haskell sources which have \"companion\" specs defined alongside them, we also need to account for this
 -- case, by stripping out the extensions and check that the LHS is a Haskell source and the RHS a spec file.
-isLocInFile :: (F.Loc a) => FilePath -> a ->  Bool 
+isLocInFile :: (F.Loc a) => FilePath -> a ->  Bool
 isLocInFile f lx = f == lifted || isCompanion
   where
     lifted :: FilePath
@@ -1212,7 +1254,7 @@
        &&  isExtFile Hs f
        &&  isExtFile Files.Spec lifted
 
-locFile :: (F.Loc a) => a -> FilePath 
+locFile :: (F.Loc a) => a -> FilePath
 locFile = Misc.fst3 . F.sourcePosElts . F.sp_start . F.srcSpan
 
 varLocSym :: Ghc.Var -> LocSymbol
@@ -1227,37 +1269,37 @@
 --   in the _target_ file, "cooks" the aliases (by conversion to SpecType), and 
 --   then saves them back as BareType.
 --------------------------------------------------------------------------------
-myRTEnv :: GhcSrc -> Bare.Env -> Bare.SigEnv -> BareRTEnv -> BareRTEnv 
-myRTEnv src env sigEnv rtEnv = mkRTE tAs' eAs 
-  where 
+myRTEnv :: GhcSrc -> Bare.Env -> Bare.SigEnv -> BareRTEnv -> BareRTEnv
+myRTEnv src env sigEnv rtEnv = mkRTE tAs' eAs
+  where
     tAs'                     = normalizeBareAlias env sigEnv name <$> tAs
-    tAs                      = myAliases typeAliases 
-    eAs                      = myAliases exprAliases 
-    myAliases fld            = filter (isLocInFile srcF) . M.elems . fld $ rtEnv 
+    tAs                      = myAliases typeAliases
+    eAs                      = myAliases exprAliases
+    myAliases fld            = filter (isLocInFile srcF) . M.elems . fld $ rtEnv
     srcF                     = _giTarget    src
     name                     = _giTargetMod src
-  
-mkRTE :: [Located (RTAlias x a)] -> [Located (RTAlias F.Symbol F.Expr)] -> RTEnv x a 
-mkRTE tAs eAs   = RTE 
-  { typeAliases = M.fromList [ (aName a, a) | a <- tAs ] 
-  , exprAliases = M.fromList [ (aName a, a) | a <- eAs ] 
-  } 
-  where aName   = rtName . F.val  
 
-normalizeBareAlias :: Bare.Env -> Bare.SigEnv -> ModName -> Located BareRTAlias 
-                   -> Located BareRTAlias 
+mkRTE :: [Located (RTAlias x a)] -> [Located (RTAlias F.Symbol F.Expr)] -> RTEnv x a
+mkRTE tAs eAs   = RTE
+  { typeAliases = M.fromList [ (aName a, a) | a <- tAs ]
+  , exprAliases = M.fromList [ (aName a, a) | a <- eAs ]
+  }
+  where aName   = rtName . F.val
+
+normalizeBareAlias :: Bare.Env -> Bare.SigEnv -> ModName -> Located BareRTAlias
+                   -> Located BareRTAlias
 normalizeBareAlias env sigEnv name lx = fixRTA <$> lx
-  where 
-    fixRTA  :: BareRTAlias -> BareRTAlias 
-    fixRTA  = mapRTAVars fixArg . fmap fixBody 
+  where
+    fixRTA  :: BareRTAlias -> BareRTAlias
+    fixRTA  = mapRTAVars fixArg . fmap fixBody
 
-    fixArg  :: Symbol -> Symbol 
-    fixArg  = F.symbol . GM.symbolTyVar 
-      
-    fixBody :: BareType -> BareType 
-    fixBody = Bare.specToBare 
-            . F.val 
-            . Bare.cookSpecType env sigEnv name Bare.RawTV 
+    fixArg  :: Symbol -> Symbol
+    fixArg  = F.symbol . GM.symbolTyVar
+
+    fixBody :: BareType -> BareType
+    fixBody = Bare.specToBare
+            . F.val
+            . Bare.cookSpecType env sigEnv name Bare.RawTV
             . F.atLoc lx
 
 
diff --git a/src/Language/Haskell/Liquid/Bare/Axiom.hs b/src/Language/Haskell/Liquid/Bare/Axiom.hs
--- a/src/Language/Haskell/Liquid/Bare/Axiom.hs
+++ b/src/Language/Haskell/Liquid/Bare/Axiom.hs
@@ -1,6 +1,5 @@
 {-# LANGUAGE OverloadedStrings    #-}
 {-# LANGUAGE FlexibleContexts     #-}
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 
 -- | This module contains the code that DOES reflection; i.e. converts Haskell
@@ -16,36 +15,36 @@
 -- import           Control.Monad.State       hiding (forM, mapM)
 import qualified Text.PrettyPrint.HughesPJ as PJ -- (text)
 import qualified Data.HashSet              as S
-import qualified Data.Maybe                as Mb 
+import qualified Data.Maybe                as Mb
 import Control.Monad.Trans.State.Lazy (runState, get, put)
 
 import           Language.Fixpoint.Misc
 import qualified Language.Haskell.Liquid.Measure as Ms
 import qualified Language.Fixpoint.Types as F
-import qualified Language.Haskell.Liquid.GHC.API as Ghc 
-import qualified Language.Haskell.Liquid.GHC.Misc as GM 
+import qualified Liquid.GHC.API as Ghc
+import qualified Liquid.GHC.Misc as GM
 import           Language.Haskell.Liquid.Types.RefType
 import           Language.Haskell.Liquid.Transforms.CoreToLogic
-import           Language.Haskell.Liquid.GHC.Misc
+import           Liquid.GHC.Misc
 import           Language.Haskell.Liquid.Types
 
 import           Language.Haskell.Liquid.Bare.Resolve as Bare
 import           Language.Haskell.Liquid.Bare.Types   as Bare
 
 -----------------------------------------------------------------------------------------------
-makeHaskellAxioms :: Config -> GhcSrc -> Bare.Env -> Bare.TycEnv -> ModName -> LogicMap -> GhcSpecSig -> Ms.BareSpec 
+makeHaskellAxioms :: Config -> GhcSrc -> Bare.Env -> Bare.TycEnv -> ModName -> LogicMap -> GhcSpecSig -> Ms.BareSpec
                   -> Bare.Lookup [(Ghc.Var, LocSpecType, F.Equation)]
 -----------------------------------------------------------------------------------------------
-makeHaskellAxioms cfg src env tycEnv name lmap spSig spec = do 
+makeHaskellAxioms cfg src env tycEnv name lmap spSig spec = do
   wiDefs     <- wiredDefs cfg env name spSig
   let refDefs = getReflectDefs src spSig spec
   return (makeAxiom env tycEnv name lmap <$> (wiDefs ++ refDefs))
 
-getReflectDefs :: GhcSrc -> GhcSpecSig -> Ms.BareSpec 
+getReflectDefs :: GhcSrc -> GhcSpecSig -> Ms.BareSpec
                -> [(LocSymbol, Maybe SpecType, Ghc.Var, Ghc.CoreExpr)]
 getReflectDefs src sig spec = findVarDefType cbs sigs <$> xs
   where
-    sigs                    = gsTySigs sig 
+    sigs                    = gsTySigs sig
     xs                      = S.toList (Ms.reflects spec)
     cbs                     = _giCbs src
 
@@ -54,22 +53,22 @@
 findVarDefType cbs sigs x = case findVarDefMethod (val x) cbs of
   -- YL: probably ok even without checking typeclass flag since user cannot
   -- manually reflect internal names
-  Just (v, e) -> if Ghc.isExportedId v || isMethod (F.symbol x) || isDictionary (F.symbol x)
+  Just (v, e) -> if GM.isExternalId v || isMethod (F.symbol x) || isDictionary (F.symbol x)
                    then (x, val <$> lookup v sigs, v, e)
                    else Ex.throw $ mkError x ("Lifted functions must be exported; please export " ++ show v)
   Nothing     -> Ex.throw $ mkError x "Cannot lift haskell function"
 
 --------------------------------------------------------------------------------
-makeAxiom :: Bare.Env -> Bare.TycEnv -> ModName -> LogicMap 
+makeAxiom :: Bare.Env -> Bare.TycEnv -> ModName -> LogicMap
           -> (LocSymbol, Maybe SpecType, Ghc.Var, Ghc.CoreExpr)
           -> (Ghc.Var, LocSpecType, F.Equation)
 --------------------------------------------------------------------------------
-makeAxiom env tycEnv name lmap (x, mbT, v, def) 
+makeAxiom env tycEnv name lmap (x, mbT, v, def)
             = (v, t, e)
-  where 
-    t       = Bare.qualifyTop env name (F.loc t0) t0 
+  where
+    t       = Bare.qualifyTop env name (F.loc t0) t0
     (t0, e) = makeAssumeType allowTC embs lmap dm x mbT v def
-    embs    = Bare.tcEmbs       tycEnv 
+    embs    = Bare.tcEmbs       tycEnv
     dm      = Bare.tcDataConMap tycEnv
     allowTC = typeclass (getConfig env)
 
@@ -81,23 +80,23 @@
   -> F.TCEmb Ghc.TyCon -> LogicMap -> DataConMap -> LocSymbol -> Maybe SpecType
   -> Ghc.Var -> Ghc.CoreExpr
   -> (LocSpecType, F.Equation)
-makeAssumeType allowTC tce lmap dm x mbT v def
-  = (x {val = aty at `strengthenRes` F.subst su ref},  F.mkEquation (val x) xts (F.subst su le) out)
+makeAssumeType allowTC tce lmap dm sym mbT v def
+  = (sym {val = aty at `strengthenRes` F.subst su ref},  F.mkEquation (val sym) xts (F.subst su le) out)
   where
-    t     = fromRTypeRep .
+    rt    = fromRTypeRep .
             (\trep@RTypeRep{..} ->
                 trep{ty_info = fmap (\rinfo -> rinfo{permitTC = Just allowTC}) ty_info}) .
-            toRTypeRep $ Mb.fromMaybe (ofType $ τ) mbT
+            toRTypeRep $ Mb.fromMaybe (ofType τ) mbT
     τ     = Ghc.varType v
-    at    = axiomType allowTC x t
-    out   = rTypeSort tce $ ares at 
-    xArgs = (F.EVar . fst) <$> aargs at
-    _msg  = unwords [showpp x, showpp mbT]
+    at    = axiomType allowTC sym rt
+    out   = rTypeSort tce $ ares at
+    xArgs = F.EVar . fst <$> aargs at
+    _msg  = unwords [showpp sym, showpp mbT]
     le    = case runToLogicWithBoolBinds bbs tce lmap dm mkErr (coreToLogic allowTC def') of
               Right e -> e
               Left  e -> panic Nothing (show e)
     ref        = F.Reft (F.vv_, F.PAtom F.Eq (F.EVar F.vv_) le)
-    mkErr s    = ErrHMeas (sourcePosSrcSpan $ loc x) (pprint $ val x) (PJ.text s)
+    mkErr s    = ErrHMeas (sourcePosSrcSpan $ loc sym) (pprint $ val sym) (PJ.text s)
     bbs        = filter isBoolBind xs
     (xs, def') = GM.notracePpr "grabBody" $ grabBody allowTC (Ghc.expandTypeSynonyms τ) $ normalize allowTC def
     su         = F.mkSubst  $ zip (F.symbol     <$> xs) xArgs
@@ -109,48 +108,48 @@
 
 grabBody :: Bool -- ^ typeclass enabled
          -> Ghc.Type -> Ghc.CoreExpr -> ([Ghc.Var], Ghc.CoreExpr)
-grabBody allowTC (Ghc.ForAllTy _ t) e 
-  = grabBody allowTC t e 
-grabBody allowTC@False (Ghc.FunTy { Ghc.ft_arg = tx, Ghc.ft_res = t}) e | Ghc.isClassPred tx 
-  = grabBody allowTC t e 
-grabBody allowTC@True (Ghc.FunTy { Ghc.ft_arg = tx, Ghc.ft_res = t}) e | isEmbeddedDictType tx 
-  = grabBody allowTC t e 
-grabBody allowTC torig@Ghc.FunTy {} (Ghc.Let (Ghc.NonRec x e) body) 
+grabBody allowTC (Ghc.ForAllTy _ ty) e
+  = grabBody allowTC ty e
+grabBody allowTC@False Ghc.FunTy{ Ghc.ft_arg = tx, Ghc.ft_res = t} e | Ghc.isClassPred tx
+  = grabBody allowTC t e
+grabBody allowTC@True Ghc.FunTy{ Ghc.ft_arg = tx, Ghc.ft_res = t} e | isEmbeddedDictType tx
+  = grabBody allowTC t e
+grabBody allowTC torig@Ghc.FunTy {} (Ghc.Let (Ghc.NonRec x e) body)
   = grabBody allowTC torig (subst (x,e) body)
-grabBody allowTC (Ghc.FunTy { Ghc.ft_res = t}) (Ghc.Lam x e) 
+grabBody allowTC Ghc.FunTy{ Ghc.ft_res = t} (Ghc.Lam x e)
   = (x:xs, e') where (xs, e') = grabBody allowTC t e
-grabBody allowTC t (Ghc.Tick _ e) 
+grabBody allowTC t (Ghc.Tick _ e)
   = grabBody allowTC t e
-grabBody allowTC t@(Ghc.FunTy {}) e               
-  = (txs++xs, e') 
-   where (ts,tr)  = splitFun t 
+grabBody allowTC ty@Ghc.FunTy{} e
+  = (txs++xs, e')
+   where (ts,tr)  = splitFun ty
          (xs, e') = grabBody allowTC tr (foldl Ghc.App e (Ghc.Var <$> txs))
-         txs      = [ stringVar ("ls" ++ show i) t |  (t,i) <- zip ts [1..]]
+         txs      = [ stringVar ("ls" ++ show i) t |  (t,i) <- zip ts [(1::Int)..]]
 grabBody _ _ e
   = ([], e)
 
 splitFun :: Ghc.Type -> ([Ghc.Type], Ghc.Type)
-splitFun = go [] 
-  where go acc (Ghc.FunTy { Ghc.ft_arg = tx, Ghc.ft_res = t}) = go (tx:acc) t 
-        go acc t                                              = (reverse acc, t)
+splitFun = go []
+  where go acc Ghc.FunTy{ Ghc.ft_arg = tx, Ghc.ft_res = t} = go (tx:acc) t
+        go acc t                                           = (reverse acc, t)
 
 
 isBoolBind :: Ghc.Var -> Bool
 isBoolBind v = isBool (ty_res $ toRTypeRep ((ofType $ Ghc.varType v) :: RRType ()))
 
 strengthenRes :: SpecType -> F.Reft -> SpecType
-strengthenRes t r = go t 
-  where 
-    go (RAllT a t r)   = RAllT a (go t) r  
+strengthenRes st rf = go st
+  where
+    go (RAllT a t r)   = RAllT a (go t) r
     go (RAllP p t)     = RAllP p $ go t
-    go (RFun x i tx t r) = RFun x i tx (go t) r 
-    go t               =  t `strengthen` F.ofReft r 
+    go (RFun x i tx t r) = RFun x i tx (go t) r
+    go t               =  t `strengthen` F.ofReft rf
 
 class Subable a where
   subst :: (Ghc.Var, Ghc.CoreExpr) -> a -> a
 
 instance Subable Ghc.Var where
-  subst (x, ex) z 
+  subst (x, ex) z
     | x == z, Ghc.Var y <- ex = y
     | otherwise           = z
 
@@ -172,8 +171,8 @@
     = Ghc.Cast (subst su e) t
   subst su (Ghc.Tick t e)
     = Ghc.Tick t (subst su e)
-  subst _ e 
-    = e 
+  subst _ e
+    = e
 
 instance Subable Ghc.CoreAlt where
   subst su (c, xs, e) = (c, xs, subst su e)
@@ -182,24 +181,24 @@
 
 -- | Specification for Haskell function
 axiomType :: Bool -> LocSymbol -> SpecType -> AxiomType
-axiomType allowTC s t = AT to (reverse xts) res  
+axiomType allowTC s st = AT to (reverse xts) res
   where
-    (to, (_,xts, Just res)) = runState (go t) (1,[], Nothing)
-    go (RAllT a t r) = RAllT a <$> go t <*> return r 
-    go (RAllP p t) = RAllP p <$> go t 
+    (to, (_,xts, Just res)) = runState (go st) (1,[], Nothing)
+    go (RAllT a t r) = RAllT a <$> go t <*> return r
+    go (RAllP p t) = RAllP p <$> go t
     go (RFun x i tx t r) | isErasable tx = (\t' -> RFun x i tx t' r) <$> go t
-    go (RFun x ii tx t r) = do 
-      (i,bs,res) <- get 
-      let x' = unDummy x i 
-      put (i+1, (x', tx):bs,res)
-      t' <- go t 
-      return $ RFun x' ii tx t' r 
-    go t = do 
-      (i,bs,_) <- get 
+    go (RFun x ii tx t r) = do
+      (i,bs,mres) <- get
+      let x' = unDummy x i
+      put (i+1, (x', tx):bs,mres)
+      t' <- go t
+      return $ RFun x' ii tx t' r
+    go t = do
+      (i,bs,_) <- get
       let ys = reverse $ map fst bs
       let t' = strengthen t (singletonApp s ys)
       put (i, bs, Just t')
-      return t' 
+      return t'
     isErasable = if allowTC then isEmbeddedClass else isClassType
 unDummy :: F.Symbol -> Int -> F.Symbol
 unDummy x i
@@ -216,20 +215,20 @@
 -- | Hardcode imported reflected functions ------------------------------------
 -------------------------------------------------------------------------------
 
-wiredReflects :: Config -> Bare.Env -> ModName -> GhcSpecSig -> 
+wiredReflects :: Config -> Bare.Env -> ModName -> GhcSpecSig ->
                  Bare.Lookup [Ghc.Var]
-wiredReflects cfg env name sigs = do 
+wiredReflects cfg env name sigs = do
   vs <- wiredDefs cfg env name sigs
   return [v | (_, _, v, _) <- vs]
 
-wiredDefs :: Config -> Bare.Env -> ModName -> GhcSpecSig 
+wiredDefs :: Config -> Bare.Env -> ModName -> GhcSpecSig
           -> Bare.Lookup [(LocSymbol, Maybe SpecType, Ghc.Var, Ghc.CoreExpr)]
 wiredDefs cfg env name spSig
   | reflection cfg = do
     let x = F.dummyLoc functionComposisionSymbol
     v    <- Bare.lookupGhcVar env name "wiredAxioms" x
     return [ (x, F.val <$> lookup v (gsTySigs spSig), v, makeCompositionExpression v) ]
-  | otherwise = 
+  | otherwise =
     return []
 
 -------------------------------------------------------------------------------
@@ -238,28 +237,28 @@
 -------------------------------------------------------------------------------
 
 
-makeCompositionExpression :: Ghc.Id -> Ghc.CoreExpr 
-makeCompositionExpression x 
+makeCompositionExpression :: Ghc.Id -> Ghc.CoreExpr
+makeCompositionExpression gid
   =  go $ Ghc.varType $ F.notracepp ( -- tracing to find  the body of . from the inline spec, 
                                       -- replace F.notrace with F.trace to print 
-      "\nv = " ++ GM.showPpr x ++ 
-      "\n realIdUnfolding = " ++ GM.showPpr (Ghc.realIdUnfolding x) ++ 
-      "\n maybeUnfoldingTemplate . realIdUnfolding = " ++ GM.showPpr (Ghc.maybeUnfoldingTemplate $ Ghc.realIdUnfolding x ) ++ 
-      "\n inl_src . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_src $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inl_inline . inlinePragInfo . Ghc.idInfo = " ++ GM.showPpr (Ghc.inl_inline $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inl_sat . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_sat $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inl_act . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_act $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inl_rule . inlinePragInfo . Ghc.idInfo = "   ++ GM.showPpr (Ghc.inl_rule $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inl_rule rule = " ++ GM.showPpr (Ghc.inl_rule $ Ghc.inlinePragInfo $ Ghc.idInfo x) ++ 
-      "\n inline spec = " ++ GM.showPpr (Ghc.inl_inline $ Ghc.inlinePragInfo $ Ghc.idInfo x)  
-     ) x 
-   where  
-    go (Ghc.ForAllTy a (Ghc.ForAllTy b (Ghc.ForAllTy c (Ghc.FunTy { Ghc.ft_arg = tf, Ghc.ft_res = Ghc.FunTy { Ghc.ft_arg = tg, Ghc.ft_res = tx}}))))
-      = let f = stringVar "f" tf 
+      "\nv = " ++ GM.showPpr gid ++
+      "\n realIdUnfolding = " ++ GM.showPpr (Ghc.realIdUnfolding gid) ++
+      "\n maybeUnfoldingTemplate . realIdUnfolding = " ++ GM.showPpr (Ghc.maybeUnfoldingTemplate $ Ghc.realIdUnfolding gid ) ++
+      "\n inl_src . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_src $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inl_inline . inlinePragInfo . Ghc.idInfo = " ++ GM.showPpr (Ghc.inl_inline $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inl_sat . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_sat $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inl_act . inlinePragInfo . Ghc.idInfo = "    ++ GM.showPpr (Ghc.inl_act $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inl_rule . inlinePragInfo . Ghc.idInfo = "   ++ GM.showPpr (Ghc.inl_rule $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inl_rule rule = " ++ GM.showPpr (Ghc.inl_rule $ Ghc.inlinePragInfo $ Ghc.idInfo gid) ++
+      "\n inline spec = " ++ GM.showPpr (Ghc.inl_inline $ Ghc.inlinePragInfo $ Ghc.idInfo gid)
+     ) gid
+   where
+    go (Ghc.ForAllTy a (Ghc.ForAllTy b (Ghc.ForAllTy c Ghc.FunTy{ Ghc.ft_arg = tf, Ghc.ft_res = Ghc.FunTy { Ghc.ft_arg = tg, Ghc.ft_res = tx}})))
+      = let f = stringVar "f" tf
             g = stringVar "g" tg
-            x = stringVar "x" tx 
-        in Ghc.Lam (Ghc.binderVar a) $ 
-           Ghc.Lam (Ghc.binderVar b) $ 
-           Ghc.Lam (Ghc.binderVar c) $ 
+            x = stringVar "x" tx
+        in Ghc.Lam (Ghc.binderVar a) $
+           Ghc.Lam (Ghc.binderVar b) $
+           Ghc.Lam (Ghc.binderVar c) $
            Ghc.Lam f $ Ghc.Lam g $ Ghc.Lam x $ Ghc.App (Ghc.Var f) (Ghc.App (Ghc.Var g) (Ghc.Var x))
     go _ = error "Axioms.go"
diff --git a/src/Language/Haskell/Liquid/Bare/Check.hs b/src/Language/Haskell/Liquid/Bare/Check.hs
--- a/src/Language/Haskell/Liquid/Bare/Check.hs
+++ b/src/Language/Haskell/Liquid/Bare/Check.hs
@@ -1,19 +1,19 @@
-{-# LANGUAGE ParallelListComp    #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE FlexibleContexts    #-}
 {-# LANGUAGE TupleSections       #-}
 {-# LANGUAGE RecordWildCards     #-}
 {-# LANGUAGE OverloadedStrings   #-}
 
-module Language.Haskell.Liquid.Bare.Check 
+module Language.Haskell.Liquid.Bare.Check
   ( checkTargetSpec
   , checkBareSpec
+  , checkTargetSrc
   ) where
 
 
 import           Language.Haskell.Liquid.Constraint.ToFixpoint
 
-import           Language.Haskell.Liquid.GHC.API                   as Ghc hiding ( Located
+import           Liquid.GHC.API                   as Ghc hiding ( Located
                                                                                  , text
                                                                                  , (<+>)
                                                                                  , panic
@@ -29,21 +29,42 @@
 import qualified Data.HashMap.Strict                       as M
 import qualified Data.HashSet                              as S
 import           Data.Hashable
-import qualified Language.Fixpoint.Misc                    as Misc  
+import qualified Language.Fixpoint.Misc                    as Misc
 import           Language.Fixpoint.SortCheck               (checkSorted, checkSortedReftFull, checkSortFull)
-import qualified Language.Fixpoint.Types                   as F 
-import qualified Language.Haskell.Liquid.GHC.Misc          as GM 
+import qualified Language.Fixpoint.Types                   as F
+import qualified Liquid.GHC.Misc          as GM
+import           Liquid.GHC.Play          (getNonPositivesTyCon)
 import           Language.Haskell.Liquid.Misc              (condNull, thd5)
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.WiredIn
 import           Language.Haskell.Liquid.LawInstances      (checkLawInstances)
 
 import qualified Language.Haskell.Liquid.Measure           as Ms
-import qualified Language.Haskell.Liquid.Bare.Types        as Bare 
-import qualified Language.Haskell.Liquid.Bare.Resolve      as Bare 
+import qualified Language.Haskell.Liquid.Bare.Types        as Bare
+import qualified Language.Haskell.Liquid.Bare.Resolve      as Bare
 
 
 ----------------------------------------------------------------------------------------------
+-- | Checking TargetSrc ------------------------------------------------------------------------
+----------------------------------------------------------------------------------------------
+checkTargetSrc :: Config -> TargetSrc -> Either Diagnostics ()
+checkTargetSrc cfg spec
+  |  nopositivity cfg
+  || nopositives == emptyDiagnostics
+  = Right ()
+  | otherwise
+  = Left nopositives
+  where nopositives = checkPositives (gsTcs spec)
+
+
+checkPositives :: [TyCon] -> Diagnostics
+checkPositives tys = mkDiagnostics [] $ mkNonPosError (getNonPositivesTyCon tys)
+
+mkNonPosError :: [(TyCon, [DataCon])]  -> [Error]
+mkNonPosError tcs = [ ErrPosTyCon (getSrcSpan tc) (pprint tc) (pprint dc <+> ":" <+> pprint (dataConRepType dc))
+                    | (tc, dc:_) <- tcs]
+
+----------------------------------------------------------------------------------------------
 -- | Checking BareSpec ------------------------------------------------------------------------
 ----------------------------------------------------------------------------------------------
 checkBareSpec :: ModName -> Ms.BareSpec -> Either Diagnostics ()
@@ -67,28 +88,28 @@
     fields    = concatMap dataDeclFields (Ms.dataDecls sp)
 
 dataDeclFields :: DataDecl -> [F.LocSymbol]
-dataDeclFields = filter (not . GM.isTmpSymbol . F.val) 
-               . Misc.hashNubWith val 
-               . concatMap dataCtorFields 
+dataDeclFields = filter (not . GM.isTmpSymbol . F.val)
+               . Misc.hashNubWith val
+               . concatMap dataCtorFields
                . fromMaybe []
                . tycDCons
 
 dataCtorFields :: DataCtor -> [F.LocSymbol]
-dataCtorFields c 
-  | isGadt c  = [] 
+dataCtorFields c
+  | isGadt c  = []
   | otherwise = F.atLoc c <$> [ f | (f,_) <- dcFields c ]
 
-isGadt :: DataCtor -> Bool 
-isGadt = isJust . dcResult 
+isGadt :: DataCtor -> Bool
+isGadt = isJust . dcResult
 
 checkUnique :: String -> [F.LocSymbol] -> Diagnostics
-checkUnique _ = mkDiagnostics mempty . checkUnique' F.val GM.fSrcSpan 
+checkUnique _ = mkDiagnostics mempty . checkUnique' F.val GM.fSrcSpan
 
-checkUnique' :: (PPrint a, Eq a, Hashable a) 
+checkUnique' :: (PPrint a, Eq a, Hashable a)
              => (t -> a) -> (t -> Ghc.SrcSpan) -> [t] -> [Error]
-checkUnique' nameF locF ts = [ErrDupSpecs l (pprint n) ls | (n, ls@(l:_)) <- dups] 
+checkUnique' nameF locF ts = [ErrDupSpecs l (pprint n) ls | (n, ls@(l:_)) <- dups]
   where
-    dups                   = [ z      | z@(_, _:_:_) <- Misc.groupList nts       ] 
+    dups                   = [ z      | z@(_, _:_:_) <- Misc.groupList nts       ]
     nts                    = [ (n, l) | t <- ts, let n = nameF t, let l = locF t ]
 
 checkDisjoints :: [S.HashSet F.LocSymbol] -> Diagnostics
@@ -109,56 +130,56 @@
                 -> [CoreBind]
                 -> TargetSpec
                 -> Either Diagnostics ()
-checkTargetSpec specs src env cbs sp
+checkTargetSpec specs src env cbs tsp
   | diagnostics == emptyDiagnostics = Right ()
   | otherwise                       = Left diagnostics
   where
     diagnostics      :: Diagnostics
-    diagnostics      =  foldMap (checkBind allowHO bsc "measure"      emb tcEnv env) (gsMeas       (gsData sp))
+    diagnostics      =  foldMap (checkBind allowHO bsc "measure"      emb tcEnv env) (gsMeas       (gsData tsp))
                      <> condNull noPrune
-                        (foldMap (checkBind allowHO bsc "constructor"  emb tcEnv env) (txCtors $ gsCtors      (gsData sp)))
-                     <> foldMap (checkBind allowHO bsc "assume"       emb tcEnv env) (gsAsmSigs    (gsSig sp))
-                     <> foldMap (checkBind allowHO bsc "reflect"      emb tcEnv env) (fmap (\sig@(_,s) -> F.notracepp (show (ty_info (toRTypeRep (F.val s)))) sig) $ gsRefSigs    (gsSig sp))
-                     <> checkTySigs allowHO bsc cbs            emb tcEnv env                (gsSig sp)
+                        (foldMap (checkBind allowHO bsc "constructor"  emb tcEnv env) (txCtors $ gsCtors      (gsData tsp)))
+                     <> foldMap (checkBind allowHO bsc "assume"       emb tcEnv env) (gsAsmSigs    (gsSig tsp))
+                     <> foldMap (checkBind allowHO bsc "reflect"      emb tcEnv env . (\sig@(_,s) -> F.notracepp (show (ty_info (toRTypeRep (F.val s)))) sig)) (gsRefSigs (gsSig tsp))
+                     <> checkTySigs allowHO bsc cbs            emb tcEnv env                (gsSig tsp)
                      -- ++ mapMaybe (checkTerminationExpr             emb       env) (gsTexprs     (gsSig  sp))
-                     <> foldMap (checkBind allowHO bsc "class method" emb tcEnv env) (clsSigs      (gsSig sp))
-                     <> foldMap (checkInv allowHO bsc emb tcEnv env)                 (gsInvariants (gsData sp))
-                     <> checkIAl allowHO bsc emb tcEnv env                            (gsIaliases   (gsData sp))
+                     <> foldMap (checkBind allowHO bsc "class method" emb tcEnv env) (clsSigs      (gsSig tsp))
+                     <> foldMap (checkInv allowHO bsc emb tcEnv env)                 (gsInvariants (gsData tsp))
+                     <> checkIAl allowHO bsc emb tcEnv env                            (gsIaliases   (gsData tsp))
                      <> checkMeasures emb env ms
-                     <> checkClassMeasures                                        (gsMeasures (gsData sp))
-                     <> checkClassMethods (gsCls src) (gsCMethods (gsVars sp)) (gsTySigs     (gsSig sp))
+                     <> checkClassMeasures                                        (gsMeasures (gsData tsp))
+                     <> checkClassMethods (gsCls src) (gsCMethods (gsVars tsp)) (gsTySigs     (gsSig tsp))
                      -- <> foldMap checkMismatch sigs
                      <> foldMap checkMismatch (L.filter (\(v,_) -> not (GM.isSCSel v || GM.isMethod v)) sigs)
-                     <> checkDuplicate                                            (gsTySigs     (gsSig sp))
+                     <> checkDuplicate                                            (gsTySigs     (gsSig tsp))
                      -- TODO-REBARE ++ checkQualifiers env                                       (gsQualifiers (gsQual sp))
-                     <> checkDuplicate                                            (gsAsmSigs    (gsSig sp))
-                     <> checkDupIntersect                                         (gsTySigs (gsSig sp)) (gsAsmSigs (gsSig sp))
+                     <> checkDuplicate                                            (gsAsmSigs    (gsSig tsp))
+                     <> checkDupIntersect                                         (gsTySigs (gsSig tsp)) (gsAsmSigs (gsSig tsp))
                      <> checkRTAliases "Type Alias" env            tAliases
                      <> checkRTAliases "Pred Alias" env            eAliases
                      -- ++ _checkDuplicateFieldNames                   (gsDconsP sp)
                      -- NV TODO: allow instances of refined classes to be refined
                      -- but make sure that all the specs are checked.
                      -- ++ checkRefinedClasses                        rClasses rInsts
-                     <> checkSizeFun emb env                                      (gsTconsP (gsName sp))
-                     <> checkPlugged (catMaybes [ fmap (F.dropSym 2 $ GM.simplesymbol x,) (getMethodType t) | (x, t) <- gsMethods (gsSig sp) ])
-                     <> checkLawInstances (gsLaws sp)
-                     <> checkRewrites sp
+                     <> checkSizeFun emb env                                      (gsTconsP (gsName tsp))
+                     <> checkPlugged (catMaybes [ fmap (F.dropSym 2 $ GM.simplesymbol x,) (getMethodType t) | (x, t) <- gsMethods (gsSig tsp) ])
+                     <> checkLawInstances (gsLaws tsp)
+                     <> checkRewrites tsp
 
-    _rClasses         = concatMap (Ms.classes  ) specs
-    _rInsts           = concatMap (Ms.rinstance) specs
+    _rClasses         = concatMap Ms.classes specs
+    _rInsts           = concatMap Ms.rinstance specs
     tAliases          = concat [Ms.aliases sp  | sp <- specs]
     eAliases          = concat [Ms.ealiases sp | sp <- specs]
-    emb              = gsTcEmbeds (gsName sp)
-    tcEnv            = gsTyconEnv (gsName sp)
-    ms               = gsMeasures (gsData sp)
+    emb              = gsTcEmbeds (gsName tsp)
+    tcEnv            = gsTyconEnv (gsName tsp)
+    ms               = gsMeasures (gsData tsp)
     clsSigs sp       = [ (v, t) | (v, t) <- gsTySigs sp, isJust (isClassOpId_maybe v) ]
-    sigs             = gsTySigs (gsSig sp) ++ gsAsmSigs (gsSig sp) ++ gsCtors (gsData sp)
+    sigs             = gsTySigs (gsSig tsp) ++ gsAsmSigs (gsSig tsp) ++ gsCtors (gsData tsp)
     -- allowTC          = typeclass (getConfig sp)
-    allowHO          = higherOrderFlag sp
-    bsc              = bscope (getConfig sp)
-    noPrune          = not (pruneFlag sp)
+    allowHO          = higherOrderFlag tsp
+    bsc              = bscope (getConfig tsp)
+    noPrune          = not (pruneFlag tsp)
     txCtors ts       = [(v, fmap (fmap (fmap (F.filterUnMatched temps))) t) | (v, t) <- ts]
-    temps            = F.makeTemplates $ gsUnsorted $ gsData sp
+    temps            = F.makeTemplates $ gsUnsorted $ gsData tsp
     -- env'             = L.foldl' (\e (x, s) -> insertSEnv x (RR s mempty) e) env wiredSortedSyms
 
 
@@ -182,14 +203,14 @@
             -> GhcSpecSig
             -> Diagnostics
 --------------------------------------------------------------------------------
-checkTySigs allowHO bsc cbs emb tcEnv env sig
-                   = mconcat (map (check env) topTs)
+checkTySigs allowHO bsc cbs emb tcEnv senv sig
+                   = mconcat (map (check senv) topTs)
                    -- = concatMap (check env) topTs
                    -- (mapMaybe   (checkT env) [ (x, t)     | (x, (t, _)) <- topTs])
                    -- ++ (mapMaybe   (checkE env) [ (x, t, es) | (x, (t, Just es)) <- topTs]) 
-                  <> coreVisitor checkVisitor env emptyDiagnostics cbs
+                  <> coreVisitor checkVisitor senv emptyDiagnostics cbs
                    -- ++ coreVisitor checkVisitor env [] cbs 
-  where 
+  where
     check env      = checkSigTExpr allowHO bsc emb tcEnv env
     locTm          = M.fromList locTs
     (locTs, topTs) = Bare.partitionLocalBinds vtes
@@ -203,17 +224,17 @@
                        , exprF = \_   acc _ -> acc
                        }
     vSort            = Bare.varSortedReft emb
-    errs env v       = case M.lookup v locTm of 
+    errs env v       = case M.lookup v locTm of
                          Nothing -> emptyDiagnostics
-                         Just t  -> check env (v, t) 
+                         Just t  -> check env (v, t)
 
-checkSigTExpr :: Bool -> BScope -> F.TCEmb TyCon -> Bare.TyConMap -> F.SEnv F.SortedReft 
-              -> (Var, (LocSpecType, Maybe [Located F.Expr])) 
+checkSigTExpr :: Bool -> BScope -> F.TCEmb TyCon -> Bare.TyConMap -> F.SEnv F.SortedReft
+              -> (Var, (LocSpecType, Maybe [Located F.Expr]))
               -> Diagnostics
-checkSigTExpr allowHO bsc emb tcEnv env (x, (t, es)) 
+checkSigTExpr allowHO bsc emb tcEnv env (x, (t, es))
            = mbErr1 <> mbErr2
-   where 
-    mbErr1 = checkBind allowHO bsc empty emb tcEnv env (x, t) 
+   where
+    mbErr1 = checkBind allowHO bsc empty emb tcEnv env (x, t)
     mbErr2 = maybe emptyDiagnostics (checkTerminationExpr emb env . (x, t,)) es
     -- mbErr2 = checkTerminationExpr emb env . (x, t,) =<< es 
 
@@ -222,7 +243,7 @@
 
 checkQualifier       :: F.SEnv F.SortedReft -> F.Qualifier -> Maybe Error
 checkQualifier env q =  mkE <$> checkSortFull (F.srcSpan q) γ F.boolSort  (F.qBody q)
-  where 
+  where
     γ                = L.foldl' (\e (x, s) -> F.insertSEnv x (F.RR s mempty) e) env (F.qualBinds q ++ wiredSortedSyms)
     mkE              = ErrBadQual (GM.fSrcSpan q) (pprint $ F.qName q)
 
@@ -256,7 +277,7 @@
   = mkError <$> duplicates
   where
     duplicates
-      = mapMaybe checkCls (rcName <$> definitions)
+      = mapMaybe (checkCls . rcName) definitions
     checkCls cls
       = case findConflicts cls of
           []        -> Nothing
@@ -351,14 +372,14 @@
                      -> F.SEnv F.SortedReft
                      -> (v, LocSpecType, [F.Located F.Expr])
                      -> Diagnostics
-checkTerminationExpr emb env (v, Loc l _ t, les)
-            = (mkErr "ill-sorted" $ go les) <> (mkErr "non-numeric" $ go' les)
+checkTerminationExpr emb env (v, Loc l _ st, les)
+            = mkErr "ill-sorted" (go les) <> mkErr "non-numeric" (go' les)
   where
     -- es      = val <$> les
     mkErr :: Doc -> Maybe (F.Expr, Doc) -> Diagnostics
     mkErr _ Nothing = emptyDiagnostics
-    mkErr k (Just e) =
-      mkDiagnostics mempty [uncurry (\ e d -> ErrTermSpec (GM.sourcePosSrcSpan l) (pprint v) k e t d) e]
+    mkErr k (Just expr') =
+      mkDiagnostics mempty [(\ (e, d) -> ErrTermSpec (GM.sourcePosSrcSpan l) (pprint v) k e st d) expr']
     -- mkErr   = uncurry (\ e d -> ErrTermSpec (GM.sourcePosSrcSpan l) (pprint v) (text "ill-sorted" ) e t d)
     -- mkErr'  = uncurry (\ e d -> ErrTermSpec (GM.sourcePosSrcSpan l) (pprint v) (text "non-numeric") e t d)
 
@@ -369,11 +390,11 @@
     go'     = L.foldl' (\err e -> err <|> (val e,) <$> checkSorted (F.srcSpan e) env' (cmpZero e)) Nothing
 
     env'    = F.sr_sort <$> L.foldl' (\e (x,s) -> F.insertSEnv x s e) env xts
-    xts     = concatMap mkClass $ zip (ty_binds trep) (ty_args trep)
-    trep    = toRTypeRep t
+    xts     = concatMap mkClss $ zip (ty_binds trep) (ty_args trep)
+    trep    = toRTypeRep st
 
-    mkClass (_, RApp c ts _ _) | isClass c = classBinds emb (rRCls c ts)
-    mkClass (x, t)                         = [(x, rSort t)]
+    mkClss (_, RApp c ts _ _) | isClass c = classBinds emb (rRCls c ts)
+    mkClss (x, t)                         = [(x, rSort t)]
 
     rSort   = rTypeSortedReft emb
     cmpZero e = F.PAtom F.Le (F.expr (0 :: Int)) (val e)
@@ -456,13 +477,13 @@
 ------------------------------------------------------------------------------------------------
 checkRType :: Bool -> BScope -> F.TCEmb TyCon -> F.SEnv F.SortedReft -> LocSpecType -> Maybe Doc
 ------------------------------------------------------------------------------------------------
-checkRType allowHO bsc emb env lt
-  =   checkAppTys t
-  <|> checkAbstractRefs t
-  <|> efoldReft farg bsc cb (tyToBind emb) (rTypeSortedReft emb) f insertPEnv env Nothing t
+checkRType allowHO bsc emb senv lt
+  =   checkAppTys st
+  <|> checkAbstractRefs st
+  <|> efoldReft farg bsc cb (tyToBind emb) (rTypeSortedReft emb) f insertPEnv senv Nothing st
   where
     -- isErasable         = if allowTC then isEmbeddedDict else isClass
-    t                  = val lt
+    st                 = val lt
     cb c ts            = classBinds emb (rRCls c ts)
     farg _ t           = allowHO || isBase t  -- NOTE: this check should be the same as the one in addCGEnv
     f env me r err     = err <|> checkReft (F.srcSpan lt) env emb me r
@@ -472,8 +493,8 @@
 tyToBind :: F.TCEmb TyCon -> RTVar RTyVar RSort  -> [(F.Symbol, F.SortedReft)]
 tyToBind emb = go . ty_var_info
   where
-    go (RTVInfo {..})   = [(rtv_name, rTypeSortedReft emb rtv_kind)]
-    go (RTVNoInfo {..}) = []
+    go RTVInfo{..} = [(rtv_name, rTypeSortedReft emb rtv_kind)]
+    go RTVNoInfo{} = []
 
 checkAppTys :: RType RTyCon t t1 -> Maybe Doc
 checkAppTys = go
@@ -494,7 +515,7 @@
     go (RHole _)        = Nothing
 
 checkTcArity :: RTyCon -> Arity -> Maybe Doc
-checkTcArity (RTyCon { rtc_tc = tc }) givenArity
+checkTcArity RTyCon{ rtc_tc = tc } givenArity
   | expectedArity < givenArity
     = Just $ text "Type constructor" <+> pprint tc
         <+> text "expects a maximum" <+> pprint expectedArity
@@ -509,9 +530,9 @@
 checkAbstractRefs
   :: (PPrint t, F.Reftable t, SubsTy RTyVar RSort t, F.Reftable (RTProp RTyCon RTyVar (UReft t))) =>
      RType RTyCon RTyVar (UReft t) -> Maybe Doc
-checkAbstractRefs t = go t
+checkAbstractRefs rt = go rt
   where
-    penv = mkPEnv t
+    penv = mkPEnv rt
 
     go t@(RAllT _ t1 r)   = check (toRSort t :: RSort) r <|>  go t1
     go (RAllP _ t)        = go t
@@ -563,7 +584,7 @@
     mkPEnv (RAllT _ t _) = mkPEnv t
     mkPEnv (RAllP p t)   = p:mkPEnv t
     mkPEnv _             = []
-    pvType' p          = Misc.safeHead (showpp p ++ " not in env of " ++ showpp t) [pvType q | q <- penv, pname p == pname q]
+    pvType' p          = Misc.safeHead (showpp p ++ " not in env of " ++ showpp rt) [pvType q | q <- penv, pname p == pname q]
 
 
 checkReft                    :: (PPrint r, F.Reftable r, SubsTy RTyVar (RType RTyCon RTyVar ()) r, F.Reftable (RTProp RTyCon RTyVar (UReft r)))
@@ -605,11 +626,11 @@
            -> SpecType
            -> Def (RRType r) DataCon
            -> Maybe Doc
-checkMBody γ emb _ sort (Def m c _ bs body) = checkMBody' emb sort γ' sp body
+checkMBody senv emb _ sort (Def m c _ bs body) = checkMBody' emb sort γ' sp body
   where
     sp    = F.srcSpan m
-    γ'    = L.foldl' (\γ (x, t) -> F.insertSEnv x t γ) γ xts
-    xts   = zip (fst <$> bs) $ rTypeSortedReft emb . subsTyVars_meet su  <$> 
+    γ'    = L.foldl' (\γ (x, t) -> F.insertSEnv x t γ) senv xts
+    xts   = zip (fst <$> bs) $ rTypeSortedReft emb . subsTyVarsMeet su  <$>
             filter keep (ty_args trep)
     keep | allowTC = not . isEmbeddedClass
          | otherwise = not . isClassType
@@ -622,17 +643,17 @@
 
 checkMBodyUnify
   :: RType t t2 t1 -> RType c tv r -> [(t2,RType c tv (),RType c tv r)]
-checkMBodyUnify                 = go
+checkMBodyUnify = go
   where
-    go (RVar tv _) t            = [(tv, toRSort t, t)]
-    go t@(RApp {}) t'@(RApp {}) = concat $ zipWith go (rt_args t) (rt_args t')
-    go _ _                      = []
+    go (RVar tv _) t      = [(tv, toRSort t, t)]
+    go t@RApp{} t'@RApp{} = concat $ zipWith go (rt_args t) (rt_args t')
+    go _ _                = []
 
 checkMBody' :: (PPrint r, F.Reftable r,SubsTy RTyVar RSort r, F.Reftable (RTProp RTyCon RTyVar r))
             => F.TCEmb TyCon
             -> RType RTyCon RTyVar r
             -> F.SEnv F.SortedReft
-            -> F.SrcSpan 
+            -> F.SrcSpan
             -> Body
             -> Maybe Doc
 checkMBody' emb sort γ sp body = case body of
@@ -661,12 +682,12 @@
                 ++ show rw
                 ++ " as a rewrite because it does not prove an equality, or the equality it proves is trivial." ]
   | otherwise
-  = refErrs ++ if cannotInstantiate then
-        [ErrRewrite (GM.fSrcSpan t) $
+  = refErrs ++
+      [ ErrRewrite (GM.fSrcSpan t) $
         text $ "Could not generate any rewrites from equality. Likely causes: "
         ++ "\n - There are free (uninstantiatable) variables on both sides of the "
-        ++ "equality\n - The rewrite would diverge"]
-        else []
+        ++ "equality\n - The rewrite would diverge"
+      | cannotInstantiate]
     where
         refErrs = map getInnerRefErr (filter (hasInnerRefinement . fst) (zip tyArgs syms))
         allowedRWs = [ (lhs, rhs) | (lhs , rhs) <- refinementEQs t
@@ -724,9 +745,9 @@
 
 
 checkClassMeasures :: [Measure SpecType DataCon] -> Diagnostics
-checkClassMeasures ms = mkDiagnostics mempty (mapMaybe checkOne byTyCon)
+checkClassMeasures measures = mkDiagnostics mempty (mapMaybe checkOne byTyCon)
   where
-  byName = L.groupBy ((==) `on` (val . msName)) ms
+  byName = L.groupBy ((==) `on` (val . msName)) measures
 
   byTyCon = concatMap (L.groupBy ((==) `on` (dataConTyCon . ctor . head . msEqns)))
                       byName
diff --git a/src/Language/Haskell/Liquid/Bare/Class.hs b/src/Language/Haskell/Liquid/Bare/Class.hs
--- a/src/Language/Haskell/Liquid/Bare/Class.hs
+++ b/src/Language/Haskell/Liquid/Bare/Class.hs
@@ -2,18 +2,17 @@
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE ParallelListComp  #-}
 {-# LANGUAGE TupleSections     #-}
-{-# LANGUAGE BangPatterns      #-}
 
-module Language.Haskell.Liquid.Bare.Class 
+module Language.Haskell.Liquid.Bare.Class
   ( makeClasses
   , makeCLaws
   , makeSpecDictionaries
   , makeDefaultMethods
   , makeMethodTypes
-  ) 
+  )
   where
 
-import           Data.Bifunctor 
+import           Data.Bifunctor
 import qualified Data.Maybe                                 as Mb
 import qualified Data.List                                  as L
 import qualified Data.HashMap.Strict                        as M
@@ -23,14 +22,14 @@
 import qualified Language.Fixpoint.Types.Visitor            as F
 
 import           Language.Haskell.Liquid.Types.Dictionaries
-import qualified Language.Haskell.Liquid.GHC.Misc           as GM
-import qualified Language.Haskell.Liquid.GHC.API            as Ghc
+import qualified Liquid.GHC.Misc           as GM
+import qualified Liquid.GHC.API            as Ghc
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Types.RefType
 import           Language.Haskell.Liquid.Types              hiding (freeTyVars)
 
 import qualified Language.Haskell.Liquid.Measure            as Ms
-import           Language.Haskell.Liquid.Bare.Types         as Bare 
+import           Language.Haskell.Liquid.Bare.Types         as Bare
 import           Language.Haskell.Liquid.Bare.Resolve       as Bare
 import           Language.Haskell.Liquid.Bare.Expand        as Bare
 import           Language.Haskell.Liquid.Bare.Misc         as Bare
@@ -44,19 +43,19 @@
 -------------------------------------------------------------------------------
 makeMethodTypes :: Bool -> DEnv Ghc.Var LocSpecType -> [DataConP] -> [Ghc.CoreBind] -> [(Ghc.Var, MethodType LocSpecType)]
 -------------------------------------------------------------------------------
-makeMethodTypes allowTC (DEnv m) cls cbs 
-  = [(x, MT (addCC allowTC x . fromRISig <$> methodType d x m) (addCC allowTC x <$> classType (splitDictionary e) x)) | (d,e) <- ds, x <- grepMethods e]
-    where 
+makeMethodTypes allowTC (DEnv hm) cls cbs
+  = [(x, MT (addCC allowTC x . fromRISig <$> methodType d x hm) (addCC allowTC x <$> classType (splitDictionary e) x)) | (d,e) <- ds, x <- grepMethods e]
+    where
       grepMethods = filter GM.isMethod . freeVars mempty
       ds = filter (GM.isDictionary . fst) (concatMap unRec cbs)
       unRec (Ghc.Rec xes) = xes
       unRec (Ghc.NonRec x e) = [(x,e)]
 
       classType Nothing _ = Nothing
-      classType (Just (d, ts, _)) x = 
-        case filter ((==d) . Ghc.dataConWorkId . dcpCon) cls of 
-          (di:_) -> fmap ((dcpLoc di `F.atLoc`) . subst (zip (dcpFreeTyVars di) ts)) $ L.lookup (mkSymbol x) (dcpTyArgs di)
-          _      -> Nothing 
+      classType (Just (d, ts, _)) x =
+        case filter ((==d) . Ghc.dataConWorkId . dcpCon) cls of
+          (di:_) -> (dcpLoc di `F.atLoc`) . subst (zip (dcpFreeTyVars di) ts) <$> L.lookup (mkSymbol x) (dcpTyArgs di)
+          _      -> Nothing
 
       methodType d x m = ihastype (M.lookup d m) x
 
@@ -65,216 +64,215 @@
 
       mkSymbol x = F.dropSym 2 $ GM.simplesymbol x
 
-      subst [] t = t 
-      subst ((a,ta):su) t = subsTyVar_meet' (a,ofType ta) (subst su t)
+      subst [] t = t
+      subst ((a,ta):su) t = subsTyVarMeet' (a,ofType ta) (subst su t)
 
 addCC :: Bool -> Ghc.Var -> LocSpecType -> LocSpecType
-addCC allowTC x zz@(Loc l l' st0) 
-  = Loc l l' 
-  . addForall hst  
-  . mkArrow [] ps' [] [] 
-  . makeCls cs' 
-  . mapExprReft (\_ -> F.applyCoSub coSub) 
-  . subts su 
-  $ st  
+addCC allowTC var zz@(Loc l l' st0)
+  = Loc l l'
+  . addForall hst
+  . mkArrow [] ps' [] []
+  . makeCls cs'
+  . mapExprReft (\_ -> F.applyCoSub coSub)
+  . subts su
+  $ st
   where
     hst           = ofType (Ghc.expandTypeSynonyms t0) :: SpecType
-    t0            = Ghc.varType x 
+    t0            = Ghc.varType var
     tyvsmap       = case Bare.runMapTyVars allowTC t0 st err of
-                          Left e  -> Ex.throw e 
+                          Left e  -> Ex.throw e
                           Right s -> Bare.vmap s
     su            = [(y, rTyVar x)           | (x, y) <- tyvsmap]
     su'           = [(y, RVar (rTyVar x) ()) | (x, y) <- tyvsmap] :: [(RTyVar, RSort)]
     coSub         = M.fromList [(F.symbol y, F.FObj (F.symbol x)) | (y, x) <- su]
     ps'           = fmap (subts su') <$> ps
-    cs'           = [(F.dummySymbol, RApp c ts [] mempty) | (c, ts) <- cs ] 
+    cs'           = [(F.dummySymbol, RApp c ts [] mempty) | (c, ts) <- cs ]
     (_,_,cs,_)    = bkUnivClass (F.notracepp "hs-spec" $ ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
     (_,ps,_ ,st)  = bkUnivClass (F.notracepp "lq-spec" st0)
 
-    makeCls cs t  = foldr (uncurry rFun) t cs
-    err hsT lqT   = ErrMismatch (GM.fSrcSpan zz) (pprint x) 
+    makeCls c t  = foldr (uncurry rFun) t c
+    err hsT lqT   = ErrMismatch (GM.fSrcSpan zz) (pprint var)
       (text "makeMethodTypes")
       (pprint $ Ghc.expandTypeSynonyms t0)
       (pprint $ toRSort st0)
       (Just (hsT, lqT))
-      (Ghc.getSrcSpan x) 
+      (Ghc.getSrcSpan var)
 
     addForall (RAllT v t r) tt@(RAllT v' _ _)
       | v == v'
       = tt
-      | otherwise 
+      | otherwise
       = RAllT (updateRTVar v) (addForall t tt) r
-    addForall (RAllT v t r) t' 
-      = RAllT (updateRTVar v) (addForall t t') r 
-    addForall (RAllP _ t) t' 
+    addForall (RAllT v t r) t'
+      = RAllT (updateRTVar v) (addForall t t') r
+    addForall (RAllP _ t) t'
       = addForall t t'
     addForall _ (RAllP p t')
-      = RAllP (fmap (subts su') p) t' 
+      = RAllP (fmap (subts su') p) t'
     addForall (RFun _ _ t1 t2 _) (RFun x i t1' t2' r)
-      = RFun x i (addForall t1 t1') (addForall t2 t2') r  
-    addForall _ t 
-      = t 
+      = RFun x i (addForall t1 t1') (addForall t2 t2') r
+    addForall _ t
+      = t
 
 
 splitDictionary :: Ghc.CoreExpr -> Maybe (Ghc.Var, [Ghc.Type], [Ghc.Var])
-splitDictionary = go [] [] 
-  where 
+splitDictionary = go [] []
+  where
     go ts xs (Ghc.App e (Ghc.Tick _ a)) = go ts xs (Ghc.App e a)
-    go ts xs (Ghc.App e (Ghc.Type t))   = go (t:ts) xs e 
-    go ts xs (Ghc.App e (Ghc.Var x))    = go ts (x:xs) e 
-    go ts xs (Ghc.Tick _ t) = go ts xs t 
+    go ts xs (Ghc.App e (Ghc.Type t))   = go (t:ts) xs e
+    go ts xs (Ghc.App e (Ghc.Var x))    = go ts (x:xs) e
+    go ts xs (Ghc.Tick _ t) = go ts xs t
     go ts xs (Ghc.Var x) = Just (x, reverse ts, reverse xs)
     go _ _ _ = Nothing
 
 
 -------------------------------------------------------------------------------
-makeCLaws :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.ModSpecs 
+makeCLaws :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.ModSpecs
           -> Bare.Lookup [(Ghc.Class, [(ModName, Ghc.Var, LocSpecType)])]
 -------------------------------------------------------------------------------
-makeCLaws env sigEnv myName specs = do 
-  zMbs <- forM classTcs $ \(name, cls, tc) -> do 
-            clsMb <- mkClass env sigEnv myName name cls tc
-            case clsMb of 
-              Nothing -> 
-                return $ Nothing 
-              Just cls -> do 
-                gcls <- Mb.maybe (err tc) Right (Ghc.tyConClass_maybe tc) 
+makeCLaws env sigEnv myName specs = do
+  zMbs <- forM classTcs $ \(name, clss, tc) -> do
+            clsMb <- mkClass env sigEnv myName name clss tc
+            case clsMb of
+              Nothing ->
+                return Nothing
+              Just cls -> do
+                gcls <- Mb.maybe (err tc) Right (Ghc.tyConClass_maybe tc)
                 return $ Just (gcls, snd cls)
   return (Mb.catMaybes zMbs)
   where
     err tc   = error ("Not a type class: " ++ F.showpp tc)
-    classTc  = Bare.maybeResolveSym env myName "makeClass" . btc_tc . rcName 
+    classTc  = Bare.maybeResolveSym env myName "makeClass" . btc_tc . rcName
     classTcs = [ (name, cls, tc) | (name, spec) <- M.toList specs
                                  , cls          <- Ms.claws spec
-                                 , tc           <- Mb.maybeToList (classTc cls) 
+                                 , tc           <- Mb.maybeToList (classTc cls)
                ]
 
 -------------------------------------------------------------------------------
-makeClasses :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.ModSpecs 
+makeClasses :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.ModSpecs
             -> Bare.Lookup ([DataConP], [(ModName, Ghc.Var, LocSpecType)])
 -------------------------------------------------------------------------------
-makeClasses env sigEnv myName specs = do 
-  mbZs <- forM classTcs $ \(name, cls, tc) -> 
-            mkClass env sigEnv myName name cls tc 
-  return . second mconcat . unzip . Mb.catMaybes $ mbZs 
+makeClasses env sigEnv myName specs = do
+  mbZs <- forM classTcs $ \(name, cls, tc) ->
+            mkClass env sigEnv myName name cls tc
+  return . second mconcat . unzip . Mb.catMaybes $ mbZs
   where
     classTcs = [ (name, cls, tc) | (name, spec) <- M.toList specs
                                  , cls          <- Ms.classes spec
                                  , tc           <- Mb.maybeToList (classTc cls) ]
-    classTc = Bare.maybeResolveSym env myName "makeClass" . btc_tc . rcName 
+    classTc = Bare.maybeResolveSym env myName "makeClass" . btc_tc . rcName
 
-mkClass :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> RClass LocBareType -> Ghc.TyCon 
+mkClass :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> RClass LocBareType -> Ghc.TyCon
         -> Bare.Lookup (Maybe (DataConP, [(ModName, Ghc.Var, LocSpecType)]))
-mkClass env sigEnv _myName name (RClass cc ss as ms) 
-  = Bare.failMaybe env name 
-  . mkClassE env sigEnv _myName name (RClass cc ss as ms) 
+mkClass env sigEnv _myName name (RClass cc ss as ms)
+  = Bare.failMaybe env name
+  . mkClassE env sigEnv _myName name (RClass cc ss as ms)
 
-mkClassE :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> RClass LocBareType -> Ghc.TyCon 
+mkClassE :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> RClass LocBareType -> Ghc.TyCon
          -> Bare.Lookup (DataConP, [(ModName, Ghc.Var, LocSpecType)])
-mkClassE env sigEnv _myName name (RClass cc ss as ms) tc = do 
-    ss'    <- mapM (mkConstr   env sigEnv name) ss 
+mkClassE env sigEnv _myName name (RClass cc ss as ms) tc = do
+    ss'    <- mapM (mkConstr   env sigEnv name) ss
     meths  <- mapM (makeMethod env sigEnv name) ms'
     let vts = [ (m, v, t) | (m, kv, t) <- meths, v <- Mb.maybeToList (plugSrc kv) ]
     let sts = [(val s, unClass $ val t) | (s, _) <- ms | (_, _, t) <- meths]
-    let dcp = DataConP l dc αs [] (val <$> ss') (reverse sts) t False (F.symbol name) l'
+    let dcp = DataConP l dc αs [] (val <$> ss') (reverse sts) rt False (F.symbol name) l'
     return  $ F.notracepp msg (dcp, vts)
   where
     c      = btc_tc cc
     l      = loc  c
     l'     = locE c
-    msg    = "MKCLASS: " ++ F.showpp (cc, as, αs) 
+    msg    = "MKCLASS: " ++ F.showpp (cc, as, αs)
     (dc:_) = Ghc.tyConDataCons tc
     αs     = bareRTyVar <$> as
     as'    = [rVar $ GM.symbolTyVar $ F.symbol a | a <- as ]
     ms'    = [ (s, rFun "" (RApp cc (flip RVar mempty <$> as) [] mempty) <$> t) | (s, t) <- ms]
-    t      = rCls tc as'
+    rt     = rCls tc as'
 
-mkConstr :: Bare.Env -> Bare.SigEnv -> ModName -> LocBareType -> Bare.Lookup LocSpecType     
-mkConstr env sigEnv name = fmap (fmap dropUniv) . Bare.cookSpecTypeE env sigEnv name Bare.GenTV 
-  where 
+mkConstr :: Bare.Env -> Bare.SigEnv -> ModName -> LocBareType -> Bare.Lookup LocSpecType
+mkConstr env sigEnv name = fmap (fmap dropUniv) . Bare.cookSpecTypeE env sigEnv name Bare.GenTV
+  where
     dropUniv t           = t' where (_, _, t') = bkUniv t
 
    --FIXME: cleanup this code
-unClass :: SpecType -> SpecType 
+unClass :: SpecType -> SpecType
 unClass = snd . bkClass . thrd3 . bkUniv
 
-makeMethod :: Bare.Env -> Bare.SigEnv -> ModName -> (LocSymbol, LocBareType) 
+makeMethod :: Bare.Env -> Bare.SigEnv -> ModName -> (LocSymbol, LocBareType)
            -> Bare.Lookup (ModName, PlugTV Ghc.Var, LocSpecType)
 makeMethod env sigEnv name (lx, bt) = (name, mbV,) <$> Bare.cookSpecTypeE env sigEnv name mbV bt
-  where 
-    mbV = maybe Bare.GenTV Bare.LqTV (Bare.maybeResolveSym env name "makeMethod" lx) 
+  where
+    mbV = maybe Bare.GenTV Bare.LqTV (Bare.maybeResolveSym env name "makeMethod" lx)
 
 -------------------------------------------------------------------------------
-makeSpecDictionaries :: Bare.Env -> Bare.SigEnv -> ModSpecs -> DEnv Ghc.Var LocSpecType 
+makeSpecDictionaries :: Bare.Env -> Bare.SigEnv -> ModSpecs -> DEnv Ghc.Var LocSpecType
 -------------------------------------------------------------------------------
 makeSpecDictionaries env sigEnv specs
-  = dfromList 
-  . concatMap (makeSpecDictionary env sigEnv) 
+  = dfromList
+  . concatMap (makeSpecDictionary env sigEnv)
   $ M.toList specs
 
 makeSpecDictionary :: Bare.Env -> Bare.SigEnv -> (ModName, Ms.BareSpec)
                    -> [(Ghc.Var, M.HashMap F.Symbol (RISig LocSpecType))]
 makeSpecDictionary env sigEnv (name, spec)
-  = Mb.catMaybes 
-  . resolveDictionaries env name 
-  . fmap (makeSpecDictionaryOne env sigEnv name) 
-  . Ms.rinstance 
+  = Mb.catMaybes
+  . resolveDictionaries env name
+  . fmap (makeSpecDictionaryOne env sigEnv name)
+  . Ms.rinstance
   $ spec
 
-makeSpecDictionaryOne :: Bare.Env -> Bare.SigEnv -> ModName 
-                      -> RInstance LocBareType 
+makeSpecDictionaryOne :: Bare.Env -> Bare.SigEnv -> ModName
+                      -> RInstance LocBareType
                       -> (F.Symbol, M.HashMap F.Symbol (RISig LocSpecType))
-makeSpecDictionaryOne env sigEnv name (RI x t xts)
-         = makeDictionary $ F.notracepp "RI" $ RI x ts [(x, mkLSpecIType t) | (x, t) <- xts ] 
+makeSpecDictionaryOne env sigEnv name (RI bt lbt xts)
+         = makeDictionary $ F.notracepp "RI" $ RI bt ts [(x, mkLSpecIType t) | (x, t) <- xts ]
   where
-    ts      = mkTy' <$> t
-    as      = concatMap (univs . val) ts
-    univs t = (\(RTVar tv _, _) -> tv) <$> as where (as, _, _) = bkUniv t 
+    ts      = mkTy' <$> lbt
+    rts     = concatMap (univs . val) ts
+    univs t = (\(RTVar tv _, _) -> tv) <$> as where (as, _, _) = bkUniv t
 
     mkTy' :: LocBareType -> LocSpecType
     mkTy' = Bare.cookSpecType env sigEnv name Bare.GenTV
     mkTy :: LocBareType -> LocSpecType
-    mkTy = fmap (mapUnis tidy) . Bare.cookSpecType env sigEnv name 
+    mkTy = fmap (mapUnis tidy) . Bare.cookSpecType env sigEnv name
                Bare.GenTV -- (Bare.HsTV (Bare.lookupGhcVar env name "rawDictionaries" x))
     mapUnis f t = mkUnivs (f as) ps t0 where (as, ps, t0) = bkUniv t
 
-    tidy vs = l ++ r 
-      where (l,r) = L.partition (\(RTVar tv _,_) -> tv `elem` as) vs 
+    tidy vs = l ++ r
+      where (l,r) = L.partition (\(RTVar tv _,_) -> tv `elem` rts) vs
 
     mkLSpecIType :: RISig LocBareType -> RISig LocSpecType
     mkLSpecIType t = fmap mkTy t
 
-resolveDictionaries :: Bare.Env -> ModName -> [(F.Symbol, M.HashMap F.Symbol (RISig LocSpecType))] 
+resolveDictionaries :: Bare.Env -> ModName -> [(F.Symbol, M.HashMap F.Symbol (RISig LocSpecType))]
                     -> [Maybe (Ghc.Var, M.HashMap F.Symbol (RISig LocSpecType))]
-resolveDictionaries env name = fmap lookupVar 
-                             . concat 
-                             . fmap addInstIndex 
-                             . Misc.groupList 
+resolveDictionaries env name = fmap lookupVar
+                             . concatMap addInstIndex
+                             . Misc.groupList
   where
     lookupVar (x, inst)      = (, inst) <$> Bare.maybeResolveSym env name "resolveDict" (F.dummyLoc x)
 
 -- formerly, addIndex
 -- GHC internal postfixed same name dictionaries with ints
 addInstIndex            :: (F.Symbol, [a]) -> [(F.Symbol, a)]
-addInstIndex (x, is) = go 0 (reverse is)
-  where 
+addInstIndex (x, ks) = go (0::Int) (reverse ks)
+  where
     go _ []          = []
     go _ [i]         = [(x, i)]
     go j (i:is)      = (F.symbol (F.symbolString x ++ show j),i) : go (j+1) is
 
 ----------------------------------------------------------------------------------
-makeDefaultMethods :: Bare.Env -> [(ModName, Ghc.Var, LocSpecType)] 
+makeDefaultMethods :: Bare.Env -> [(ModName, Ghc.Var, LocSpecType)]
                    -> [(ModName, Ghc.Var, LocSpecType)]
 ----------------------------------------------------------------------------------
-makeDefaultMethods env mts = [ (mname, dm, t) 
+makeDefaultMethods env mts = [ (mname, dm, t)
                                  | (mname, m, t) <- mts
-                                 , dm            <- lookupDefaultVar env mname m ]  
+                                 , dm            <- lookupDefaultVar env mname m ]
 
-lookupDefaultVar :: Bare.Env -> ModName -> Ghc.Var -> [Ghc.Var] 
-lookupDefaultVar env name v = Mb.maybeToList 
-                            . Bare.maybeResolveSym env name "default-method" 
+lookupDefaultVar :: Bare.Env -> ModName -> Ghc.Var -> [Ghc.Var]
+lookupDefaultVar env name v = Mb.maybeToList
+                            . Bare.maybeResolveSym env name "default-method"
                             $ dmSym
-  where 
+  where
     dmSym                   = F.atLoc v (GM.qualifySymbol mSym dnSym)
     dnSym                   = F.mappendSym "$dm" nSym
-    (mSym, nSym)            = GM.splitModuleName (F.symbol v) 
+    (mSym, nSym)            = GM.splitModuleName (F.symbol v)
diff --git a/src/Language/Haskell/Liquid/Bare/DataType.hs b/src/Language/Haskell/Liquid/Bare/DataType.hs
--- a/src/Language/Haskell/Liquid/Bare/DataType.hs
+++ b/src/Language/Haskell/Liquid/Bare/DataType.hs
@@ -7,7 +7,7 @@
 
   -- * Names for accessing Data Constuctors 
   , makeDataConChecker
-  , makeDataConSelector 
+  , makeDataConSelector
   , addClassEmbeds
 
   -- * Constructors
@@ -17,6 +17,7 @@
   , meetDataConSpec
   -- , makeTyConEmbeds
 
+  , dataDeclSize
   ) where
 
 import           Prelude                                hiding (error)
@@ -26,11 +27,11 @@
 import qualified Data.List                              as L
 import qualified Data.HashMap.Strict                    as M
 import qualified Data.HashSet                           as S
-import qualified Data.Maybe                             as Mb 
+import qualified Data.Maybe                             as Mb
 
 import qualified Language.Fixpoint.Types                as F
-import qualified Language.Haskell.Liquid.GHC.Misc       as GM 
-import qualified Language.Haskell.Liquid.GHC.API        as Ghc 
+import qualified Liquid.GHC.Misc       as GM
+import qualified Liquid.GHC.API        as Ghc
 import           Language.Haskell.Liquid.Types.PredType (dataConPSpecType)
 import qualified Language.Haskell.Liquid.Types.RefType  as RT
 import           Language.Haskell.Liquid.Types.Types
@@ -39,10 +40,12 @@
 import qualified Language.Haskell.Liquid.Misc           as Misc
 import           Language.Haskell.Liquid.Types.Variance
 import           Language.Haskell.Liquid.WiredIn
+import           Language.Haskell.Liquid.Types.Names (selfSymbol)
 
 import qualified Language.Haskell.Liquid.Measure        as Ms
-import qualified Language.Haskell.Liquid.Bare.Types     as Bare  
-import qualified Language.Haskell.Liquid.Bare.Resolve   as Bare 
+
+import qualified Language.Haskell.Liquid.Bare.Types     as Bare
+import qualified Language.Haskell.Liquid.Bare.Resolve   as Bare
 import           Text.Printf                     (printf)
 import Text.PrettyPrint ((<+>))
 
@@ -64,7 +67,7 @@
 --------------------------------------------------------------------------------
 makeDataConChecker :: Ghc.DataCon -> F.Symbol
 --------------------------------------------------------------------------------
-makeDataConChecker = F.testSymbol . F.symbol 
+makeDataConChecker = F.testSymbol . F.symbol
 
 --------------------------------------------------------------------------------
 -- | 'makeDataConSelector d' creates the selector `select$d$i`
@@ -74,11 +77,11 @@
 --------------------------------------------------------------------------------
 makeDataConSelector :: Maybe Bare.DataConMap -> Ghc.DataCon -> Int -> F.Symbol
 makeDataConSelector dmMb d i = M.lookupDefault def (F.symbol d, i) dm
-  where 
-    dm                       = Mb.fromMaybe M.empty dmMb 
+  where
+    dm                       = Mb.fromMaybe M.empty dmMb
     def                      = makeDataConSelector' d i
- 
 
+
 makeDataConSelector' :: Ghc.DataCon -> Int -> F.Symbol
 makeDataConSelector' d i
   = symbolMeasure "$select" (dcSymbol d) (Just i)
@@ -89,13 +92,13 @@
 symbolMeasure :: String -> F.Symbol -> Maybe Int -> F.Symbol
 symbolMeasure f d iMb = foldr1 F.suffixSymbol (dcPrefix : F.symbol f : d : rest)
   where
-    rest          = maybe [] (Misc.singleton . F.symbol . show) iMb
+    rest          = maybe [] (Misc.single . F.symbol . show) iMb
 
 
 --------------------------------------------------------------------------------
 -- | makeClassEmbeds: sort-embeddings for numeric, and family-instance tycons
 --------------------------------------------------------------------------------
-addClassEmbeds :: Maybe [Ghc.ClsInst] -> [Ghc.TyCon] -> F.TCEmb Ghc.TyCon 
+addClassEmbeds :: Maybe [Ghc.ClsInst] -> [Ghc.TyCon] -> F.TCEmb Ghc.TyCon
                -> F.TCEmb Ghc.TyCon
 addClassEmbeds instenv fiTcs = makeFamInstEmbeds fiTcs . makeNumEmbeds instenv
 
@@ -106,10 +109,10 @@
 --   with the actual family instance  types that have numeric instances as int [Check!]
 --------------------------------------------------------------------------------
 makeFamInstEmbeds :: [Ghc.TyCon] -> F.TCEmb Ghc.TyCon -> F.TCEmb Ghc.TyCon
-makeFamInstEmbeds cs0 embs = L.foldl' embed embs famInstSorts
+makeFamInstEmbeds cs0 embeds = L.foldl' embed embeds famInstSorts
   where
     famInstSorts          = F.notracepp "famInstTcs"
-                            [ (c, RT.typeSort embs ty)
+                            [ (c, RT.typeSort embeds ty)
                                 | c   <- cs
                                 , ty  <- Mb.maybeToList (RT.famInstTyConType c) ]
     embed embs (c, t)     = F.tceInsert c t F.NoArgs embs
@@ -209,27 +212,27 @@
               -> [Located DataConP]
               -> (Diagnostics, [F.DataDecl])
 makeDataDecls cfg tce name tds ds
-  | makeDecls        = (mkDiagnostics warns [], okDecs)  
+  | makeDecls        = (mkDiagnostics warns [], okDecs)
   | otherwise        = (mempty, [])
   where
     makeDecls        = exactDCFlag cfg && not (noADT cfg)
     warns            = (mkWarnDecl . fst . fst . snd <$> badTcs) ++ (mkWarnDecl <$> badDecs)
     tds'             = resolveTyCons name tds
-    tcDds            = filter ((/= Ghc.listTyCon) . fst) 
+    tcDds            = filter ((/= Ghc.listTyCon) . fst)
                      $ groupDataCons tds' ds
     (okTcs, badTcs)  = L.partition isVanillaTc tcDds
-    decs             = [ makeFDataDecls tce tc dd ctors | (tc, (dd, ctors)) <- okTcs] 
+    decs             = [ makeFDataDecls tce tc dd ctors | (tc, (dd, ctors)) <- okTcs]
     (okDecs,badDecs) = checkRegularData decs
 
 isVanillaTc :: (a, (b, [(Ghc.DataCon, c)])) -> Bool
-isVanillaTc (_, (_, ctors)) = all (Ghc.isVanillaDataCon . fst) ctors 
+isVanillaTc (_, (_, ctors)) = all (Ghc.isVanillaDataCon . fst) ctors
 
 checkRegularData :: [F.DataDecl] -> ([F.DataDecl], [F.DataDecl])
 checkRegularData ds = (oks, badDs)
   where
     badDs           = F.checkRegular ds
     badSyms         = {- F.notracepp "BAD-Data" . -} S.fromList . fmap F.symbol $ badDs
-    oks             = [ d |  d <- ds, not (S.member (F.symbol d) badSyms) ] 
+    oks             = [ d |  d <- ds, not (S.member (F.symbol d) badSyms) ]
 
 mkWarnDecl :: (F.Loc a, F.Symbolic a) => a -> Warning
 mkWarnDecl d = mkWarning (GM.fSrcSpan d) ("Non-regular data declaration" <+> pprint (F.symbol d))
@@ -265,8 +268,8 @@
 -}
 resolveTyCons :: ModName -> [(ModName, Ghc.TyCon, DataPropDecl)]
               -> [(Ghc.TyCon, (ModName, DataPropDecl))]
-resolveTyCons m mtds = [(tc, (m, d)) | (tc, mds) <- M.toList tcDecls
-                                     , (m, d)    <- Mb.maybeToList $ resolveDecls m tc mds ]
+resolveTyCons mn mtds = [(tc, (m, d)) | (tc, mds) <- M.toList tcDecls
+                                      , (m, d)    <- Mb.maybeToList $ resolveDecls mn tc mds ]
   where
     tcDecls          = Misc.group [ (tc, (m, d)) | (m, tc, d) <- mtds ]
 
@@ -339,7 +342,7 @@
 makeDataFields tce _c as xts = [ F.DField x (fSort t) | (x, t) <- xts]
   where
     su    = zip (F.symbol <$> as) [0..]
-    fSort = F.substVars su . F.mapFVar (+ (length as)) . RT.rTypeSort tce
+    fSort = F.substVars su . F.mapFVar (+ length as) . RT.rTypeSort tce
 
 {- 
 muSort :: F.FTycon -> Int -> F.Sort -> F.Sort
@@ -351,45 +354,82 @@
 -}
 
 --------------------------------------------------------------------------------
-meetDataConSpec :: Bool -> F.TCEmb Ghc.TyCon -> [(Ghc.Var, SpecType)] -> [DataConP] 
+meetDataConSpec :: Bool -> F.TCEmb Ghc.TyCon -> [(Ghc.Var, SpecType)] -> [DataConP]
                 -> [(Ghc.Var, SpecType)]
 --------------------------------------------------------------------------------
 meetDataConSpec allowTC emb xts dcs  = M.toList $ snd <$> L.foldl' upd dcm0 xts
   where
-    dcm0                     = M.fromList (dataConSpec' allowTC dcs)
+    dcm0                     = M.fromListWith meetM (dataConSpec' allowTC dcs)
     upd dcm (x, t)           = M.insert x (Ghc.getSrcSpan x, tx') dcm
                                 where
                                   tx' = maybe t (meetX x t) (M.lookup x dcm)
-    meetX x t (sp', t')      = F.notracepp (_msg x t t') $ meetVarTypes emb (pprint x) (Ghc.getSrcSpan x, t) (sp', t') 
+    meetM (l,t) (_,t')       = (l, t `F.meet` t')
+    meetX x t (sp', t')      = F.notracepp (_msg x t t') $ meetVarTypes emb (pprint x) (Ghc.getSrcSpan x, t) (sp', t')
     _msg x t t'              = "MEET-VAR-TYPES: " ++ showpp (x, t, t')
 
 dataConSpec' :: Bool -> [DataConP] -> [(Ghc.Var, (Ghc.SrcSpan, SpecType))]
-dataConSpec' allowTC = concatMap tx 
+dataConSpec' allowTC = concatMap tx
   where
     tx dcp   =  [ (x, res) | (x, t0) <- dataConPSpecType allowTC dcp
-                          , let t    = RT.expandProductType x t0  
+                          , let t    = RT.expandProductType x t0
                           , let res  = (GM.fSrcSpan dcp, t)
                 ]
 --------------------------------------------------------------------------------
 -- | Bare Predicate: DataCon Definitions ---------------------------------------
 --------------------------------------------------------------------------------
-makeConTypes :: ModName -> Bare.Env -> [(ModName, Ms.BareSpec)] 
+makeConTypes :: ModName -> Bare.Env -> [(ModName, Ms.BareSpec)]
              -> Bare.Lookup ([(ModName, TyConP, Maybe DataPropDecl)], [[Located DataConP]])
 makeConTypes myName env specs =
-  Misc.concatUnzip <$> mapM (makeConTypes' myName env) specs 
+  Misc.concatUnzip <$> mapM (makeConTypes' myName env) specs
 
-  
-makeConTypes' :: ModName -> Bare.Env -> (ModName, Ms.BareSpec) 
+
+makeConTypes' :: ModName -> Bare.Env -> (ModName, Ms.BareSpec)
              -> Bare.Lookup ([(ModName, TyConP, Maybe DataPropDecl)], [[Located DataConP]])
 makeConTypes' _myName env (name, spec) = do
   dcs'   <- canonizeDecls env name dcs
-  let gvs = groupVariances dcs' vdcs
+  let dcs'' = dataDeclSize spec dcs'
+  let gvs = groupVariances dcs'' vdcs
   zong <- catLookups . map (uncurry (ofBDataDecl env name)) $ gvs
   return (unzip zong)
   where
-    dcs  = Ms.dataDecls spec 
-    vdcs = Ms.dvariance spec 
+    dcs  = Ms.dataDecls spec
+    vdcs = Ms.dvariance spec
 
+
+type DSizeMap = M.HashMap F.Symbol (F.Symbol, [F.Symbol])
+normalizeDSize :: [([LocBareType], F.LocSymbol)] -> DSizeMap
+normalizeDSize ds = M.fromList (concatMap go ds)
+  where go (ts,x) = let xs = Mb.mapMaybe (getTc . val) ts
+                    in [(tc, (val x, xs)) | tc <- xs]
+        getTc (RAllT _ t _)  = getTc t
+        getTc (RApp c _ _ _) = Just (val $ btc_tc c)
+        getTc _ = Nothing
+
+dataDeclSize :: Ms.BareSpec -> [DataDecl] -> [DataDecl]
+dataDeclSize spec dcs = makeSize smap <$> dcs
+  where smap = normalizeDSize $ Ms.dsize spec
+
+
+makeSize :: DSizeMap -> DataDecl -> DataDecl
+makeSize smap d
+  | Just p <- M.lookup (F.symbol $ tycName d) smap
+  = d {tycDCons = fmap (fmap (makeSizeCtor p)) (tycDCons d) }
+  | otherwise
+   = d
+
+makeSizeCtor :: (F.Symbol, [F.Symbol]) -> DataCtor -> DataCtor
+makeSizeCtor (s,xs) d = d {dcFields = Misc.mapSnd (mapBot go) <$> dcFields d}
+  where
+    go (RApp c ts rs r) | F.symbol c `elem` xs
+                        = RApp c ts rs (r `F.meet` rsz)
+    go t                = t
+    rsz  = MkUReft (F.Reft (F.vv_, F.PAtom F.Lt
+                                      (F.EApp (F.EVar s) (F.EVar F.vv_))
+                                      (F.EApp (F.EVar s) (F.EVar selfSymbol))
+                                      ))
+                   mempty
+
+
 catLookups :: [Bare.Lookup a] -> Bare.Lookup [a]
 catLookups = sequence . Mb.mapMaybe skipResolve
 
@@ -401,7 +441,7 @@
 isErrResolve ErrResolve {} = True
 isErrResolve _             =  False
 
-left' :: [e] -> Maybe (Either [e] a)  
+left' :: [e] -> Maybe (Either [e] a)
 left' [] = Nothing
 left' es = Just (Left es)
 
@@ -412,9 +452,9 @@
 --   instead of the unlifted versions.
 
 canonizeDecls :: Bare.Env -> ModName -> [DataDecl] -> Bare.Lookup [DataDecl]
-canonizeDecls env name ds = do
-  kds <- forM ds $ \d -> do
-           k <- dataDeclKey env name d 
+canonizeDecls env name dataDecls = do
+  kds <- forM dataDecls $ \d -> do
+           k <- dataDeclKey env name d
            return (fmap (, d) k)
   case Misc.uniqueByKey' selectDD (Mb.catMaybes kds) of
     Left  decls  -> Left [err decls]
@@ -428,13 +468,13 @@
     err ds@(d:_) = {- uError $ -} errDupSpecs (pprint (tycName d)) (GM.fSrcSpan <$> ds)
     err _        = impossible Nothing "canonizeDecls"
 
-dataDeclKey :: Bare.Env -> ModName -> DataDecl -> Bare.Lookup (Maybe F.Symbol) 
+dataDeclKey :: Bare.Env -> ModName -> DataDecl -> Bare.Lookup (Maybe F.Symbol)
 dataDeclKey env name d = do
   tcMb  <- Bare.lookupGhcDnTyCon env name "canonizeDecls" (tycName d)
   case tcMb of
-    Nothing -> 
+    Nothing ->
       return Nothing
-    Just tc -> do 
+    Just tc -> do
       _ <- checkDataCtors env name tc d (tycDCons d)
       return $ Just (F.symbol tc)
 
@@ -460,19 +500,18 @@
   -- The data constructors in the spec (which we have to qualify for them to match the GHC data constructors)
   mbDcs <- mapM (Bare.failMaybe env name . Bare.lookupGhcDataCon env name "checkDataCtors" . dcName) cons
   let rdcs = S.fromList . fmap F.symbol . Mb.catMaybes $ mbDcs
-
   if dcs == rdcs
     then mapM checkDataCtorDupField cons
     else Left [errDataConMismatch (dataNameSymbol (tycName dd)) dcs rdcs]
 
 -- | Checks whether the given data constructor has duplicate fields.
 --
-checkDataCtorDupField :: DataCtor -> Bare.Lookup DataCtor 
-checkDataCtorDupField d 
-  | x : _ <- dups = Left [err lc x]
-  | otherwise     = return d 
+checkDataCtorDupField :: DataCtor -> Bare.Lookup DataCtor
+checkDataCtorDupField d
+  | x : _ <- dups = Left [err sym x]
+  | otherwise     = return d
     where
-      lc          = dcName   d 
+      sym         = dcName   d
       xts         = dcFields d
       dups        = [ x | (x, ts) <- Misc.groupList xts, 2 <= length ts ]
       err lc x    = ErrDupField (GM.sourcePosSrcSpan $ loc lc) (pprint $ val lc) (pprint x)
@@ -511,7 +550,7 @@
     isGADT        = Ghc.isGadtSyntaxTyCon c
 
 getDnTyCon :: Bare.Env -> ModName -> DataName -> Bare.Lookup Ghc.TyCon
-getDnTyCon env name dn = do 
+getDnTyCon env name dn = do
   tcMb <- Bare.lookupGhcDnTyCon env name "ofBDataDecl-1" dn
   case tcMb of
     Just tc -> return tc
@@ -522,7 +561,7 @@
 -- FIXME: ES: why the maybes?
 ofBDataDecl :: Bare.Env -> ModName -> Maybe DataDecl -> Maybe (LocSymbol, [Variance])
             -> Bare.Lookup ( (ModName, TyConP, Maybe DataPropDecl), [Located DataConP] )
-ofBDataDecl env name (Just dd@(DataDecl tc as ps cts pos sfun pt _)) maybe_invariance_info = do 
+ofBDataDecl env name (Just dd@(DataDecl tc as ps cts pos sfun pt _)) maybe_invariance_info = do
   let Loc lc lc' _ = dataNameSymbol tc
   let πs           = Bare.ofBPVar env name pos <$> ps
   let αs           = RTV . GM.symbolTyVar <$> as
@@ -530,21 +569,21 @@
   let initmap      = zip (RT.uPVar <$> πs) [0..]
   tc'             <- getDnTyCon env name tc
   cts'            <- mapM (ofBDataCtor env name lc lc' tc' αs ps πs) (Mb.fromMaybe [] cts)
-  unless (checkDataDecl tc' dd) (Left [err])  
-  let pd           = Bare.ofBareType env name lc (Just []) <$> (F.tracepp "ofBDataDecl-prop" pt)
+  unless (checkDataDecl tc' dd) (Left [err])
+  let pd           = Bare.ofBareType env name lc (Just []) <$> F.tracepp "ofBDataDecl-prop" pt
   let tys          = [t | dcp <- cts', (_, t) <- dcpTyArgs dcp]
   let varInfo      = L.nub $  concatMap (getPsSig initmap True) tys
   let defPs        = varSignToVariance varInfo <$> [0 .. (length πs - 1)]
   let (tvi, pvi)   = case maybe_invariance_info of
                        Nothing     -> ([], defPs)
-                       Just (_,is) -> let is_n = drop n is in 
+                       Just (_,is) -> let is_n = drop n is in
                                       (take n is, if null is_n then defPs else is_n)
   let tcp          = TyConP lc tc' αs πs tvi pvi sfun
   return ((name, tcp, Just (dd { tycDCons = cts }, pd)), Loc lc lc' <$> cts')
   where
-    err            = ErrBadData (GM.fSrcSpan tc) (pprint tc) "Mismatch in number of type variables" 
+    err            = ErrBadData (GM.fSrcSpan tc) (pprint tc) "Mismatch in number of type variables"
 
-ofBDataDecl env name Nothing (Just (tc, is)) =  
+ofBDataDecl env name Nothing (Just (tc, is)) =
   case Bare.lookupGhcTyCon env name "ofBDataDecl-2" tc of
     Left e    -> Left e
     Right tc' -> Right ((name, TyConP srcpos tc' [] [] tcov tcontr Nothing, Nothing), [])
@@ -556,7 +595,7 @@
   = panic Nothing "Bare.DataType.ofBDataDecl called on invalid inputs"
 
 -- TODO:EFFECTS:ofBDataCon
-ofBDataCtor :: Bare.Env 
+ofBDataCtor :: Bare.Env
             -> ModName
             -> F.SourcePos
             -> F.SourcePos
@@ -568,29 +607,29 @@
             -> Bare.Lookup DataConP
 ofBDataCtor env name l l' tc αs ps πs dc = do
   c' <- Bare.lookupGhcDataCon env name "ofBDataCtor" (dcName dc)
-  return (ofBDataCtorTc env name l l' tc αs ps πs dc c') 
+  return (ofBDataCtorTc env name l l' tc αs ps πs dc c')
 
-ofBDataCtorTc :: Bare.Env -> ModName -> F.SourcePos -> F.SourcePos -> 
-                 Ghc.TyCon -> [RTyVar] -> [PVar BSort] -> [PVar RSort] -> DataCtor -> Ghc.DataCon -> 
+ofBDataCtorTc :: Bare.Env -> ModName -> F.SourcePos -> F.SourcePos ->
+                 Ghc.TyCon -> [RTyVar] -> [PVar BSort] -> [PVar RSort] -> DataCtor -> Ghc.DataCon ->
                  DataConP
-ofBDataCtorTc env name l l' tc αs ps πs _ctor@(DataCtor _c as _ xts res) c' = 
-  DataConP 
-    { dcpLoc        = l                
-    , dcpCon        = c'                
-    , dcpFreeTyVars = RT.symbolRTyVar <$> as 
-    , dcpFreePred   = πs                 
-    , dcpTyConstrs  = cs                
-    , dcpTyArgs     = zts                 
-    , dcpTyRes      = ot                
-    , dcpIsGadt     = isGadt                
-    , dcpModule     = F.symbol name          
+ofBDataCtorTc env name l l' tc αs ps πs _ctor@(DataCtor _c as _ xts res) c' =
+  DataConP
+    { dcpLoc        = l
+    , dcpCon        = c'
+    , dcpFreeTyVars = RT.symbolRTyVar <$> as
+    , dcpFreePred   = πs
+    , dcpTyConstrs  = cs
+    , dcpTyArgs     = zts
+    , dcpTyRes      = ot
+    , dcpIsGadt     = isGadt
+    , dcpModule     = F.symbol name
     , dcpLocE       = l'
-    } 
+    }
   where
     ts'           = Bare.ofBareType env name l (Just ps) <$> ts
     res'          = Bare.ofBareType env name l (Just ps) <$> res
     t0'           = dataConResultTy c' αs t0 res'
-    _cfg          = getConfig env 
+    _cfg          = getConfig env
     (yts, ot)     = qualifyDataCtor (not isGadt) name dLoc (zip xs ts', t0')
     zts           = zipWith (normalizeField c') [1..] (reverse yts)
     usedTvs       = S.fromList (ty_var_value <$> concatMap RT.freeTyVars (t0':ts'))
@@ -636,8 +675,8 @@
 getPsSigPs m pos (RProp _ t) = getPsSig m pos t
 
 addps :: [(UsedPVar, a)] -> b -> UReft t -> [(a, b)]
-addps m pos (MkUReft _ ps) = (flip (,)) pos . f  <$> pvars ps
-  where 
+addps m pos (MkUReft _ ps) = (, pos) . f  <$> pvars ps
+  where
     f = Mb.fromMaybe (panic Nothing "Bare.addPs: notfound") . (`L.lookup` m) . RT.uPVar
 
 keepPredType :: S.HashSet RTyVar -> SpecType -> Bool
@@ -656,7 +695,7 @@
                 -> SpecType
 dataConResultTy c _ _ (Just t) = F.notracepp ("dataConResultTy-3 : vanilla = " ++ show (Ghc.isVanillaDataCon c) ++ " : ") t
 dataConResultTy c _ t _
-  | Ghc.isVanillaDataCon c     = F.notracepp ("dataConResultTy-1 : " ++ F.showpp c) $ t
+  | Ghc.isVanillaDataCon c     = F.notracepp ("dataConResultTy-1 : " ++ F.showpp c) t
   | otherwise                  = F.notracepp ("dataConResultTy-2 : " ++ F.showpp c) $ RT.ofType ct
   where
     (_,_,_,_,_,ct)             = Ghc.dataConFullSig c
@@ -679,18 +718,18 @@
 type CtorType = ([(F.Symbol, SpecType)], SpecType)
 
 qualifyDataCtor :: Bool -> ModName -> F.Located a -> CtorType -> CtorType
-qualifyDataCtor qualFlag name l ct@(xts, t)
+qualifyDataCtor qualFlag name l ct@(xts, st)
  | qualFlag  = (xts', t')
  | otherwise = ct
  where
-   t'        = F.subst su <$> t
+   t'        = F.subst su <$> st
    xts'      = [ (qx, F.subst su t)       | (qx, t, _) <- fields ]
    su        = F.mkSubst [ (x, F.eVar qx) | (qx, _, Just x) <- fields ]
    fields    = [ (qx, t, mbX) | (x, t) <- xts, let (mbX, qx) = qualifyField name (F.atLoc l x) ]
 
 qualifyField :: ModName -> LocSymbol -> (Maybe F.Symbol, F.Symbol)
 qualifyField name lx
- | needsQual = (Just x, F.notracepp msg $ qualifyModName name x) 
+ | needsQual = (Just x, F.notracepp msg $ qualifyModName name x)
  | otherwise = (Nothing, x)
  where
    msg       = "QUALIFY-NAME: " ++ show x ++ " in module " ++ show (F.symbol name)
@@ -698,18 +737,18 @@
    needsQual = not (isWiredIn lx)
 
 checkRecordSelectorSigs :: [(Ghc.Var, LocSpecType)] -> [(Ghc.Var, LocSpecType)]
-checkRecordSelectorSigs vts = [ (v, take1 v ts) | (v, ts) <- Misc.groupList vts ] 
-  where 
-    take1 v ts              = case Misc.nubHashOn (showpp . val) ts of 
-                                [t]    -> t 
+checkRecordSelectorSigs vts = [ (v, take1 v lspecTys) | (v, lspecTys) <- Misc.groupList vts ]
+  where
+    take1 v lsts            = case Misc.nubHashOn (showpp . val) lsts of
+                                [t]    -> t
                                 (t:ts) -> Ex.throw (ErrDupSpecs (GM.fSrcSpan t) (pprint v) (GM.fSrcSpan <$> ts) :: Error)
                                 _      -> impossible Nothing "checkRecordSelectorSigs"
 
 
 strengthenClassSel :: Ghc.Var -> LocSpecType -> LocSpecType
-strengthenClassSel v lt = lt { val = t }
+strengthenClassSel v lt = lt { val = st }
  where
-  t = runReader (go (F.val lt)) (1, [])
+  st = runReader (go (F.val lt)) (1, [])
   s = GM.namedLocSymbol v
   extend :: F.Symbol -> (Int, [F.Symbol]) -> (Int, [F.Symbol])
   extend x (i, xs) = (i + 1, x : xs)
@@ -717,7 +756,7 @@
   go (RAllT a t r) = RAllT a <$> go t <*> pure r
   go (RAllP p t  ) = RAllP p <$> go t
   go (RFun x i tx t r) | isEmbeddedClass tx =
-    RFun <$> pure x <*> return i <*> pure tx <*> go t <*> pure r
+    RFun x i tx <$> go t <*> pure r
   go (RFun x i tx t r) = do
     x' <- unDummy x <$> reader fst
     r' <- singletonApp s <$> (L.reverse <$> reader snd)
@@ -745,13 +784,13 @@
     || any (isFunTy . snd) args && not (higherOrderFlag env)   -- OR function-valued fields
     || dcpIsGadt dcp              -- OR GADT style datcon
     = []
-    | otherwise 
-    = [ (v, t) | (Just v, t) <- zip fs ts ] 
+    | otherwise
+    = [ (v, t) | (Just v, t) <- zip fs ts ]
     where
       maybe_cls = Ghc.tyConClass_maybe (Ghc.dataConTyCon dc)
       dc  = dcpCon dcp
       fls = Ghc.dataConFieldLabels dc
-      fs  = Bare.lookupGhcNamedVar env name . Ghc.flSelector <$> fls 
+      fs  = Bare.lookupGhcNamedVar env name . Ghc.flSelector <$> fls
       ts :: [ LocSpecType ]
       ts = [ Loc l l' (mkArrow (zip (makeRTVar <$> dcpFreeTyVars dcp) (repeat mempty)) []
                                  [] [(z, classRFInfo True, res, mempty)]
@@ -761,12 +800,12 @@
                -- the measure singleton refinement, eg `v = getBar foo`
              , let mt = RT.uReft (vv, F.PAtom F.Eq (F.EVar vv) (F.EApp (F.EVar x) (F.EVar z)))
              ]
-  
+
       su   = F.mkSubst [ (x, F.EApp (F.EVar x) (F.EVar z)) | x <- fst <$> args ]
       args = dcpTyArgs dcp
       z    = "lq$recSel"
       res  = dropPreds (dcpTyRes dcp)
-  
+
       -- FIXME: this is clearly imprecise, but the preds in the DataConP seem
       -- to be malformed. If we leave them in, tests/pos/kmp.hs fails with
       -- a malformed predicate application. Niki, help!!
diff --git a/src/Language/Haskell/Liquid/Bare/Elaborate.hs b/src/Language/Haskell/Liquid/Bare/Elaborate.hs
--- a/src/Language/Haskell/Liquid/Bare/Elaborate.hs
+++ b/src/Language/Haskell/Liquid/Bare/Elaborate.hs
@@ -6,6 +6,12 @@
 {-# LANGUAGE LambdaCase                #-}
 {-# LANGUAGE OverloadedStrings         #-}
 {-# LANGUAGE CPP                       #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- TODO(#1913): Fix import of Data.Functor.Foldable.Fix
+{-# OPTIONS_GHC -Wno-unused-top-binds #-} -- TODO(#1914): Is RTypeF even used?
+
 -- | This module uses GHC API to elaborate the resolves expressions
 
 -- TODO: Genearlize to BareType and replace the existing resolution mechanisms
@@ -19,8 +25,8 @@
 
 import qualified Language.Fixpoint.Types       as F
 -- import           Control.Arrow
-import           Language.Haskell.Liquid.GHC.API hiding (panic, varName)
-import qualified Language.Haskell.Liquid.GHC.Misc
+import           Liquid.GHC.API hiding (panic, varName)
+import qualified Liquid.GHC.Misc
                                                as GM
 import           Language.Haskell.Liquid.Types.Types
 import           Language.Haskell.Liquid.Types.RefType
@@ -36,34 +42,13 @@
 import           Data.Functor.Foldable
 #endif
 
--- import           TcRnMonad (TcRn)
 import           Data.Char                      ( isUpper )
-#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
 import           GHC.Types.Name.Occurrence
-#else
-import           OccName
-#endif
--- import           GHC
--- import           GhcPlugins                     ( isDFunId
---                                                 )
-
--- import           FastString
--- import           CoreSyn
--- import           PrelNames
-import qualified Language.Haskell.Liquid.GHC.API as Ghc
+import qualified Liquid.GHC.API as Ghc
                                                 (noExtField)
-
--- import qualified Outputable                    as O
--- import           TysWiredIn                     ( boolTyCon
---                                                 , true_RDR
---                                                 )
--- import           RdrName
--- import           BasicTypes
 import           Data.Default                   ( def )
 import qualified Data.Maybe                    as Mb
--- import qualified CoreUtils                     as Utils
 
-
 -- TODO: make elaboration monadic so typeclass names are unified to something
 -- that is generated in advance. This can greatly simplify the implementation
 -- of elaboration
@@ -282,22 +267,22 @@
 -- | returns (lambda binders, forall binders)
 collectSpecTypeBinders :: SpecType -> ([F.Symbol], [F.Symbol])
 collectSpecTypeBinders = para $ \case
-  RFunF bind _ (tin, _) (_, (bs, abs)) _ | isClassType tin -> (bs, abs)
-                                       | otherwise       -> (bind : bs, abs)
-  RImpFF bind _ (tin, _) (_, (bs, abs)) _ | isClassType tin -> (bs, abs)
-                                        | otherwise       -> (bind : bs, abs)
-  RAllEF b _ (_, (bs, abs))  -> (b : bs, abs)
-  RAllTF (RTVar (RTV ab) _) (_, (bs, abs)) _ -> (bs, F.symbol ab : abs)
-  RExF b _ (_, (bs, abs))    -> (b : bs, abs)
-  RAppTyF _ (_, (bs, abs)) _ -> (bs, abs)
-  RRTyF _ _ _ (_, (bs, abs)) -> (bs, abs)
+  RFunF bind _ (tin, _) (_, (bs, abs')) _ | isClassType tin -> (bs, abs')
+                                       | otherwise       -> (bind : bs, abs')
+  RImpFF bind _ (tin, _) (_, (bs, abs')) _ | isClassType tin -> (bs, abs')
+                                        | otherwise       -> (bind : bs, abs')
+  RAllEF b _ (_, (bs, abs'))  -> (b : bs, abs')
+  RAllTF (RTVar (RTV ab) _) (_, (bs, abs')) _ -> (bs, F.symbol ab : abs')
+  RExF b _ (_, (bs, abs'))    -> (b : bs, abs')
+  RAppTyF _ (_, (bs, abs')) _ -> (bs, abs')
+  RRTyF _ _ _ (_, (bs, abs')) -> (bs, abs')
   _                          -> ([], [])
 
 -- really should be fused with collectBinders. However, we need the binders
 -- to correctly convert fixpoint expressions to ghc expressions because of
 -- namespace related issues (whether the symbol denotes a varName or a datacon)
 buildHsExpr :: LHsExpr GhcPs -> SpecType -> LHsExpr GhcPs
-buildHsExpr res = para $ \case
+buildHsExpr result = para $ \case
   RFunF bind _ (tin, _) (_, res) _
     | isClassType tin -> res
     | otherwise       -> mkHsLam [nlVarPat (varSymbolToRdrName bind)] res
@@ -309,7 +294,7 @@
   RExF    _ _        (_, res) -> res
   RAppTyF _ (_, res) _        -> res
   RRTyF _ _ _ (_, res)        -> res
-  _                           -> res
+  _                           -> result
 
 
 
@@ -504,8 +489,7 @@
     -- in the future
     RExprArg _ -> impossible Nothing "RExprArg should not appear here"
     RHole    _ -> impossible Nothing "RHole should not appear here"
-    RRTy _ _ _ _ ->
-      todo Nothing ("Not sure how to elaborate RRTy" ++ F.showpp t)
+    RRTy{}     -> todo Nothing ("Not sure how to elaborate RRTy" ++ F.showpp t)
  where
   boolType = RApp (RTyCon boolTyCon [] def) [] [] mempty :: SpecType
   elaborateReft
@@ -515,7 +499,7 @@
     -> ([F.Symbol] -> F.Expr -> TcRn a)
     -> TcRn a
   elaborateReft (reft@(F.Reft (vv, e)), vvTy) trivial nonTrivialCont =
-    if isTrivial reft
+    if isTrivial' reft
       then trivial
       else do
         let
@@ -531,16 +515,9 @@
             buildHsExpr (fixExprToHsExpr (S.fromList origBinders) e)
                         querySpecType :: LHsExpr GhcPs
           exprWithTySigs = noLoc $ ExprWithTySig
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)        
-            (mkLHsSigWcType (specTypeToLHsType querySpecType))
-            hsExpr
-#else
             Ghc.noExtField
             hsExpr
             (mkLHsSigWcType (specTypeToLHsType querySpecType))
-#endif
-#endif
         eeWithLamsCore <- GM.elabRnExpr TM_Inst exprWithTySigs
         eeWithLamsCore' <- simplify eeWithLamsCore
         let
@@ -549,7 +526,7 @@
               . ofType
               . exprType
               $ eeWithLamsCore'
-          substTy = zip tyBinders origTyBinders
+          substTy' = zip tyBinders origTyBinders
           eeWithLams =
             coreToLogic (GM.notracePpr "eeWithLamsCore" eeWithLamsCore')
           (bs', ee) = F.notracepp "grabLams" $ grabLams ([], eeWithLams)
@@ -563,11 +540,11 @@
               "Oops, Ghc gave back more/less binders than I expected"
         ret <- nonTrivialCont
           dictbs
-          ( renameBinderCoerc (\x -> Mb.fromMaybe x (L.lookup x substTy))
+          ( renameBinderCoerc (\x -> Mb.fromMaybe x (L.lookup x substTy'))
           . F.substa (\x -> Mb.fromMaybe x (L.lookup x subst))
           $ F.notracepp
               (  "elaborated: subst "
-              ++ F.showpp substTy
+              ++ F.showpp substTy'
               ++ "  "
               ++ F.showpp
                    (ofType $ exprType eeWithLamsCore' :: SpecType)
@@ -576,9 +553,9 @@
           )  -- (GM.dropModuleUnique <$> bs')
         pure (F.notracepp "result" ret)
                            -- (F.substa )
-  isTrivial :: F.Reft -> Bool
-  isTrivial (F.Reft (_, F.PTrue)) = True
-  isTrivial _                     = False
+  isTrivial' :: F.Reft -> Bool
+  isTrivial' (F.Reft (_, F.PTrue)) = True
+  isTrivial' _                     = False
 
   grabLams :: ([F.Symbol], F.Expr) -> ([F.Symbol], F.Expr)
   grabLams (bs, F.ELam (b, _) e) = grabLams (b : bs, e)
@@ -607,7 +584,7 @@
   rename (   F.PIff e0 e1      ) = F.PIff (rename e0) (rename e1)
   rename (   F.PAtom brel e0 e1) = F.PAtom brel (rename e0) (rename e1)
   rename (F.ECoerc _ _ e') = rename e'
-    
+
   rename e = panic
     Nothing
     ("renameBinderCoerc: Not sure how to handle the expression " ++ F.showpp e)
@@ -630,11 +607,7 @@
 
 
 mkHsTyConApp ::  IdP (GhcPass p) -> [LHsType (GhcPass p)] -> LHsType (GhcPass p)
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-mkHsTyConApp = nlHsTyConApp 
-#else
 mkHsTyConApp tyconId tyargs = nlHsTyConApp Prefix tyconId (map HsValArg tyargs)
-#endif
 
 -- | Embed fixpoint expressions into parsed haskell expressions.
 --   It allows us to bypass the GHC parser and use arbitrary symbols
@@ -755,21 +728,14 @@
   flip (ghylo (distPara @SpecType) distAna) (fmap pure . project) $ \case
     RVarF (RTV tv) _ -> nlHsTyVar
       -- (GM.notracePpr ("varRdr" ++ F.showpp (F.symbol tv)) $ getRdrName tv)
-      (symbolToRdrNameNs tvName (F.symbol tv)) 
+      (symbolToRdrNameNs tvName (F.symbol tv))
     RFunF _ _ (tin, tin') (_, tout) _
       | isClassType tin -> noLoc $ HsQualTy Ghc.noExtField (noLoc [tin']) tout
       | otherwise       -> nlHsFunTy tin' tout
     RImpFF _ _ (_, tin) (_, tout) _              -> nlHsFunTy tin tout
     RAllTF (ty_var_value -> (RTV tv)) (_, t) _ -> noLoc $ HsForAllTy
       Ghc.noExtField
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
-      ForallInvis
-#endif
-      [noLoc $ UserTyVar Ghc.noExtField (noLoc $ symbolToRdrNameNs tvName (F.symbol tv))]
-#else
       (mkHsForAllInvisTele [noLoc $ UserTyVar Ghc.noExtField SpecifiedSpec (noLoc $ symbolToRdrNameNs tvName (F.symbol tv))])
-#endif
       t
     RAllPF _ (_, ty)                    -> ty
     RAppF RTyCon { rtc_tc = tc } ts _ _ -> mkHsTyConApp
@@ -789,68 +755,3 @@
     RHoleF _                 -> noLoc $ HsWildCardTy Ghc.noExtField
     RExprArgF _ ->
       todo Nothing "Oops, specTypeToLHsType doesn't know how to handle RExprArg"
-
-
-bareTypeToLHsType :: BareType -> LHsType GhcPs
--- surprised that the type application is necessary
-bareTypeToLHsType =
-  flip (ghylo (distPara @BareType) distAna) (fmap pure . project) $ \case
-    RVarF (BTV tv) _ -> nlHsTyVar
-      -- (GM.notracePpr ("varRdr" ++ F.showpp (F.symbol tv)) $ getRdrName tv)
-      (symbolToRdrNameNs tvName (F.symbol tv)) 
-    RFunF _ _ (tin, tin') (_, tout) _
-      | isClassType tin -> noLoc $ HsQualTy Ghc.noExtField (noLoc [tin']) tout
-      | otherwise       -> nlHsFunTy tin' tout
-    RImpFF _ _ (_, tin) (_, tout) _              -> nlHsFunTy tin tout
-    RAllTF (ty_var_value -> (BTV tv)) (_, t) _ -> noLoc $ HsForAllTy
-      Ghc.noExtField
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
-      ForallInvis
-#endif
-      [noLoc $ UserTyVar Ghc.noExtField (noLoc $ symbolToRdrNameNs tvName (F.symbol tv))]
-#else
-      (mkHsForAllInvisTele [noLoc $ UserTyVar Ghc.noExtField SpecifiedSpec (noLoc $ symbolToRdrNameNs tvName (F.symbol tv))])
-#endif
-      t
-    RAllPF _ (_, ty)                    -> ty
-    RAppF BTyCon { btc_tc = tc } ts _ _ -> mkHsTyConApp
-      (symbolToRdrNameNs tcName (F.val tc))
-      [ hst | (t, hst) <- ts, notExprArg t ]
-     where
-      notExprArg (RExprArg _) = False
-      notExprArg _            = True
-    RAllEF _ (_, tin) (_, tout) -> nlHsFunTy tin tout
-    RExF   _ (_, tin) (_, tout) -> nlHsFunTy tin tout
-    -- impossible
-    RAppTyF _ (RExprArg _, _) _ ->
-      impossible Nothing "RExprArg should not appear here"
-    RAppTyF (_, t) (_, t') _ -> nlHsAppTy t t'
-    -- YL: todo..
-    RRTyF _ _ _ (_, t)       -> t
-    RHoleF _                 -> noLoc $ HsWildCardTy Ghc.noExtField
-    RExprArgF _ ->
-      todo Nothing "Oops, specTypeToLHsType doesn't know how to handle RExprArg"
-
-
--- the core expression returned by ghc might be eta-expanded
--- we need to do elimination so Pred doesn't contain lambda terms
-eliminateEta :: F.Expr -> F.Expr
-eliminateEta (F.EApp e0 e1) = F.EApp (eliminateEta e0) (eliminateEta e1)
-eliminateEta (F.ENeg e    ) = F.ENeg (eliminateEta e)
-eliminateEta (F.EBin bop e0 e1) =
-  F.EBin bop (eliminateEta e0) (eliminateEta e1)
-eliminateEta (F.EIte e0 e1 e2) =
-  F.EIte (eliminateEta e0) (eliminateEta e1) (eliminateEta e2)
-eliminateEta (F.ECst e0 s) = F.ECst (eliminateEta e0) s
-eliminateEta (F.ELam (x, t) body)
-  | F.EApp e0 (F.EVar x') <- ebody, x == x' && notElem x (F.syms e0) = e0
-  | otherwise = F.ELam (x, t) ebody
-  where ebody = eliminateEta body
-eliminateEta (F.PAnd es   ) = F.PAnd (eliminateEta <$> es)
-eliminateEta (F.POr  es   ) = F.POr (eliminateEta <$> es)
-eliminateEta (F.PNot e    ) = F.PNot (eliminateEta e)
-eliminateEta (F.PImp e0 e1) = F.PImp (eliminateEta e0) (eliminateEta e1)
-eliminateEta (F.PAtom brel e0 e1) =
-  F.PAtom brel (eliminateEta e0) (eliminateEta e1)
-eliminateEta e = e
diff --git a/src/Language/Haskell/Liquid/Bare/Expand.hs b/src/Language/Haskell/Liquid/Bare/Expand.hs
--- a/src/Language/Haskell/Liquid/Bare/Expand.hs
+++ b/src/Language/Haskell/Liquid/Bare/Expand.hs
@@ -2,19 +2,16 @@
 --   and the pipeline for "cooking" a @BareType@ into a @SpecType@. 
 --   TODO: _only_ export `makeRTEnv`, `cookSpecType` and maybe `qualifyExpand`...
 
-{-# LANGUAGE TupleSections         #-}
-{-# LANGUAGE TypeSynonymInstances  #-}
 {-# LANGUAGE FlexibleInstances     #-}
 {-# LANGUAGE PartialTypeSignatures #-}
 {-# LANGUAGE OverloadedStrings     #-}
 
-
-module Language.Haskell.Liquid.Bare.Expand 
+module Language.Haskell.Liquid.Bare.Expand
   ( -- * Create alias expansion environment
-    makeRTEnv 
+    makeRTEnv
 
     -- * Expand and Qualify 
-  , qualifyExpand 
+  , qualifyExpand
 
     -- * Converting BareType to SpecType
   , cookSpecType
@@ -30,23 +27,23 @@
 import Data.Maybe
 
 import           Control.Monad.State
+import           Data.Functor ((<&>))
 import qualified Control.Exception         as Ex
 import qualified Data.HashMap.Strict       as M
-import qualified Data.HashSet              as S
 import qualified Data.Char                 as Char
 import qualified Data.List                 as L
-import qualified Text.Printf               as Printf 
+import qualified Text.Printf               as Printf
 import qualified Text.PrettyPrint.HughesPJ as PJ
 
-import qualified Language.Fixpoint.Types               as F 
+import qualified Language.Fixpoint.Types               as F
 -- import qualified Language.Fixpoint.Types.Visitor       as F 
-import qualified Language.Fixpoint.Misc                as Misc 
+import qualified Language.Fixpoint.Misc                as Misc
 import           Language.Fixpoint.Types (Expr(..)) -- , Symbol, symbol) 
-import qualified Language.Haskell.Liquid.GHC.Misc      as GM 
-import qualified Language.Haskell.Liquid.GHC.API       as Ghc 
-import qualified Language.Haskell.Liquid.Types.RefType as RT 
+import qualified Liquid.GHC.Misc      as GM
+import qualified Liquid.GHC.API       as Ghc
+import qualified Language.Haskell.Liquid.Types.RefType as RT
 import           Language.Haskell.Liquid.Types         hiding (fresh)
-import qualified Language.Haskell.Liquid.Misc          as Misc 
+import qualified Language.Haskell.Liquid.Misc          as Misc
 import qualified Language.Haskell.Liquid.Measure       as Ms
 import qualified Language.Haskell.Liquid.Bare.Resolve  as Bare
 import qualified Language.Haskell.Liquid.Bare.Types    as Bare
@@ -56,10 +53,10 @@
 -- | `makeRTEnv` initializes the env needed to `expand` refinements and types,
 --   that is, the below needs to be called *before* we use `Expand.expand`
 --------------------------------------------------------------------------------
-makeRTEnv :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.ModSpecs -> LogicMap 
-          -> BareRTEnv 
+makeRTEnv :: Bare.Env -> ModName -> Ms.BareSpec -> Bare.ModSpecs -> LogicMap
+          -> BareRTEnv
 --------------------------------------------------------------------------------
-makeRTEnv env m mySpec iSpecs lmap 
+makeRTEnv env modName mySpec iSpecs lmap
           = renameRTArgs $ makeRTAliases tAs $ makeREAliases eAs
   where
     tAs   = [ t                   | (_, s)  <- specs, t <- Ms.aliases  s ]
@@ -69,60 +66,60 @@
                                               -- this clearly breaks things if a signature
                                               -- contains lmap functions but never gets
                                               -- elaborated
-              else [ specREAlias env m e | (_, xl) <- M.toList (lmSymDefs lmap)
+              else [ specREAlias env modName e | (_, xl) <- M.toList (lmSymDefs lmap)
                                   , let e    = lmapEAlias xl             ]
-    specs = (m, mySpec) : M.toList iSpecs
+    specs = (modName, mySpec) : M.toList iSpecs
 
 -- | We apply @renameRTArgs@ *after* expanding each alias-definition, to 
 --   ensure that the substitutions work properly (i.e. don't miss expressions 
 --   hidden inside @RExprArg@ or as strange type parameters. 
-renameRTArgs :: BareRTEnv -> BareRTEnv 
-renameRTArgs rte = RTE 
-  { typeAliases = M.map (fmap ( renameTys . renameVV . renameRTVArgs)) (typeAliases rte) 
-  , exprAliases = M.map (fmap (                        renameRTVArgs)) (exprAliases rte) 
-  } 
+renameRTArgs :: BareRTEnv -> BareRTEnv
+renameRTArgs rte = RTE
+  { typeAliases = M.map (fmap (renameTys . renameVV . renameRTVArgs)) (typeAliases rte)
+  , exprAliases = M.map (fmap                         renameRTVArgs) (exprAliases rte)
+  }
 
-makeREAliases :: [Located (RTAlias F.Symbol F.Expr)] -> BareRTEnv 
-makeREAliases = graphExpand buildExprEdges f mempty 
+makeREAliases :: [Located (RTAlias F.Symbol F.Expr)] -> BareRTEnv
+makeREAliases = graphExpand buildExprEdges f mempty
   where
     f rtEnv xt = setREAlias rtEnv (expandLoc rtEnv xt)
 
 
 -- | @renameTys@ ensures that @RTAlias@ type parameters have distinct names 
 --   to avoid variable capture e.g. as in T1556.hs
-renameTys :: RTAlias F.Symbol BareType -> RTAlias F.Symbol BareType 
-renameTys rt = rt { rtTArgs = ys, rtBody = subts (rtBody rt) (zip xs ys) }
-  where 
-    xs    = rtTArgs rt 
+renameTys :: RTAlias F.Symbol BareType -> RTAlias F.Symbol BareType
+renameTys rt = rt { rtTArgs = ys, rtBody = sbts (rtBody rt) (zip xs ys) }
+  where
+    xs    = rtTArgs rt
     ys    = (`F.suffixSymbol` rtName rt) <$> xs
-    subts = foldl (flip subt)
+    sbts  = foldl (flip subt)
 
 
-renameVV :: RTAlias F.Symbol BareType -> RTAlias F.Symbol BareType 
+renameVV :: RTAlias F.Symbol BareType -> RTAlias F.Symbol BareType
 renameVV rt = rt { rtBody = RT.shiftVV (rtBody rt) (F.vv (Just 0)) }
 
 -- | @renameRTVArgs@ ensures that @RTAlias@ value parameters have distinct names 
 --   to avoid variable capture e.g. as in tests-names-pos-Capture01.hs
-renameRTVArgs :: (F.PPrint a, F.Subable a) => RTAlias x a -> RTAlias x a 
+renameRTVArgs :: (F.PPrint a, F.Subable a) => RTAlias x a -> RTAlias x a
 renameRTVArgs rt = rt { rtVArgs = newArgs
-                      , rtBody  = F.notracepp msg $ F.subst su (rtBody rt) 
-                      } 
-  where 
+                      , rtBody  = F.notracepp msg $ F.subst su (rtBody rt)
+                      }
+  where
     msg          = "renameRTVArgs: " ++ F.showpp su
-    su           = F.mkSubst (zip oldArgs (F.eVar <$> newArgs)) 
-    newArgs      = zipWith rtArg (rtVArgs rt) [0..]
+    su           = F.mkSubst (zip oldArgs (F.eVar <$> newArgs))
+    newArgs      = zipWith rtArg (rtVArgs rt) [(0::Int)..]
     oldArgs      = rtVArgs rt
-    rtArg x i    = F.suffixSymbol x (F.intSymbol "rta" i) 
+    rtArg x i    = F.suffixSymbol x (F.intSymbol "rta" i)
 
-makeRTAliases :: [Located (RTAlias F.Symbol BareType)] -> BareRTEnv -> BareRTEnv  
-makeRTAliases lxts rte = graphExpand buildTypeEdges f rte lxts 
+makeRTAliases :: [Located (RTAlias F.Symbol BareType)] -> BareRTEnv -> BareRTEnv
+makeRTAliases lxts rte = graphExpand buildTypeEdges f rte lxts
   where
     f rtEnv xt         = setRTAlias rtEnv (expandLoc rtEnv xt)
 
-specREAlias :: Bare.Env -> ModName -> Located (RTAlias F.Symbol F.Expr) -> Located (RTAlias F.Symbol F.Expr) 
-specREAlias env m la = F.atLoc la $ a { rtBody = Bare.qualify env m (loc la) (rtVArgs a) (rtBody a) } 
-  where 
-    a     = val la 
+specREAlias :: Bare.Env -> ModName -> Located (RTAlias F.Symbol F.Expr) -> Located (RTAlias F.Symbol F.Expr)
+specREAlias env m la = F.atLoc la $ a { rtBody = Bare.qualify env m (loc la) (rtVArgs a) (rtBody a) }
+  where
+    a     = val la
 
 --------------------------------------------------------------------------------------------------------------
 
@@ -132,22 +129,22 @@
             -> thing                                     -- ^ initial
             -> [Located (RTAlias x t)]                   -- ^ vertices
             -> thing                                     -- ^ final 
-graphExpand buildEdges expBody env lxts 
+graphExpand buildEdges expBody env lxts
            = L.foldl' expBody env (genExpandOrder table' graph)
-  where 
+  where
     -- xts    = val <$> lxts
     table  = buildAliasTable lxts
     graph  = buildAliasGraph (buildEdges table) lxts
     table' = checkCyclicAliases table graph
 
-setRTAlias :: RTEnv x t -> Located (RTAlias x t) -> RTEnv x t 
-setRTAlias env a = env { typeAliases =  M.insert n a (typeAliases env) } 
-  where 
-    n            = rtName (val a)  
+setRTAlias :: RTEnv x t -> Located (RTAlias x t) -> RTEnv x t
+setRTAlias env a = env { typeAliases =  M.insert n a (typeAliases env) }
+  where
+    n            = rtName (val a)
 
-setREAlias :: RTEnv x t -> Located (RTAlias F.Symbol F.Expr) -> RTEnv x t 
-setREAlias env a = env { exprAliases = M.insert n a (exprAliases env) } 
-  where 
+setREAlias :: RTEnv x t -> Located (RTAlias F.Symbol F.Expr) -> RTEnv x t
+setREAlias env a = env { exprAliases = M.insert n a (exprAliases env) }
+  where
     n            = rtName (val a)
 
 
@@ -167,20 +164,20 @@
 type Graph t = [Node t]
 type Node  t = (t, t, [t])
 
-buildAliasGraph :: (PPrint t) => (t -> [F.Symbol]) -> [Located (RTAlias x t)] 
+buildAliasGraph :: (PPrint t) => (t -> [F.Symbol]) -> [Located (RTAlias x t)]
                 -> Graph F.Symbol
 buildAliasGraph buildEdges = map (buildAliasNode buildEdges)
 
-buildAliasNode :: (PPrint t) => (t -> [F.Symbol]) -> Located (RTAlias x t) 
+buildAliasNode :: (PPrint t) => (t -> [F.Symbol]) -> Located (RTAlias x t)
                -> Node F.Symbol
 buildAliasNode f la = (rtName a, rtName a, f (rtBody a))
-  where 
-    a               = val la 
+  where
+    a               = val la
 
-checkCyclicAliases :: AliasTable x t -> Graph F.Symbol -> AliasTable x t 
+checkCyclicAliases :: AliasTable x t -> Graph F.Symbol -> AliasTable x t
 checkCyclicAliases table graph
   = case mapMaybe go (stronglyConnComp graph) of
-      []   -> table 
+      []   -> table
       sccs -> Ex.throw (cycleAliasErr table <$> sccs)
     where
       go (CyclicSCC vs) = Just vs
@@ -188,8 +185,8 @@
 
 cycleAliasErr :: AliasTable x t -> [F.Symbol] -> Error
 cycleAliasErr _ []          = panic Nothing "checkCyclicAliases: No type aliases in reported cycle"
-cycleAliasErr t scc@(rta:_) = ErrAliasCycle { pos    = fst (locate rta)
-                                            , acycle = map locate scc }
+cycleAliasErr t symList@(rta:_) = ErrAliasCycle { pos    = fst (locate rta)
+                                                , acycle = map locate symList }
   where
     locate sym = ( GM.fSrcSpan $ fromAliasSymbol t sym
                  , pprint sym )
@@ -261,8 +258,8 @@
 ----------------------------------------------------------------------------------
 -- | Using the `BareRTEnv` to do alias-expansion 
 ----------------------------------------------------------------------------------
-class Expand a where 
-  expand :: BareRTEnv -> F.SourcePos -> a -> a 
+class Expand a where
+  expand :: BareRTEnv -> F.SourcePos -> a -> a
 
 ----------------------------------------------------------------------------------
 -- | @qualifyExpand@ first qualifies names so that we can successfully resolve them during expansion.
@@ -284,11 +281,11 @@
     qualifiedRTEnv = rtEnv { typeAliases = M.map (Bare.qualify env name l bs) (typeAliases rtEnv) }
 
 ----------------------------------------------------------------------------------
-expandLoc :: (Expand a) => BareRTEnv -> Located a -> Located a 
-expandLoc rtEnv lx = expand rtEnv (F.loc lx) <$> lx 
+expandLoc :: (Expand a) => BareRTEnv -> Located a -> Located a
+expandLoc rtEnv lx = expand rtEnv (F.loc lx) <$> lx
 
-instance Expand Expr where 
-  expand = expandExpr 
+instance Expand Expr where
+  expand = expandExpr
 
 instance Expand F.Reft where
   expand rtEnv l (F.Reft (v, ra)) = F.Reft (v, expand rtEnv l ra)
@@ -296,7 +293,7 @@
 instance Expand RReft where
   expand rtEnv l = fmap (expand rtEnv l)
 
-expandReft :: (Expand r) => BareRTEnv -> F.SourcePos -> RType c tv r -> RType c tv r 
+expandReft :: (Expand r) => BareRTEnv -> F.SourcePos -> RType c tv r -> RType c tv r
 expandReft rtEnv l = fmap (expand rtEnv l)
 -- expandReft rtEnv l = emapReft (expand rtEnv l)
 
@@ -308,68 +305,68 @@
 --   3. stuff from @LogicMap@
 
 instance Expand SpecType where
-  expand = expandReft 
+  expand = expandReft
 
 -- | @expand@ on a BareType actually applies the type- and expression- aliases.
-instance Expand BareType where 
+instance Expand BareType where
   expand rtEnv l
     = expandReft     rtEnv l -- apply expression aliases
     . expandBareType rtEnv l -- apply type       aliases
 
-instance Expand (RTAlias F.Symbol Expr) where 
-  expand rtEnv l x = x { rtBody = expand rtEnv l (rtBody x) } 
+instance Expand (RTAlias F.Symbol Expr) where
+  expand rtEnv l x = x { rtBody = expand rtEnv l (rtBody x) }
 
-instance Expand BareRTAlias where 
-  expand rtEnv l x = x { rtBody = expand rtEnv l (rtBody x) } 
+instance Expand BareRTAlias where
+  expand rtEnv l x = x { rtBody = expand rtEnv l (rtBody x) }
 
-instance Expand Body where 
-  expand rtEnv l (P   p) = P   (expand rtEnv l p) 
+instance Expand Body where
+  expand rtEnv l (P   p) = P   (expand rtEnv l p)
   expand rtEnv l (E   e) = E   (expand rtEnv l e)
   expand rtEnv l (R x p) = R x (expand rtEnv l p)
 
-instance Expand DataCtor where 
+instance Expand DataCtor where
   expand rtEnv l c = c
-    { dcTheta  = expand rtEnv l (dcTheta c) 
-    , dcFields = [(x, expand rtEnv l t) | (x, t) <- dcFields c ] 
+    { dcTheta  = expand rtEnv l (dcTheta c)
+    , dcFields = [(x, expand rtEnv l t) | (x, t) <- dcFields c ]
     , dcResult = expand rtEnv l (dcResult c)
     }
- 
-instance Expand DataDecl where 
-  expand rtEnv l d = d 
+
+instance Expand DataDecl where
+  expand rtEnv l d = d
     { tycDCons  = expand rtEnv l (tycDCons  d)
-    , tycPropTy = expand rtEnv l (tycPropTy d) 
-    } 
+    , tycPropTy = expand rtEnv l (tycPropTy d)
+    }
 
-instance Expand BareMeasure where 
-  expand rtEnv l m = m 
-    { msSort = expand rtEnv l (msSort m) 
+instance Expand BareMeasure where
+  expand rtEnv l m = m
+    { msSort = expand rtEnv l (msSort m)
     , msEqns = expand rtEnv l (msEqns m)
-    } 
+    }
 
-instance Expand BareDef where 
-  expand rtEnv l d = d 
-    { dsort = expand rtEnv l (dsort d) 
-    , binds = [ (x, expand rtEnv l t) | (x, t) <- binds d] 
-    , body  = expand rtEnv l (body  d) 
-    } 
+instance Expand BareDef where
+  expand rtEnv l d = d
+    { dsort = expand rtEnv l (dsort d)
+    , binds = [ (x, expand rtEnv l t) | (x, t) <- binds d]
+    , body  = expand rtEnv l (body  d)
+    }
 
 instance Expand Ms.BareSpec where
   expand = expandBareSpec
 
-instance Expand a => Expand (F.Located a) where 
-  expand rtEnv _ = expandLoc rtEnv 
+instance Expand a => Expand (F.Located a) where
+  expand rtEnv _ = expandLoc rtEnv
 
-instance Expand a => Expand (F.LocSymbol, a) where 
+instance Expand a => Expand (F.LocSymbol, a) where
   expand rtEnv l (x, y) = (x, expand rtEnv l y)
 
-instance Expand a => Expand (Maybe a) where 
-  expand rtEnv l = fmap (expand rtEnv l) 
+instance Expand a => Expand (Maybe a) where
+  expand rtEnv l = fmap (expand rtEnv l)
 
-instance Expand a => Expand [a] where 
-  expand rtEnv l = fmap (expand rtEnv l) 
+instance Expand a => Expand [a] where
+  expand rtEnv l = fmap (expand rtEnv l)
 
-instance Expand a => Expand (M.HashMap k a) where 
-  expand rtEnv l = fmap (expand rtEnv l) 
+instance Expand a => Expand (M.HashMap k a) where
+  expand rtEnv l = fmap (expand rtEnv l)
 
 -- | Expands a 'BareSpec'.
 expandBareSpec :: BareRTEnv -> F.SourcePos -> Ms.BareSpec -> Ms.BareSpec
@@ -385,32 +382,32 @@
   }
   where f      = expand rtEnv l
 
-expandBareType :: BareRTEnv -> F.SourcePos -> BareType -> BareType 
-expandBareType rtEnv _ = go 
+expandBareType :: BareRTEnv -> F.SourcePos -> BareType -> BareType
+expandBareType rtEnv _ = go
   where
-    go (RApp c ts rs r)  = case lookupRTEnv c rtEnv of 
-                             Just rta -> expandRTAliasApp (GM.fSourcePos c) rta (go <$> ts) r 
-                             Nothing  -> RApp c (go <$> ts) (goRef <$> rs) r 
+    go (RApp c ts rs r)  = case lookupRTEnv c rtEnv of
+                             Just rta -> expandRTAliasApp (GM.fSourcePos c) rta (go <$> ts) r
+                             Nothing  -> RApp c (go <$> ts) (goRef <$> rs) r
     go (RAppTy t1 t2 r)  = RAppTy (go t1) (go t2) r
-    go (RImpF x i t1 t2 r) = RImpF x i (go t1) (go t2) r 
-    go (RFun  x i t1 t2 r) = RFun  x i (go t1) (go t2) r 
+    go (RImpF x i t1 t2 r) = RImpF x i (go t1) (go t2) r
+    go (RFun  x i t1 t2 r) = RFun  x i (go t1) (go t2) r
     go (RAllT a t r)     = RAllT a (go t) r
-    go (RAllP a t)       = RAllP a (go t) 
+    go (RAllP a t)       = RAllP a (go t)
     go (RAllE x t1 t2)   = RAllE x (go t1) (go t2)
     go (REx x t1 t2)     = REx   x (go t1) (go t2)
     go (RRTy e r o t)    = RRTy  e r o     (go t)
-    go t@(RHole {})      = t 
-    go t@(RVar {})       = t 
-    go t@(RExprArg {})   = t 
+    go t@RHole{}         = t
+    go t@RVar{}          = t
+    go t@RExprArg{}      = t
     goRef (RProp ss t)   = RProp ss (go t)
 
 lookupRTEnv :: BTyCon -> BareRTEnv -> Maybe (Located BareRTAlias)
 lookupRTEnv c rtEnv = M.lookup (F.symbol c) (typeAliases rtEnv)
 
-expandRTAliasApp :: F.SourcePos -> Located BareRTAlias -> [BareType] -> RReft -> BareType 
-expandRTAliasApp l (Loc la _ rta) args r = case isOK of 
+expandRTAliasApp :: F.SourcePos -> Located BareRTAlias -> [BareType] -> RReft -> BareType
+expandRTAliasApp l (Loc la _ rta) args r = case isOK of
   Just e     -> Ex.throw e
-  Nothing    -> F.subst esu . (`RT.strengthen` r) . RT.subsTyVars_meet tsu $ rtBody rta
+  Nothing    -> F.subst esu . (`RT.strengthen` r) . RT.subsTyVarsMeet tsu $ rtBody rta
   where
     tsu       = zipWith (\α t -> (α, toRSort t, t)) αs ts
     esu       = F.mkSubst $ zip (F.symbol <$> εs) es
@@ -423,32 +420,32 @@
     -- ERROR Checking Code
     msg       = "EXPAND-RTALIAS-APP: " ++ F.showpp (rtName rta)
     nαs       = length αs
-    nεs       = length εs 
-    nargs     = length args 
+    nεs       = length εs
+    nargs     = length args
     ntargs    = length targs
     neargs    = length eargs
-    err       = errRTAliasApp l la rta 
+    err       = errRTAliasApp l la rta
     isOK :: Maybe Error
     isOK
       | nargs /= ntargs + neargs
       = err $ PJ.hsep ["Expects", pprint nαs, "type arguments and then", pprint nεs, "expression arguments, but is given", pprint nargs]
       | nargs /= nαs + nεs
-      = err $ PJ.hsep ["Expects", pprint nαs, "type arguments and "    , pprint nεs, "expression arguments, but is given", pprint nargs]
+      = err $ PJ.hsep ["Expects", pprint nαs, "type arguments and"     , pprint nεs, "expression arguments, but is given", pprint nargs]
       | nαs /= ntargs, not (null eargs)
       = err $ PJ.hsep ["Expects", pprint nαs, "type arguments before expression arguments"]
       | otherwise
       = Nothing
 
 isRExprArg :: RType c tv r -> Bool
-isRExprArg (RExprArg _) = True 
-isRExprArg _            = False 
+isRExprArg (RExprArg _) = True
+isRExprArg _            = False
 
-errRTAliasApp :: F.SourcePos -> F.SourcePos -> BareRTAlias -> PJ.Doc -> Maybe Error 
-errRTAliasApp l la rta = Just . ErrAliasApp  sp name sp' 
-  where 
+errRTAliasApp :: F.SourcePos -> F.SourcePos -> BareRTAlias -> PJ.Doc -> Maybe Error
+errRTAliasApp l la rta = Just . ErrAliasApp  sp name sp'
+  where
     name            = pprint              (rtName rta)
     sp              = GM.sourcePosSrcSpan l
-    sp'             = GM.sourcePosSrcSpan la 
+    sp'             = GM.sourcePosSrcSpan la
 
 
 
@@ -464,8 +461,8 @@
 --   `exprArg` converts that `BareType` into an `Expr`.
 --------------------------------------------------------------------------------
 exprArg :: F.SourcePos -> String -> BareType -> Expr
-exprArg l msg = F.notracepp ("exprArg: " ++ msg) . go 
-  where 
+exprArg l msg = F.notracepp ("exprArg: " ++ msg) . go
+  where
     go :: BareType -> Expr
     go (RExprArg e)     = val e
     go (RVar x _)       = EVar (F.symbol x)
@@ -481,36 +478,33 @@
 --   in multiple steps, into a @SpecType@. See [NOTE:Cooking-SpecType] for 
 --   details of each of the individual steps.
 ----------------------------------------------------------------------------------------
-cookSpecType :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocBareType 
-             -> LocSpecType 
+cookSpecType :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocBareType
+             -> LocSpecType
 cookSpecType env sigEnv name x bt
          = either Ex.throw id (cookSpecTypeE env sigEnv name x bt)
-  where 
+  where
     _msg = "cookSpecType: " ++ GM.showPpr (z, Ghc.varType <$> z)
-    z    = Bare.plugSrc x 
+    z    = Bare.plugSrc x
 
 
 -----------------------------------------------------------------------------------------
-cookSpecTypeE :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocBareType 
-              -> Bare.Lookup LocSpecType 
+cookSpecTypeE :: Bare.Env -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocBareType
+              -> Bare.Lookup LocSpecType
 -----------------------------------------------------------------------------------------
 cookSpecTypeE env sigEnv name@(ModName _ _) x bt
-  = id
-  . fmap (if doplug || not allowTC then plugHoles allowTC sigEnv name x else id) 
-  . fmap (fmap (addTyConInfo   embs tyi))
-  . fmap (Bare.txRefSort tyi embs)     
-  . fmap (fmap txExpToBind)      -- What does this function DO
-  . fmap (specExpandType rtEnv)                        
-  . fmap (fmap (generalizeWith x))
-  . fmap (if doplug || not allowTC then maybePlug allowTC  sigEnv name x else id)
-  -- we do not qualify/resolve Expr/Pred when typeclass is enabled
-  -- since ghci will not be able to recognize fully qualified names
-  -- instead, we leave qualification to ghc elaboration
-  . fmap (Bare.qualifyTop env name l )
-  . bareSpecType       env name 
-  . bareExpandType     rtEnv
-  $ bt 
+  = fmap f . bareSpecType env name $ bareExpandType rtEnv bt
   where
+    f = (if doplug || not allowTC then plugHoles allowTC sigEnv name x else id)
+        . fmap (addTyConInfo embs tyi)
+        . Bare.txRefSort tyi embs
+        . fmap txExpToBind -- What does this function DO
+        . (specExpandType rtEnv . fmap (generalizeWith x))
+        . (if doplug || not allowTC then maybePlug allowTC sigEnv name x else id)
+        -- we do not qualify/resolve Expr/Pred when typeclass is enabled
+        -- since ghci will not be able to recognize fully qualified names
+        -- instead, we leave qualification to ghc elaboration
+        . Bare.qualifyTop env name l
+
     allowTC = typeclass (getConfig env)
     -- modT   = mname `S.member` wiredInMods
     doplug
@@ -522,24 +516,24 @@
       = True
     _msg i = "cook-" ++ show i ++ " : " ++ F.showpp x
     rtEnv  = Bare.sigRTEnv    sigEnv
-    embs   = Bare.sigEmbs     sigEnv 
+    embs   = Bare.sigEmbs     sigEnv
     tyi    = Bare.sigTyRTyMap sigEnv
     l      = F.loc bt
 
 -- | We don't want to generalize type variables that maybe bound in the 
 --   outer scope, e.g. see tests/basic/pos/LocalPlug00.hs 
 
-generalizeWith :: Bare.PlugTV Ghc.Var -> SpecType -> SpecType 
-generalizeWith (Bare.HsTV v) t = generalizeVar v t 
-generalizeWith  Bare.RawTV   t = t 
-generalizeWith _             t = RT.generalize t 
+generalizeWith :: Bare.PlugTV Ghc.Var -> SpecType -> SpecType
+generalizeWith (Bare.HsTV v) t = generalizeVar v t
+generalizeWith  Bare.RawTV   t = t
+generalizeWith _             t = RT.generalize t
 
-generalizeVar :: Ghc.Var -> SpecType -> SpecType 
-generalizeVar v t = mkUnivs (zip as (repeat mempty)) [] t 
-  where 
+generalizeVar :: Ghc.Var -> SpecType -> SpecType
+generalizeVar v t = mkUnivs (zip as (repeat mempty)) [] t
+  where
     as            = filter isGen (freeTyVars t)
-    (vas,_)       = Ghc.splitForAllTys (GM.expandVarType v) 
-    isGen (RTVar (RTV a) _) = a `elem` vas 
+    (vas,_)       = Ghc.splitForAllTys (GM.expandVarType v)
+    isGen (RTVar (RTV a) _) = a `elem` vas
 
 -- splitForAllTys :: Type -> ([TyVar], Type)
 -- 
@@ -547,28 +541,28 @@
 -- generalize t = mkUnivs (freeTyVars t) [] [] t 
 
 
-bareExpandType :: BareRTEnv -> LocBareType -> LocBareType 
-bareExpandType = expandLoc 
+bareExpandType :: BareRTEnv -> LocBareType -> LocBareType
+bareExpandType = expandLoc
 
 specExpandType :: BareRTEnv -> LocSpecType -> LocSpecType
-specExpandType = expandLoc 
+specExpandType = expandLoc
 
-bareSpecType :: Bare.Env -> ModName -> LocBareType -> Bare.Lookup LocSpecType 
-bareSpecType env name bt = case Bare.ofBareTypeE env name (F.loc bt) Nothing (val bt) of 
-  Left e  -> Left e 
+bareSpecType :: Bare.Env -> ModName -> LocBareType -> Bare.Lookup LocSpecType
+bareSpecType env name bt = case Bare.ofBareTypeE env name (F.loc bt) Nothing (val bt) of
+  Left e  -> Left e
   Right t -> Right (F.atLoc bt t)
 
-maybePlug :: Bool -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocSpecType -> LocSpecType 
-maybePlug allowTC sigEnv name kx = case Bare.plugSrc kx of 
-                             Nothing -> id  
-                             Just _  -> plugHoles allowTC sigEnv name kx 
+maybePlug :: Bool -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocSpecType -> LocSpecType
+maybePlug allowTC sigEnv name kx = case Bare.plugSrc kx of
+                             Nothing -> id
+                             Just _  -> plugHoles allowTC sigEnv name kx
 
-plugHoles :: Bool -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocSpecType -> LocSpecType 
+plugHoles :: Bool -> Bare.SigEnv -> ModName -> Bare.PlugTV Ghc.Var -> LocSpecType -> LocSpecType
 plugHoles allowTC sigEnv name = Bare.makePluggedSig allowTC name embs tyi exports
-  where 
-    embs              = Bare.sigEmbs     sigEnv 
-    tyi               = Bare.sigTyRTyMap sigEnv 
-    exports           = Bare.sigExports  sigEnv 
+  where
+    embs              = Bare.sigEmbs     sigEnv
+    tyi               = Bare.sigTyRTyMap sigEnv
+    exports           = Bare.sigExports  sigEnv
 
 {- [NOTE:Cooking-SpecType] 
     A @SpecType@ is _raw_ when it is obtained directly from a @BareType@, i.e. 
@@ -628,7 +622,7 @@
     go e@(EApp _ _)     = expandEApp rtEnv l (F.splitEApp e)
     go (EVar x)         = expandSym  rtEnv l x
     go (ENeg e)         = ENeg       (go e)
-    go (ECst e s)       = ECst       (go e) s 
+    go (ECst e s)       = ECst       (go e) s
     go (PAnd ps)        = PAnd       (go <$> ps)
     go (POr ps)         = POr        (go <$> ps)
     go (PNot p)         = PNot       (go p)
@@ -636,8 +630,8 @@
     go (PExist xs p)    = PExist xs  (go p)
     go (ELam xt e)      = ELam xt    (go e)
     go (ECoerc a t e)   = ECoerc a t (go e)
-    go (ETApp e s)      = ETApp      (go e) s 
-    go (ETAbs e s)      = ETAbs      (go e) s 
+    go (ETApp e s)      = ETApp      (go e) s
+    go (ETAbs e s)      = ETAbs      (go e) s
     go (EBin op e1 e2)  = EBin op    (go e1) (go e2)
     go (PImp    e1 e2)  = PImp       (go e1) (go e2)
     go (PIff    e1 e2)  = PIff       (go e1) (go e2)
@@ -679,7 +673,7 @@
   where
     re              = F.val lre
     args            = F.mkSubst <$> Misc.zipMaybe (rtVArgs re) es
-    err             :: UserError 
+    err             :: UserError
     err             = ErrAliasApp sp alias sp' msg
     sp              = GM.sourcePosSrcSpan l
     alias           = pprint           (rtName re)
@@ -695,7 +689,7 @@
 txExpToBind   :: SpecType -> SpecType
 -------------------------------------------------------------------------------
 txExpToBind t = evalState (expToBindT t) (ExSt 0 M.empty πs)
-  where 
+  where
     πs        = M.fromList [(pname p, p) | p <- ty_preds $ toRTypeRep t ]
 
 data ExSt = ExSt { fresh :: Int
@@ -714,10 +708,10 @@
        t2' <- expToBindT t2
        expToBindRef r >>= addExists . RFun x i t1' t2'
 expToBindT (RAllT a t r)
-  = do t' <- expToBindT t 
-       expToBindRef r >>= addExists . RAllT a t' 
+  = do t' <- expToBindT t
+       expToBindRef r >>= addExists . RAllT a t'
 expToBindT (RAllP p t)
-  = liftM (RAllP p) (expToBindT t)
+  = fmap (RAllP p) (expToBindT t)
 expToBindT (RApp c ts rs r)
   = do ts' <- mapM expToBindT ts
        rs' <- mapM expToBindReft rs
@@ -743,39 +737,39 @@
 
 getBinds :: State ExSt (M.HashMap F.Symbol (RSort, F.Expr))
 getBinds
-  = do bds <- emap <$> get
+  = do bds <- gets emap
        modify $ \st -> st{emap = M.empty}
        return bds
 
 addExists :: SpecType -> State ExSt SpecType
-addExists t = liftM (M.foldlWithKey' addExist t) getBinds
+addExists t = fmap (M.foldlWithKey' addExist t) getBinds
 
 addExist :: SpecType -> F.Symbol -> (RSort, F.Expr) -> SpecType
 addExist t x (tx, e) = REx x t' t
-  where 
-    t'               = (ofRSort tx) `strengthen` uTop r
+  where
+    t'               = ofRSort tx `strengthen` uTop r
     r                = F.exprReft e
 
 expToBindRef :: UReft r -> State ExSt (UReft r)
 expToBindRef (MkUReft r (Pr p))
-  = mapM expToBind p >>= return . (MkUReft r) . Pr
+  = mapM expToBind p <&> (MkUReft r . Pr)
 
 expToBind :: UsedPVar -> State ExSt UsedPVar
-expToBind p = do 
-  res <- liftM (M.lookup (pname p)) (pmap <$> get)
-  case res of 
-    Nothing -> 
-      panic Nothing ("expToBind: " ++ show p) 
+expToBind p = do
+  res <- gets (M.lookup (pname p) . pmap)
+  case res of
+    Nothing ->
+      panic Nothing ("expToBind: " ++ show p)
     Just π  -> do
       let pargs0 = zip (pargs p) (Misc.fst3 <$> pargs π)
       pargs' <- mapM expToBindParg pargs0
       return $ p { pargs = pargs' }
 
 expToBindParg :: (((), F.Symbol, F.Expr), RSort) -> State ExSt ((), F.Symbol, F.Expr)
-expToBindParg ((t, s, e), s') = liftM ((,,) t s) (expToBindExpr e s')
+expToBindParg ((t, s, e), s') = fmap ((,,) t s) (expToBindExpr e s')
 
 expToBindExpr :: F.Expr ->  RSort -> State ExSt F.Expr
-expToBindExpr e@(EVar s) _ 
+expToBindExpr e@(EVar s) _
   | Char.isLower $ F.headSym $ F.symbol s
   = return e
 expToBindExpr e t
@@ -785,7 +779,7 @@
 
 freshSymbol :: State ExSt F.Symbol
 freshSymbol
-  = do n <- fresh <$> get
+  = do n <- gets fresh
        modify $ \s -> s {fresh = n+1}
        return $ F.symbol $ "ex#" ++ show n
 
diff --git a/src/Language/Haskell/Liquid/Bare/Laws.hs b/src/Language/Haskell/Liquid/Bare/Laws.hs
--- a/src/Language/Haskell/Liquid/Bare/Laws.hs
+++ b/src/Language/Haskell/Liquid/Bare/Laws.hs
@@ -3,52 +3,52 @@
 import qualified Data.Maybe                                 as Mb
 import qualified Data.List                                  as L
 import qualified Data.HashMap.Strict                        as M
-import           Control.Monad (join)
+import           Control.Monad ((<=<))
 
 import qualified Language.Haskell.Liquid.Measure            as Ms
 import qualified Language.Fixpoint.Types                    as F
-import qualified Language.Haskell.Liquid.GHC.Misc           as GM
-import           Language.Haskell.Liquid.Bare.Types         as Bare 
+import qualified Liquid.GHC.Misc           as GM
+import           Language.Haskell.Liquid.Bare.Types         as Bare
 import           Language.Haskell.Liquid.Bare.Resolve       as Bare
 import           Language.Haskell.Liquid.Bare.Expand        as Bare
 import           Language.Haskell.Liquid.Types
-import           Language.Haskell.Liquid.GHC.API            
+import           Liquid.GHC.API
 
 
 
-makeInstanceLaws :: Bare.Env -> Bare.SigEnv -> [(Var,LocSpecType)] 
+makeInstanceLaws :: Bare.Env -> Bare.SigEnv -> [(Var,LocSpecType)]
                 -> Bare.ModSpecs -> [LawInstance]
-makeInstanceLaws env sigEnv sigs specs 
-  = [makeInstanceLaw env sigEnv sigs name rilaw 
+makeInstanceLaws env sigEnv sigs specs
+  = [makeInstanceLaw env sigEnv sigs name rilaw
               | (name, spec) <- M.toList specs
               , rilaw <- Ms.ilaws spec ]
 
 
-makeInstanceLaw :: Bare.Env -> Bare.SigEnv -> [(Var,LocSpecType)] -> ModName  
+makeInstanceLaw :: Bare.Env -> Bare.SigEnv -> [(Var,LocSpecType)] -> ModName
                 -> RILaws LocBareType -> LawInstance
 makeInstanceLaw env sigEnv sigs name rilaw = LawInstance
   { lilName   = Mb.fromMaybe errmsg tc
-  , liSupers  = mkTy <$> rilSupers rilaw 
+  , liSupers  = mkTy <$> rilSupers rilaw
   , lilTyArgs = mkTy <$> rilTyArgs rilaw
-  , lilEqus   = [(mkVar l, mkTypedVar r) | (l,r)<- rilEqus rilaw ]  
+  , lilEqus   = [(mkVar l, mkTypedVar r) | (l,r)<- rilEqus rilaw ]
   , lilPos    = GM.sourcePosSrcSpan $ loc $ rilPos rilaw
-  } 
+  }
   where
-    tc    :: Maybe Class 
+    tc    :: Maybe Class
     tc     = classTc (rilName rilaw)
     errmsg = error ("Not a type class: " ++ F.showpp tc)
 
-    classTc = join . fmap tyConClass_maybe . Bare.maybeResolveSym env name "makeClass" . btc_tc  
+    classTc = tyConClass_maybe <=< (Bare.maybeResolveSym env name "makeClass" . btc_tc)
 
     mkTy :: LocBareType -> LocSpecType
-    mkTy = Bare.cookSpecType env sigEnv name Bare.GenTV 
-    mkVar :: LocSymbol -> VarOrLocSymbol 
-    mkVar x = case Bare.maybeResolveSym env name "makeInstanceLaw" x of 
-                Just v -> Left v 
-                _      -> Right x 
+    mkTy = Bare.cookSpecType env sigEnv name Bare.GenTV
+    mkVar :: LocSymbol -> VarOrLocSymbol
+    mkVar x = case Bare.maybeResolveSym env name "makeInstanceLaw" x of
+                Just v -> Left v
+                _      -> Right x
 
     mkTypedVar :: LocSymbol -> (VarOrLocSymbol, Maybe LocSpecType)
-    mkTypedVar l = case mkVar l of 
+    mkTypedVar l = case mkVar l of
                      Left x -> (Left x, Just $ Mb.fromMaybe (dummyLoc $ ofType $ varType x) (L.lookup x sigs))
                      Right x -> (Right x, Nothing)
 
diff --git a/src/Language/Haskell/Liquid/Bare/Measure.hs b/src/Language/Haskell/Liquid/Bare/Measure.hs
--- a/src/Language/Haskell/Liquid/Bare/Measure.hs
+++ b/src/Language/Haskell/Liquid/Bare/Measure.hs
@@ -34,95 +34,95 @@
 import qualified Language.Fixpoint.Misc                as Misc
 import qualified Language.Haskell.Liquid.Misc          as Misc
 import           Language.Haskell.Liquid.Misc             ((.||.))
-import qualified Language.Haskell.Liquid.GHC.API       as Ghc 
-import qualified Language.Haskell.Liquid.GHC.Misc      as GM
+import qualified Liquid.GHC.API       as Ghc
+import qualified Liquid.GHC.Misc      as GM
 import qualified Language.Haskell.Liquid.Types.RefType as RT
 import           Language.Haskell.Liquid.Types
 -- import           Language.Haskell.Liquid.Types.Bounds
 import qualified Language.Haskell.Liquid.Measure       as Ms
 
-import qualified Language.Haskell.Liquid.Bare.Types    as Bare 
-import qualified Language.Haskell.Liquid.Bare.Resolve  as Bare 
-import qualified Language.Haskell.Liquid.Bare.Expand   as Bare 
-import qualified Language.Haskell.Liquid.Bare.DataType as Bare 
-import qualified Language.Haskell.Liquid.Bare.ToBare   as Bare 
+import qualified Language.Haskell.Liquid.Bare.Types    as Bare
+import qualified Language.Haskell.Liquid.Bare.Resolve  as Bare
+import qualified Language.Haskell.Liquid.Bare.Expand   as Bare
+import qualified Language.Haskell.Liquid.Bare.DataType as Bare
+import qualified Language.Haskell.Liquid.Bare.ToBare   as Bare
 import Control.Monad (mapM)
 
 --------------------------------------------------------------------------------
 makeHaskellMeasures :: Bool -> GhcSrc -> Bare.TycEnv -> LogicMap -> Ms.BareSpec
                     -> [Measure (Located BareType) LocSymbol]
 --------------------------------------------------------------------------------
-makeHaskellMeasures allowTC src tycEnv lmap spec 
+makeHaskellMeasures allowTC src tycEnv lmap spec
           = Bare.measureToBare <$> ms
-  where 
-    ms    = makeMeasureDefinition allowTC tycEnv lmap cbs <$> mSyms 
-    cbs   = nonRecCoreBinds   (_giCbs src) 
+  where
+    ms    = makeMeasureDefinition allowTC tycEnv lmap cbs <$> mSyms
+    cbs   = nonRecCoreBinds   (_giCbs src)
     mSyms = S.toList (Ms.hmeas spec)
-  
-makeMeasureDefinition :: Bool -> Bare.TycEnv -> LogicMap -> [Ghc.CoreBind] -> LocSymbol 
+
+makeMeasureDefinition :: Bool -> Bare.TycEnv -> LogicMap -> [Ghc.CoreBind] -> LocSymbol
                       -> Measure LocSpecType Ghc.DataCon
-makeMeasureDefinition allowTC tycEnv lmap cbs x = 
+makeMeasureDefinition allowTC tycEnv lmap cbs x =
   case GM.findVarDef (val x) cbs of
-    Nothing       -> Ex.throw $ errHMeas x "Cannot extract measure from haskell function"
-    Just (v, def) -> Ms.mkM vx vinfo mdef MsLifted (makeUnSorted allowTC (Ghc.varType v) mdef) 
-                     where 
+    Nothing        -> Ex.throw $ errHMeas x "Cannot extract measure from haskell function"
+    Just (v, cexp) -> Ms.mkM vx vinfo mdef MsLifted (makeUnSorted allowTC (Ghc.varType v) mdef)
+                     where
                        vx           = F.atLoc x (F.symbol v)
-                       mdef         = coreToDef' allowTC tycEnv lmap vx v def
+                       mdef         = coreToDef' allowTC tycEnv lmap vx v cexp
                        vinfo        = GM.varLocInfo (logicType allowTC) v
 
 makeUnSorted :: Bool -> Ghc.Type -> [Def LocSpecType Ghc.DataCon] -> UnSortedExprs
-makeUnSorted allowTC t defs
-  | isMeasureType ta 
+makeUnSorted allowTC ty defs
+  | isMeasureType ta
   = mempty
   | otherwise
   = map defToUnSortedExpr defs
   where
-    ta = go $ Ghc.expandTypeSynonyms t
+    ta = go $ Ghc.expandTypeSynonyms ty
 
-    go (Ghc.ForAllTy _ t) = go t 
-    go (Ghc.FunTy { Ghc.ft_arg = p, Ghc.ft_res = t}) | isErasable p = go t 
-    go (Ghc.FunTy { Ghc.ft_arg = t }) = t 
+    go (Ghc.ForAllTy _ t) = go t
+    go Ghc.FunTy{ Ghc.ft_arg = p, Ghc.ft_res = t} | isErasable p = go t
+    go Ghc.FunTy{ Ghc.ft_arg = t } = t
     go t                  = t -- this should never happen!
 
     isMeasureType (Ghc.TyConApp _ ts) = all Ghc.isTyVarTy ts
-    isMeasureType _                   = False  
+    isMeasureType _                   = False
 
-    defToUnSortedExpr def = (xx:(fst <$> binds def), 
-                             Ms.bodyPred (F.mkEApp (measure def) [F.expr xx]) (body def)) 
+    defToUnSortedExpr defn = (xx:(fst <$> binds defn),
+                             Ms.bodyPred (F.mkEApp (measure defn) [F.expr xx]) (body defn))
 
     xx = F.vv $ Just 10000
     isErasable = if allowTC then GM.isEmbeddedDictType else Ghc.isClassPred
 
-coreToDef' :: Bool -> Bare.TycEnv -> LogicMap -> LocSymbol -> Ghc.Var -> Ghc.CoreExpr 
-           -> [Def LocSpecType Ghc.DataCon] 
-coreToDef' allowTC tycEnv lmap vx v def = 
-  case runToLogic embs lmap dm (errHMeas vx) (coreToDef allowTC vx v def) of
+coreToDef' :: Bool -> Bare.TycEnv -> LogicMap -> LocSymbol -> Ghc.Var -> Ghc.CoreExpr
+           -> [Def LocSpecType Ghc.DataCon]
+coreToDef' allowTC tycEnv lmap vx v defn =
+  case runToLogic embs lmap dm (errHMeas vx) (coreToDef allowTC vx v defn) of
     Right l -> l
     Left e  -> Ex.throw e
-  where 
-    embs    = Bare.tcEmbs       tycEnv 
-    dm      = Bare.tcDataConMap tycEnv  
+  where
+    embs    = Bare.tcEmbs       tycEnv
+    dm      = Bare.tcDataConMap tycEnv
 
 errHMeas :: LocSymbol -> String -> Error
 errHMeas x str = ErrHMeas (GM.sourcePosSrcSpan $ loc x) (pprint $ val x) (text str)
 
 --------------------------------------------------------------------------------
-makeHaskellInlines :: Bool -> GhcSrc -> F.TCEmb Ghc.TyCon -> LogicMap -> Ms.BareSpec 
+makeHaskellInlines :: Bool -> GhcSrc -> F.TCEmb Ghc.TyCon -> LogicMap -> Ms.BareSpec
                    -> [(LocSymbol, LMap)]
 --------------------------------------------------------------------------------
-makeHaskellInlines allowTC src embs lmap spec 
-         = makeMeasureInline allowTC embs lmap cbs <$> inls 
+makeHaskellInlines allowTC src embs lmap spec
+         = makeMeasureInline allowTC embs lmap cbs <$> inls
   where
-    cbs  = nonRecCoreBinds (_giCbs src) 
+    cbs  = nonRecCoreBinds (_giCbs src)
     inls = S.toList        (Ms.inlines spec)
 
 makeMeasureInline :: Bool -> F.TCEmb Ghc.TyCon -> LogicMap -> [Ghc.CoreBind] -> LocSymbol
                   -> (LocSymbol, LMap)
-makeMeasureInline allowTC embs lmap cbs x = 
-  case GM.findVarDef (val x) cbs of 
-    Nothing       -> Ex.throw $ errHMeas x "Cannot inline haskell function"
-    Just (v, def) -> (vx, coreToFun' allowTC embs Nothing lmap vx v def ok)
-                     where 
+makeMeasureInline allowTC embs lmap cbs x =
+  case GM.findVarDef (val x) cbs of
+    Nothing        -> Ex.throw $ errHMeas x "Cannot inline haskell function"
+    Just (v, defn) -> (vx, coreToFun' allowTC embs Nothing lmap vx v defn ok)
+                     where
                        vx         = F.atLoc x (F.symbol v)
                        ok (xs, e) = LMap vx (F.symbol <$> xs) (either id id e)
 
@@ -133,26 +133,27 @@
 
 coreToFun' :: Bool -> F.TCEmb Ghc.TyCon -> Maybe Bare.DataConMap -> LogicMap -> LocSymbol -> Ghc.Var -> Ghc.CoreExpr
            -> (([Ghc.Var], Either F.Expr F.Expr) -> a) -> a
-coreToFun' allowTC embs dmMb lmap x v def ok = either Ex.throw ok act 
-  where 
-    act  = runToLogic embs lmap dm err xFun 
-    xFun = coreToFun allowTC x v def  
-    err  = errHMeas x  
-    dm   = Mb.fromMaybe mempty dmMb 
+coreToFun' allowTC embs dmMb lmap x v defn ok = either Ex.throw ok act
+  where
+    act  = runToLogic embs lmap dm err xFun
+    xFun = coreToFun allowTC x v defn
+    err  = errHMeas x
+    dm   = Mb.fromMaybe mempty dmMb
 
 
 nonRecCoreBinds :: [Ghc.CoreBind] -> [Ghc.CoreBind]
-nonRecCoreBinds            = concatMap go 
-  where 
+nonRecCoreBinds            = concatMap go
+  where
     go cb@(Ghc.NonRec _ _) = [cb]
     go    (Ghc.Rec xes)    = [Ghc.NonRec x e | (x, e) <- xes]
 
 -------------------------------------------------------------------------------
-makeHaskellDataDecls :: Config -> ModName -> Ms.BareSpec -> [Ghc.TyCon] 
+makeHaskellDataDecls :: Config -> ModName -> Ms.BareSpec -> [Ghc.TyCon]
                      -> [DataDecl]
 --------------------------------------------------------------------------------
 makeHaskellDataDecls cfg name spec tcs
-  | exactDCFlag cfg = Mb.mapMaybe tyConDataDecl
+  | exactDCFlag cfg = Bare.dataDeclSize spec
+                    . Mb.mapMaybe tyConDataDecl
                     -- . F.tracepp "makeHaskellDataDecls-3"
                     . zipMap   (hasDataDecl name spec . fst)
                     -- . F.tracepp "makeHaskellDataDecls-2"
@@ -167,7 +168,7 @@
 isReflectableTyCon  = Ghc.isFamInstTyCon .||. Ghc.isVanillaAlgTyCon
 
 liftableTyCons :: [Ghc.TyCon] -> [(Ghc.TyCon, DataName)]
-liftableTyCons 
+liftableTyCons
   = F.notracepp "LiftableTCs 3"
   . zipMapMaybe (tyConDataName True)
   . F.notracepp "LiftableTCs 2"
@@ -183,25 +184,25 @@
 zipMapMaybe f = Mb.mapMaybe (\x -> (x, ) <$> f x)
 
 hasDataDecl :: ModName -> Ms.BareSpec -> Ghc.TyCon -> HasDataDecl
-hasDataDecl mod spec
-                 = \tc -> F.notracepp (msg tc) $ M.lookupDefault def (tcName tc) decls
+hasDataDecl modName spec
+                 = \tc -> F.notracepp (msg tc) $ M.lookupDefault defn (tcName tc) decls
   where
     msg tc       = "hasDataDecl " ++ show (tcName tc)
-    def          = NoDecl Nothing
-    tcName       = fmap (qualifiedDataName mod) . tyConDataName True
-    dcName       =       qualifiedDataName mod  . tycName
+    defn         = NoDecl Nothing
+    tcName       = fmap (qualifiedDataName modName) . tyConDataName True
+    dcName       =       qualifiedDataName modName  . tycName
     decls        = M.fromList [ (Just dn, hasDecl d)
                                 | d     <- Ms.dataDecls spec
                                 , let dn = dcName d]
 
 qualifiedDataName :: ModName -> DataName -> DataName
-qualifiedDataName mod (DnName lx) = DnName (qualifyModName mod <$> lx)
-qualifiedDataName mod (DnCon  lx) = DnCon  (qualifyModName mod <$> lx)
+qualifiedDataName modName (DnName lx) = DnName (qualifyModName modName <$> lx)
+qualifiedDataName modName (DnCon  lx) = DnCon  (qualifyModName modName <$> lx)
 
 {-tyConDataDecl :: {tc:TyCon | isAlgTyCon tc} -> Maybe DataDecl @-}
 tyConDataDecl :: ((Ghc.TyCon, DataName), HasDataDecl) -> Maybe DataDecl
 tyConDataDecl (_, HasDecl)
-  = Nothing 
+  = Nothing
 tyConDataDecl ((tc, dn), NoDecl szF)
   = Just $ DataDecl
       { tycName   = dn
@@ -217,8 +218,8 @@
 
 tyConDataName :: Bool -> Ghc.TyCon -> Maybe DataName
 tyConDataName full tc
-  | vanillaTc  = Just (DnName ((post . F.symbol) <$> GM.locNamedThing tc))
-  | d:_ <- dcs = Just (DnCon  ((post . F.symbol) <$> GM.locNamedThing d ))
+  | vanillaTc  = Just (DnName (post . F.symbol <$> GM.locNamedThing tc))
+  | d:_ <- dcs = Just (DnCon  (post . F.symbol <$> GM.locNamedThing d ))
   | otherwise  = Nothing
   where
     post       = if full then id else GM.dropModuleNamesAndUnique
@@ -233,11 +234,11 @@
     xts           = [(Bare.makeDataConSelector Nothing d i, RT.bareOfType t) | (i, t) <- its ]
     dx            = F.symbol <$> GM.locNamedThing d
     its           = zip [1..] ts
-    (as,_ps,ts,t)  = Ghc.dataConSig d
-    outT          = Just (RT.bareOfType t :: BareType) 
+    (as,_ps,ts,ty)  = Ghc.dataConSig d
+    outT          = Just (RT.bareOfType ty :: BareType)
     _outT :: Maybe BareType
     _outT
-      | isGadt    = Just (RT.bareOfType t)
+      | isGadt    = Just (RT.bareOfType ty)
       | otherwise = Nothing
 
 
@@ -251,13 +252,13 @@
 
 makeMeasureSelectors :: Config -> Bare.DataConMap -> Located DataConP -> [Measure SpecType Ghc.DataCon]
 makeMeasureSelectors cfg dm (Loc l l' c)
-  = (Misc.condNull (exactDCFlag cfg) $ checker : Mb.catMaybes (go' <$> fields)) --  internal measures, needed for reflection
- ++ (Misc.condNull (autofields)      $           Mb.catMaybes (go  <$> fields)) --  user-visible measures.
+  = Misc.condNull (exactDCFlag cfg) (checker : Mb.mapMaybe go' fields) --  internal measures, needed for reflection
+ ++ Misc.condNull autofields (Mb.mapMaybe go fields) --  user-visible measures.
   where
-    dc         = dcpCon    c 
-    isGadt     = dcpIsGadt c 
+    dc         = dcpCon    c
+    isGadt     = dcpIsGadt c
     xts        = dcpTyArgs c
-    autofields = not (isGadt)
+    autofields = not isGadt
     go ((x, t), i)
       -- do not make selectors for functional fields
       | isFunTy t && not (higherOrderFlag cfg)
@@ -292,18 +293,18 @@
 
 -- bkDataCon :: DataCon -> Int -> ([RTVar RTyVar RSort], [SpecType], (Symbol, SpecType, RReft))
 bkDataCon :: (F.Reftable (RTProp RTyCon RTyVar r), PPrint r, F.Reftable r) => Bool -> Ghc.DataCon -> Int -> ([RTVar RTyVar RSort], [RRType r], (F.Symbol, RFInfo, RRType r, r))
-bkDataCon permitTC dc nFlds  = (as, ts, (F.dummySymbol, classRFInfo permitTC, t, mempty))
+bkDataCon permitTC dcn nFlds  = (as, ts, (F.dummySymbol, classRFInfo permitTC, t, mempty))
   where
     ts                = RT.ofType <$> Misc.takeLast nFlds (map Ghc.irrelevantMult _ts)
     t                 = -- Misc.traceShow ("bkDataConResult" ++ GM.showPpr (dc, _t, _t0)) $
                           RT.ofType  $ Ghc.mkTyConApp tc tArgs'
     as                = makeRTVar . RT.rTyVar <$> (αs ++ αs')
-    ((αs,αs',_,_,_ts,_t), _t0) = hammer dc
+    ((αs,αs',_,_,_ts,_t), _t0) = hammer dcn
     tArgs'            = take (nArgs - nVars) tArgs ++ (Ghc.mkTyVarTy <$> αs)
     nVars             = length αs
     nArgs             = length tArgs
     (tc, tArgs)       = Mb.fromMaybe err (Ghc.splitTyConApp_maybe _t)
-    err               = GM.namedPanic dc ("Cannot split result type of DataCon " ++ show dc)
+    err               = GM.namedPanic dcn ("Cannot split result type of DataCon " ++ show dcn)
     hammer dc         = (Ghc.dataConFullSig dc, Ghc.varType . Ghc.dataConWorkId $ dc)
 
 data DataConSel = Check | Proj Int
@@ -324,15 +325,15 @@
 makeMeasureSelector x s dc n i = M { msName = x, msSort = s, msEqns = [eqn], msKind = MsSelector, msUnSorted = mempty}
   where
     eqn                        = Def x dc Nothing args (E (F.EVar $ mkx i))
-    args                       = ((, Nothing) . mkx) <$> [1 .. n]
+    args                       = (, Nothing) . mkx <$> [1 .. n]
     mkx j                      = F.symbol ("xx" ++ show j)
 
 makeMeasureChecker :: LocSymbol -> SpecType -> Ghc.DataCon -> Int -> Measure SpecType Ghc.DataCon
 makeMeasureChecker x s0 dc n = M { msName = x, msSort = s, msEqns = eqn : (eqns <$> filter (/= dc) dcs), msKind = MsChecker, msUnSorted = mempty }
   where
     s       = F.notracepp ("makeMeasureChecker: " ++ show x) s0
-    eqn     = Def x dc Nothing (((, Nothing) . mkx) <$> [1 .. n])       (P F.PTrue)
-    eqns d  = Def x d  Nothing (((, Nothing) . mkx) <$> [1 .. nArgs d]) (P F.PFalse)
+    eqn     = Def x dc Nothing ((, Nothing) . mkx <$> [1 .. n])       (P F.PTrue)
+    eqns d  = Def x d  Nothing ((, Nothing) . mkx <$> [1 .. nArgs d]) (P F.PFalse)
     nArgs d = length (Ghc.dataConOrigArgTys d)
     mkx j   = F.symbol ("xx" ++ show j)
     dcs     = Ghc.tyConDataCons (Ghc.dataConTyCon dc)
@@ -341,41 +342,41 @@
 ----------------------------------------------------------------------------------------------
 makeMeasureSpec' :: Bool -> MSpec SpecType Ghc.DataCon -> ([(Ghc.Var, SpecType)], [(LocSymbol, RRType F.Reft)])
 ----------------------------------------------------------------------------------------------
-makeMeasureSpec' allowTC mspec0 = (ctorTys, measTys) 
-  where 
+makeMeasureSpec' allowTC mspec0 = (ctorTys, measTys)
+  where
     ctorTys             = Misc.mapSnd RT.uRType <$> ctorTys0
-    (ctorTys0, measTys) = Ms.dataConTypes allowTC mspec 
+    (ctorTys0, measTys) = Ms.dataConTypes allowTC mspec
     mspec               = first (mapReft ur_reft) mspec0
 
 ----------------------------------------------------------------------------------------------
-makeMeasureSpec :: Bare.Env -> Bare.SigEnv -> ModName -> (ModName, Ms.BareSpec) -> 
+makeMeasureSpec :: Bare.Env -> Bare.SigEnv -> ModName -> (ModName, Ms.BareSpec) ->
                    Bare.Lookup (Ms.MSpec SpecType Ghc.DataCon)
 ----------------------------------------------------------------------------------------------
-makeMeasureSpec env sigEnv myName (name, spec) 
-  = mkMeasureDCon env               name 
-  . mkMeasureSort env               name 
-  . first val 
-  . bareMSpec     env sigEnv myName name 
-  $ spec 
+makeMeasureSpec env sigEnv myName (name, spec)
+  = mkMeasureDCon env               name
+  . mkMeasureSort env               name
+  . first val
+  . bareMSpec     env sigEnv myName name
+  $ spec
 
-bareMSpec :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> Ms.BareSpec -> Ms.MSpec LocBareType LocSymbol 
-bareMSpec env sigEnv myName name spec = Ms.mkMSpec ms cms ims 
+bareMSpec :: Bare.Env -> Bare.SigEnv -> ModName -> ModName -> Ms.BareSpec -> Ms.MSpec LocBareType LocSymbol
+bareMSpec env sigEnv myName name spec = Ms.mkMSpec ms cms ims
   where
     cms        = F.notracepp "CMS" $ filter inScope1 $             Ms.cmeasures spec
     ms         = F.notracepp "UMS" $ filter inScope2 $ expMeas <$> Ms.measures  spec
     ims        = F.notracepp "IMS" $ filter inScope2 $ expMeas <$> Ms.imeasures spec
     expMeas    = expandMeasure env name  rtEnv
     rtEnv      = Bare.sigRTEnv          sigEnv
-    force      = name == myName 
-    inScope1 z = F.notracepp ("inScope1: " ++ F.showpp (msName z)) $ (force ||  okSort z)
-    inScope2 z = F.notracepp ("inScope2: " ++ F.showpp (msName z)) $ (force || (okSort z && okCtors z))
-    okSort     = Bare.knownGhcType env name . msSort 
-    okCtors    = all (Bare.knownGhcDataCon env name . ctor) . msEqns 
+    force      = name == myName
+    inScope1 z = F.notracepp ("inScope1: " ++ F.showpp (msName z)) (force ||  okSort z)
+    inScope2 z = F.notracepp ("inScope2: " ++ F.showpp (msName z)) (force || (okSort z && okCtors z))
+    okSort     = Bare.knownGhcType env name . msSort
+    okCtors    = all (Bare.knownGhcDataCon env name . ctor) . msEqns
 
 mkMeasureDCon :: Bare.Env -> ModName -> Ms.MSpec t LocSymbol -> Bare.Lookup (Ms.MSpec t Ghc.DataCon)
 mkMeasureDCon env name m = do
   let ns = measureCtors m
-  dcs   <- mapM (Bare.lookupGhcDataCon env name "measure-datacon") ns 
+  dcs   <- mapM (Bare.lookupGhcDataCon env name "measure-datacon") ns
   return $ mkMeasureDCon_ m (zip (val <$> ns) dcs)
 
 -- mkMeasureDCon env name m = mkMeasureDCon_ m [ (val n, symDC n) | n <- measureCtors m ]
@@ -392,53 +393,53 @@
 measureCtors ::  Ms.MSpec t LocSymbol -> [LocSymbol]
 measureCtors = Misc.sortNub . fmap ctor . concat . M.elems . Ms.ctorMap
 
-mkMeasureSort :: Bare.Env -> ModName -> Ms.MSpec BareType LocSymbol 
+mkMeasureSort :: Bare.Env -> ModName -> Ms.MSpec BareType LocSymbol
               -> Ms.MSpec SpecType LocSymbol
-mkMeasureSort env name (Ms.MSpec c mm cm im) = 
-  Ms.MSpec (map txDef <$> c) (tx <$> mm) (tx <$> cm) (tx <$> im) 
+mkMeasureSort env name (Ms.MSpec c mm cm im) =
+  Ms.MSpec (map txDef <$> c) (tx <$> mm) (tx <$> cm) (tx <$> im)
     where
       ofMeaSort :: F.SourcePos -> BareType -> SpecType
-      ofMeaSort l = Bare.ofBareType env name l Nothing 
+      ofMeaSort l = Bare.ofBareType env name l Nothing
 
       tx :: Measure BareType ctor -> Measure SpecType ctor
       tx (M n s eqs k u) = M n (ofMeaSort l s) (txDef <$> eqs) k u where l = GM.fSourcePos n
 
       txDef :: Def BareType ctor -> Def SpecType ctor
-      txDef d = first (ofMeaSort l) d                              where l = GM.fSourcePos (measure d) 
+      txDef d = first (ofMeaSort l) d                              where l = GM.fSourcePos (measure d)
 
 
-  
+
 --------------------------------------------------------------------------------
 -- | Expand Measures -----------------------------------------------------------
 --------------------------------------------------------------------------------
 -- type BareMeasure = Measure LocBareType LocSymbol
 
 expandMeasure :: Bare.Env -> ModName -> BareRTEnv -> BareMeasure -> BareMeasure
-expandMeasure env name rtEnv m = m 
+expandMeasure env name rtEnv m = m
   { msSort = RT.generalize                   <$> msSort m
-  , msEqns = expandMeasureDef env name rtEnv <$> msEqns m 
+  , msEqns = expandMeasureDef env name rtEnv <$> msEqns m
   }
 
 expandMeasureDef :: Bare.Env -> ModName -> BareRTEnv -> Def t LocSymbol -> Def t LocSymbol
-expandMeasureDef env name rtEnv d = d 
+expandMeasureDef env name rtEnv d = d
   { body  = F.notracepp msg $ Bare.qualifyExpand env name rtEnv l bs (body d) }
-  where 
-    l     = loc (measure d) 
-    bs    = fst <$> binds d 
-    msg   = "QUALIFY-EXPAND-BODY" ++ F.showpp (bs, body d) 
+  where
+    l     = loc (measure d)
+    bs    = fst <$> binds d
+    msg   = "QUALIFY-EXPAND-BODY" ++ F.showpp (bs, body d)
 
 ------------------------------------------------------------------------------
 varMeasures :: (Monoid r) => Bare.Env -> [(F.Symbol, Located (RRType r))]
 ------------------------------------------------------------------------------
-varMeasures env = 
-  [ (F.symbol v, varSpecType v) 
-      | v <- knownVars env 
+varMeasures env =
+  [ (F.symbol v, varSpecType v)
+      | v <- knownVars env
       , GM.isDataConId v
       , isSimpleType (Ghc.varType v) ]
 
 knownVars :: Bare.Env -> [Ghc.Var]
-knownVars env = [ v | (_, xThings)   <- M.toList (Bare._reTyThings env) 
-                    , (_,Ghc.AnId v) <- xThings 
+knownVars env = [ v | (_, xThings)   <- M.toList (Bare._reTyThings env)
+                    , (_,Ghc.AnId v) <- xThings
                 ]
 
 varSpecType :: (Monoid r) => Ghc.Var -> Located (RRType r)
@@ -449,7 +450,7 @@
 
 makeClassMeasureSpec :: MSpec (RType c tv (UReft r2)) t
                      -> [(LocSymbol, CMeasure (RType c tv r2))]
-makeClassMeasureSpec (Ms.MSpec {..}) = tx <$> M.elems cmeasMap
+makeClassMeasureSpec Ms.MSpec{..} = tx <$> M.elems cmeasMap
   where
     tx (M n s _ _ _) = (n, CM n (mapReft ur_reft s))
 
diff --git a/src/Language/Haskell/Liquid/Bare/Misc.hs b/src/Language/Haskell/Liquid/Bare/Misc.hs
--- a/src/Language/Haskell/Liquid/Bare/Misc.hs
+++ b/src/Language/Haskell/Liquid/Bare/Misc.hs
@@ -1,6 +1,7 @@
 {-# LANGUAGE FlexibleContexts         #-}
 
-module Language.Haskell.Liquid.Bare.Misc 
+
+module Language.Haskell.Liquid.Bare.Misc
   ( joinVar
   , mkVarExpr
   , vmap
@@ -14,17 +15,16 @@
 
 import           Prelude                               hiding (error)
 
-import           Language.Haskell.Liquid.GHC.API       as Ghc  hiding (Located, showPpr)
+import           Liquid.GHC.API       as Ghc  hiding (Located, showPpr)
 
 import           Control.Monad.Except                  (MonadError, throwError)
 import           Control.Monad.State
 import qualified Data.Maybe                            as Mb --(fromMaybe, isNothing)
 
-import qualified Text.PrettyPrint.HughesPJ             as PJ 
+import qualified Text.PrettyPrint.HughesPJ             as PJ
 import qualified Data.List                             as L
-import           Language.Fixpoint.Misc                as Misc -- (singleton, sortNub)
 import qualified Language.Fixpoint.Types as F
-import           Language.Haskell.Liquid.GHC.Misc
+import           Liquid.GHC.Misc
 import           Language.Haskell.Liquid.Types.RefType
 import           Language.Haskell.Liquid.Types.Types
 
@@ -48,7 +48,7 @@
       hasBasicArgs (FunTy _ tx t)   = isBaseTy tx && hasBasicArgs t
       hasBasicArgs _              = True
 
--} 
+-}
 
 {- 
 HEAD
@@ -101,12 +101,12 @@
 --     f γ _ r xs = let F.Reft (v, _) = F.toReft r in
 --                  [ x | x <- F.syms r, x /= v, not (x `F.memberSEnv` γ)] : xs
 
--} 
+-}
 -------------------------------------------------------------------------------
 -- Renaming Type Variables in Haskell Signatures ------------------------------
 -------------------------------------------------------------------------------
 runMapTyVars :: Bool -> Type -> SpecType -> (PJ.Doc -> PJ.Doc -> Error) -> Either Error MapTyVarST
-runMapTyVars allowTC τ t err = execStateT (mapTyVars allowTC τ t) (MTVST [] err) 
+runMapTyVars allowTC τ t err = execStateT (mapTyVars allowTC τ t) (MTVST [] err)
 
 data MapTyVarST = MTVST
   { vmap   :: [(Var, RTyVar)]
@@ -116,7 +116,7 @@
 mapTyVars :: Bool -> Type -> SpecType -> StateT MapTyVarST (Either Error) ()
 mapTyVars allowTC t (RImpF _ _ _ t' _)
    = mapTyVars allowTC t t'
-mapTyVars allowTC (FunTy { ft_arg = τ, ft_res = τ'}) t 
+mapTyVars allowTC (FunTy { ft_arg = τ, ft_res = τ'}) t
   | isErasable τ
   = mapTyVars allowTC τ' t
   where isErasable = if allowTC then isEmbeddedDictType else isClassPred
@@ -150,8 +150,8 @@
 mapTyVars allowTC (ForAllTy _ τ) t
   = mapTyVars allowTC τ t
 mapTyVars _ hsT lqT
-  = do err <- errmsg <$> get
-       throwError (err (F.pprint hsT) (F.pprint lqT)) 
+  = do err <- gets errmsg
+       throwError (err (F.pprint hsT) (F.pprint lqT))
 
 isKind :: Kind -> Bool
 isKind = classifiesTypeWithValues -- TODO:GHC-863 isStarKind k --  typeKind k
@@ -166,7 +166,7 @@
       Nothing             -> return $ MTVST ((α,a):αas) err
 
 matchKindArgs' :: [Type] -> [SpecType] -> [SpecType]
-matchKindArgs' ts1 ts2 = reverse $ go (reverse ts1) (reverse ts2)
+matchKindArgs' ts1' = reverse . go (reverse ts1') . reverse
   where
     go (_:ts1) (t2:ts2) = t2:go ts1 ts2
     go ts      []       | all isKind ts
@@ -175,7 +175,7 @@
 
 
 matchKindArgs :: [SpecType] -> [SpecType] -> [SpecType]
-matchKindArgs ts1 ts2 = reverse $ go (reverse ts1) (reverse ts2)
+matchKindArgs ts1' = reverse . go (reverse ts1') . reverse
   where
     go (_:ts1) (t2:ts2) = t2:go ts1 ts2
     go ts      []       = ts
diff --git a/src/Language/Haskell/Liquid/Bare/Plugged.hs b/src/Language/Haskell/Liquid/Bare/Plugged.hs
--- a/src/Language/Haskell/Liquid/Bare/Plugged.hs
+++ b/src/Language/Haskell/Liquid/Bare/Plugged.hs
@@ -1,8 +1,7 @@
 {-# LANGUAGE OverloadedStrings     #-}
-{-# LANGUAGE TupleSections         #-}
 {-# LANGUAGE PartialTypeSignatures #-}
 
-module Language.Haskell.Liquid.Bare.Plugged 
+module Language.Haskell.Liquid.Bare.Plugged
   ( makePluggedSig
   , makePluggedDataCon
   ) where
@@ -15,16 +14,16 @@
 import qualified Control.Exception                 as Ex
 import qualified Data.HashMap.Strict               as M
 import qualified Data.HashSet                      as S
-import qualified Data.Maybe                        as Mb 
-import qualified Data.List                         as L 
+import qualified Data.Maybe                        as Mb
+import qualified Data.List                         as L
 import qualified Language.Fixpoint.Types           as F
 import qualified Language.Fixpoint.Types.Visitor   as F
-import qualified Language.Haskell.Liquid.GHC.Misc  as GM 
-import qualified Language.Haskell.Liquid.GHC.API   as Ghc 
-import           Language.Haskell.Liquid.GHC.Types (StableName, mkStableName)
+import qualified Liquid.GHC.Misc  as GM
+import qualified Liquid.GHC.API   as Ghc
+import           Liquid.GHC.Types (StableName, mkStableName)
 import           Language.Haskell.Liquid.Types.RefType ()
 import           Language.Haskell.Liquid.Types
-import qualified Language.Haskell.Liquid.Misc       as Misc 
+import qualified Language.Haskell.Liquid.Misc       as Misc
 import qualified Language.Haskell.Liquid.Bare.Types as Bare
 import qualified Language.Haskell.Liquid.Bare.Misc  as Bare
 
@@ -52,10 +51,10 @@
                -> Bare.PlugTV Ghc.Var -> LocSpecType
                -> LocSpecType
 
-makePluggedSig allowTC name embs tyi exports kx t 
-  | Just x <- kxv = mkPlug x 
+makePluggedSig allowTC name embs tyi exports kx t
+  | Just x <- kxv = mkPlug x
   | otherwise     = t
-  where 
+  where
     kxv           = Bare.plugSrc kx
     mkPlug x      = plugHoles allowTC kx embs tyi  r τ t
       where
@@ -65,12 +64,12 @@
 
 
 -- makePluggedDataCon = makePluggedDataCon_old 
--- plugHoles          = plugHoles_old 
+-- plugHoles          = plugHolesOld 
 -- makePluggedDataCon = makePluggedDataCon_new 
 
--- plugHoles _         = plugHoles_old
+-- plugHoles _         = plugHolesOld
 
-plugHoles :: (Ghc.NamedThing a, PPrint a, Show a) 
+plugHoles :: (Ghc.NamedThing a, PPrint a, Show a)
           => Bool
           -> Bare.PlugTV a
           -> F.TCEmb Ghc.TyCon
@@ -79,37 +78,37 @@
           -> Ghc.Type
           -> LocSpecType
           -> LocSpecType
-plugHoles allowTC (Bare.HsTV x) a b = plugHoles_old allowTC a b x 
-plugHoles allowTC (Bare.LqTV x) a b = plugHoles_new allowTC a b x 
+plugHoles allowTC (Bare.HsTV x) a b = plugHolesOld allowTC a b x
+plugHoles allowTC (Bare.LqTV x) a b = plugHolesNew allowTC a b x
 plugHoles _ _                   _ _ = \_ _ t -> t
 
 
 makePluggedDataCon :: Bool -> F.TCEmb Ghc.TyCon -> Bare.TyConMap -> Located DataConP -> Located DataConP
-makePluggedDataCon allowTC embs tyi ldcp 
+makePluggedDataCon allowTC embs tyi ldcp
   | mismatchFlds      = Ex.throw (err "fields") -- (err $  "fields:" <+> F.pprint (length dts) <+> " vs " <+> F.pprint ( dcArgs))
   | mismatchTyVars    = Ex.throw (err "type variables")
-  | otherwise         = F.atLoc ldcp $ F.notracepp "makePluggedDataCon" $ dcp 
+  | otherwise         = F.atLoc ldcp $ F.notracepp "makePluggedDataCon" $ dcp
                           { dcpFreeTyVars = dcVars
-                          , dcpTyArgs     = reverse tArgs 
-                          , dcpTyRes      = tRes 
+                          , dcpTyArgs     = reverse tArgs
+                          , dcpTyRes      = tRes
                           }
-  where 
+  where
     (tArgs, tRes)     = plugMany allowTC  embs tyi ldcp (das, dts, dt) (dcVars, dcArgs, dcpTyRes dcp)
     (das, _, dts, dt) = {- F.notracepp ("makePluggedDC: " ++ F.showpp dc) $ -} Ghc.dataConSig dc
-    dcArgs            = filter (not . (if allowTC then isEmbeddedClass else isClassType) . snd) $ reverse (dcpTyArgs dcp)
-    dcVars            = if isGADT 
-                          then padGADVars $ L.nub (dcpFreeTyVars dcp ++ (concatMap (map ty_var_value . freeTyVars) (dcpTyRes dcp:(snd <$> dcArgs))))
-                          else dcpFreeTyVars dcp 
+    dcArgs            = reverse $ filter (not . (if allowTC then isEmbeddedClass else isClassType) . snd) (dcpTyArgs dcp)
+    dcVars            = if isGADT
+                          then padGADVars $ L.nub (dcpFreeTyVars dcp ++ concatMap (map ty_var_value . freeTyVars) (dcpTyRes dcp:(snd <$> dcArgs)))
+                          else dcpFreeTyVars dcp
     dc                = dcpCon        dcp
-    dcp               = val           ldcp 
+    dcp               = val           ldcp
 
     isGADT            = Ghc.isGadtSyntaxTyCon $ Ghc.dataConTyCon dc
 
     -- hack to match LH and GHC GADT vars, since it is unclear how ghc generates free vars 
     padGADVars vs = (RTV <$> take (length das - length vs) das) ++ vs
 
-    mismatchFlds      = length dts /= length dcArgs 
-    mismatchTyVars    = length das /= length dcVars 
+    mismatchFlds      = length dts /= length dcArgs
+    mismatchTyVars    = length das /= length dcVars
     err things        = ErrBadData (GM.fSrcSpan dcp) (pprint dc) ("GHC and Liquid specifications have different numbers of" <+> things) :: UserError
 
 
@@ -128,29 +127,29 @@
 -- 
 --   and not, forall b. a -> a -> Bool.
 
-plugMany :: Bool -> F.TCEmb Ghc.TyCon -> Bare.TyConMap 
-         -> Located DataConP            
+plugMany :: Bool -> F.TCEmb Ghc.TyCon -> Bare.TyConMap
+         -> Located DataConP
          -> ([Ghc.Var], [Ghc.Type],             Ghc.Type)   -- ^ hs type 
          -> ([RTyVar] , [(F.Symbol, SpecType)], SpecType)   -- ^ lq type 
          -> ([(F.Symbol, SpecType)], SpecType)              -- ^ plugged lq type
-plugMany allowTC embs tyi ldcp (hsAs, hsArgs, hsRes) (lqAs, lqArgs, lqRes) 
-                     = F.notracepp msg (drop nTyVars (zip xs ts), t) 
-  where 
-    (_,(xs,_,ts,_), t) = bkArrow (val pT) 
+plugMany allowTC embs tyi ldcp (hsAs, hsArgs, hsRes) (lqAs, lqArgs, lqRes)
+                     = F.notracepp msg (drop nTyVars (zip xs ts), t)
+  where
+    (_,(xs,_,ts,_), t) = bkArrow (val pT)
     pT               = plugHoles allowTC (Bare.LqTV dcName) embs tyi (const killHoles) hsT (F.atLoc ldcp lqT)
-    hsT              = foldr (Ghc.mkFunTy Ghc.VisArg Ghc.Many) hsRes hsArgs' 
-    lqT              = foldr (uncurry (rFun' (classRFInfo allowTC))) lqRes lqArgs' 
-    hsArgs'          = [ Ghc.mkTyVarTy a               | a <- hsAs] ++ hsArgs 
-    lqArgs'          = [(F.dummySymbol, RVar a mempty) | a <- lqAs] ++ lqArgs 
+    hsT              = foldr (Ghc.mkFunTy Ghc.VisArg Ghc.Many) hsRes hsArgs'
+    lqT              = foldr (uncurry (rFun' (classRFInfo allowTC))) lqRes lqArgs'
+    hsArgs'          = [ Ghc.mkTyVarTy a               | a <- hsAs] ++ hsArgs
+    lqArgs'          = [(F.dummySymbol, RVar a mempty) | a <- lqAs] ++ lqArgs
     nTyVars          = length hsAs -- == length lqAs
     dcName           = Ghc.dataConName . dcpCon . val $ ldcp
     msg              = "plugMany: " ++ F.showpp (dcName, hsT, lqT)
 
-plugHoles_old, plugHoles_new 
+plugHolesOld, plugHolesNew
   :: (Ghc.NamedThing a, PPrint a, Show a)
   => Bool
   -> F.TCEmb Ghc.TyCon
-  -> Bare.TyConMap 
+  -> Bare.TyConMap
   -> a
   -> (SpecType -> RReft -> RReft)
   -> Ghc.Type
@@ -158,102 +157,102 @@
   -> LocSpecType
 
 -- NOTE: this use of toType is safe as rt' is derived from t.
-plugHoles_old allowTC tce tyi x f t0 zz@(Loc l l' st0) 
-    = Loc l l' 
-    . mkArrow (zip (updateRTVar <$> αs') rs) ps' [] [] 
-    . makeCls cs' 
-    . goPlug tce tyi err f (subts su rt) 
-    . mapExprReft (\_ -> F.applyCoSub coSub) 
-    . subts su 
+plugHolesOld allowTC tce tyi xx f t0 zz@(Loc l l' st0)
+    = Loc l l'
+    . mkArrow (zip (updateRTVar <$> αs') rs) ps' [] []
+    . makeCls cs'
+    . goPlug tce tyi err f (subts su rt)
+    . mapExprReft (\_ -> F.applyCoSub coSub)
+    . subts su
     $ st
-  where 
+  where
     tyvsmap      = case Bare.runMapTyVars allowTC (toType False rt) st err of
-                          Left e  -> Ex.throw e 
+                          Left e  -> Ex.throw e
                           Right s -> Bare.vmap s
     su           = [(y, rTyVar x)           | (x, y) <- tyvsmap]
     su'          = [(y, RVar (rTyVar x) ()) | (x, y) <- tyvsmap] :: [(RTyVar, RSort)]
     coSub        = M.fromList [(F.symbol y, F.FObj (F.symbol x)) | (y, x) <- su]
     ps'          = fmap (subts su') <$> ps
-    cs'          = [(F.dummySymbol, RApp c ts [] mempty) | (c, ts) <- cs ] 
+    cs'          = [(F.dummySymbol, RApp c ts [] mempty) | (c, ts) <- cs2 ]
     (αs', rs)    = unzip αs
-    (αs,_,cs,rt) = bkUnivClass (F.notracepp "hs-spec" $ ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
+    (αs,_,cs2,rt) = bkUnivClass (F.notracepp "hs-spec" $ ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
     (_,ps,_ ,st) = bkUnivClass (F.notracepp "lq-spec" st0)
 
     makeCls cs t = foldr (uncurry (rFun' (classRFInfo allowTC))) t cs
-    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint x) 
+    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint xx)
                           (text "Plugged Init types old")
                           (pprint $ Ghc.expandTypeSynonyms t0)
                           (pprint $ toRSort st0)
                           (Just (hsT, lqT))
-                          (Ghc.getSrcSpan x) 
+                          (Ghc.getSrcSpan xx)
 
 
 
-plugHoles_new allowTC@False tce tyi x f t0 zz@(Loc l l' st0) 
-    = Loc l l' 
-    . mkArrow (zip (updateRTVar <$> as'') rs) ps [] [] 
-    . makeCls cs' 
-    . goPlug tce tyi err f rt' 
-    $ st 
-  where 
+plugHolesNew allowTC@False tce tyi xx f t0 zz@(Loc l l' st0)
+    = Loc l l'
+    . mkArrow (zip (updateRTVar <$> as'') rs) ps [] []
+    . makeCls cs'
+    . goPlug tce tyi err f rt'
+    $ st
+  where
     rt'          = tx rt
     as''         = subRTVar su <$> as'
-    (as',rs)     = unzip as 
-    cs'          = [ (F.dummySymbol, ct) | (c, t) <- cs, let ct = tx (RApp c t [] mempty) ]
+    (as',rs)     = unzip as
+    cs'          = [ (F.dummySymbol, ct) | (c, t) <- tyCons, let ct = tx (RApp c t [] mempty) ]
     tx           = subts su
     su           = case Bare.runMapTyVars allowTC (toType False rt) st err of
-                          Left e  -> Ex.throw e 
+                          Left e  -> Ex.throw e
                           Right s -> [ (rTyVar x, y) | (x, y) <- Bare.vmap s]
-    (as,_,cs,rt) = bkUnivClass (ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
+    (as,_,tyCons,rt) = bkUnivClass (ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
     (_,ps,_ ,st) = bkUnivClass st0
 
     makeCls cs t = foldr (uncurry (rFun' (classRFInfo allowTC))) t cs
-    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint x) 
+    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint xx)
                           (text "Plugged Init types new")
                           (pprint $ Ghc.expandTypeSynonyms t0)
                           (pprint $ toRSort st0)
                           (Just (hsT, lqT))
-                          (Ghc.getSrcSpan x) 
+                          (Ghc.getSrcSpan xx)
 
 
-plugHoles_new allowTC@True tce tyi x f t0 zz@(Loc l l' st0) 
-    = Loc l l' 
+plugHolesNew allowTC@True tce tyi a f t0 zz@(Loc l l' st0)
+    = Loc l l'
     . mkArrow (zip (updateRTVar <$> as'') rs) ps [] (if length cs > length cs' then cs else cs')
     -- . makeCls cs' 
-    . goPlug tce tyi err f rt' 
-    $ st 
-  where 
+    . goPlug tce tyi err f rt'
+    $ st
+  where
     rt'          = tx rt
     as''         = subRTVar su <$> as'
-    (as',rs)     = unzip as 
+    (as',rs)     = unzip as
     -- cs'          = [ (F.dummySymbol, ct) | (c, t) <- cs, let ct = tx (RApp c t [] mempty) ]
     tx           = subts su
     su           = case Bare.runMapTyVars allowTC (toType False rt) st err of
-                          Left e  -> Ex.throw e 
+                          Left e  -> Ex.throw e
                           Right s -> [ (rTyVar x, y) | (x, y) <- Bare.vmap s]
     (as,_,cs0,rt) = bkUnivClass' (ofType (Ghc.expandTypeSynonyms t0) :: SpecType)
     (_,ps,cs0' ,st) = bkUnivClass' st0
     cs  = [ (x, classRFInfo allowTC, t, r) | (x,t,r)<-cs0]
     cs' = [ (x, classRFInfo allowTC, t, r) | (x,t,r)<-cs0']
 
-    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint x) 
+    err hsT lqT  = ErrMismatch (GM.fSrcSpan zz) (pprint a)
                           (text "Plugged Init types new")
                           (pprint $ Ghc.expandTypeSynonyms t0)
                           (pprint $ toRSort st0)
                           (Just (hsT, lqT))
-                          (Ghc.getSrcSpan x) 
+                          (Ghc.getSrcSpan a)
 
-subRTVar :: [(RTyVar, RTyVar)] -> SpecRTVar -> SpecRTVar 
+subRTVar :: [(RTyVar, RTyVar)] -> SpecRTVar -> SpecRTVar
 subRTVar su a@(RTVar v i) = Mb.maybe a (`RTVar` i) (lookup v su)
 
 goPlug :: F.TCEmb Ghc.TyCon -> Bare.TyConMap -> (Doc -> Doc -> Error) -> (SpecType -> RReft -> RReft) -> SpecType -> SpecType
        -> SpecType
-goPlug tce tyi err f = go 
+goPlug tce tyi err f = go
   where
-    go t (RHole r) = (addHoles t') { rt_reft = f t r }
+    go st (RHole r) = (addHoles t') { rt_reft = f st r }
       where
-        t'         = everywhere (mkT $ addRefs tce tyi) t
-        addHoles   = everywhere (mkT $ addHole)
+        t'         = everywhere (mkT $ addRefs tce tyi) st
+        addHoles   = everywhere (mkT addHole)
         -- NOTE: make sure we only add holes to RVar and RApp (NOT RFun)
         addHole :: SpecType -> SpecType
         addHole t@(RVar v _)       = RVar v (f t (uReft ("v", hole)))
@@ -272,7 +271,7 @@
     go (RAppTy t1 t2 _) (RAppTy t1' t2' r) = RAppTy     (go t1 t1') (go t2 t2') r
     -- zipWithDefM: if ts and ts' have different length then the liquid and haskell types are different.
     -- keep different types for now, as a pretty error message will be created at Bare.Check
-    go (RApp _ ts _ _)  (RApp c ts' p r)   
+    go (RApp _ ts _ _)  (RApp c ts' p r)
       | length ts == length ts'            = RApp c     (Misc.zipWithDef go ts $ Bare.matchKindArgs ts ts') p r
     go hsT lqT                             = Ex.throw (err (F.pprint hsT) (F.pprint lqT))
 
diff --git a/src/Language/Haskell/Liquid/Bare/Resolve.hs b/src/Language/Haskell/Liquid/Bare/Resolve.hs
--- a/src/Language/Haskell/Liquid/Bare/Resolve.hs
+++ b/src/Language/Haskell/Liquid/Bare/Resolve.hs
@@ -3,7 +3,6 @@
 --   2. USE the environment to translate plain symbols into Var, TyCon, etc. 
 
 {-# LANGUAGE OverloadedStrings     #-}
-{-# LANGUAGE TypeSynonymInstances  #-}
 {-# LANGUAGE FlexibleContexts      #-}
 {-# LANGUAGE FlexibleInstances     #-}
 {-# LANGUAGE LambdaCase            #-}
@@ -12,29 +11,29 @@
 {-# LANGUAGE ConstraintKinds       #-}
 {-# LANGUAGE TupleSections         #-}
 
-module Language.Haskell.Liquid.Bare.Resolve 
+module Language.Haskell.Liquid.Bare.Resolve
   ( -- * Creating the Environment
-    makeEnv 
+    makeEnv
 
     -- * Resolving symbols 
   , ResolveSym (..)
   , Qualify (..)
   , Lookup
   , qualifyTop, qualifyTopDummy
-  
+
   -- * Looking up names
-  , maybeResolveSym 
-  , lookupGhcDataCon 
-  , lookupGhcDnTyCon 
-  , lookupGhcTyCon 
-  , lookupGhcVar 
-  , lookupGhcNamedVar 
+  , maybeResolveSym
+  , lookupGhcDataCon
+  , lookupGhcDnTyCon
+  , lookupGhcTyCon
+  , lookupGhcVar
+  , lookupGhcNamedVar
 
   -- * Checking if names exist
-  , knownGhcVar 
-  , knownGhcTyCon 
-  , knownGhcDataCon 
-  , knownGhcType 
+  , knownGhcVar
+  , knownGhcTyCon
+  , knownGhcDataCon
+  , knownGhcType
 
   -- * Misc 
   , srcVars
@@ -50,37 +49,37 @@
   , errResolve
 
   -- * Fixing local variables
-  , resolveLocalBinds 
-  , partitionLocalBinds 
-  ) where 
+  , resolveLocalBinds
+  , partitionLocalBinds
+  ) where
 
-import qualified Control.Exception                 as Ex 
-import qualified Data.List                         as L 
-import qualified Data.HashSet                      as S 
+import qualified Control.Exception                 as Ex
+import qualified Data.List                         as L
+import qualified Data.HashSet                      as S
 import qualified Data.Maybe                        as Mb
 import qualified Data.HashMap.Strict               as M
 import qualified Data.Text                         as T
-import qualified Text.PrettyPrint.HughesPJ         as PJ 
+import qualified Text.PrettyPrint.HughesPJ         as PJ
 
-import qualified Language.Fixpoint.Utils.Files         as F 
-import qualified Language.Fixpoint.Types               as F 
-import qualified Language.Fixpoint.Types.Visitor       as F 
-import qualified Language.Fixpoint.Misc                as Misc 
-import qualified Language.Haskell.Liquid.GHC.API       as Ghc 
-import qualified Language.Haskell.Liquid.GHC.Misc      as GM 
-import qualified Language.Haskell.Liquid.Misc          as Misc 
+import qualified Language.Fixpoint.Utils.Files         as F
+import qualified Language.Fixpoint.Types               as F
+import qualified Language.Fixpoint.Types.Visitor       as F
+import qualified Language.Fixpoint.Misc                as Misc
+import qualified Liquid.GHC.API       as Ghc
+import qualified Liquid.GHC.Misc      as GM
+import qualified Language.Haskell.Liquid.Misc          as Misc
 import qualified Language.Haskell.Liquid.Types.RefType as RT
-import qualified Language.Haskell.Liquid.Types.Errors  as Errors 
-import           Language.Haskell.Liquid.Types.Types   
+import qualified Language.Haskell.Liquid.Types.Errors  as Errors
+import           Language.Haskell.Liquid.Types.Types
 import           Language.Haskell.Liquid.Measure       (BareSpec)
 import           Language.Haskell.Liquid.Types.Specs   hiding (BareSpec)
-import           Language.Haskell.Liquid.Types.Visitors 
-import           Language.Haskell.Liquid.Bare.Types 
-import           Language.Haskell.Liquid.Bare.Misc   
-import           Language.Haskell.Liquid.WiredIn 
+import           Language.Haskell.Liquid.Types.Visitors
+import           Language.Haskell.Liquid.Bare.Types
+import           Language.Haskell.Liquid.Bare.Misc
+import           Language.Haskell.Liquid.WiredIn
 
 myTracepp :: (F.PPrint a) => String -> a -> a
-myTracepp = F.notracepp 
+myTracepp = F.notracepp
 
 -- type Lookup a = Misc.Validate [Error] a
 type Lookup a = Either [Error] a
@@ -88,49 +87,49 @@
 -------------------------------------------------------------------------------
 -- | Creating an environment 
 -------------------------------------------------------------------------------
-makeEnv :: Config -> GhcSrc -> LogicMap -> [(ModName, BareSpec)] -> Env 
-makeEnv cfg src lmap specs = RE 
+makeEnv :: Config -> GhcSrc -> LogicMap -> [(ModName, BareSpec)] -> Env
+makeEnv cfg src lmap specs = RE
   { reLMap      = lmap
-  , reSyms      = syms 
-  , _reSubst    = makeVarSubst   src 
-  , _reTyThings = makeTyThingMap src 
+  , reSyms      = syms
+  , _reSubst    = makeVarSubst   src
+  , _reTyThings = makeTyThingMap src
   , reQualImps  = _gsQualImps     src
   , reAllImps   = _gsAllImps      src
-  , reLocalVars = makeLocalVars  src 
+  , reLocalVars = makeLocalVars  src
   , reSrc       = src
-  , reGlobSyms  = S.fromList     globalSyms 
+  , reGlobSyms  = S.fromList     globalSyms
   , reCfg       = cfg
-  } 
-  where 
+  }
+  where
     globalSyms  = concatMap getGlobalSyms specs
-    syms        = [ (F.symbol v, v) | v <- vars ] 
+    syms        = [ (F.symbol v, v) | v <- vars ]
     vars        = srcVars src
 
 getGlobalSyms :: (ModName, BareSpec) -> [F.Symbol]
-getGlobalSyms (_, spec) 
-  = filter (not . GM.isQualifiedSym) 
-       $ (mbName <$> measures  spec) 
+getGlobalSyms (_, spec)
+  = filter (not . GM.isQualifiedSym)
+       $ (mbName <$> measures  spec)
       ++ (mbName <$> cmeasures spec)
       ++ (mbName <$> imeasures spec)
-  where 
+  where
     mbName = F.val . msName
 
-makeLocalVars :: GhcSrc -> LocalVars 
+makeLocalVars :: GhcSrc -> LocalVars
 makeLocalVars = localVarMap . localBinds . _giCbs
 
 -- TODO: rewrite using CoreVisitor
 localBinds :: [Ghc.CoreBind] -> [Ghc.Var]
-localBinds                    = concatMap (bgo S.empty) 
+localBinds                    = concatMap (bgo S.empty)
   where
-    add  x g                  = maybe g (`S.insert` g) (localKey x) 
-    adds b g                  = foldr add g (Ghc.bindersOf b) 
-    take x g                  = maybe [] (\k -> if S.member k g then [] else [x]) (localKey x)
-    pgo g (x, e)              = take x g ++ go (add x g) e
-    bgo g (Ghc.NonRec x e)    = pgo g (x, e) 
-    bgo g (Ghc.Rec xes)       = concatMap (pgo g) xes 
+    add  x g                  = maybe g (`S.insert` g) (localKey x)
+    adds b g                  = foldr add g (Ghc.bindersOf b)
+    take' x g                 = maybe [] (\k -> [x | not (S.member k g)]) (localKey x)
+    pgo g (x, e)              = take' x g ++ go (add x g) e
+    bgo g (Ghc.NonRec x e)    = pgo g (x, e)
+    bgo g (Ghc.Rec xes)       = concatMap (pgo g) xes
     go  g (Ghc.App e a)       = concatMap (go  g) [e, a]
     go  g (Ghc.Lam _ e)       = go g e
-    go  g (Ghc.Let b e)       = bgo g b ++ go (adds b g) e 
+    go  g (Ghc.Let b e)       = bgo g b ++ go (adds b g) e
     go  g (Ghc.Tick _ e)      = go g e
     go  g (Ghc.Cast e _)      = go g e
     go  g (Ghc.Case e _ _ cs) = go g e ++ concatMap (go g . Misc.thd3) cs
@@ -138,28 +137,28 @@
     go  _ _                   = []
 
 localVarMap :: [Ghc.Var] -> LocalVars
-localVarMap vs = 
-  Misc.group [ (x, (i, v)) | v    <- vs
-                           , x    <- Mb.maybeToList (localKey v) 
+localVarMap vs =
+  Misc.group [ (x, (i, v)) | v <- vs
                            , let i = F.unPos (F.srcLine v)
+                           , x <- Mb.maybeToList (localKey v)
              ]
 
 localKey   :: Ghc.Var -> Maybe F.Symbol
-localKey v 
-  | isLocal m = Just x 
+localKey v
+  | isLocal m = Just x
   | otherwise = Nothing
-  where 
-    (m, x)    = splitModuleNameExact . GM.dropModuleUnique . F.symbol $ v 
+  where
+    (m, x)    = splitModuleNameExact . GM.dropModuleUnique . F.symbol $ v
 
-makeVarSubst :: GhcSrc -> F.Subst 
-makeVarSubst src = F.mkSubst unqualSyms 
-  where 
-    unqualSyms   = [ (x, mkVarExpr v) 
-                       | (x, mxs) <- M.toList       (makeSymMap src) 
-                       , v        <- Mb.maybeToList (okUnqualified me mxs) 
+makeVarSubst :: GhcSrc -> F.Subst
+makeVarSubst src = F.mkSubst unqualSyms
+  where
+    unqualSyms   = [ (x, mkVarExpr v)
+                       | (x, mxs) <- M.toList (makeSymMap src)
                        , not (isWiredInName x)
-                   ] 
-    me           = F.symbol (_giTargetMod src) 
+                       , v <- Mb.maybeToList (okUnqualified me mxs)
+                   ]
+    me           = F.symbol (_giTargetMod src)
 
 -- | @okUnqualified mod mxs@ takes @mxs@ which is a list of modulenames-var 
 --   pairs all of which have the same unqualified symbol representation. 
@@ -167,85 +166,85 @@
 --   1. that list is a singleton i.e. there is a UNIQUE unqualified version, OR
 --   2. there is a version whose module equals @me@.
 
-okUnqualified :: F.Symbol -> [(F.Symbol, a)] -> Maybe a 
-okUnqualified _ [(_, x)] = Just x 
-okUnqualified me mxs     = go mxs 
-  where 
-    go []                = Nothing 
-    go ((m,x) : rest)    
-      | me == m          = Just x 
-      | otherwise        = go rest 
+okUnqualified :: F.Symbol -> [(F.Symbol, a)] -> Maybe a
+okUnqualified _ [(_, x)] = Just x
+okUnqualified me mxs     = go mxs
+  where
+    go []                = Nothing
+    go ((m,x) : rest)
+      | me == m          = Just x
+      | otherwise        = go rest
 
 
 makeSymMap :: GhcSrc -> M.HashMap F.Symbol [(F.Symbol, Ghc.Var)]
-makeSymMap src = Misc.group [ (sym, (m, x)) 
+makeSymMap src = Misc.group [ (sym, (m, x))
                                 | x           <- srcVars src
                                 , let (m, sym) = qualifiedSymbol x ]
 
-makeTyThingMap :: GhcSrc -> TyThingMap 
+makeTyThingMap :: GhcSrc -> TyThingMap
 makeTyThingMap src =
   Misc.group [ (x, (m, t))  | t         <- srcThings src
                             , tSym      <- Mb.maybeToList (tyThingSymbol t)
-                            , let (m, x) = qualifiedSymbol tSym 
+                            , let (m, x) = qualifiedSymbol tSym
                             , not (isLocal m)
-             ] 
+             ]
 
-tyThingSymbol :: Ghc.TyThing -> Maybe F.Symbol 
+tyThingSymbol :: Ghc.TyThing -> Maybe F.Symbol
 tyThingSymbol (Ghc.AnId     x) = Just (F.symbol x)
 tyThingSymbol (Ghc.ATyCon   c) = Just (F.symbol c)
-tyThingSymbol (Ghc.AConLike d) = conLikeSymbol d 
+tyThingSymbol (Ghc.AConLike d) = conLikeSymbol d
 tyThingSymbol _tt              = Nothing -- panic Nothing ("TODO: tyThingSymbol" ++ showPpr tt)
 
 
-conLikeSymbol :: Ghc.ConLike -> Maybe F.Symbol 
-conLikeSymbol (Ghc.RealDataCon d) = Just (F.symbol d) 
+conLikeSymbol :: Ghc.ConLike -> Maybe F.Symbol
+conLikeSymbol (Ghc.RealDataCon d) = Just (F.symbol d)
 conLikeSymbol _z                   = Nothing -- panic Nothing ("TODO: conLikeSymbol -- " ++ showPpr z)
 
 
 
 
 isLocal :: F.Symbol -> Bool
-isLocal = isEmptySymbol 
+isLocal = isEmptySymbol
 
 qualifiedSymbol :: (F.Symbolic a) => a -> (F.Symbol, F.Symbol)
-qualifiedSymbol = splitModuleNameExact . F.symbol 
+qualifiedSymbol = splitModuleNameExact . F.symbol
 
-isEmptySymbol :: F.Symbol -> Bool 
-isEmptySymbol x = F.lengthSym x == 0 
+isEmptySymbol :: F.Symbol -> Bool
+isEmptySymbol x = F.lengthSym x == 0
 
-srcThings :: GhcSrc -> [Ghc.TyThing] 
-srcThings src = myTracepp "SRCTHINGS" 
-              $ Misc.hashNubWith F.showpp (_gsTyThings src ++ mySrcThings src) 
+srcThings :: GhcSrc -> [Ghc.TyThing]
+srcThings src = myTracepp "SRCTHINGS"
+              $ Misc.hashNubWith F.showpp (_gsTyThings src ++ mySrcThings src)
 
-mySrcThings :: GhcSrc -> [Ghc.TyThing] 
-mySrcThings src = [ Ghc.AnId   x | x <- vars ] 
-               ++ [ Ghc.ATyCon c | c <- tcs  ] 
-               ++ [ aDataCon   d | d <- dcs  ] 
-  where 
+mySrcThings :: GhcSrc -> [Ghc.TyThing]
+mySrcThings src = [ Ghc.AnId   x | x <- vars ]
+               ++ [ Ghc.ATyCon c | c <- tcs  ]
+               ++ [ aDataCon   d | d <- dcs  ]
+  where
     vars        = Misc.sortNub $ dataConVars dcs ++ srcVars  src
-    dcs         = Misc.sortNub $ concatMap Ghc.tyConDataCons tcs 
-    tcs         = Misc.sortNub $ srcTyCons src  
-    aDataCon    = Ghc.AConLike . Ghc.RealDataCon 
+    dcs         = Misc.sortNub $ concatMap Ghc.tyConDataCons tcs
+    tcs         = Misc.sortNub $ srcTyCons src
+    aDataCon    = Ghc.AConLike . Ghc.RealDataCon
 
 srcTyCons :: GhcSrc -> [Ghc.TyCon]
-srcTyCons src = concat 
-  [ _gsTcs     src 
-  , _gsFiTcs   src 
+srcTyCons src = concat
+  [ _gsTcs     src
+  , _gsFiTcs   src
   , _gsPrimTcs src
-  , srcVarTcs src 
+  , srcVarTcs src
   ]
 
 srcVarTcs :: GhcSrc -> [Ghc.TyCon]
-srcVarTcs = varTyCons . srcVars 
+srcVarTcs = varTyCons . srcVars
 
 varTyCons :: [Ghc.Var] -> [Ghc.TyCon]
-varTyCons = concatMap (typeTyCons . Ghc.dropForAlls . Ghc.varType) 
+varTyCons = concatMap (typeTyCons . Ghc.dropForAlls . Ghc.varType)
 
 typeTyCons :: Ghc.Type -> [Ghc.TyCon]
-typeTyCons t = tops t ++ inners t 
-  where 
+typeTyCons t = tops t ++ inners t
+  where
     tops     = Mb.maybeToList . Ghc.tyConAppTyCon_maybe
-    inners   = concatMap typeTyCons . snd . Ghc.splitAppTys 
+    inners   = concatMap typeTyCons . snd . Ghc.splitAppTys
 
 -- | We prioritize the @Ghc.Var@ in @srcVars@ because @_giDefVars@ and @gsTyThings@ 
 --   have _different_ values for the same binder, with different types where the 
@@ -255,144 +254,141 @@
 --      tests-absref-pos-Papp00.hs 
 
 srcVars :: GhcSrc -> [Ghc.Var]
-srcVars src = filter Ghc.isId .  fmap Misc.thd3 . Misc.fstByRank $ concat 
-  [ key "SRC-VAR-DEF" 0 <$> _giDefVars src 
+srcVars src = filter Ghc.isId .  fmap Misc.thd3 . Misc.fstByRank $ concat
+  [ key "SRC-VAR-DEF" 0 <$> _giDefVars src
   , key "SRC-VAR-DER" 1 <$> S.toList (_giDerVars src)
-  , key "SRC-VAR-IMP" 2 <$> _giImpVars src 
-  , key "SRC-VAR-USE" 3 <$> _giUseVars src 
+  , key "SRC-VAR-IMP" 2 <$> _giImpVars src
+  , key "SRC-VAR-USE" 3 <$> _giUseVars src
   , key "SRC-VAR-THN" 4 <$> [ x | Ghc.AnId x <- _gsTyThings src ]
   ]
-  where 
+  where
     key :: String -> Int -> Ghc.Var -> (Int, F.Symbol, Ghc.Var)
-    key _ i x  = (i, F.symbol x, {- dump s -} x) 
+    key _ i x  = (i, F.symbol x, {- dump s -} x)
     _dump msg x = fst . myTracepp msg $ (x, RT.ofType (Ghc.expandTypeSynonyms (Ghc.varType x)) :: SpecType)
 
 dataConVars :: [Ghc.DataCon] -> [Ghc.Var]
-dataConVars dcs = concat 
-  [ Ghc.dataConWorkId <$> dcs 
-  , Ghc.dataConWrapId <$> dcs 
-  ] 
+dataConVars dcs = (Ghc.dataConWorkId <$> dcs) ++ (Ghc.dataConWrapId <$> dcs)
 
 -------------------------------------------------------------------------------
 -- | Qualify various names 
 -------------------------------------------------------------------------------
-qualifyTop :: (Qualify a) => Env -> ModName -> F.SourcePos -> a -> a 
+qualifyTop :: (Qualify a) => Env -> ModName -> F.SourcePos -> a -> a
 qualifyTop env name l = qualify env name l []
 
-qualifyTopDummy :: (Qualify a) => Env -> ModName -> a -> a 
+qualifyTopDummy :: (Qualify a) => Env -> ModName -> a -> a
 qualifyTopDummy env name = qualifyTop env name dummySourcePos
 
-dummySourcePos :: F.SourcePos 
+dummySourcePos :: F.SourcePos
 dummySourcePos = F.loc (F.dummyLoc ())
 
-class Qualify a where 
-  qualify :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a 
+class Qualify a where
+  qualify :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a
 
-instance Qualify TyConMap where 
-  qualify env name l bs tyi = tyi 
-    { tcmTyRTy = tx <$> tcmTyRTy tyi 
-    , tcmFIRTy = tx <$> tcmFIRTy tyi 
-    } 
-    where 
-      tx :: (Qualify a) => a -> a 
-      tx = qualify env name l bs 
+instance Qualify TyConMap where
+  qualify env name l bs tyi = tyi
+    { tcmTyRTy = tx <$> tcmTyRTy tyi
+    , tcmFIRTy = tx <$> tcmFIRTy tyi
+    }
+    where
+      tx :: (Qualify a) => a -> a
+      tx = qualify env name l bs
 
-instance Qualify TyConP where 
+instance Qualify TyConP where
   qualify env name _ bs tcp = tcp { tcpSizeFun = qualify env name (tcpLoc tcp) bs <$> tcpSizeFun tcp }
 
-instance Qualify SizeFun where 
+instance Qualify SizeFun where
   qualify env name _ bs (SymSizeFun lx) = SymSizeFun (qualify env name (F.loc lx) bs lx)
   qualify _   _    _ _  sf              = sf
 
-instance Qualify F.Equation where 
+instance Qualify F.Equation where
   qualify _env _name _l _bs x = x -- TODO-REBARE 
 -- REBARE: qualifyAxiomEq :: Bare.Env -> Var -> Subst -> AxiomEq -> AxiomEq
 -- REBARE: qualifyAxiomEq v su eq = subst su eq { eqName = symbol v}
 
-instance Qualify F.Symbol where 
-  qualify env name l bs x = qualifySymbol env name l bs x 
+instance Qualify F.Symbol where
+  qualify env name l bs x = qualifySymbol env name l bs x
 
-qualifySymbol :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> F.Symbol -> F.Symbol                                                   
+qualifySymbol :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> F.Symbol -> F.Symbol
 qualifySymbol env name l bs x
-  | isSpl     = x 
-  | otherwise = case resolveLocSym env name "Symbol" (F.Loc l l x) of 
-                  Left _ -> x 
-                  Right v -> v 
-  where 
+  | isSpl     = x
+  | otherwise = case resolveLocSym env name "Symbol" (F.Loc l l x) of
+                  Left _ -> x
+                  Right v -> v
+  where
     isSpl     = isSplSymbol env bs x
 
-isSplSymbol :: Env -> [F.Symbol] -> F.Symbol -> Bool 
-isSplSymbol env bs x 
-  =  isWiredInName x 
-  || elem x bs 
-  || S.member x (reGlobSyms env) 
+isSplSymbol :: Env -> [F.Symbol] -> F.Symbol -> Bool
+isSplSymbol env bs x
+  =  isWiredInName x
+  || elem x bs
+  || S.member x (reGlobSyms env)
 
-instance (Qualify a) => Qualify (Located a) where 
-  qualify env name l bs = fmap (qualify env name l bs) 
+instance (Qualify a) => Qualify (Located a) where
+  qualify env name l bs = fmap (qualify env name l bs)
 
 instance (Qualify a) => Qualify [a] where
   qualify env name l bs = fmap (qualify env name l bs)
 
-instance (Qualify a) => Qualify (Maybe a) where 
-  qualify env name l bs = fmap (qualify env name l bs) 
+instance (Qualify a) => Qualify (Maybe a) where
+  qualify env name l bs = fmap (qualify env name l bs)
 
-instance Qualify Body where 
-  qualify env name l bs (P   p) = P   (qualify env name l bs p) 
+instance Qualify Body where
+  qualify env name l bs (P   p) = P   (qualify env name l bs p)
   qualify env name l bs (E   e) = E   (qualify env name l bs e)
   qualify env name l bs (R x p) = R x (qualify env name l bs p)
 
-instance Qualify TyConInfo where 
+instance Qualify TyConInfo where
   qualify env name l bs tci = tci { sizeFunction = qualify env name l bs <$> sizeFunction tci }
 
-instance Qualify RTyCon where 
+instance Qualify RTyCon where
   qualify env name l bs rtc = rtc { rtc_info = qualify env name l bs (rtc_info rtc) }
 
-instance Qualify (Measure SpecType Ghc.DataCon) where 
+instance Qualify (Measure SpecType Ghc.DataCon) where
   qualify env name _ bs m = m -- FIXME substEnv env name bs $ 
-    { msName = qualify env name l bs     lname 
-    , msEqns = qualify env name l bs <$> msEqns m 
+    { msName = qualify env name l bs     lname
+    , msEqns = qualify env name l bs <$> msEqns m
     }
-    where 
+    where
       l      = F.loc  lname
       lname  = msName m
 
 
-instance Qualify (Def ty ctor) where 
-  qualify env name l bs d = d 
-    { body  = qualify env name l (bs ++ bs') (body d) } 
-    where 
+instance Qualify (Def ty ctor) where
+  qualify env name l bs d = d
+    { body  = qualify env name l (bs ++ bs') (body d) }
+    where
       bs'   = fst <$> binds d
 
-instance Qualify BareMeasure where 
-  qualify env name l bs m = m 
+instance Qualify BareMeasure where
+  qualify env name l bs m = m
     { msEqns = qualify env name l bs (msEqns m)
-    } 
+    }
 
-instance Qualify DataCtor where 
+instance Qualify DataCtor where
   qualify env name l bs c = c
-    { dcTheta  = qualify env name l bs (dcTheta  c) 
-    , dcFields = qualify env name l bs (dcFields c) 
+    { dcTheta  = qualify env name l bs (dcTheta  c)
+    , dcFields = qualify env name l bs (dcFields c)
     , dcResult = qualify env name l bs (dcResult c)
     }
- 
-instance Qualify DataDecl where 
-  qualify env name l bs d = d 
+
+instance Qualify DataDecl where
+  qualify env name l bs d = d
     { tycDCons  = qualify env name l bs (tycDCons  d)
-    , tycPropTy = qualify env name l bs (tycPropTy d) 
-    } 
+    , tycPropTy = qualify env name l bs (tycPropTy d)
+    }
 
-instance Qualify ModSpecs where 
-  qualify env name l bs = Misc.hashMapMapWithKey (\_ -> qualify env name l bs) 
+instance Qualify ModSpecs where
+  qualify env name l bs = Misc.hashMapMapWithKey (\_ -> qualify env name l bs)
 
-instance Qualify b => Qualify (a, b) where 
+instance Qualify b => Qualify (a, b) where
   qualify env name l bs (x, y) = (x, qualify env name l bs y)
 
-instance Qualify BareSpec where 
-  qualify = qualifyBareSpec 
+instance Qualify BareSpec where
+  qualify = qualifyBareSpec
 
-qualifyBareSpec :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> BareSpec -> BareSpec 
-qualifyBareSpec env name l bs sp = sp 
-  { measures   = qualify env name l bs (measures   sp) 
+qualifyBareSpec :: Env -> ModName -> F.SourcePos -> [F.Symbol] -> BareSpec -> BareSpec
+qualifyBareSpec env name l bs sp = sp
+  { measures   = qualify env name l bs (measures   sp)
   , asmSigs    = qualify env name l bs (asmSigs    sp)
   , sigs       = qualify env name l bs (sigs       sp)
   , localSigs  = qualify env name l bs (localSigs  sp)
@@ -400,8 +396,8 @@
   , dataDecls  = qualify env name l bs (dataDecls  sp)
   , newtyDecls = qualify env name l bs (newtyDecls sp)
   , ialiases   = [ (f x, f y) | (x, y) <- ialiases sp ]
-  } 
-  where f      = qualify env name l bs 
+  }
+  where f      = qualify env name l bs
 
 instance Qualify a => Qualify (RTAlias F.Symbol a) where
   qualify env name l bs rtAlias
@@ -411,40 +407,40 @@
              , rtBody  = qualify env name l bs (rtBody rtAlias)
              }
 
-instance Qualify F.Expr where 
-  qualify = substEnv 
+instance Qualify F.Expr where
+  qualify = substEnv
 
-instance Qualify RReft where 
+instance Qualify RReft where
   qualify = substEnv
 
-instance Qualify F.Qualifier where 
-  qualify env name _ bs q = q { F.qBody = qualify env name (F.qPos q) bs' (F.qBody q) } 
-    where 
+instance Qualify F.Qualifier where
+  qualify env name _ bs q = q { F.qBody = qualify env name (F.qPos q) bs' (F.qBody q) }
+    where
       bs'                 = bs ++ (F.qpSym <$> F.qParams q)
 
-substEnv :: (F.Subable a) => Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a 
-substEnv env name l bs = F.substa (qualifySymbol env name l bs) 
+substEnv :: (F.Subable a) => Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a
+substEnv env name l bs = F.substa (qualifySymbol env name l bs)
 
-instance Qualify SpecType where 
-  qualify x1 x2 x3 x4 x5 = emapReft (substFreeEnv x1 x2 x3) x4 x5            
+instance Qualify SpecType where
+  qualify x1 x2 x3 x4 x5 = emapReft (substFreeEnv x1 x2 x3) x4 x5
 
-instance Qualify BareType where 
-  qualify x1 x2 x3 x4 x5 = emapReft (substFreeEnv x1 x2 x3) x4 x5 
+instance Qualify BareType where
+  qualify x1 x2 x3 x4 x5 = emapReft (substFreeEnv x1 x2 x3) x4 x5
 
-substFreeEnv :: (F.Subable a) => Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a 
-substFreeEnv env name l bs = F.substf (F.EVar . qualifySymbol env name l bs) 
+substFreeEnv :: (F.Subable a) => Env -> ModName -> F.SourcePos -> [F.Symbol] -> a -> a
+substFreeEnv env name l bs = F.substf (F.EVar . qualifySymbol env name l bs)
 
 -------------------------------------------------------------------------------
 lookupGhcNamedVar :: (Ghc.NamedThing a, F.Symbolic a) => Env -> ModName -> a -> Maybe Ghc.Var
 -------------------------------------------------------------------------------
 lookupGhcNamedVar env name z = maybeResolveSym  env name "Var" lx
-  where 
+  where
     lx                       = GM.namedLocSymbol z
 
-lookupGhcVar :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.Var 
-lookupGhcVar env name kind lx = case resolveLocSym env name kind lx of 
-    Right v -> Mb.maybe (Right v) Right (lookupLocalVar env lx [v]) 
-    Left  e -> Mb.maybe (Left  e) Right (lookupLocalVar env lx []) 
+lookupGhcVar :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.Var
+lookupGhcVar env name kind lx = case resolveLocSym env name kind lx of
+    Right v -> Mb.maybe (Right v) Right (lookupLocalVar env lx [v])
+    Left  e -> Mb.maybe (Left  e) Right (lookupLocalVar env lx [])
 
   -- where
     -- err e   = Misc.errorP "error-lookupGhcVar" (F.showpp (e, F.loc lx, lx))
@@ -456,18 +452,18 @@
 
 lookupLocalVar :: Env -> LocSymbol -> [Ghc.Var] -> Maybe Ghc.Var
 lookupLocalVar env lx gvs = Misc.findNearest lxn kvs
-  where 
+  where
     _msg                  = "LOOKUP-LOCAL: " ++ F.showpp (F.val lx, lxn, kvs)
-    kvs                   = gs ++ M.lookupDefault [] x (reLocalVars env) 
+    kvs                   = gs ++ M.lookupDefault [] x (reLocalVars env)
     gs                    = [(F.unPos (F.srcLine v), v) | v <- gvs]
     lxn                   = F.unPos (F.srcLine lx)
     (_, x)                = unQualifySymbol (F.val lx)
 
-lookupGhcDataCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.DataCon 
+lookupGhcDataCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.DataCon
 lookupGhcDataCon = resolveLocSym -- strictResolveSym 
 
-lookupGhcTyCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.TyCon 
-lookupGhcTyCon env name k lx = myTracepp ("LOOKUP-TYCON: " ++ F.showpp (val lx)) 
+lookupGhcTyCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.TyCon
+lookupGhcTyCon env name k lx = myTracepp ("LOOKUP-TYCON: " ++ F.showpp (val lx))
                                $ {- strictResolveSym -} resolveLocSym env name k lx
 
 lookupGhcDnTyCon :: Env -> ModName -> String -> DataName -> Lookup (Maybe Ghc.TyCon)
@@ -475,78 +471,78 @@
 lookupGhcDnTyCon env name msg = failMaybe env name . lookupGhcDnTyConE env name msg
 
 lookupGhcDnTyConE :: Env -> ModName -> String -> DataName -> Lookup Ghc.TyCon
-lookupGhcDnTyConE env name msg (DnCon  s) 
+lookupGhcDnTyConE env name msg (DnCon  s)
   = lookupGhcDnCon env name msg s
-lookupGhcDnTyConE env name msg (DnName s) 
-  = case resolveLocSym env name msg s of 
-      Right r -> Right r 
-      Left  e -> case lookupGhcDnCon  env name msg s of 
-                   Right r -> Right r 
+lookupGhcDnTyConE env name msg (DnName s)
+  = case resolveLocSym env name msg s of
+      Right r -> Right r
+      Left  e -> case lookupGhcDnCon  env name msg s of
+                   Right r -> Right r
                    Left  _ -> Left  e
 
 
-lookupGhcDnCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.TyCon 
+lookupGhcDnCon :: Env -> ModName -> String -> LocSymbol -> Lookup Ghc.TyCon
 lookupGhcDnCon env name msg = fmap Ghc.dataConTyCon . resolveLocSym env name msg
 
 -------------------------------------------------------------------------------
 -- | Checking existence of names 
 -------------------------------------------------------------------------------
 knownGhcType :: Env ->  ModName -> LocBareType -> Bool
-knownGhcType env name (F.Loc l _ t) = 
-  case ofBareTypeE env name l Nothing t of 
-    Left e  -> myTracepp ("knownType: " ++ F.showpp (t, e)) $ False 
-    Right _ -> True 
+knownGhcType env name (F.Loc l _ t) =
+  case ofBareTypeE env name l Nothing t of
+    Left e  -> myTracepp ("knownType: " ++ F.showpp (t, e)) False
+    Right _ -> True
 
 
 
 _rTypeTyCons :: (Ord c) => RType c tv r -> [c]
-_rTypeTyCons        = Misc.sortNub . foldRType f []   
-  where 
-    f acc t@RApp {} = rt_tycon t : acc 
+_rTypeTyCons        = Misc.sortNub . foldRType f []
+  where
+    f acc t@RApp {} = rt_tycon t : acc
     f acc _         = acc
 
 -- Aargh. Silly that each of these is the SAME code, only difference is the type.
 
-knownGhcVar :: Env -> ModName -> LocSymbol -> Bool 
-knownGhcVar env name lx = Mb.isJust v 
-  where 
+knownGhcVar :: Env -> ModName -> LocSymbol -> Bool
+knownGhcVar env name lx = Mb.isJust v
+  where
     v :: Maybe Ghc.Var -- This annotation is crucial
-    v = myTracepp ("knownGhcVar " ++ F.showpp lx) 
-      $ maybeResolveSym env name "known-var" lx 
+    v = myTracepp ("knownGhcVar " ++ F.showpp lx)
+      $ maybeResolveSym env name "known-var" lx
 
-knownGhcTyCon :: Env -> ModName -> LocSymbol -> Bool 
-knownGhcTyCon env name lx = myTracepp  msg $ Mb.isJust v 
-  where 
+knownGhcTyCon :: Env -> ModName -> LocSymbol -> Bool
+knownGhcTyCon env name lx = myTracepp  msg $ Mb.isJust v
+  where
     msg = "knownGhcTyCon: "  ++ F.showpp lx
     v :: Maybe Ghc.TyCon -- This annotation is crucial
-    v = maybeResolveSym env name "known-tycon" lx 
+    v = maybeResolveSym env name "known-tycon" lx
 
-knownGhcDataCon :: Env -> ModName -> LocSymbol -> Bool 
-knownGhcDataCon env name lx = Mb.isJust v 
-  where 
+knownGhcDataCon :: Env -> ModName -> LocSymbol -> Bool
+knownGhcDataCon env name lx = Mb.isJust v
+  where
     v :: Maybe Ghc.DataCon -- This annotation is crucial
-    v = myTracepp ("knownGhcDataCon" ++ F.showpp lx) 
-      $ maybeResolveSym env name "known-datacon" lx 
+    v = myTracepp ("knownGhcDataCon" ++ F.showpp lx)
+      $ maybeResolveSym env name "known-datacon" lx
 
 -------------------------------------------------------------------------------
 -- | Using the environment 
 -------------------------------------------------------------------------------
-class ResolveSym a where 
+class ResolveSym a where
   resolveLocSym :: Env -> ModName -> String -> LocSymbol -> Lookup a
 
-instance ResolveSym Ghc.Var where 
-  resolveLocSym = resolveWith "variable" $ \case 
-                    Ghc.AnId x -> Just x 
+instance ResolveSym Ghc.Var where
+  resolveLocSym = resolveWith "variable" $ \case
+                    Ghc.AnId x -> Just x
                     _          -> Nothing
 
-instance ResolveSym Ghc.TyCon where 
-  resolveLocSym = resolveWith "type constructor" $ \case 
+instance ResolveSym Ghc.TyCon where
+  resolveLocSym = resolveWith "type constructor" $ \case
                     Ghc.ATyCon x -> Just x
                     _            -> Nothing
 
-instance ResolveSym Ghc.DataCon where 
-  resolveLocSym = resolveWith "data constructor" $ \case 
-                    Ghc.AConLike (Ghc.RealDataCon x) -> Just x 
+instance ResolveSym Ghc.DataCon where
+  resolveLocSym = resolveWith "data constructor" $ \case
+                    Ghc.AConLike (Ghc.RealDataCon x) -> Just x
                     _                                -> Nothing
 
 
@@ -611,26 +607,26 @@
 
 
 
-resolveWith :: (PPrint a) => PJ.Doc -> (Ghc.TyThing -> Maybe a) -> Env -> ModName -> String -> LocSymbol 
-            -> Lookup a 
+resolveWith :: (PPrint a) => PJ.Doc -> (Ghc.TyThing -> Maybe a) -> Env -> ModName -> String -> LocSymbol
+            -> Lookup a
 resolveWith kind f env name str lx =
   -- case Mb.mapMaybe f things of 
   case rankedThings f things of
     []  -> Left [errResolve kind str lx]
-    [x] -> Right x 
+    [x] -> Right x
     xs  -> Left [ErrDupNames sp (pprint (F.val lx)) (pprint <$> xs)]
   where
     _xSym   = F.val lx
     sp      = GM.fSrcSpanSrcSpan (F.srcSpan lx)
-    things  = myTracepp msg $ lookupTyThing env name lx 
+    things  = myTracepp msg $ lookupTyThing env name lx
     msg     = "resolveWith: " ++ str ++ " " ++ F.showpp (val lx)
 
 
 rankedThings :: (Misc.EqHash k) => (a -> Maybe b) -> [(k, a)] -> [b]
-rankedThings f ias = case Misc.sortOn fst (Misc.groupList ibs) of 
+rankedThings f ias = case Misc.sortOn fst (Misc.groupList ibs) of
                        (_,ts):_ -> ts
                        []       -> []
-  where 
+  where
     ibs            = Mb.mapMaybe (\(k, x) -> (k,) <$> f x) ias
 
 -------------------------------------------------------------------------------
@@ -642,19 +638,19 @@
 -------------------------------------------------------------------------------
 lookupTyThing :: Env -> ModName -> LocSymbol -> [((Int, F.Symbol), Ghc.TyThing)]
 -------------------------------------------------------------------------------
-lookupTyThing env name lsym = [ (k, t) | (k, ts) <- ordMatches, t <- ts] 
-                              
-  where 
+lookupTyThing env mdname lsym = [ (k, t) | (k, ts) <- ordMatches, t <- ts]
+
+  where
     ordMatches             = Misc.sortOn fst (Misc.groupList matches)
     matches                = myTracepp ("matches-" ++ msg)
                              [ ((k, m), t) | (m, t) <- lookupThings env x
-                                           , k      <- myTracepp msg $ mm nameSym m mods ]
-    msg                    = "lookupTyThing: " ++ F.showpp (lsym, x, mods)
-    (x, mods)              = symbolModules env (F.val lsym)
-    nameSym                = F.symbol name
-    allowExt               = allowExtResolution env lsym 
-    mm name m mods         = myTracepp ("matchMod: " ++ F.showpp (lsym, name, m, mods, allowExt)) $ 
-                               matchMod env name m allowExt mods 
+                                           , k      <- myTracepp msg $ mm nameSym m mds ]
+    msg                    = "lookupTyThing: " ++ F.showpp (lsym, x, mds)
+    (x, mds)               = symbolModules env (F.val lsym)
+    nameSym                = F.symbol mdname
+    allowExt               = allowExtResolution env lsym
+    mm name m mods         = myTracepp ("matchMod: " ++ F.showpp (lsym, name, m, mods, allowExt)) $
+                               matchMod env name m allowExt mods
 
 -- | [NOTE:External-Resolution] @allowExtResolution@ determines whether a @LocSymbol@ 
 --   can be resolved by a @TyThing@ that is _outside_ the module corresponding to @LocSymbol@. 
@@ -664,37 +660,37 @@
 --   should already be FULLY-qualified to to their actual definition (e.g. Data.Set.Internal.Set) 
 --   and so we should DISALLOW external-resolution in such cases.
 
-allowExtResolution :: Env -> LocSymbol -> Bool 
-allowExtResolution env lx = case fileMb of 
-  Nothing   -> True 
-  Just f    -> myTracepp ("allowExt: " ++ show (f, tgtFile)) 
-                 $ f == tgtFile || Misc.isIncludeFile incDir f || F.isExtFile F.Spec f 
-  where 
+allowExtResolution :: Env -> LocSymbol -> Bool
+allowExtResolution env lx = case fileMb of
+  Nothing   -> True
+  Just f    -> myTracepp ("allowExt: " ++ show (f, tgtFile))
+                 $ f == tgtFile || Misc.isIncludeFile incDir f || F.isExtFile F.Spec f
+  where
     tgtFile = _giTarget (reSrc env)
     incDir  = _giIncDir (reSrc env)
-    fileMb  = Errors.srcSpanFileMb (GM.fSrcSpan lx) 
+    fileMb  = Errors.srcSpanFileMb (GM.fSrcSpan lx)
 
-lookupThings :: Env -> F.Symbol -> [(F.Symbol, Ghc.TyThing)] 
-lookupThings env x = myTracepp ("lookupThings: " ++ F.showpp x) 
+lookupThings :: Env -> F.Symbol -> [(F.Symbol, Ghc.TyThing)]
+lookupThings env x = myTracepp ("lookupThings: " ++ F.showpp x)
                    $ Misc.fromFirstMaybes [] (get <$> [x, GM.stripParensSym x])
-  where 
+  where
     get z          = M.lookup z (_reTyThings env)
 
 matchMod :: Env -> F.Symbol -> F.Symbol -> Bool -> Maybe [F.Symbol] -> [Int]
-matchMod env tgtName defName allowExt = go 
-  where 
+matchMod env tgtName defName allowExt = go
+  where
     go Nothing               -- Score UNQUALIFIED names 
      | defName == tgtName = [0]                       -- prioritize names defined in *this* module 
      | otherwise          = [matchImp env defName 1]  -- prioritize directly imported modules over 
                                                       -- names coming from elsewhere, with a 
 
     go (Just ms)             -- Score QUALIFIED names
-     |  isEmptySymbol defName 
+     |  isEmptySymbol defName
      && ms == [tgtName]   = [0]                       -- local variable, see tests-names-pos-local00.hs
      | ms == [defName]    = [1]
      | allowExt && isExt  = [matchImp env defName 2]  -- to allow matching re-exported names e.g. Data.Set.union for Data.Set.Internal.union
      | otherwise          = []
-     where 
+     where
        isExt              = any (`isParentModuleOf` defName) ms
 
 -- | Returns 'True' if the 'Symbol' given as a first argument represents a parent module for the second.
@@ -721,11 +717,11 @@
 
 
 symbolModules :: Env -> F.Symbol -> (F.Symbol, Maybe [F.Symbol])
-symbolModules env s = (x, glerb <$> modMb) 
-  where 
-    (modMb, x)      = unQualifySymbol s 
-    glerb m         = M.lookupDefault [m] m qImps 
-    qImps           = qiNames (reQualImps env)  
+symbolModules env s = (x, glerb <$> modMb)
+  where
+    (modMb, x)      = unQualifySymbol s
+    glerb m         = M.lookupDefault [m] m qImps
+    qImps           = qiNames (reQualImps env)
 
 -- | @matchImp@ lets us prioritize @TyThing@ defined in directly imported modules over 
 --   those defined elsewhere. Specifically, in decreasing order of priority we have 
@@ -733,32 +729,32 @@
 --   * DIRECTLY     imported WITHOUT qualification 
 --   * TRANSITIVELY imported (e.g. were re-exported by SOME imported module)
 --   * QUALIFIED    imported (so qualify the symbol to get this result!) 
- 
-matchImp :: Env -> F.Symbol -> Int -> Int 
-matchImp env defName i   
-  | isUnqualImport = i      
-  | isQualImport   = i + 2  
-  | otherwise      = i + 1  
+
+matchImp :: Env -> F.Symbol -> Int -> Int
+matchImp env defName i
+  | isUnqualImport = i
+  | isQualImport   = i + 2
+  | otherwise      = i + 1
   where
-    isUnqualImport = S.member defName (reAllImps env) && not isQualImport 
+    isUnqualImport = S.member defName (reAllImps env) && not isQualImport
     isQualImport   = S.member defName (qiModules (reQualImps env))
 
 
 -- | `unQualifySymbol name sym` splits `sym` into a pair `(mod, rest)` where 
 --   `mod` is the name of the module, derived from `sym` if qualified.
 unQualifySymbol :: F.Symbol -> (Maybe F.Symbol, F.Symbol)
-unQualifySymbol sym 
-  | GM.isQualifiedSym sym = Misc.mapFst Just (splitModuleNameExact sym) 
-  | otherwise             = (Nothing, sym) 
+unQualifySymbol sym
+  | GM.isQualifiedSym sym = Misc.mapFst Just (splitModuleNameExact sym)
+  | otherwise             = (Nothing, sym)
 
 splitModuleNameExact :: F.Symbol -> (F.Symbol, F.Symbol)
-splitModuleNameExact x' = myTracepp ("splitModuleNameExact for " ++ F.showpp x) 
+splitModuleNameExact x' = myTracepp ("splitModuleNameExact for " ++ F.showpp x)
                           (GM.takeModuleNames x, GM.dropModuleNames x)
   where
-    x = GM.stripParensSym x' 
+    x = GM.stripParensSym x'
 
-errResolve :: PJ.Doc -> String -> LocSymbol -> Error 
-errResolve k msg lx = ErrResolve (GM.fSrcSpan lx) k (F.pprint (F.val lx)) (PJ.text msg) 
+errResolve :: PJ.Doc -> String -> LocSymbol -> Error
+errResolve k msg lx = ErrResolve (GM.fSrcSpan lx) k (F.pprint (F.val lx)) (PJ.text msg)
 
 -- -- | @strictResolve@ wraps the plain @resolve@ to throw an error 
 -- --   if the name being searched for is unknown.
@@ -769,54 +765,54 @@
 
 -- | @maybeResolve@ wraps the plain @resolve@ to return @Nothing@ 
 --   if the name being searched for is unknown.
-maybeResolveSym :: (ResolveSym a) => Env -> ModName -> String -> LocSymbol -> Maybe a 
-maybeResolveSym env name kind x = case resolveLocSym env name kind x of 
-  Left  _   -> Nothing 
-  Right val -> Just val 
-  
+maybeResolveSym :: (ResolveSym a) => Env -> ModName -> String -> LocSymbol -> Maybe a
+maybeResolveSym env name kind x = case resolveLocSym env name kind x of
+  Left  _   -> Nothing
+  Right val -> Just val
+
 -------------------------------------------------------------------------------
 -- | @ofBareType@ and @ofBareTypeE@ should be the _only_ @SpecType@ constructors
 -------------------------------------------------------------------------------
-ofBareType :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> SpecType 
-ofBareType env name l ps t = either fail id (ofBareTypeE env name l ps t)
-  where 
-    fail                   = Ex.throw 
+ofBareType :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> SpecType
+ofBareType env name l ps t = either fail' id (ofBareTypeE env name l ps t)
+  where
+    fail'                  = Ex.throw
     -- fail                   = Misc.errorP "error-ofBareType" . F.showpp 
 
-ofBareTypeE :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> Lookup SpecType 
-ofBareTypeE env name l ps t = ofBRType env name (resolveReft env name l ps t) l t 
+ofBareTypeE :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> Lookup SpecType
+ofBareTypeE env name l ps t = ofBRType env name (resolveReft env name l ps t) l t
 
-resolveReft :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> [F.Symbol] -> RReft -> RReft 
+resolveReft :: Env -> ModName -> F.SourcePos -> Maybe [PVar BSort] -> BareType -> [F.Symbol] -> RReft -> RReft
 resolveReft env name l ps t bs
-        = qualify env name l bs 
+        = qualify env name l bs
         . txParam l RT.subvUReft (RT.uPVar <$> πs) t
         . fixReftTyVars t       -- same as fixCoercions 
-  where 
-    πs  = Mb.fromMaybe tπs ps  
-    tπs = ty_preds (toRTypeRep t) 
-     
-fixReftTyVars :: BareType -> RReft -> RReft 
-fixReftTyVars bt  = coSubRReft coSub 
   where
+    πs  = Mb.fromMaybe tπs ps
+    tπs = ty_preds (toRTypeRep t)
+
+fixReftTyVars :: BareType -> RReft -> RReft
+fixReftTyVars bt  = coSubRReft coSub
+  where
     coSub         = M.fromList [ (F.symbol a, F.FObj (specTvSymbol a)) | a <- tvs ]
     tvs           = RT.allTyVars bt
     specTvSymbol  = F.symbol . RT.bareRTyVar
 
-coSubRReft :: F.CoSub -> RReft -> RReft 
-coSubRReft su r = r { ur_reft = coSubReft su (ur_reft r) } 
+coSubRReft :: F.CoSub -> RReft -> RReft
+coSubRReft su r = r { ur_reft = coSubReft su (ur_reft r) }
 
-coSubReft :: F.CoSub -> F.Reft -> F.Reft 
+coSubReft :: F.CoSub -> F.Reft -> F.Reft
 coSubReft su (F.Reft (x, e)) = F.Reft (x, F.applyCoSub su e)
 
 
-ofBSort :: Env -> ModName -> F.SourcePos -> BSort -> RSort 
+ofBSort :: Env -> ModName -> F.SourcePos -> BSort -> RSort
 ofBSort env name l t = either (Misc.errorP "error-ofBSort" . F.showpp) id (ofBSortE env name l t)
 
-ofBSortE :: Env -> ModName -> F.SourcePos -> BSort -> Lookup RSort 
-ofBSortE env name l t = ofBRType env name (const id) l t 
-  
+ofBSortE :: Env -> ModName -> F.SourcePos -> BSort -> Lookup RSort
+ofBSortE env name l t = ofBRType env name (const id) l t
+
 ofBPVar :: Env -> ModName -> F.SourcePos -> BPVar -> RPVar
-ofBPVar env name l = fmap (ofBSort env name l) 
+ofBPVar env name l = fmap (ofBSort env name l)
 
 --------------------------------------------------------------------------------
 txParam :: F.SourcePos -> ((UsedPVar -> UsedPVar) -> t) -> [UsedPVar] -> RType c tv r -> t
@@ -829,7 +825,7 @@
           | otherwise            = pargs π'
     π'    = Mb.fromMaybe err $ M.lookup (pname π) m
     err   = uError $ ErrUnbPred sp (pprint π)
-    sp    = GM.sourcePosSrcSpan l 
+    sp    = GM.sourcePosSrcSpan l
 
 predMap :: [UsedPVar] -> RType c tv r -> M.HashMap F.Symbol UsedPVar
 predMap πs t = M.fromList [(pname π, π) | π <- πs ++ rtypePredBinds t]
@@ -845,32 +841,32 @@
                     , SubsTy RTyVar (RType RTyCon RTyVar ()) r
                     , F.Reftable (RTProp RTyCon RTyVar r))
 
-ofBRType :: (Expandable r) => Env -> ModName -> ([F.Symbol] -> r -> r) -> F.SourcePos -> BRType r 
+ofBRType :: (Expandable r) => Env -> ModName -> ([F.Symbol] -> r -> r) -> F.SourcePos -> BRType r
          -> Lookup (RRType r)
-ofBRType env name f l t  = go [] t 
+ofBRType env name f l = go []
   where
-    goReft bs r             = return (f bs r) 
+    goReft bs r             = return (f bs r)
     goRImpF bs x i t1 t2 r  = RImpF x i <$> (rebind x <$> go bs t1) <*> go (x:bs) t2 <*> goReft bs r
     goRFun  bs x i t1 t2 r  = RFun  x i{permitTC = Just (typeclass (getConfig env))} <$> (rebind x <$> go bs t1) <*> go (x:bs) t2 <*> goReft bs r
     rebind x t              = F.subst1 t (x, F.EVar $ rTypeValueVar t)
     go bs (RAppTy t1 t2 r)  = RAppTy <$> go bs t1 <*> go bs t2 <*> goReft bs r
-    go bs (RApp tc ts rs r) = goRApp bs tc ts rs r 
-    go bs (RImpF x i t1 t2 r) = goRImpF bs x i t1 t2 r 
-    go bs (RFun  x i t1 t2 r) = goRFun  bs x i t1 t2 r 
+    go bs (RApp tc ts rs r) = goRApp bs tc ts rs r
+    go bs (RImpF x i t1 t2 r) = goRImpF bs x i t1 t2 r
+    go bs (RFun  x i t1 t2 r) = goRFun  bs x i t1 t2 r
     go bs (RVar a r)        = RVar (RT.bareRTyVar a) <$> goReft bs r
-    go bs (RAllT a t r)     = RAllT a' <$> go bs t <*> goReft bs r 
-      where a'              = dropTyVarInfo (mapTyVarValue RT.bareRTyVar a) 
-    go bs (RAllP a t)       = RAllP a' <$> go bs t 
-      where a'              = ofBPVar env name l a 
+    go bs (RAllT a t r)     = RAllT a' <$> go bs t <*> goReft bs r
+      where a'              = dropTyVarInfo (mapTyVarValue RT.bareRTyVar a)
+    go bs (RAllP a t)       = RAllP a' <$> go bs t
+      where a'              = ofBPVar env name l a
     go bs (RAllE x t1 t2)   = RAllE x  <$> go bs t1    <*> go bs t2
     go bs (REx x t1 t2)     = REx   x  <$> go bs t1    <*> go (x:bs) t2
     go bs (RRTy xts r o t)  = RRTy  <$> xts' <*> goReft bs r <*> pure o <*> go bs t
       where xts'            = mapM (Misc.mapSndM (go bs)) xts
     go bs (RHole r)         = RHole    <$> goReft bs r
-    go bs (RExprArg le)     = return    $ RExprArg (qualify env name l bs le) 
+    go bs (RExprArg le)     = return    $ RExprArg (qualify env name l bs le)
     goRef bs (RProp ss (RHole r)) = rPropP <$> mapM goSyms ss <*> goReft bs r
     goRef bs (RProp ss t)         = RProp  <$> mapM goSyms ss <*> go bs t
-    goSyms (x, t)                 = (x,) <$> ofBSortE env name l t 
+    goSyms (x, t)                 = (x,) <$> ofBSortE env name l t
     goRApp bs tc ts rs r          = bareTCApp <$> goReft bs r <*> lc' <*> mapM (goRef bs) rs <*> mapM (go bs) ts
       where
         lc'                    = F.atLoc lc <$> matchTyCon env name lc (length ts)
@@ -899,23 +895,23 @@
 matchTyCon :: Env -> ModName -> LocSymbol -> Int -> Lookup Ghc.TyCon
 matchTyCon env name lc@(Loc _ _ c) arity
   | isList c && arity == 1  = Right Ghc.listTyCon
-  | isTuple c               = Right tuplTc 
-  | otherwise               = resolveLocSym env name msg lc 
-  where 
+  | isTuple c               = Right tuplTc
+  | otherwise               = resolveLocSym env name msg lc
+  where
     msg                     = "matchTyCon: " ++ F.showpp c
-    tuplTc                  = Ghc.tupleTyCon Ghc.Boxed arity 
+    tuplTc                  = Ghc.tupleTyCon Ghc.Boxed arity
 
 
-bareTCApp :: (Expandable r) 
+bareTCApp :: (Expandable r)
           => r
           -> Located Ghc.TyCon
           -> [RTProp RTyCon RTyVar r]
           -> [RType RTyCon RTyVar r]
-          -> (RType RTyCon RTyVar r)
+          -> RType RTyCon RTyVar r
 bareTCApp r (Loc l _ c) rs ts | Just rhs <- Ghc.synTyConRhs_maybe c
-  = if (GM.kindTCArity c < length ts) 
+  = if GM.kindTCArity c < length ts
       then Ex.throw err -- error (F.showpp err)
-      else tyApp (RT.subsTyVars_meet su $ RT.ofType rhs) (drop nts ts) rs r
+      else tyApp (RT.subsTyVarsMeet su $ RT.ofType rhs) (drop nts ts) rs r
     where
        tvs = [ v | (v, b) <- zip (GM.tyConTyVarsDef c) (Ghc.tyConBinders c), GM.isAnonBinder b]
        su  = zipWith (\a t -> (RT.rTyVar a, toRSort t, t)) tvs ts
@@ -924,8 +920,8 @@
        err :: Error
        err = ErrAliasApp (GM.sourcePosSrcSpan l) (pprint c) (Ghc.getSrcSpan c)
                          (PJ.hcat [ PJ.text "Expects"
-                                  , pprint (GM.realTcArity c) 
-                                  , PJ.text "arguments, but is given" 
+                                  , pprint (GM.realTcArity c)
+                                  , PJ.text "arguments, but is given"
                                   , pprint (length ts) ] )
 -- TODO expandTypeSynonyms here to
 bareTCApp r (Loc _ _ c) rs ts | Ghc.isFamilyTyCon c && isTrivial t
@@ -936,11 +932,11 @@
   = RT.rApp c ts rs r
 
 
-tyApp :: F.Reftable r => RType c tv r -> [RType c tv r] -> [RTProp c tv r] -> r 
+tyApp :: F.Reftable r => RType c tv r -> [RType c tv r] -> [RTProp c tv r] -> r
       -> RType c tv r
 tyApp (RApp c ts rs r) ts' rs' r' = RApp c (ts ++ ts') (rs ++ rs') (r `F.meet` r')
 tyApp t                []  []  r  = t `RT.strengthen` r
-tyApp _                 _  _   _  = panic Nothing $ "Bare.Type.tyApp on invalid inputs"
+tyApp _                 _  _   _  = panic Nothing "Bare.Type.tyApp on invalid inputs"
 
 expandRTypeSynonyms :: (Expandable r) => RRType r -> RRType r
 expandRTypeSynonyms = RT.ofType . Ghc.expandTypeSynonyms . RT.toType False
@@ -968,28 +964,28 @@
 txRefSort :: TyConMap -> F.TCEmb Ghc.TyCon -> LocSpecType -> LocSpecType
 txRefSort tyi tce t = F.atLoc t $ mapBot (addSymSort (GM.fSrcSpan t) tce tyi) (val t)
 
-addSymSort :: Ghc.SrcSpan -> F.TCEmb Ghc.TyCon -> TyConMap -> SpecType -> SpecType 
-addSymSort sp tce tyi (RApp rc@(RTyCon {}) ts rs r)
-  = RApp rc ts (zipWith3 (addSymSortRef sp rc) pvs rargs [1..]) r'
+addSymSort :: Ghc.SrcSpan -> F.TCEmb Ghc.TyCon -> TyConMap -> SpecType -> SpecType
+addSymSort sp tce tyi (RApp rc@RTyCon{} ts rs rr)
+  = RApp rc ts (zipWith3 (addSymSortRef sp rc) pvs rargs [1..]) r2
   where
     (_, pvs)           = RT.appRTyCon tce tyi rc ts
     -- pvs             = rTyConPVs rc'
     (rargs, rrest)     = splitAt (length pvs) rs
-    r'                 = L.foldl' go r rrest
+    r2                 = L.foldl' go rr rrest
     go r (RProp _ (RHole r')) = r' `F.meet` r
     go r (RProp  _ t' )       = let r' = Mb.fromMaybe mempty (stripRTypeBase t') in r `F.meet` r'
 
 addSymSort _ _ _ t
   = t
 
-addSymSortRef :: (PPrint s) => Ghc.SrcSpan -> s -> RPVar -> SpecProp -> Int -> SpecProp 
+addSymSortRef :: (PPrint s) => Ghc.SrcSpan -> s -> RPVar -> SpecProp -> Int -> SpecProp
 addSymSortRef sp rc p r i
   | isPropPV p
   = addSymSortRef' sp rc i p r
   | otherwise
   = panic Nothing "addSymSortRef: malformed ref application"
-              
-addSymSortRef' :: (PPrint s) => Ghc.SrcSpan -> s -> Int -> RPVar -> SpecProp -> SpecProp 
+
+addSymSortRef' :: (PPrint s) => Ghc.SrcSpan -> s -> Int -> RPVar -> SpecProp -> SpecProp
 addSymSortRef' _ _ _ p (RProp s (RVar v r)) | isDummy v
   = RProp xs t
     where
@@ -1016,7 +1012,7 @@
       xs = spliceArgs "addSymSortRef 2" s p
 
 spliceArgs :: String  -> [(F.Symbol, b)] -> PVar t -> [(F.Symbol, t)]
-spliceArgs msg s p = go (fst <$> s) (pargs p)
+spliceArgs msg syms p = go (fst <$> syms) (pargs p)
   where
     go []     []           = []
     go []     ((s,x,_):as) = (x, s):go [] as
@@ -1030,43 +1026,43 @@
 --   source variables that are visible at that at non-top-level scope. 
 --   e.g. tests-names-pos-local02.hs  
 ---------------------------------------------------------------------------------
-resolveLocalBinds :: Env -> [(Ghc.Var, LocBareType, Maybe [Located F.Expr])] 
+resolveLocalBinds :: Env -> [(Ghc.Var, LocBareType, Maybe [Located F.Expr])]
                   -> [(Ghc.Var, LocBareType, Maybe [Located F.Expr])]
 ---------------------------------------------------------------------------------
 resolveLocalBinds env xtes = [ (x,t,es) | (x, (t, es)) <- topTs ++ replace locTs ]
-  where 
-    (locTs, topTs)         = partitionLocalBinds [ (x, (t, es)) | (x, t, es) <- xtes] 
-    replace                = M.toList . replaceSigs . M.fromList 
-    replaceSigs sigm       = coreVisitor replaceVisitor M.empty sigm cbs 
+  where
+    (locTs, topTs)         = partitionLocalBinds [ (x, (t, es)) | (x, t, es) <- xtes]
+    replace                = M.toList . replaceSigs . M.fromList
+    replaceSigs sigm       = coreVisitor replaceVisitor M.empty sigm cbs
     cbs                    = _giCbs (reSrc env)
 
-replaceVisitor :: CoreVisitor SymMap SigMap 
-replaceVisitor = CoreVisitor 
+replaceVisitor :: CoreVisitor SymMap SigMap
+replaceVisitor = CoreVisitor
   { envF  = addBind
   , bindF = updSigMap
-  , exprF = \_ m _ -> m 
+  , exprF = \_ m _ -> m
   }
 
-addBind :: SymMap -> Ghc.Var -> SymMap 
-addBind env v = case localKey v of 
-  Just vx -> M.insert vx (F.symbol v) env 
+addBind :: SymMap -> Ghc.Var -> SymMap
+addBind env v = case localKey v of
+  Just vx -> M.insert vx (F.symbol v) env
   Nothing -> env
-    
-updSigMap :: SymMap -> SigMap -> Ghc.Var -> SigMap 
-updSigMap env m v = case M.lookup v m of 
-  Nothing  -> m 
+
+updSigMap :: SymMap -> SigMap -> Ghc.Var -> SigMap
+updSigMap env m v = case M.lookup v m of
+  Nothing  -> m
   Just tes -> M.insert v (myTracepp ("UPD-LOCAL-SIG " ++ GM.showPpr v) $ renameLocalSig env tes) m
 
-renameLocalSig :: SymMap -> (LocBareType, Maybe [Located F.Expr]) 
-               -> (LocBareType, Maybe [Located F.Expr])  
-renameLocalSig env (t, es) = (F.substf tSub t, F.substf esSub es) 
-  where 
-    tSub                   = F.EVar . qualifySymMap env 
+renameLocalSig :: SymMap -> (LocBareType, Maybe [Located F.Expr])
+               -> (LocBareType, Maybe [Located F.Expr])
+renameLocalSig env (t, es) = (F.substf tSub t, F.substf esSub es)
+  where
+    tSub                   = F.EVar . qualifySymMap env
     esSub                  = tSub `F.substfExcept` xs
-    xs                     = ty_binds (toRTypeRep (F.val t)) 
+    xs                     = ty_binds (toRTypeRep (F.val t))
 
-qualifySymMap :: SymMap -> F.Symbol -> F.Symbol 
-qualifySymMap env x = M.lookupDefault x x env 
+qualifySymMap :: SymMap -> F.Symbol -> F.Symbol
+qualifySymMap env x = M.lookupDefault x x env
 
 type SigMap = M.HashMap Ghc.Var  (LocBareType, Maybe [Located F.Expr])
 type SymMap = M.HashMap F.Symbol F.Symbol
diff --git a/src/Language/Haskell/Liquid/Bare/Slice.hs b/src/Language/Haskell/Liquid/Bare/Slice.hs
--- a/src/Language/Haskell/Liquid/Bare/Slice.hs
+++ b/src/Language/Haskell/Liquid/Bare/Slice.hs
@@ -1,14 +1,6 @@
-{-# LANGUAGE DerivingVia                #-}
-{-# LANGUAGE DerivingStrategies         #-}
-{-# LANGUAGE DeriveGeneric              #-}
-{-# LANGUAGE TypeSynonymInstances       #-}
 {-# LANGUAGE FlexibleInstances          #-}
 {-# LANGUAGE FlexibleContexts           #-}
-{-# LANGUAGE DeriveGeneric              #-}
-{-# LANGUAGE DerivingStrategies         #-}
 {-# LANGUAGE DerivingVia                #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE RecordWildCards            #-}
 
 
 -- | This module has a function that computes the "slice" i.e. subset of the `Ms.BareSpec` that 
diff --git a/src/Language/Haskell/Liquid/Bare/ToBare.hs b/src/Language/Haskell/Liquid/Bare/ToBare.hs
--- a/src/Language/Haskell/Liquid/Bare/ToBare.hs
+++ b/src/Language/Haskell/Liquid/Bare/ToBare.hs
@@ -14,8 +14,8 @@
 
 import           Language.Fixpoint.Misc (mapSnd)
 import qualified Language.Fixpoint.Types as F
-import           Language.Haskell.Liquid.GHC.Misc
-import           Language.Haskell.Liquid.GHC.API
+import           Liquid.GHC.Misc
+import           Liquid.GHC.API
 import           Language.Haskell.Liquid.Types
 -- import           Language.Haskell.Liquid.Measure
 -- import           Language.Haskell.Liquid.Types.RefType
@@ -37,7 +37,7 @@
 measureToBare = bimap (fmap specToBare) dataConToBare
 
 dataConToBare :: DataCon -> LocSymbol
-dataConToBare d = (dropModuleNames . F.symbol) <$> locNamedThing d
+dataConToBare d = dropModuleNames . F.symbol <$> locNamedThing d
   where
     _msg  = "dataConToBare dc = " ++ show d ++ " v = " ++ show v ++ " vx = " ++ show vx
     v     = dataConWorkId d
@@ -83,7 +83,7 @@
 txRTV cF vF (RTVar α z) = RTVar (vF α) (txRType cF vF <$> z)
 
 txPV :: (c1 -> c2) -> (tv1 -> tv2) -> PVU c1 tv1 -> PVU c2 tv2
-txPV cF vF (PV x k y txes) = PV x k' y txes'
+txPV cF vF (PV sym k y txes) = PV sym k' y txes'
   where
     txes'                  = [ (tx t, x, e) | (t, x, e) <- txes]
     k'                     = tx <$> k
diff --git a/src/Language/Haskell/Liquid/Bare/Typeclass.hs b/src/Language/Haskell/Liquid/Bare/Typeclass.hs
--- a/src/Language/Haskell/Liquid/Bare/Typeclass.hs
+++ b/src/Language/Haskell/Liquid/Bare/Typeclass.hs
@@ -1,5 +1,6 @@
 {-# LANGUAGE OverloadedStrings         #-}
 {-# LANGUAGE FlexibleContexts          #-}
+
 module Language.Haskell.Liquid.Bare.Typeclass
   ( compileClasses
   , elaborateClassDcp
@@ -19,9 +20,9 @@
 import qualified Language.Fixpoint.Misc        as Misc
 import           Optics
 import           Language.Haskell.Liquid.Bare.Elaborate
-import qualified Language.Haskell.Liquid.GHC.Misc
+import qualified Liquid.GHC.Misc
                                                as GM
-import qualified Language.Haskell.Liquid.GHC.API
+import qualified Liquid.GHC.API
                                                as Ghc
 import qualified Language.Haskell.Liquid.Misc  as Misc
 import           Language.Haskell.Liquid.Types
@@ -45,7 +46,7 @@
   -> [(ModName, Ms.BareSpec)]
   -> (Ms.BareSpec, [(Ghc.ClsInst, [Ghc.Var])])
 compileClasses src env (name, spec) rest =
-  (spec { sigs = sigs' } <> clsSpec, instmethods)
+  (spec { sigs = sigsNew } <> clsSpec, instmethods)
  where
   clsSpec = mempty
     { dataDecls = clsDecls
@@ -62,13 +63,13 @@
     }
   clsDecls                = makeClassDataDecl (M.toList refinedMethods)
       -- class methods
-  (refinedMethods, sigs') = foldr grabClassSig (mempty, mempty) (sigs spec)
+  (refinedMethods, sigsNew) = foldr grabClassSig (mempty, mempty) (sigs spec)
   grabClassSig
     :: (F.LocSymbol, ty)
     -> (M.HashMap Ghc.Class [(Ghc.Id, ty)], [(F.LocSymbol, ty)])
     -> (M.HashMap Ghc.Class [(Ghc.Id, ty)], [(F.LocSymbol, ty)])
-  grabClassSig sig@(lsym, ref) (refs, sigs') = case clsOp of
-    Nothing         -> (refs, sig : sigs')
+  grabClassSig sigPair@(lsym, ref) (refs, sigs') = case clsOp of
+    Nothing         -> (refs, sigPair : sigs')
     Just (cls, sig) -> (M.alter (merge sig) cls refs, sigs')
    where
     clsOp = do
@@ -231,19 +232,19 @@
     t
   -- YL: is this redundant if we already have strengthenClassSel?
   strengthenTy :: F.Symbol -> SpecType -> SpecType
-  strengthenTy x t = mkUnivs tvs pvs (RFun z i cls (t' `RT.strengthen` mt) r)
+  strengthenTy x t = mkUnivs tvs pvs (RFun z i clas (t' `RT.strengthen` mt) r)
    where
-    (tvs, pvs, RFun z i cls t' r) = bkUniv t
+    (tvs, pvs, RFun z i clas t' r) = bkUniv t
     vv = rTypeValueVar t'
     mt = RT.uReft (vv, F.PAtom F.Eq (F.EVar vv) (F.EApp (F.EVar x) (F.EVar z)))
 
 
 elaborateMethod :: F.Symbol -> S.HashSet F.Symbol -> SpecType -> SpecType
-elaborateMethod dc methods t = mapExprReft
-  (\_ -> substClassOpBinding tcbind dc methods)
-  t
+elaborateMethod dc methods st = mapExprReft
+  (\_ -> substClassOpBinding tcbindSym dc methods)
+  st
  where
-  tcbind = grabtcbind t
+  tcbindSym = grabtcbind st
   grabtcbind :: SpecType -> F.Symbol
   grabtcbind t =
     F.notracepp "grabtcbind"
@@ -260,7 +261,7 @@
 -- After: Funcctor.fmap ($p1Applicative##GHC.Base.Applicative)
 substClassOpBinding
   :: F.Symbol -> F.Symbol -> S.HashSet F.Symbol -> F.Expr -> F.Expr
-substClassOpBinding tcbind dc methods e = go e
+substClassOpBinding tcbind dc methods = go
  where
   go :: F.Expr -> F.Expr
   go (F.EApp e0 e1)
@@ -309,8 +310,8 @@
   = RRTy (over (each % _2) (renameTvs rename) env) r obl (renameTvs rename ty)
   | RHole _ <- t
   = t
-  
 
+
 makeClassAuxTypes ::
      (SpecType -> Ghc.TcRn SpecType)
   -> [F.Located DataConP]
@@ -353,19 +354,19 @@
     elaboratedSig  <- flip addCoherenceOblig preft <$> elab fullSig
 
     let retSig =  mapExprReft (\_ -> substAuxMethod dfunSym methodsSet) (F.notracepp ("elaborated" ++ GM.showPpr method) elaboratedSig)
-    let tysub  = F.notracepp "tysub" $ M.fromList $ zip (F.notracepp "newtype-vars" $ allTyVars' (F.notracepp "new-type" $  retSig)) (F.notracepp "ghc-type-vars" (allTyVars' ((F.notracepp "ghc-type" $ ofType (Ghc.varType method)) :: SpecType)))
+    let tysub  = F.notracepp "tysub" $ M.fromList $ zip (F.notracepp "newtype-vars" $ allTyVars' (F.notracepp "new-type" retSig)) (F.notracepp "ghc-type-vars" (allTyVars' ((F.notracepp "ghc-type" $ ofType (Ghc.varType method)) :: SpecType)))
         cosub  = M.fromList [ (F.symbol a, F.fObj (GM.namedLocSymbol b)) |  (a,RTV b) <- M.toList tysub]
         tysubf x = F.notracepp ("cosub:" ++ F.showpp cosub) $ tysub ^. at x % non x
         subbedTy = mapReft (Bare.coSubRReft cosub) (renameTvs tysubf retSig)
     -- need to make the variable names consistent
-    pure (method, F.dummyLoc (F.notracepp ("vars:" ++ F.showpp (F.symbol <$> allTyVars' subbedTy)) $ subbedTy))
+    pure (method, F.dummyLoc (F.notracepp ("vars:" ++ F.showpp (F.symbol <$> allTyVars' subbedTy)) subbedTy))
 
   -- "is" is used as a shorthand for instance, following the convention of the Ghc api
   where
     -- recsel = F.symbol ("lq$recsel" :: String)
     (_,predTys,_,_) = Ghc.instanceSig inst
     dfunApped = F.mkEApp dfunSymL [F.eVar $ F.vv (Just i) | (i,_) <- zip [0,1..] predTys]
-    prefts  = L.reverse . take (length yts) $ fmap (F.notracepp "prefts" . Just . (flip MkUReft mempty) . mconcat) preftss ++ repeat Nothing
+    prefts  = L.reverse . take (length yts) $ fmap (F.notracepp "prefts" . Just . flip MkUReft mempty . mconcat) preftss ++ repeat Nothing
     preftss = F.notracepp "preftss" $ (fmap.fmap) (uncurry (GM.coherenceObligToRefE dfunApped)) (GM.buildCoherenceOblig cls)
     yts' = zip (fst <$> yts) (zip (snd <$> yts) prefts)
     cls = Mb.fromJust . Ghc.tyConClass_maybe $ Ghc.dataConTyCon (dcpCon dcp)
@@ -398,10 +399,10 @@
     clsTvs = dcpFreeTyVars dcp
         -- copy/pasted from Bare/Class.hs
     subst [] t = t
-    subst ((a, ta):su) t = subsTyVar_meet' (a, ta) (subst su t)
+    subst ((a, ta):su) t = subsTyVarMeet' (a, ta) (subst su t)
 
 substAuxMethod :: F.Symbol -> M.HashMap F.Symbol F.Symbol -> F.Expr -> F.Expr
-substAuxMethod dfun methods e = F.notracepp "substAuxMethod" $ go e
+substAuxMethod dfun methods = F.notracepp "substAuxMethod" . go
   where go :: F.Expr -> F.Expr
         go (F.EApp e0 e1)
           | F.EVar x <- F.notracepp "e0" e0
diff --git a/src/Language/Haskell/Liquid/Bare/Types.hs b/src/Language/Haskell/Liquid/Bare/Types.hs
--- a/src/Language/Haskell/Liquid/Bare/Types.hs
+++ b/src/Language/Haskell/Liquid/Bare/Types.hs
@@ -28,7 +28,6 @@
   , failMaybe
   ) where 
 
-import qualified Control.Exception                     as Ex 
 import qualified Text.PrettyPrint.HughesPJ             as PJ 
 import qualified Data.HashSet                          as S
 import qualified Data.HashMap.Strict                   as M
@@ -37,8 +36,8 @@
 import qualified Language.Haskell.Liquid.Types.RefType as RT 
 import           Language.Haskell.Liquid.Types.Types
 import           Language.Haskell.Liquid.Types.Specs   hiding (BareSpec)
-import           Language.Haskell.Liquid.GHC.API       as Ghc hiding (Located, Env)
-import           Language.Haskell.Liquid.GHC.Types     (StableName)
+import           Liquid.GHC.API       as Ghc hiding (Located, Env)
+import           Liquid.GHC.Types     (StableName)
 
 
 type ModSpecs = M.HashMap ModName Ms.BareSpec
@@ -130,7 +129,7 @@
   , meDataCons    :: ![(Ghc.Var,  LocSpecType)]           
   , meClasses     :: ![DataConP]                           
   , meMethods     :: ![(ModName, Ghc.Var, LocSpecType)]  
-  , meCLaws       :: !([(Ghc.Class, [(ModName, Ghc.Var, LocSpecType)])])  
+  , meCLaws       :: ![(Ghc.Class, [(ModName, Ghc.Var, LocSpecType)])]  
   }
 
 instance Semigroup MeasEnv where
diff --git a/src/Language/Haskell/Liquid/Constraint/Constraint.hs b/src/Language/Haskell/Liquid/Constraint/Constraint.hs
--- a/src/Language/Haskell/Liquid/Constraint/Constraint.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Constraint.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 
 -- TODO: what exactly is the purpose of this module? What do these functions do?
@@ -36,18 +35,18 @@
           (last (fst <$> xts), r))
           | xts <- xss]
   where
-   xts      = init binds
-   (xs, ts) = unzip xts
+   symRts   = init binds
+   (xs, ts) = unzip symRts
    r        = snd $ last binds
    xss      = combinations ((\t -> [(x, t) | x <- localBindsOfType t γ]) <$> ts)
 
 subConstraintToLogicOne :: (Foldable t, Reftable r, Reftable r1)
                         => t (Symbol, (Symbol, RType t1 t2 r))
                         -> (Symbol, (Symbol, RType t3 t4 r1)) -> Expr
-subConstraintToLogicOne xts (x', (x, t)) = PImp (pAnd rs) r
+subConstraintToLogicOne xts (sym', (sym, rt)) = PImp (pAnd rs) r
   where
-        (rs , su) = foldl go ([], []) xts
-        ([r], _ ) = go ([], su) (x', (x, t))
+        (rs , symExprs) = foldl go ([], []) xts
+        ([r], _ ) = go ([], symExprs) (sym', (sym, rt))
         go (acc, su) (x', (x, t)) = let (Reft(v, p)) = toReft (fromMaybe mempty (stripRTypeBase t))
                                         su'          = (x', EVar x):(v, EVar x) : su
                                     in
diff --git a/src/Language/Haskell/Liquid/Constraint/Env.hs b/src/Language/Haskell/Liquid/Constraint/Env.hs
--- a/src/Language/Haskell/Liquid/Constraint/Env.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Env.hs
@@ -1,15 +1,9 @@
 {-# LANGUAGE ScopedTypeVariables       #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE FlexibleInstances         #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE BangPatterns              #-}
-{-# LANGUAGE PatternGuards             #-}
-{-# LANGUAGE DeriveFunctor             #-}
 {-# LANGUAGE MultiParamTypeClasses     #-}
 {-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE ImplicitParams            #-}
 {-# LANGUAGE PartialTypeSignatures     #-}
 
@@ -72,9 +66,9 @@
 
 
 
-import           Language.Haskell.Liquid.GHC.API hiding (panic)
+import           Liquid.GHC.API hiding (panic)
 import           Language.Haskell.Liquid.Types.RefType
-import qualified Language.Haskell.Liquid.GHC.SpanStack as Sp
+import qualified Liquid.GHC.SpanStack as Sp
 import           Language.Haskell.Liquid.Types            hiding (binds, Loc, loc, freeTyVars, Def)
 import           Language.Haskell.Liquid.Constraint.Types
 import           Language.Haskell.Liquid.Constraint.Fresh ()
@@ -94,7 +88,7 @@
 
 -- RJ: REnv-Split-Bug?
 filterREnv :: (SpecType -> Bool) -> REnv -> REnv
-filterREnv f rE        = rE `updREnvLocal` (M.filter f)
+filterREnv f rE        = rE `updREnvLocal` M.filter f
 
 fromListREnv :: [(F.Symbol, SpecType)] -> [(F.Symbol, SpecType)] -> REnv
 fromListREnv gXts lXts = REnv
@@ -104,10 +98,10 @@
 
 -- RJ: REnv-Split-Bug?
 deleteREnv :: F.Symbol -> REnv -> REnv
-deleteREnv x rE = rE `updREnvLocal` (M.delete x)
+deleteREnv x rE = rE `updREnvLocal` M.delete x
 
 insertREnv :: F.Symbol -> SpecType -> REnv -> REnv
-insertREnv x y rE = {- trace ("insertREnv: " ++ show x) $ -} rE `updREnvLocal` (M.insert x y)
+insertREnv x y rE = {- trace ("insertREnv: " ++ show x) $ -} rE `updREnvLocal` M.insert x y
 
 lookupREnv :: F.Symbol -> REnv -> Maybe SpecType
 lookupREnv x rE = msum $ M.lookup x <$> renvMaps rE
@@ -142,7 +136,7 @@
 extendEnvWithVV :: CGEnv -> SpecType -> CG CGEnv
 --------------------------------------------------------------------------------
 extendEnvWithVV γ t
-  | F.isNontrivialVV vv && not (vv `memberREnv` (renv γ))
+  | F.isNontrivialVV vv && not (vv `memberREnv` renv γ)
   = γ += ("extVV", vv, t)
   | otherwise
   = return γ
@@ -155,7 +149,7 @@
 addBind :: SrcSpan -> F.Symbol -> F.SortedReft -> CG ((F.Symbol, F.Sort), F.BindId)
 addBind l x r = do
   st          <- get
-  let (i, bs') = F.insertBindEnv x r (binds st)
+  let (i, bs') = F.insertBindEnv x r (Ci l Nothing Nothing) (binds st)
   put          $ st { binds = bs' } { bindSpans = M.insert i l (bindSpans st) }
   return ((x, F.sr_sort r), {- traceShow ("addBind: " ++ showpp x) -} i)
 
@@ -169,8 +163,8 @@
   γ' <- addCGEnv tx γ (eMsg, y', tyy)
   addCGEnv tx γ' (eMsg, x, tyx `F.subst1` (y, F.EVar y'))
 
-addCGEnv tx γ (eMsg, x, RAllE yy tyy tyx)
-  = addCGEnv tx γ (eMsg, x, t)
+addCGEnv tx γ (eMsg, sym, RAllE yy tyy tyx)
+  = addCGEnv tx γ (eMsg, sym, t)
   where
     xs            = localBindsOfType tyy (renv γ)
     t             = L.foldl' F.meet ttrue [ tyx' `F.subst1` (yy, F.EVar x) | x <- xs]
@@ -182,13 +176,13 @@
   let t  = tx $ normalize idx t'
   let l  = getLocation γ
   let γ' = γ { renv = insertREnv x t (renv γ) }
-  tem   <- getTemplates 
+  tem   <- getTemplates
   is    <- (:) <$> addBind l x (rTypeSortedReft' γ' tem t) <*> addClassBind γ' l t
   return $ γ' { fenv = insertsFEnv (fenv γ) is }
 
 rTypeSortedReft' :: (PPrint r, F.Reftable r, SubsTy RTyVar RSort r, F.Reftable (RTProp RTyCon RTyVar r))
     => CGEnv -> F.Templates -> RRType r -> F.SortedReft
-rTypeSortedReft' γ t 
+rTypeSortedReft' γ t
   = pruneUnsortedReft (feEnv $ fenv γ) t . f
    where
    f         = rTypeSortedReft (emb γ)
@@ -198,7 +192,7 @@
 normalize idx = normalizeVV idx . normalizePds
 
 normalizeVV :: Integer -> SpecType -> SpecType
-normalizeVV idx t@(RApp _ _ _ _)
+normalizeVV idx t@RApp{}
   | not (F.isNontrivialVV (rTypeValueVar t))
   = shiftVV t (F.vv $ Just idx)
 
@@ -221,7 +215,7 @@
   where
     s = unlines [ eMsg ++ " Duplicate binding for " ++ F.symbolString x
                 , "   New: " ++ showpp r
-                , "   Old: " ++ showpp (x `lookupREnv` (renv γ)) ]
+                , "   Old: " ++ showpp (x `lookupREnv` renv γ) ]
 
 --------------------------------------------------------------------------------
 globalize :: CGEnv -> CGEnv
diff --git a/src/Language/Haskell/Liquid/Constraint/Fresh.hs b/src/Language/Haskell/Liquid/Constraint/Fresh.hs
--- a/src/Language/Haskell/Liquid/Constraint/Fresh.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Fresh.hs
@@ -3,18 +3,18 @@
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE OverloadedStrings     #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TupleSections         #-}
-{-# LANGUAGE TypeSynonymInstances  #-}
 {-# LANGUAGE UndecidableInstances  #-}
 {-# LANGUAGE BangPatterns          #-}
 {-# LANGUAGE ConstraintKinds       #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+
 module Language.Haskell.Liquid.Constraint.Fresh
   ( -- module Language.Haskell.Liquid.Types.Fresh
     -- , 
     refreshArgsTop
-  , freshTy_type
-  , freshTy_expr
+  , freshTyType
+  , freshTyExpr
   , trueTy
   , addKuts
   )
@@ -37,8 +37,8 @@
 -- import           Language.Haskell.Liquid.Types.RefType
 -- import           Language.Haskell.Liquid.Types.Fresh
 import           Language.Haskell.Liquid.Constraint.Types
-import qualified Language.Haskell.Liquid.GHC.Misc as GM 
-import           Language.Haskell.Liquid.GHC.API as Ghc
+import qualified Liquid.GHC.Misc as GM
+import           Liquid.GHC.API as Ghc
 
 --------------------------------------------------------------------------------
 -- | This is all hardwiring stuff to CG ----------------------------------------
@@ -64,26 +64,26 @@
 -- | Right now, we generate NO new pvars. Rather than clutter code
 --   with `uRType` calls, put it in one place where the above
 --   invariant is /obviously/ enforced.
---   Constraint generation should ONLY use @freshTy_type@ and @freshTy_expr@
+--   Constraint generation should ONLY use @freshTyType@ and @freshTyExpr@
 
-freshTy_type        :: Bool -> KVKind -> CoreExpr -> Type -> CG SpecType
-freshTy_type allowTC k e τ  =  F.notracepp ("freshTy_type: " ++ F.showpp k ++ GM.showPpr e) 
-                   <$> freshTy_reftype allowTC k (ofType τ)
+freshTyType        :: Bool -> KVKind -> CoreExpr -> Type -> CG SpecType
+freshTyType allowTC k e τ  =  F.notracepp ("freshTyType: " ++ F.showpp k ++ GM.showPpr e)
+                   <$> freshTyReftype allowTC k (ofType τ)
 
-freshTy_expr        :: Bool -> KVKind -> CoreExpr -> Type -> CG SpecType
-freshTy_expr allowTC k e _  = freshTy_reftype allowTC k $ exprRefType e
+freshTyExpr        :: Bool -> KVKind -> CoreExpr -> Type -> CG SpecType
+freshTyExpr allowTC k e _  = freshTyReftype allowTC k $ exprRefType e
 
-freshTy_reftype     :: Bool -> KVKind -> SpecType -> CG SpecType
-freshTy_reftype allowTC k _t = (fixTy t >>= refresh allowTC) =>> addKVars k
+freshTyReftype     :: Bool -> KVKind -> SpecType -> CG SpecType
+freshTyReftype allowTC k _t = (fixTy t >>= refresh allowTC) =>> addKVars k
   where
-    t                = {- F.tracepp ("freshTy_reftype:" ++ show k) -} _t
+    t                = {- F.tracepp ("freshTyReftype:" ++ show k) -} _t
 
 -- | Used to generate "cut" kvars for fixpoint. Typically, KVars for recursive
 --   definitions, and also to update the KVar profile.
 addKVars        :: KVKind -> SpecType -> CG ()
 addKVars !k !t  = do
-    cfg <- getConfig  <$> gets ghcI
-    when (True)        $ modify $ \s -> s { kvProf = updKVProf k ks (kvProf s) }
+    cfg <- gets (getConfig . ghcI)
+    when True          $ modify $ \s -> s { kvProf = updKVProf k ks (kvProf s) }
     when (isKut cfg k) $ addKuts k t
   where
     ks         = F.KS $ S.fromList $ specTypeKVars t
@@ -102,7 +102,7 @@
        | otherwise  = {- F.tracepp ("addKuts: " ++ showpp _x) -} ks'
 
 specTypeKVars :: SpecType -> [F.KVar]
-specTypeKVars = foldReft False (\ _ r ks -> (kvarsExpr $ F.reftPred $ ur_reft r) ++ ks) []
+specTypeKVars = foldReft False (\ _ r ks -> kvarsExpr (F.reftPred $ ur_reft r) ++ ks) []
 
 --------------------------------------------------------------------------------
 trueTy  :: Bool -> Type -> CG SpecType
@@ -113,8 +113,8 @@
 ofType' = fixTy . ofType
 
 fixTy :: SpecType -> CG SpecType
-fixTy t = do tyi   <- tyConInfo  <$> get
-             tce   <- tyConEmbed <$> get
+fixTy t = do tyi   <- gets tyConInfo
+             tce   <- gets tyConEmbed
              return $ addTyConInfo tce tyi t
 
 exprRefType :: CoreExpr -> SpecType
diff --git a/src/Language/Haskell/Liquid/Constraint/Generate.hs b/src/Language/Haskell/Liquid/Constraint/Generate.hs
--- a/src/Language/Haskell/Liquid/Constraint/Generate.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Generate.hs
@@ -1,42 +1,36 @@
-{-# LANGUAGE CPP                       #-}
-{-# LANGUAGE DeriveFoldable            #-}
 {-# LANGUAGE DeriveTraversable         #-}
+{-# LANGUAGE LambdaCase                #-}
 {-# LANGUAGE StandaloneDeriving        #-}
 {-# LANGUAGE ScopedTypeVariables       #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE BangPatterns              #-}
 {-# LANGUAGE PatternGuards             #-}
-{-# LANGUAGE DeriveFunctor             #-}
 {-# LANGUAGE MultiParamTypeClasses     #-}
 {-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE ImplicitParams            #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+
 -- | This module defines the representation of Subtyping and WF Constraints,
 --   and the code for syntax-directed constraint generation.
 
 module Language.Haskell.Liquid.Constraint.Generate ( generateConstraints, generateConstraintsWithEnv, caseEnv, consE ) where
 
-#if !MIN_VERSION_base(4,14,0)
-import Control.Monad.Fail
-#endif
-
 import           Prelude                                       hiding (error)
 import           GHC.Stack
-import           Language.Haskell.Liquid.GHC.API                   as Ghc hiding ( panic
+import           Liquid.GHC.API                   as Ghc hiding ( panic
                                                                                  , checkErr
                                                                                  , (<+>)
                                                                                  , text
                                                                                  , vcat
                                                                                  )
-import           Language.Haskell.Liquid.GHC.TypeRep           ()
-import           Text.PrettyPrint.HughesPJ hiding ((<>)) 
+import           Liquid.GHC.TypeRep           ()
+import           Text.PrettyPrint.HughesPJ hiding ((<>))
 import           Control.Monad.State
-import           Data.Maybe                                    (fromMaybe, catMaybes, isJust)
+import           Data.Functor ((<&>))
+import           Data.Maybe                                    (fromMaybe, catMaybes, isJust, mapMaybe)
 import qualified Data.HashMap.Strict                           as M
 import qualified Data.HashSet                                  as S
 import qualified Data.List                                     as L
@@ -52,17 +46,18 @@
 import           Language.Haskell.Liquid.Constraint.Env
 import           Language.Haskell.Liquid.Constraint.Monad
 import           Language.Haskell.Liquid.Constraint.Split
+import           Language.Haskell.Liquid.Constraint.Relational (consAssmRel, consRelTop)
 import           Language.Haskell.Liquid.Types.Dictionaries
-import           Language.Haskell.Liquid.GHC.Play          (isHoleVar) 
-import qualified Language.Haskell.Liquid.GHC.Resugar           as Rs
-import qualified Language.Haskell.Liquid.GHC.SpanStack         as Sp
-import qualified Language.Haskell.Liquid.GHC.Misc         as GM -- ( isInternal, collectArguments, tickSrcSpan, showPpr )
+import           Liquid.GHC.Play          (isHoleVar)
+import qualified Liquid.GHC.Resugar           as Rs
+import qualified Liquid.GHC.SpanStack         as Sp
+import qualified Liquid.GHC.Misc         as GM -- ( isInternal, collectArguments, tickSrcSpan, showPpr )
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Constraint.Types
 import           Language.Haskell.Liquid.Constraint.Constraint
 import           Language.Haskell.Liquid.Transforms.Rec
-import           Language.Haskell.Liquid.Transforms.CoreToLogic (weakenResult)
-import           Language.Haskell.Liquid.Bare.DataType (makeDataConChecker)
+import           Language.Haskell.Liquid.Transforms.CoreToLogic (weakenResult, runToLogic, coreToLogic)
+import           Language.Haskell.Liquid.Bare.DataType (dataConMap, makeDataConChecker)
 
 import           Language.Haskell.Liquid.Types hiding (binds, Loc, loc, Def)
 
@@ -85,16 +80,20 @@
 
 consAct :: CGEnv -> Config -> TargetInfo -> CG ()
 consAct γ cfg info = do
-  let sSpc = gsSig . giSpec $ info  
+  let sSpc = gsSig . giSpec $ info
   let gSrc = giSrc info
   when (gradual cfg) (mapM_ (addW . WfC γ . val . snd) (gsTySigs sSpc ++ gsAsmSigs sSpc))
-  foldM_ (consCBTop cfg info) γ (giCbs gSrc)
-  mapM_ (consClass γ) (gsMethods $ gsSig $ giSpec info) 
+  γ' <- foldM (consCBTop cfg info) γ (giCbs gSrc)
+  -- Relational Checking: the following only runs when the list of relational specs is not empty
+  (ψ, γ'') <- foldM (consAssmRel cfg info) ([], γ') (gsAsmRel sSpc ++ gsRelation sSpc)
+  mapM_ (consRelTop cfg info γ'' ψ) (gsRelation sSpc)
+  -- End: Relational Checking
+  mapM_ (consClass γ) (gsMethods $ gsSig $ giSpec info)
   hcs <- gets hsCs
   hws <- gets hsWfs
   fcs <- concat <$> mapM (splitC (typeclass (getConfig info))) hcs
   fws <- concat <$> mapM splitW hws
-  modify $ \st -> st { fEnv     = feEnv (fenv γ)
+  modify $ \st -> st { fEnv     = fEnv    st `mappend` feEnv (fenv γ)
                      , cgLits   = litEnv   γ
                      , cgConsts = cgConsts st `mappend` constEnv γ
                      , fixCs    = fcs
@@ -107,12 +106,12 @@
 --------------------------------------------------------------------------------
 
 consClass :: CGEnv -> (Var, MethodType LocSpecType) -> CG ()
-consClass γ (x,mt) 
-  | Just ti <- tyInstance mt 
-  , Just tc <- tyClass    mt 
+consClass γ (x,mt)
+  | Just ti <- tyInstance mt
+  , Just tc <- tyClass    mt
   = addC (SubC (γ `setLocation` Sp.Span (GM.fSrcSpan (F.loc ti))) (val ti) (val tc)) ("cconsClass for " ++ GM.showPpr x)
-consClass _ _ 
-  = return () 
+consClass _ _
+  = return ()
 
 --------------------------------------------------------------------------------
 -- | TERMINATION TYPE ----------------------------------------------------------
@@ -121,7 +120,7 @@
 makeDecrIndex (x, Assumed t, args)
   = do dindex <- makeDecrIndexTy x t args
        case dindex of
-         Left _  -> return []
+         Left msg -> addWarning msg >> return []
          Right i -> return i
 makeDecrIndex (x, Asserted t, args)
   = do dindex <- makeDecrIndexTy x t args
@@ -131,24 +130,25 @@
 makeDecrIndex _ = return []
 
 makeDecrIndexTy :: Var -> SpecType -> [Var] -> CG (Either (TError t) [Int])
-makeDecrIndexTy x t args
-  = do spDecr <- specDecr <$> get
-       autosz <- autoSize <$> get
+makeDecrIndexTy x st args
+  = do spDecr <- gets specDecr
+       autosz <- gets autoSize
        hint   <- checkHint' autosz (L.lookup x spDecr)
        case dindex autosz of
          Nothing -> return $ Left msg
          Just i  -> return $ Right $ fromMaybe [i] hint
     where
-       ts         = ty_args trep
-       tvs        = zip ts args
-       checkHint' = \autosz -> checkHint x ts (isDecreasing autosz cenv)
-       dindex     = \autosz -> L.findIndex (p autosz) tvs
-       p autosz (t, v) = isDecreasing autosz cenv t && not (isIdTRecBound v)
-       msg        = ErrTermin (getSrcSpan x) [F.pprint x] (text "No decreasing parameter")
-       cenv       = makeNumEnv ts
-       trep       = toRTypeRep $ unOCons t
+       ts   = ty_args trep
+       tvs  = zip ts args
+       msg  = ErrTermin (getSrcSpan x) [F.pprint x] (text "No decreasing parameter")
+       cenv = makeNumEnv ts
+       trep = toRTypeRep $ unOCons st
 
+       p autosz (t, v)   = isDecreasing autosz cenv t && not (isIdTRecBound v)
+       checkHint' autosz = checkHint x ts (isDecreasing autosz cenv)
+       dindex     autosz = L.findIndex (p autosz) tvs
 
+
 recType :: F.Symbolic a
         => S.HashSet TyCon
         -> (([a], [Int]), (t, [Int], SpecType))
@@ -172,7 +172,7 @@
     where
        loc   = getSrcSpan x
        ts    = ty_args $ toRTypeRep $ unOCons $ unTemplate t
-       msg1  = ErrTermin loc [xd] ("No decreasing" <+> F.pprint index <-> "-th argument on" <+> xd <+> "with" <+> (F.pprint vs))
+       msg1  = ErrTermin loc [xd] ("No decreasing" <+> F.pprint index <-> "-th argument on" <+> xd <+> "with" <+> F.pprint vs)
        msg2  = ErrTermin loc [xd] "No decreasing parameter"
        xd    = F.pprint x
 
@@ -192,14 +192,14 @@
     trep       = toRTypeRep $ unOCons t
 
 unOCons :: RType c tv r -> RType c tv r
-unOCons (RAllT v t r)      = RAllT v (unOCons t) r 
+unOCons (RAllT v t r)      = RAllT v (unOCons t) r
 unOCons (RAllP p t)        = RAllP p $ unOCons t
 unOCons (RFun x i tx t r)  = RFun x i (unOCons tx) (unOCons t) r
 unOCons (RRTy _ _ OCons t) = unOCons t
 unOCons t                  = t
 
 mergecondition :: RType c tv r -> RType c tv r -> RType c tv r
-mergecondition (RAllT _ t1 _) (RAllT v t2 r2)          = RAllT v (mergecondition t1 t2) r2 
+mergecondition (RAllT _ t1 _) (RAllT v t2 r2)          = RAllT v (mergecondition t1 t2) r2
 mergecondition (RAllP _ t1) (RAllP p t2)               = RAllP p (mergecondition t1 t2)
 mergecondition (RRTy xts r OCons t1) t2                = RRTy xts r OCons (mergecondition t1 t2)
 mergecondition (RFun _ _ t11 t12 _) (RFun x2 i t21 t22 r2) = RFun x2 i (mergecondition t11 t21) (mergecondition t12 t22) r2
@@ -222,7 +222,7 @@
     dx  = F.pprint x
 
 checkHint x ts f (Just ns)
-  = (mapM (checkValidHint x ts f) ns) >>= (return . Just . catMaybes)
+  = mapM (checkValidHint x ts f) ns <&> (Just . catMaybes)
 
 checkValidHint :: (NamedThing a, PPrint a, PPrint a1)
                => a -> [a1] -> (a1 -> Bool) -> Int -> CG (Maybe Int)
@@ -241,7 +241,7 @@
 consCBLet :: CGEnv -> CoreBind -> CG CGEnv
 --------------------------------------------------------------------------------
 consCBLet γ cb = do
-  oldtcheck <- tcheck <$> get
+  oldtcheck <- gets tcheck
   isStr     <- doTermCheck (getConfig γ) cb
   -- TODO: yuck.
   modify $ \s -> s { tcheck = oldtcheck && isStr }
@@ -254,16 +254,16 @@
 --------------------------------------------------------------------------------
 consCBTop :: Config -> TargetInfo -> CGEnv -> CoreBind -> CG CGEnv
 --------------------------------------------------------------------------------
-consCBTop cfg info γ cb
+consCBTop cfg info cgenv cb
   | all (trustVar cfg info) xs
-  = foldM addB γ xs
+  = foldM addB cgenv xs
     where
        xs   = bindersOf cb
        tt   = trueTy (typeclass cfg) . varType
        addB γ x = tt x >>= (\t -> γ += ("derived", F.symbol x, t))
 
 consCBTop _ _ γ cb
-  = do oldtcheck <- tcheck <$> get
+  = do oldtcheck <- gets tcheck
        -- lazyVars  <- specLazy <$> get
        isStr     <- doTermCheck (getConfig γ) cb
        modify $ \s -> s { tcheck = oldtcheck && isStr}
@@ -284,11 +284,11 @@
 derivedVar src x = S.member x (giDerVars src)
 
 doTermCheck :: Config -> Bind Var -> CG Bool
-doTermCheck cfg bind = do 
-  lazyVs    <- specLazy   <$> get 
-  termVs    <- specTmVars <$> get
+doTermCheck cfg bind = do
+  lazyVs    <- gets specLazy
+  termVs    <- gets specTmVars
   let skip   = any (\x -> S.member x lazyVs || nocheck x) xs
-  let chk    = not (structuralTerm cfg) || any (\x -> S.member x termVs) xs
+  let chk    = not (structuralTerm cfg) || any (`S.member` termVs) xs
   return     $ chk && not skip
   where
     nocheck  = if typeclass cfg then GM.isEmbeddedDictVar else GM.isInternal
@@ -299,43 +299,43 @@
 -- RJ: AAAAAAARGHHH!!!!!! THIS CODE IS HORRIBLE!!!!!!!!!
 consCBSizedTys :: CGEnv -> [(Var, CoreExpr)] -> CG CGEnv
 consCBSizedTys γ xes
-  = do xets     <- forM xes $ \(x, e) -> liftM (x, e,) (varTemplate γ (x, Just e))
-       autoenv  <- autoSize <$> get
-       ts       <- mapM (T.mapM refreshArgs) $ (thd3 <$> xets)
-       let vs    = zipWith collectArgs ts es
-       is       <- mapM makeDecrIndex (zip3 xs ts vs) >>= checkSameLens
-       let xeets = (\vis -> [(vis, x) | x <- zip3 xs is $ map unTemplate ts]) <$> (zip vs is)
-       (L.transpose <$> mapM checkIndex (zip4 xs vs ts is)) >>= checkEqTypes
+  = do xets     <- forM xes $ \(x, e) -> fmap (x, e,) (varTemplate γ (x, Just e))
+       autoenv  <- gets autoSize
+       ts       <- mapM (T.mapM refreshArgs) (thd3 <$> xets)
+       let vs    = zipWith collectArgs' ts es
+       is       <- mapM makeDecrIndex (zip3 vars ts vs) >>= checkSameLens
+       let xeets = (\vis -> [(vis, x) | x <- zip3 vars is $ map unTemplate ts]) <$> zip vs is
+       _ <- mapM checkIndex (zip4 vars vs ts is) >>= checkEqTypes . L.transpose
        let rts   = (recType autoenv <$>) <$> xeets
-       let xts   = zip xs ts
+       let xts   = zip vars ts
        γ'       <- foldM extender γ xts
-       let γs    = zipWith makeRecInvariants [γ' `setTRec` zip xs rts' | rts' <- rts] (filter (not . noMakeRec) <$> vs)
-       let xets' = zip3 xs es ts
+       let γs    = zipWith makeRecInvariants [γ' `setTRec` zip vars rts' | rts' <- rts] (filter (not . noMakeRec) <$> vs)
+       let xets' = zip3 vars es ts
        mapM_ (uncurry $ consBind True) (zip γs xets')
        return γ'
   where
        noMakeRec      = if allowTC then GM.isEmbeddedDictVar else GM.isPredVar
        allowTC        = typeclass (getConfig γ)
-       (xs, es)       = unzip xes
-       dxs            = F.pprint <$> xs
-       collectArgs    = GM.collectArguments . length . ty_binds . toRTypeRep . unOCons . unTemplate
+       (vars, es)     = unzip xes
+       dxs            = F.pprint <$> vars
+       collectArgs'   = GM.collectArguments . length . ty_binds . toRTypeRep . unOCons . unTemplate
        checkEqTypes :: [[Maybe SpecType]] -> CG [[SpecType]]
-       checkEqTypes x = mapM (checkAll err1 toRSort) (catMaybes <$> x)
-       checkSameLens  = checkAll err2 length
+       checkEqTypes x = mapM (checkAll' err1 toRSort) (catMaybes <$> x)
+       checkSameLens  = checkAll' err2 length
        err1           = ErrTermin loc dxs $ text "The decreasing parameters should be of same type"
        err2           = ErrTermin loc dxs $ text "All Recursive functions should have the same number of decreasing parameters"
-       loc            = getSrcSpan (head xs)
+       loc            = getSrcSpan (head vars)
 
-       checkAll _   _ []            = return []
-       checkAll err f (x:xs)
-         | all (==(f x)) (f <$> xs) = return (x:xs)
+       checkAll' _   _ []            = return []
+       checkAll' err f (x:xs)
+         | all (== f x) (f <$> xs) = return (x:xs)
          | otherwise                = addWarning err >> return []
 
 consCBWithExprs :: CGEnv -> [(Var, CoreExpr)] -> CG CGEnv
 consCBWithExprs γ xes
-  = do xets     <- forM xes $ \(x, e) -> liftM (x, e,) (varTemplate γ (x, Just e))
-       texprs    <- termExprs <$> get
-       let xtes   = catMaybes $ (`lookup` texprs) <$> xs
+  = do xets     <- forM xes $ \(x, e) -> fmap (x, e,) (varTemplate γ (x, Just e))
+       texprs   <- gets termExprs
+       let xtes  = mapMaybe (`lookup'` texprs) xs
        let ts    = safeFromAsserted err . thd3 <$> xets
        ts'      <- mapM refreshArgs ts
        let xts   = zip xs (Asserted <$> ts')
@@ -345,8 +345,8 @@
        mapM_ (uncurry $ consBind True) (zip γs xets')
        return γ'
   where (xs, es) = unzip xes
-        lookup k m | Just x <- M.lookup k m = Just (k, x)
-                   | otherwise              = Nothing
+        lookup' k m | Just x <- M.lookup k m = Just (k, x)
+                    | otherwise              = Nothing
         err      = "Constant: consCBWithExprs"
 
 makeTermEnvs :: CGEnv -> [(Var, [F.Located F.Expr])] -> [(Var, CoreExpr)]
@@ -354,19 +354,19 @@
              -> [CGEnv]
 makeTermEnvs γ xtes xes ts ts' = setTRec γ . zip xs <$> rts
   where
-    vs   = zipWith collectArgs ts es
-    ys   = (fst5 . bkArrowDeep) <$> ts
-    ys'  = (fst5 . bkArrowDeep) <$> ts'
-    sus' = zipWith mkSub ys ys'
-    sus  = zipWith mkSub ys ((F.symbol <$>) <$> vs)
-    ess  = (\x -> (safeFromJust (err x) $ (x `L.lookup` xtes))) <$> xs
+    vs   = zipWith collectArgs' ts ces
+    syms = fst5 . bkArrowDeep <$> ts
+    syms' = fst5 . bkArrowDeep <$> ts'
+    sus' = zipWith mkSub syms syms'
+    sus  = zipWith mkSub syms ((F.symbol <$>) <$> vs)
+    ess  = (\x -> safeFromJust (err x) (x `L.lookup` xtes)) <$> xs
     tes  = zipWith (\su es -> F.subst su <$> es)  sus ess
     tes' = zipWith (\su es -> F.subst su <$> es)  sus' ess
     rss  = zipWith makeLexRefa tes' <$> (repeat <$> tes)
     rts  = zipWith (addObligation OTerm) ts' <$> rss
-    (xs, es)     = unzip xes
+    (xs, ces)    = unzip xes
     mkSub ys ys' = F.mkSubst [(x, F.EVar y) | (x, y) <- zip ys ys']
-    collectArgs  = GM.collectArguments . length . ty_binds . toRTypeRep
+    collectArgs' = GM.collectArguments . length . ty_binds . toRTypeRep
     err x        = "Constant: makeTermEnvs: no terminating expression for " ++ GM.showPpr x
 
 addObligation :: Oblig -> SpecType -> RReft -> SpecType
@@ -382,19 +382,19 @@
 --------------------------------------------------------------------------------
 -- do termination checking
 consCB True _ γ (Rec xes)
-  = do texprs <- termExprs <$> get
+  = do texprs <- gets termExprs
        modify $ \i -> i { recCount = recCount i + length xes }
-       let xxes = catMaybes $ (`lookup` texprs) <$> xs
+       let xxes = mapMaybe (`lookup'` texprs) xs
        if null xxes
          then consCBSizedTys γ xes
          else check xxes <$> consCBWithExprs γ xes
     where
-      xs = fst (unzip xes)
+      xs = map fst xes
       check ys r | length ys == length xs = r
-                 | otherwise              = panic (Just loc) $ msg
+                 | otherwise              = panic (Just loc) msg
       msg        = "Termination expressions must be provided for all mutually recursive binders"
       loc        = getSrcSpan (head xs)
-      lookup k m = (k,) <$> M.lookup k m
+      lookup' k m = (k,) <$> M.lookup k m
 
 -- don't do termination checking, but some strata checks?
 consCB _ False γ (Rec xes)
@@ -407,7 +407,7 @@
 
 -- don't do termination checking, and don't do any strata checks either?
 consCB _ _ γ (Rec xes)
-  = do xets   <- forM xes $ \(x, e) -> liftM (x, e,) (varTemplate γ (x, Just e))
+  = do xets   <- forM xes $ \(x, e) -> fmap (x, e,) (varTemplate γ (x, Just e))
        modify $ \i -> i { recCount = recCount i + length xes }
        let xts = [(x, to) | (x, _, to) <- xets]
        γ'     <- foldM extender (γ `setRecs` (fst <$> xts)) xts
@@ -424,30 +424,30 @@
 
 
 consCB _ _ γ (NonRec x _ ) | isHoleVar x && typedHoles (getConfig γ)
-  = return γ 
+  = return γ
 
 consCB _ _ γ (NonRec x def)
   | Just (w, τ) <- grepDictionary def
   , Just d      <- dlookup (denv γ) w
-  = do t        <- mapM (trueTy (typeclass (getConfig γ))) τ
-       mapM addW (WfC γ <$> t)
-       let xts   = dmap (fmap (f t)) d
+  = do st       <- mapM (trueTy (typeclass (getConfig γ))) τ
+       mapM_ addW (WfC γ <$> st)
+       let xts   = dmap (fmap (f st)) d
        let  γ'   = γ { denv = dinsert (denv γ) x xts }
        t        <- trueTy (typeclass (getConfig γ)) (varType x)
        extender γ' (x, Assumed t)
    where
-    f [t']    (RAllT α te _) = subsTyVar_meet' (ty_var_value α, t') te
-    f (t':ts) (RAllT α te _) = f ts $ subsTyVar_meet' (ty_var_value α, t') te
+    f [t']    (RAllT α te _) = subsTyVarMeet' (ty_var_value α, t') te
+    f (t':ts) (RAllT α te _) = f ts $ subsTyVarMeet' (ty_var_value α, t') te
     f _ _ = impossible Nothing "consCB on Dictionary: this should not happen"
 
 consCB _ _ γ (NonRec x e)
   = do to  <- varTemplate γ (x, Nothing)
-       to' <- consBind False γ (x, e, to) >>= (addPostTemplate γ)
+       to' <- consBind False γ (x, e, to) >>= addPostTemplate γ
        extender γ (x, makeSingleton γ (simplify e) <$> to')
 
 grepDictionary :: CoreExpr -> Maybe (Var, [Type])
 grepDictionary = go []
-  where 
+  where
     go ts (App (Var w) (Type t)) = Just (w, reverse (t:ts))
     go ts (App e (Type t))       = go (t:ts) e
     go ts (App e (Var _))        = go ts e
@@ -461,24 +461,24 @@
   | RecSelId {} <- idDetails x -- don't check record selectors with assumed specs
   = return $ F.notracepp ("TYPE FOR SELECTOR " ++ show x) $ Assumed t
 
-consBind isRec γ (x, e, Asserted spect)
+consBind isRec' γ (x, e, Asserted spect)
   = do let γ'       = γ `setBind` x
            (_,πs,_) = bkUniv spect
-       γπ    <- foldM addPToEnv γ' πs
+       cgenv    <- foldM addPToEnv γ' πs
 
        -- take implcits out of the function's SpecType and into the env
        let tyr = toRTypeRep spect
        let spect' = fromRTypeRep (tyr { ty_ebinds = [], ty_einfo = [], ty_eargs = [], ty_erefts = [] })
-       γπ <- foldM (+=) γπ $ (\(y,t)->("implicitError",y,t)) <$> zip (ty_ebinds tyr) (ty_eargs tyr)
+       γπ <- foldM (+=) cgenv $ (\(y,t)->("implicitError",y,t)) <$> zip (ty_ebinds tyr) (ty_eargs tyr)
 
        cconsE γπ e (weakenResult (typeclass (getConfig γ)) x spect')
        when (F.symbol x `elemHEnv` holes γ) $
          -- have to add the wf constraint here for HOLEs so we have the proper env
          addW $ WfC γπ $ fmap killSubst spect
-       addIdA x (defAnn isRec spect)
+       addIdA x (defAnn isRec' spect)
        return $ Asserted spect
 
-consBind isRec γ (x, e, Internal spect)
+consBind isRec' γ (x, e, Internal spect)
   = do let γ'       = γ `setBind` x
            (_,πs,_) = bkUniv spect
        γπ    <- foldM addPToEnv γ' πs
@@ -487,24 +487,24 @@
        when (F.symbol x `elemHEnv` holes γ) $
          -- have to add the wf constraint here for HOLEs so we have the proper env
          addW $ WfC γπ $ fmap killSubst spect
-       addIdA x (defAnn isRec spect)
+       addIdA x (defAnn isRec' spect)
        return $ Internal spect
   where
     explanation = "Cannot give singleton type to the function definition."
 
-consBind isRec γ (x, e, Assumed spect)
+consBind isRec' γ (x, e, Assumed spect)
   = do let γ' = γ `setBind` x
        γπ    <- foldM addPToEnv γ' πs
        cconsE γπ e =<< true (typeclass (getConfig γ)) spect
-       addIdA x (defAnn isRec spect)
+       addIdA x (defAnn isRec' spect)
        return $ Asserted spect
     where πs   = ty_preds $ toRTypeRep spect
 
-consBind isRec γ (x, e, Unknown)
+consBind isRec' γ (x, e, Unknown)
   = do t'    <- consE (γ `setBind` x) e
        t     <- topSpecType x t'
-       addIdA x (defAnn isRec t)
-       when (isExportedId x) (addKuts x t)
+       addIdA x (defAnn isRec' t)
+       when (GM.isExternalId x) (addKuts x t)
        return $ Asserted t
 
 killSubst :: RReft -> RReft
@@ -589,7 +589,7 @@
       (_, Just t, _, _) -> Asserted <$> refreshArgsTop (x, t)
       (_, _, _, Just t) -> Internal <$> refreshArgsTop (x, t)
       (_, _, Just t, _) -> Assumed  <$> refreshArgsTop (x, t)
-      (Just e, _, _, _) -> do t  <- freshTy_expr (typeclass (getConfig γ)) (RecBindE x) e (exprType e)
+      (Just e, _, _, _) -> do t  <- freshTyExpr (typeclass (getConfig γ)) (RecBindE x) e (exprType e)
                               addW (WfC γ t)
                               Asserted <$> refreshArgsTop (x, t)
       (_,      _, _, _) -> return Unknown
@@ -597,7 +597,7 @@
 -- | @topSpecType@ strips out the top-level refinement of "derived var"
 topSpecType :: Var -> SpecType -> CG SpecType
 topSpecType x t = do
-  info  <- ghcI <$> get
+  info <- gets ghcI
   return $ if derivedVar (giSrc info) x then topRTypeBase t else t
 
 --------------------------------------------------------------------------------
@@ -622,8 +622,8 @@
     in void $ consCBLet γ' (Rec [(x, e')])
 
 cconsE' γ e@(Let b@(NonRec x _) ee) t
-  = do sp <- specLVars <$> get
-       if (x `S.member` sp)
+  = do sp <- gets specLVars
+       if x `S.member` sp
          then cconsLazyLet γ e t
          else do γ'  <- consCBLet γ b
                  cconsE γ' ee t
@@ -645,12 +645,12 @@
        forM_ cases $ cconsCase γ' x t nonDefAlts
     where
        nonDefAlts = [a | (a, _, _) <- cases, a /= DEFAULT]
-       _msg = "cconsE' #nonDefAlts = " ++ show (length (nonDefAlts))
+       _msg = "cconsE' #nonDefAlts = " ++ show (length nonDefAlts)
 
 cconsE' γ (Lam α e) (RAllT α' t r) | isTyVar α
   = do γ' <- updateEnvironment γ α
        addForAllConstraint γ' α e (RAllT α' t r)
-       cconsE γ' e $ subsTyVar_meet' (ty_var_value α', rVar α) t
+       cconsE γ' e $ subsTyVarMeet' (ty_var_value α', rVar α) t
 
 cconsE' γ (Lam x e) (RFun y i ty t r)
   | not (isTyVar x)
@@ -664,7 +664,7 @@
     r'  = r `F.subst1` (y, F.EVar x')
 
 cconsE' γ (Tick tt e) t
-  = cconsE (γ `setLocation` (Sp.Tick tt)) e t
+  = cconsE (γ `setLocation` Sp.Tick tt) e t
 
 cconsE' γ (Cast e co) t
   -- See Note [Type classes with a single method]
@@ -676,44 +676,47 @@
        addC (SubC γ (F.notracepp ("Casted Type for " ++ GM.showPpr e ++ "\n init type " ++ showpp t) t') t) ("cconsE Cast: " ++ GM.showPpr e)
 
 cconsE' γ (Var x) t | isHoleVar x && typedHoles (getConfig γ)
-  = addHole x t γ 
+  = addHole x t γ
 
 cconsE' γ e t
   = do  te  <- consE γ e
         te' <- instantiatePreds γ e te >>= addPost γ
         addC (SubC γ te' t) ("cconsE: " ++ "\n t = " ++ showpp t ++ "\n te = " ++ showpp te ++ GM.showPpr e)
 
-lambdaSingleton :: CGEnv -> F.TCEmb TyCon -> Var -> CoreExpr -> UReft F.Reft
+lambdaSingleton :: CGEnv -> F.TCEmb TyCon -> Var -> CoreExpr -> CG (UReft F.Reft)
 lambdaSingleton γ tce x e
-  | higherOrderFlag γ, Just e' <- lamExpr γ e
-  = uTop $ F.exprReft $ F.ELam (F.symbol x, sx) e'
+  | higherOrderFlag γ
+  = lamExpr γ e >>= \case
+      Just e' -> return $ uTop $ F.exprReft $ F.ELam (F.symbol x, sx) e'
+      _ -> return mempty
   where
     sx = typeSort tce $ Ghc.expandTypeSynonyms $ varType x
 lambdaSingleton _ _ _ _
-  = mempty
+  = return mempty
 
 addForAllConstraint :: CGEnv -> Var -> CoreExpr -> SpecType -> CG ()
-addForAllConstraint γ _ _ (RAllT a t r)
-  | F.isTauto r 
+addForAllConstraint γ _ _ (RAllT rtv rt rr)
+  | F.isTauto rr
   = return ()
   | otherwise
-  = do t'       <- true (typeclass (getConfig γ)) t
-       let truet = RAllT a $ unRAllP t'
-       addC (SubC γ (truet mempty) $ truet r) "forall constraint true"
-  where unRAllP (RAllT a t r) = RAllT a (unRAllP t) r  
-        unRAllP (RAllP _ t)   = unRAllP t 
-        unRAllP t             = t 
+  = do t'       <- true (typeclass (getConfig γ)) rt
+       let truet = RAllT rtv $ unRAllP t'
+       addC (SubC γ (truet mempty) $ truet rr) "forall constraint true"
+  where unRAllP (RAllT a t r) = RAllT a (unRAllP t) r
+        unRAllP (RAllP _ t)   = unRAllP t
+        unRAllP t             = t
 addForAllConstraint γ _ _ _
   = impossible (Just $ getLocation γ) "addFunctionConstraint: called on non function argument"
 
-  
+
 addFunctionConstraint :: CGEnv -> Var -> CoreExpr -> SpecType -> CG ()
 addFunctionConstraint γ x e (RFun y i ty t r)
   = do ty'      <- true (typeclass (getConfig γ)) ty
        t'       <- true (typeclass (getConfig γ)) t
        let truet = RFun y i ty' t'
-       case (lamExpr γ e, higherOrderFlag γ) of
-          (Just e', True) -> do tce    <- tyConEmbed <$> get
+       lamE <- lamExpr γ e
+       case (lamE, higherOrderFlag γ) of
+          (Just e', True) -> do tce    <- gets tyConEmbed
                                 let sx  = typeSort tce $ varType x
                                 let ref = uTop $ F.exprReft $ F.ELam (F.symbol x, sx) e'
                                 addC (SubC γ (truet ref) $ truet r)    "function constraint singleton"
@@ -806,6 +809,20 @@
 
 -- [NOTE: PLE-OPT] We *disable* refined instantiation for 
 -- reflected functions inside proofs.
+
+-- If datacon definitions have references to self for fancy termination,
+-- ignore them at the construction. 
+consE γ (Var x) | GM.isDataConId x
+  = do t0 <- varRefType γ x
+       -- NV: The check is expected to fail most times, so 
+       --     it is cheaper than direclty fmap ignoreSelf. 
+       let hasSelf = selfSymbol `elem` F.syms t0
+       let t = if hasSelf
+                then fmap ignoreSelf <$> t0
+                else t0
+       addLocA (Just x) (getLocation γ) (varAnn γ x t)
+       return t
+
 consE γ (Var x)
   = do t <- varRefType γ x
        addLocA (Just x) (getLocation γ) (varAnn γ x t)
@@ -816,17 +833,17 @@
 
 consE γ e'@(App e a@(Type τ))
   = do RAllT α te _ <- checkAll ("Non-all TyApp with expr", e) γ <$> consE γ e
-       t            <- if not (nopolyinfer (getConfig γ)) && isPos α && isGenericVar (ty_var_value α) te 
-                         then freshTy_type (typeclass (getConfig γ)) TypeInstE e τ 
+       t            <- if not (nopolyinfer (getConfig γ)) && isPos α && isGenericVar (ty_var_value α) te
+                         then freshTyType (typeclass (getConfig γ)) TypeInstE e τ
                          else trueTy (typeclass (getConfig γ)) τ
        addW          $ WfC γ t
        t'           <- refreshVV t
-       tt0          <- instantiatePreds γ e' (subsTyVar_meet' (ty_var_value α, t') te)
+       tt0          <- instantiatePreds γ e' (subsTyVarMeet' (ty_var_value α, t') te)
        let tt        = makeSingleton γ (simplify e') $ subsTyReft γ (ty_var_value α) τ tt0
        case rTVarToBind α of
          Just (x, _) -> return $ maybe (checkUnbound γ e' x tt a) (F.subst1 tt . (x,)) (argType τ)
          Nothing     -> return tt
-  where 
+  where
     isPos α = not (extensionality (getConfig γ)) || rtv_is_pol (ty_var_info α)
 
 consE γ e'@(App e a) | Just aDict <- getExprDict γ a
@@ -843,18 +860,18 @@
         addPost γ'        $ maybe (checkUnbound γ' e' x t a) (F.subst1 t . (x,)) (argExpr γ a)
 
 consE γ e'@(App e a)
-  = do ([], πs, te) <- bkUniv <$> consE γ ({- GM.tracePpr ("APP-EXPR: " ++ GM.showPpr (exprType e)) -} e)
-       te'          <- instantiatePreds γ e' $ foldr RAllP te πs
-       (γ', te''')  <- dropExists γ te'
-       te''         <- dropConstraints γ te'''
-       updateLocA (exprLoc e) te''
-       (hasGhost, γ'', te''')     <- instantiateGhosts γ' te''
-       let RFun x _ tx t _ = checkFun ("Non-fun App with caller ", e') γ te'''
+  = do ([], πs, te) <- bkUniv <$> consE γ {- GM.tracePpr ("APP-EXPR: " ++ GM.showPpr (exprType e)) -} e
+       te1        <- instantiatePreds γ e' $ foldr RAllP te πs
+       (γ', te2)  <- dropExists γ te1
+       te3        <- dropConstraints γ te2
+       updateLocA (exprLoc e) te3
+       (hasGhost, γ'', te4)     <- instantiateGhosts γ' te3
+       let RFun x _ tx t _ = checkFun ("Non-fun App with caller ", e') γ te4
        cconsE γ'' a tx
-       tout <- makeSingleton γ'' (simplify e') <$> (addPost γ'' $ maybe (checkUnbound γ'' e' x t a) (F.subst1 t . (x,)) (argExpr γ $ simplify a))
+       tout <- makeSingleton γ'' (simplify e') <$> addPost γ'' (maybe (checkUnbound γ'' e' x t a) (F.subst1 t . (x,)) (argExpr γ $ simplify a))
        if hasGhost
           then do
-           tk   <- freshTy_type (typeclass (getConfig γ)) ImplictE e' $ exprType e'
+           tk   <- freshTyType (typeclass (getConfig γ)) ImplictE e' $ exprType e'
            addW $ WfC γ tk
            addC (SubC γ'' tout tk) ""
            return tk
@@ -866,13 +883,14 @@
        return $ RAllT (makeRTVar $ rTyVar α) t' mempty
 
 consE γ  e@(Lam x e1)
-  = do tx      <- freshTy_type (typeclass (getConfig γ)) LamE (Var x) τx
+  = do tx      <- freshTyType (typeclass (getConfig γ)) LamE (Var x) τx
        γ'      <- γ += ("consE", F.symbol x, tx)
        t1      <- consE γ' e1
        addIdA x $ AnnDef tx
        addW     $ WfC γ tx
-       tce     <- tyConEmbed <$> get
-       return   $ RFun (F.symbol x) (mkRFInfo $ getConfig γ) tx t1 $ lambdaSingleton γ tce x e1
+       tce     <- gets tyConEmbed
+       lamSing <- lambdaSingleton γ tce x e1
+       return   $ RFun (F.symbol x) (mkRFInfo $ getConfig γ) tx t1 lamSing
     where
       FunTy { ft_arg = τx } = exprType e
 
@@ -880,7 +898,7 @@
   = cconsFreshE LetE γ e
 
 consE γ e@(Case _ _ _ [_])
-  | Just p@(Rs.PatProject {}) <- Rs.lift e
+  | Just p@Rs.PatProject{} <- Rs.lift e
   = consPattern γ p (exprType e)
 
 consE γ e@(Case _ _ _ cs)
@@ -944,9 +962,9 @@
 --
 --------------------------------------------------------------------------------
 
-subsTyReft :: CGEnv -> RTyVar -> Type -> SpecType -> SpecType 
-subsTyReft γ a t = mapExprReft (\_ -> F.applyCoSub coSub) 
-  where 
+subsTyReft :: CGEnv -> RTyVar -> Type -> SpecType -> SpecType
+subsTyReft γ a t = mapExprReft (\_ -> F.applyCoSub coSub)
+  where
     coSub        = M.fromList [(F.symbol a, typeSort (emb γ) t)]
 
 --------------------------------------------------------------------------------
@@ -965,8 +983,7 @@
   tx <- checkMonad (msg, e1) γ <$> consE γ e1
   γ' <- γ += ("consPattern", F.symbol x, tx)
   addIdA x (AnnDef tx)
-  mt <- consE γ' e2
-  return mt
+  consE γ' e2
   where
     msg = "This expression has a refined monadic type; run with --no-pattern-inline: "
 
@@ -990,7 +1007,7 @@
 
 consPattern γ (Rs.PatProject xe _ τ c ys i) _ = do
   let yi = ys !! i
-  t    <- (addW . WfC γ) <<= freshTy_type (typeclass (getConfig γ)) ProjectE (Var yi) τ
+  t    <- (addW . WfC γ) <<= freshTyType (typeclass (getConfig γ)) ProjectE (Var yi) τ
   γ'   <- caseEnv γ xe [] (DataAlt c) ys (Just [i])
   ti   <- {- γ' ??= yi -} varRefType γ' yi
   addC (SubC γ' ti t) "consPattern:project"
@@ -999,19 +1016,19 @@
 consPattern γ (Rs.PatSelfBind _ e) _ =
   consE γ e
 
-consPattern γ p@(Rs.PatSelfRecBind {}) _ =
+consPattern γ p@Rs.PatSelfRecBind{} _ =
   cconsFreshE LetE γ (Rs.lower p)
 
-mkRAppTy :: SpecType -> SpecType -> SpecType -> SpecType 
-mkRAppTy mt et (RAppTy _ _ _)    = RAppTy mt et mempty 
-mkRAppTy _  et (RApp c [_] [] _) = RApp c [et] [] mempty 
-mkRAppTy _  _  _                 = panic Nothing $ "Unexpected return-pattern" 
+mkRAppTy :: SpecType -> SpecType -> SpecType -> SpecType
+mkRAppTy mt et RAppTy{}          = RAppTy mt et mempty
+mkRAppTy _  et (RApp c [_] [] _) = RApp c [et] [] mempty
+mkRAppTy _  _  _                 = panic Nothing "Unexpected return-pattern"
 
 checkMonad :: (Outputable a) => (String, a) -> CGEnv -> SpecType -> SpecType
 checkMonad x g = go . unRRTy
  where
    go (RApp _ ts [] _)
-     | length ts > 0 = last ts
+     | not (null ts) = last ts
    go (RAppTy _ t _) = t
    go t              = checkErr x g t
 
@@ -1028,9 +1045,7 @@
 
 castTy γ t e (SymCo (AxiomInstCo ca _ _))
   = do mtc <- lookupNewType (coAxiomTyCon ca)
-       case mtc of
-        Just tc -> cconsE γ e tc
-        Nothing -> return ()
+       F.forM_ mtc (cconsE γ e)
        castTy' γ t e
 
 castTy γ t e _
@@ -1038,17 +1053,17 @@
 
 
 castTy' γ τ (Var x)
-  = do t <- trueTy (typeclass (getConfig γ)) τ
-       -- tx <- varRefType γ x -- NV HERE: the refinements of the var x do not get into the 
-       --                      -- environment. Check 
-       let ce = if typeclass (getConfig γ) && (noADT (getConfig γ)) then F.expr x
-                else eCoerc (typeSort (emb γ) $ Ghc.expandTypeSynonyms $ varType x) 
-                       (typeSort (emb γ) τ) 
-                       $ F.expr x  
-       return ((t `strengthen` (uTop $ F.uexprReft $ ce)) {- `F.meet` tx -})
-  where eCoerc s t e 
+  = do t0 <- trueTy (typeclass (getConfig γ)) τ
+       tx <- varRefType γ x 
+       let t = mergeCastTys t0 tx 
+       let ce = if typeclass (getConfig γ) && noADT (getConfig γ) then F.expr x
+                else eCoerc (typeSort (emb γ) $ Ghc.expandTypeSynonyms $ varType x)
+                       (typeSort (emb γ) τ)
+                       $ F.expr x
+       return (t `strengthen` uTop (F.uexprReft ce) {- `F.meet` tx -})
+  where eCoerc s t e
          | s == t    = e
-         | otherwise = F.ECoerc s t e 
+         | otherwise = F.ECoerc s t e
 
 castTy' γ t (Tick _ e)
   = castTy' γ t e
@@ -1056,7 +1071,25 @@
 castTy' _ _ e
   = panic Nothing $ "castTy cannot handle expr " ++ GM.showPpr e
 
+
 {-
+mergeCastTys tcorrect trefined 
+  tcorrect has the correct GHC skeleton, 
+  trefined has the correct refinements (before coercion)
+  mergeCastTys keeps the trefined when the two GHC types match 
+-}
+
+mergeCastTys :: SpecType -> SpecType -> SpecType 
+mergeCastTys t1 t2 
+  | toType False t1 == toType False t2 
+  = t2 
+mergeCastTys (RApp c1 ts1 ps1 r1) (RApp c2 ts2 _ _) 
+  | c1 == c2 
+  = RApp c1 (zipWith mergeCastTys ts1 ts2) ps1 r1
+mergeCastTys t _ 
+  = t
+
+{-
 showCoercion :: Coercion -> String
 showCoercion (AxiomInstCo co1 co2 co3)
   = "AxiomInstCo " ++ showPpr co1 ++ "\t\t " ++ showPpr co2 ++ "\t\t" ++ showPpr co3 ++ "\n\n" ++
@@ -1115,7 +1148,7 @@
 --------------------------------------------------------------------------------
 cconsFreshE :: KVKind -> CGEnv -> CoreExpr -> CG SpecType
 cconsFreshE kvkind γ e = do
-  t   <- freshTy_type (typeclass (getConfig γ)) kvkind e $ exprType e
+  t   <- freshTyType (typeclass (getConfig γ)) kvkind e $ exprType e
   addW $ WfC γ t
   cconsE γ e t
   return t
@@ -1124,7 +1157,7 @@
 checkUnbound :: (Show a, Show a2, F.Subable a)
              => CGEnv -> CoreExpr -> F.Symbol -> a -> a2 -> a
 checkUnbound γ e x t a
-  | x `notElem` (F.syms t) = t
+  | x `notElem` F.syms t = t
   | otherwise              = panic (Just $ getLocation γ) msg
   where
     msg = unlines [ "checkUnbound: " ++ show x ++ " is elem of syms of " ++ show t
@@ -1136,14 +1169,14 @@
 dropExists γ t            = return (γ, t)
 
 dropConstraints :: CGEnv -> SpecType -> CG SpecType
-dropConstraints γ (RFun x i tx@(RApp c _ _ _) t r) | isErasable c
-  = (flip (RFun x i tx)) r <$> dropConstraints γ t
+dropConstraints cgenv (RFun x i tx@(RApp c _ _ _) t r) | isErasable c
+  = flip (RFun x i tx) r <$> dropConstraints cgenv t
   where
-    isErasable = if typeclass (getConfig γ) then isEmbeddedDict else isClass
-dropConstraints γ (RRTy cts _ OCons t)
-  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("splitS", x,t)) γ xts
+    isErasable = if typeclass (getConfig cgenv) then isEmbeddedDict else isClass
+dropConstraints cgenv (RRTy cts _ OCons rt)
+  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("splitS", x,t)) cgenv xts
        addC (SubC  γ' t1 t2)  "dropConstraints"
-       dropConstraints γ t
+       dropConstraints cgenv rt
   where
     (xts, t1, t2) = envToSub cts
 
@@ -1169,29 +1202,44 @@
 -------------------------------------------------------------------------------------
 caseEnv   :: CGEnv -> Var -> [AltCon] -> AltCon -> [Var] -> Maybe [Int] -> CG CGEnv
 -------------------------------------------------------------------------------------
-caseEnv γ x _   (DataAlt c) ys pIs = do 
+caseEnv γ x _   (DataAlt c) ys pIs = do
 
   let (x' : ys')   = F.symbol <$> (x:ys)
   xt0             <- checkTyCon ("checkTycon cconsCase", x) γ <$> γ ??= x
-  let xt           = shiftVV xt0 x'
-  tdc             <- (γ ??= (dataConWorkId c) >>= refreshVV)
-  let (rtd,yts',_) = unfoldR tdc xt ys
+  let rt           = shiftVV xt0 x'
+  tdc             <- γ ??= dataConWorkId c >>= refreshVV
+  let (rtd,yts',_) = unfoldR tdc rt ys
   yts             <- projectTypes (typeclass (getConfig γ))  pIs yts'
   let ys''         = F.symbol <$> filter (not . if allowTC then GM.isEmbeddedDictVar else GM.isEvVar) ys
   let r1           = dataConReft   c   ys''
   let r2           = dataConMsReft rtd ys''
-  let xt           = (xt0 `F.meet` rtd) `strengthen` (uTop (r1 `F.meet` r2))
-  let cbs          = safeZip "cconsCase" (x':ys') (xt0 : yts)
-  cγ'             <- addBinders γ   x' cbs
-  addBinders cγ' x' [(x', xt)]
+  let xt           = (xt0 `F.meet` rtd) `strengthen` uTop (r1 `F.meet` r2)
+  let cbs          = safeZip "cconsCase" (x':ys')
+                         (map (`F.subst1` (selfSymbol, F.EVar x'))
+                         (xt0 : yts))
+  cγ'             <- addBinders γ x' cbs
+  addBinders cγ' x' [(x', substSelf <$> xt)]
   where allowTC    = typeclass (getConfig γ)
-  
-caseEnv γ x acs a _ _ = do 
+
+caseEnv γ x acs a _ _ = do
   let x'  = F.symbol x
   xt'    <- (`strengthen` uTop (altReft γ acs a)) <$> (γ ??= x)
-  cγ     <- addBinders γ x' [(x', xt')]
-  return cγ
+  addBinders γ x' [(x', xt')]
 
+
+------------------------------------------------------
+-- SELF special substitutions 
+------------------------------------------------------
+
+substSelf :: UReft F.Reft -> UReft F.Reft
+substSelf (MkUReft r p) = MkUReft (substSelfReft r) p
+
+substSelfReft :: F.Reft -> F.Reft
+substSelfReft (F.Reft (v, e)) = F.Reft (v, F.subst1 e (selfSymbol, F.EVar v))
+
+ignoreSelf :: F.Reft -> F.Reft
+ignoreSelf = F.mapExpr (\r -> if selfSymbol `elem` F.syms r then F.PTrue else r)
+
 --------------------------------------------------------------------------------
 -- | `projectTypes` masks (i.e. true's out) all types EXCEPT those
 --   at given indices; it is used to simplify the environment used
@@ -1199,7 +1247,7 @@
 --------------------------------------------------------------------------------
 projectTypes :: Bool -> Maybe [Int] -> [SpecType] -> CG [SpecType]
 projectTypes _ Nothing   ts = return ts
-projectTypes allowTC (Just is) ts = mapM (projT is) (zip [0..] ts)
+projectTypes allowTC (Just ints) ts = mapM (projT ints) (zip [0..] ts)
   where
     projT is (j, t)
       | j `elem` is       = return t
@@ -1221,10 +1269,10 @@
         tbody              = instantiatePvs (instantiateTys td ts) (reverse rs)
         -- TODO: if we ever want to support applying implicits explicitly, will need to rejigger
         ((_,_,_,_),(ys0,_,yts',_), rt) = safeBkArrow (F.notracepp msg $ instantiateTys tbody tvs')
-        msg                = "INST-TY: " ++ F.showpp (td, ts, tbody, ys, tvs') 
+        msg                = "INST-TY: " ++ F.showpp (td, ts, tbody, ys, tvs')
         yts''              = zipWith F.subst sus (yts'++[rt])
         (t3,yts)           = (last yts'', init yts'')
-        sus                = F.mkSubst <$> (L.inits [(x, F.EVar y) | (x, y) <- zip ys0 ys'])
+        sus                = F.mkSubst <$> L.inits [(x, F.EVar y) | (x, y) <- zip ys0 ys']
         (αs, ys')          = mapSnd (F.symbol <$>) $ L.partition isTyVar ys
         tvs' :: [SpecType]
         tvs'               = rVar <$> αs
@@ -1234,27 +1282,27 @@
 
 instantiateTys :: SpecType -> [SpecType] -> SpecType
 instantiateTys = L.foldl' go
-  where 
-    go (RAllT α tbody _) t = subsTyVar_meet' (ty_var_value α, t) tbody
+  where
+    go (RAllT α tbody _) t = subsTyVarMeet' (ty_var_value α, t) tbody
     go _ _                 = panic Nothing "Constraint.instantiateTy"
 
 instantiatePvs :: SpecType -> [SpecProp] -> SpecType
 instantiatePvs           = L.foldl' go
-  where 
+  where
     go (RAllP p tbody) r = replacePreds "instantiatePv" tbody [(p, r)]
     go t               _ = errorP "" ("Constraint.instantiatePvs: t = " ++ showpp t)
 
 checkTyCon :: (Outputable a) => (String, a) -> CGEnv -> SpecType -> SpecType
-checkTyCon _ _ t@(RApp _ _ _ _) = t
-checkTyCon x g t                = checkErr x g t
+checkTyCon _ _ t@RApp{} = t
+checkTyCon x g t        = checkErr x g t
 
 checkFun :: (Outputable a) => (String, a) -> CGEnv -> SpecType -> SpecType
-checkFun _ _ t@(RFun _ _ _ _ _) = t
-checkFun x g t                  = checkErr x g t
+checkFun _ _ t@RFun{} = t
+checkFun x g t        = checkErr x g t
 
 checkAll :: (Outputable a) => (String, a) -> CGEnv -> SpecType -> SpecType
-checkAll _ _ t@(RAllT _ _ _)  = t
-checkAll x g t                = checkErr x g t
+checkAll _ _ t@RAllT{} = t
+checkAll x g t         = checkErr x g t
 
 checkErr :: (Outputable a) => (String, a) -> CGEnv -> SpecType -> SpecType
 checkErr (msg, e) γ t         = panic (Just sp) $ msg ++ GM.showPpr e ++ ", type: " ++ showpp t
@@ -1270,10 +1318,10 @@
 -- | Helpers: Creating Fresh Refinement -------------------------------
 -----------------------------------------------------------------------
 freshPredRef :: CGEnv -> CoreExpr -> PVar RSort -> CG SpecProp
-freshPredRef γ e (PV _ (PVProp τ) _ as)
-  = do t    <- freshTy_type (typeclass (getConfig γ))  PredInstE e (toType False τ)
-       args <- mapM (\_ -> fresh) as
-       let targs = [(x, s) | (x, (s, y, z)) <- zip args as, (F.EVar y) == z ]
+freshPredRef γ e (PV _ (PVProp rsort) _ as)
+  = do t    <- freshTyType (typeclass (getConfig γ))  PredInstE e (toType False rsort)
+       args <- mapM (const fresh) as
+       let targs = [(x, s) | (x, (s, y, z)) <- zip args as, F.EVar y == z ]
        γ' <- foldM (+=) γ [("freshPredRef", x, ofRSort τ) | (x, τ) <- targs]
        addW $ WfC γ' t
        return $ RProp targs t
@@ -1303,29 +1351,18 @@
 argExpr _ (Var v)     = Just $ F.eVar v
 argExpr γ (Lit c)     = snd  $ literalConst (emb γ) c
 argExpr γ (Tick _ e)  = argExpr γ e
-argExpr γ (App e (Type _)) = argExpr γ e 
+argExpr γ (App e (Type _)) = argExpr γ e
 argExpr _ _           = Nothing
 
 
--- NIKI TODO: merge arg/lam/fun-Expr
-lamExpr :: CGEnv -> CoreExpr -> Maybe F.Expr
-lamExpr _ (Var v)     =  Just $ F.eVar v
-lamExpr γ (Lit c)     = snd  $ literalConst (emb γ) c
-lamExpr γ (Tick _ e)  = lamExpr γ e
-lamExpr γ (App e (Type _)) = lamExpr γ e
-lamExpr γ (App e1 e2) = case (lamExpr γ e1, lamExpr γ e2) of
-                              (Just p1, Just p2) | not ((if allowTC then GM.isEmbeddedDictExpr else GM.isPredExpr) e2) -- (isClassPred $ exprType e2)
-                                                 -> Just $ F.EApp p1 p2
-                              (Just p1, Just _ ) -> Just p1
-                              _  -> Nothing
-  where allowTC = typeclass (getConfig γ)
-lamExpr γ (Let (NonRec x ex) e) = case (lamExpr γ ex, lamExpr γ e) of
-                                       (Just px, Just p) -> Just (p `F.subst1` (F.symbol x, px))
-                                       _  -> Nothing
-lamExpr γ (Lam x e)   = case lamExpr γ e of
-                            Just p -> Just $ F.ELam (F.symbol x, typeSort (emb γ) $ Ghc.expandTypeSynonyms $ varType x) p
-                            _ -> Nothing
-lamExpr _ _           = Nothing
+lamExpr :: CGEnv -> CoreExpr -> CG (Maybe F.Expr)
+lamExpr g e = do
+    adts <- gets cgADTs
+    allowTC <- gets cgiTypeclass
+    let dm = dataConMap adts
+    case runToLogic (emb g) mempty dm (\x -> todo Nothing ("coreToLogic not working lamExpr: " ++ x)) (coreToLogic allowTC e) of
+               Left  _  -> return Nothing
+               Right ce -> return (Just ce)
 
 --------------------------------------------------------------------------------
 (??=) :: (?callStack :: CallStack) => CGEnv -> Var -> CG SpecType
@@ -1342,20 +1379,19 @@
 --------------------------------------------------------------------------------
 varRefType :: (?callStack :: CallStack) => CGEnv -> Var -> CG SpecType
 --------------------------------------------------------------------------------
-varRefType γ x = do
-  xt <- varRefType' γ x <$> (γ ??= x)
-  return xt -- F.tracepp (printf "varRefType x = [%s]" (showpp x))
+varRefType γ x =
+  varRefType' γ x <$> (γ ??= x) -- F.tracepp (printf "varRefType x = [%s]" (showpp x))
 
 varRefType' :: CGEnv -> Var -> SpecType -> SpecType
 varRefType' γ x t'
   | Just tys <- trec γ, Just tr  <- M.lookup x' tys
-  = strengthen tr xr
+  = strengthen' tr xr
   | otherwise
-  = strengthen t' xr
+  = strengthen' t' xr
   where
     xr = singletonReft x
     x' = F.symbol x
-    strengthen
+    strengthen'
       | higherOrderFlag γ
       = strengthenMeet
       | otherwise
@@ -1363,26 +1399,26 @@
 
 -- | create singleton types for function application
 makeSingleton :: CGEnv -> CoreExpr -> SpecType -> SpecType
-makeSingleton γ e t
-  | higherOrderFlag γ, App f x <- simplify e
+makeSingleton γ cexpr t
+  | higherOrderFlag γ, App f x <- simplify cexpr
   = case (funExpr γ f, argForAllExpr x) of
       (Just f', Just x')
-                 | not (if (typeclass (getConfig γ)) then GM.isEmbeddedDictExpr x else GM.isPredExpr x) -- (isClassPred $ exprType x)
+                 | not (if typeclass (getConfig γ) then GM.isEmbeddedDictExpr x else GM.isPredExpr x) -- (isClassPred $ exprType x)
                  -> strengthenMeet t (uTop $ F.exprReft (F.EApp f' x'))
       (Just f', Just _)
                  -> strengthenMeet t (uTop $ F.exprReft f')
       _ -> t
   | rankNTypes (getConfig γ)
-  = case argExpr γ (simplify e) of 
-       Just e' -> strengthenMeet t $ (uTop $ F.exprReft e')
-       _       -> t  
+  = case argExpr γ (simplify cexpr) of
+       Just e' -> strengthenMeet t $ uTop (F.exprReft e')
+       _       -> t
   | otherwise
   = t
-  where 
+  where
     argForAllExpr (Var x)
       | rankNTypes (getConfig γ)
       , Just e <- M.lookup x (forallcb γ)
-      = Just e 
+      = Just e
     argForAllExpr e
       = argExpr γ e
 
@@ -1390,7 +1426,7 @@
 
 funExpr :: CGEnv -> CoreExpr -> Maybe F.Expr
 
-funExpr _ (Var v) 
+funExpr _ (Var v)
   = Just $ F.EVar (F.symbol v)
 
 funExpr γ (App e1 e2)
@@ -1408,7 +1444,7 @@
 simplify (Tick _ e)       = simplify e
 simplify (App e (Type _)) = simplify e
 simplify (App e1 e2)      = App (simplify e1) (simplify e2)
-simplify (Lam x e) | isTyVar x = simplify e 
+simplify (Lam x e) | isTyVar x = simplify e
 simplify e                = e
 
 
@@ -1452,8 +1488,8 @@
 
 -- | @isGenericVar@ determines whether the @RTyVar@ has no class constraints
 isGenericVar :: RTyVar -> SpecType -> Bool
-isGenericVar α t =  all (\(c, α') -> (α'/=α) || isGenericClass c ) (classConstrs t)
-  where 
+isGenericVar α st =  all (\(c, α') -> (α'/=α) || isGenericClass c ) (classConstrs st)
+  where
     classConstrs t = [(c, ty_var_value α')
                         | (c, ts) <- tyClasses t
                         , t'      <- ts
@@ -1463,5 +1499,5 @@
 -- instance MonadFail CG where 
 --  fail msg = panic Nothing msg
 
-instance MonadFail Data.Functor.Identity.Identity where 
+instance MonadFail Data.Functor.Identity.Identity where
   fail msg = panic Nothing msg
diff --git a/src/Language/Haskell/Liquid/Constraint/Init.hs b/src/Language/Haskell/Liquid/Constraint/Init.hs
--- a/src/Language/Haskell/Liquid/Constraint/Init.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Init.hs
@@ -1,6 +1,5 @@
 {-# LANGUAGE ScopedTypeVariables       #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE TupleSections             #-}
@@ -17,7 +16,7 @@
 
 import           Prelude                                       hiding (error, undefined)
 import           Control.Monad.State
-import           Data.Maybe                                    (isNothing, fromMaybe, catMaybes)
+import           Data.Maybe                                    (isNothing, fromMaybe, catMaybes, mapMaybe)
 import qualified Data.HashMap.Strict                           as M
 import qualified Data.HashSet                                  as S
 import qualified Data.List                                     as L
@@ -28,9 +27,9 @@
 import           Language.Haskell.Liquid.Constraint.Fresh
 import           Language.Haskell.Liquid.Constraint.Env
 import           Language.Haskell.Liquid.WiredIn               (dictionaryVar)
-import qualified Language.Haskell.Liquid.GHC.SpanStack         as Sp
-import           Language.Haskell.Liquid.GHC.Misc             ( idDataConM, hasBaseTypeVar, isDataConId) -- dropModuleNames, simplesymbol)
-import           Language.Haskell.Liquid.GHC.API               as Ghc hiding (mapSndM)
+import qualified Liquid.GHC.SpanStack         as Sp
+import           Liquid.GHC.Misc             ( idDataConM, hasBaseTypeVar, isDataConId) -- dropModuleNames, simplesymbol)
+import           Liquid.GHC.API               as Ghc hiding (mapSndM)
 import           Language.Haskell.Liquid.Misc
 import           Language.Fixpoint.Misc
 import           Language.Haskell.Liquid.Constraint.Types
@@ -45,7 +44,7 @@
        let fVars = giImpVars (giSrc info)
        let dcs   = filter isConLikeId (snd <$> gsFreeSyms (gsName sp))
        let dcs'  = filter isConLikeId fVars
-       defaults <- forM fVars $ \x -> liftM (x,) (trueTy allowTC $ varType x)
+       defaults <- forM fVars $ \x -> fmap (x,) (trueTy allowTC $ varType x)
        dcsty    <- forM dcs   (makeDataConTypes allowTC)
        dcsty'   <- forM dcs'  (makeDataConTypes allowTC)
        (hs,f0)  <- refreshHoles allowTC $ grty info                           -- asserted refinements     (for defined vars)
@@ -55,60 +54,60 @@
        f1'      <- refreshArgs' $ makeExactDc dcsty                   -- data constructors
        f2       <- refreshArgs' $ assm info                           -- assumed refinements      (for imported vars)
        f3'      <- refreshArgs' =<< recSelectorsTy info                      -- assumed refinements      (for record selectors)
-       f3       <- addPolyInfo' <$> (refreshArgs' $ vals gsAsmSigs (gsSig sp))                 -- assumed refinedments     (with `assume`)
-       f40      <- makeExactDc <$> (refreshArgs' $ vals gsCtors (gsData sp)) -- constructor refinements  (for measures)
+       f3       <- addPolyInfo' <$> refreshArgs' (vals gsAsmSigs (gsSig sp))                 -- assumed refinedments     (with `assume`)
+       f40      <- makeExactDc <$> refreshArgs' (vals gsCtors (gsData sp)) -- constructor refinements  (for measures)
        f5       <- refreshArgs' $ vals gsInSigs (gsSig sp)                   -- internal refinements     (from Haskell measures)
        fi       <- refreshArgs' $ catMaybes $ [(x,) . val <$> getMethodType mt | (x, mt) <- gsMethods $ gsSig $ giSpec info ]
        (invs1, f41) <- mapSndM refreshArgs' $ makeAutoDecrDataCons dcsty  (gsAutosize (gsTerm sp)) dcs
        (invs2, f42) <- mapSndM refreshArgs' $ makeAutoDecrDataCons dcsty' (gsAutosize (gsTerm sp)) dcs'
        let f4    = mergeDataConTypes tce (mergeDataConTypes tce f40 (f41 ++ f42)) (filter (isDataConId . fst) f2)
        let tx    = mapFst F.symbol . addRInv ialias . predsUnify sp
-       f6       <- (map tx . addPolyInfo') <$> (refreshArgs' $ vals gsRefSigs (gsSig sp))  
+       f6       <- map tx . addPolyInfo' <$> refreshArgs' (vals gsRefSigs (gsSig sp))
        let bs    = (tx <$> ) <$> [f0 ++ f0' ++ fi, f1 ++ f1', f2, f3 ++ f3', f4, f5]
        modify $ \s -> s { dataConTys = f4 }
-       lt1s     <- F.toListSEnv . cgLits <$> get
+       lt1s     <- gets (F.toListSEnv . cgLits)
        let lt2s  = [ (F.symbol x, rTypeSort tce t) | (x, t) <- f1' ]
        let tcb   = mapSnd (rTypeSort tce) <$> concat bs
        let cbs   = giCbs . giSrc $ info
-       rTrue   <- mapM (mapSndM (true allowTC)) f6 
+       rTrue   <- mapM (mapSndM (true allowTC)) f6
        let γ0    = measEnv sp (head bs) cbs tcb lt1s lt2s (f6 ++ bs!!3) (bs!!5) hs info
-       γ  <- globalize <$> foldM (+=) γ0 ( [("initEnv", x, y) | (x, y) <- concat $ (rTrue:tail bs)])
+       γ  <- globalize <$> foldM (+=) γ0 ( [("initEnv", x, y) | (x, y) <- concat (rTrue:tail bs)])
        return γ {invs = is (invs1 ++ invs2)}
   where
-    allowTC        = typeclass (getConfig info)
+    allowTC      = typeclass (getConfig info)
     sp           = giSpec info
     ialias       = mkRTyConIAl (gsIaliases (gsData sp))
     vals f       = map (mapSnd val) . f
-    mapSndM f    = \(x,y) -> ((x,) <$> f y)
-    makeExactDc dcs = if exactDCFlag info then map strengthenDataConType dcs else dcs
     is autoinv   = mkRTyConInv    (gsInvariants (gsData sp) ++ ((Nothing,) <$> autoinv))
-    addPolyInfo' = if reflection (getConfig info) then map (mapSnd addPolyInfo) else id 
+    addPolyInfo' = if reflection (getConfig info) then map (mapSnd addPolyInfo) else id
 
+    makeExactDc dcs = if exactDCFlag info then map strengthenDataConType dcs else dcs
+
 addPolyInfo :: SpecType -> SpecType
-addPolyInfo t = mkUnivs (go <$> as) ps t' 
-  where 
-    (as, ps, t') = bkUniv t 
-    pos          = tyVarsPosition t' 
-    go (a,r) = if {- ty_var_value a `elem` ppos pos && -}  ty_var_value a `notElem` pneg pos 
-               then (setRtvPol a False,r)  
-               else (a,r) 
+addPolyInfo t = mkUnivs (go <$> as) ps t'
+  where
+    (as, ps, t') = bkUniv t
+    pos          = tyVarsPosition t'
+    go (a,r) = if {- ty_var_value a `elem` ppos pos && -}  ty_var_value a `notElem` pneg pos
+               then (setRtvPol a False,r)
+               else (a,r)
 
 makeDataConTypes :: Bool -> Var -> CG (Var, SpecType)
-makeDataConTypes allowTC x = (x,) <$> (trueTy allowTC $ varType x)
+makeDataConTypes allowTC x = (x,) <$> trueTy allowTC (varType x)
 
 makeAutoDecrDataCons :: [(Id, SpecType)] -> S.HashSet TyCon -> [Id] -> ([LocSpecType], [(Id, SpecType)])
 makeAutoDecrDataCons dcts specenv dcs
-  = (simplify invs, tys)
+  = (simplify rsorts, tys)
   where
-    (invs, tys) = unzip $ concatMap go tycons
-    tycons      = L.nub $ catMaybes $ map idTyCon dcs
+    (rsorts, tys) = unzip $ concatMap go tycons
+    tycons      = L.nub $ mapMaybe idTyCon dcs
 
     go tycon
       | S.member tycon specenv =  zipWith (makeSizedDataCons dcts) (tyConDataCons tycon) [0..]
     go _
       = []
 
-    simplify invs = dummyLoc . (`strengthen` invariant) .  fmap (\_ -> mempty) <$> L.nub invs
+    simplify invs = dummyLoc . (`strengthen` invariant) .  fmap (const mempty) <$> L.nub invs
     invariant = MkUReft (F.Reft (F.vv_, F.PAtom F.Ge (lenOf F.vv_) (F.ECon $ F.I 0)) ) mempty
 
 idTyCon :: Id -> Maybe TyCon
@@ -121,11 +120,11 @@
 makeSizedDataCons dcts x' n = (toRSort $ ty_res trep, (x, fromRTypeRep trep{ty_res = tres}))
     where
       x      = dataConWorkId x'
-      t      = fromMaybe (impossible Nothing "makeSizedDataCons: this should never happen") $ L.lookup x dcts
-      trep   = toRTypeRep t
+      st     = fromMaybe (impossible Nothing "makeSizedDataCons: this should never happen") $ L.lookup x dcts
+      trep   = toRTypeRep st
       tres   = ty_res trep `strengthen` MkUReft (F.Reft (F.vv_, F.PAtom F.Eq (lenOf F.vv_) computelen)) mempty
 
-      recarguments = filter (\(t,_) -> (toRSort t == toRSort tres)) (zip (ty_args trep) (ty_binds trep))
+      recarguments = filter (\(t,_) -> toRSort t == toRSort tres) (zip (ty_args trep) (ty_binds trep))
       computelen   = foldr (F.EBin F.Plus) (F.ECon $ F.I n) (lenOf .  snd <$> recarguments)
 
 mergeDataConTypes ::  F.TCEmb TyCon -> [(Var, SpecType)] -> [(Var, SpecType)] -> [(Var, SpecType)]
@@ -208,7 +207,7 @@
 assm = assmGrty (giImpVars . giSrc)
 
 grty :: TargetInfo -> [(Var, SpecType)]
-grty = assmGrty (giDefVars . giSrc) 
+grty = assmGrty (giDefVars . giSrc)
 
 assmGrty :: (TargetInfo -> [Var]) -> TargetInfo -> [(Var, SpecType)]
 assmGrty f info = [ (x, val t) | (x, t) <- sigs, x `S.member` xs ]
@@ -224,9 +223,9 @@
     isTop v      = isExportedVar (giSrc info) v && not (v `S.member` sigVs) &&  isRecordSelector v
     sigVs        = S.fromList [v | (v,_) <- gsTySigs sp ++ gsAsmSigs sp ++ gsRefSigs sp ++ gsInSigs sp]
     sp           = gsSig . giSpec $ info
-    
 
 
+
 grtyTop :: TargetInfo -> CG [(Var, SpecType)]
 grtyTop info     = forM topVs $ \v -> (v,) <$> trueTy (typeclass (getConfig info)) (varType v)
   where
@@ -269,9 +268,10 @@
   , termExprs  = M.fromList [(v, es) | (v, _, es) <- gsTexprs (gsSig spc) ]
   , specDecr   = gsDecr  tspc
   , specLVars  = gsLvars (gsVars spc)
-  , specLazy   = dictionaryVar `S.insert` (gsLazy tspc)
+  , specLazy   = dictionaryVar `S.insert` gsLazy tspc
   , specTmVars = gsNonStTerm tspc
   , tcheck     = terminationCheck cfg
+  , cgiTypeclass = typeclass cfg
   , pruneRefs  = pruneUnsorted cfg
   , logErrors  = []
   , kvProf     = emptyKVProf
@@ -283,7 +283,7 @@
   , unsorted   = F.notracepp "UNSORTED" $ F.makeTemplates $ gsUnsorted $ gsData spc
   }
   where
-    tce        = gsTcEmbeds nspc 
+    tce        = gsTcEmbeds nspc
     tspc       = gsTerm spc
     spc        = giSpec info
     tyi        = gsTyconEnv nspc
diff --git a/src/Language/Haskell/Liquid/Constraint/Monad.hs b/src/Language/Haskell/Liquid/Constraint/Monad.hs
--- a/src/Language/Haskell/Liquid/Constraint/Monad.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Monad.hs
@@ -1,10 +1,7 @@
 -- | This module contains various functions that add/update in the CG monad.
 
-{-# LANGUAGE TupleSections             #-}
 {-# LANGUAGE BangPatterns              #-}
-{-# LANGUAGE PatternGuards             #-}
 {-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE ImplicitParams            #-}
 {-# LANGUAGE FlexibleContexts          #-}
 
 module Language.Haskell.Liquid.Constraint.Monad  where
@@ -13,14 +10,14 @@
 import qualified Data.Text           as T
 
 import           Control.Monad
-import           Control.Monad.State (get, modify)
+import           Control.Monad.State (get, gets, modify)
 import           Language.Haskell.Liquid.Types hiding (loc)
 import           Language.Haskell.Liquid.Constraint.Types
 import           Language.Haskell.Liquid.Constraint.Env
 import           Language.Fixpoint.Misc hiding (errorstar)
-import           Language.Haskell.Liquid.GHC.Misc -- (concatMapM)
-import           Language.Haskell.Liquid.GHC.SpanStack (srcSpan)
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding (panic, showPpr)
+import           Liquid.GHC.Misc -- (concatMapM)
+import           Liquid.GHC.SpanStack (srcSpan)
+import           Liquid.GHC.API as Ghc hiding (panic, showPpr)
 
 --------------------------------------------------------------------------------
 -- | `addC` adds a subtyping constraint into the global pool.
@@ -29,11 +26,11 @@
 --------------------------------------------------------------------------------
 addC c@(SubC γ t1 t2) _msg
   | toType False t1 /= toType False t2
-  = panic (Just $ getLocation γ) $ "addC: malformed constraint:\n" ++ _msg ++ showpp t1 ++ "\n <: \n" ++ showpp t2 
+  = panic (Just $ getLocation γ) $ "addC: malformed constraint:\n" ++ _msg ++ showpp t1 ++ "\n <: \n" ++ showpp t2
   | otherwise
-  = modify $ \s -> s { hsCs  = c : (hsCs s) }
- 
+  = modify $ \s -> s { hsCs  = c : hsCs s }
 
+
 addC c _msg
   = modify $ \s -> s { hsCs  = c : hsCs s }
 
@@ -42,29 +39,29 @@
 --------------------------------------------------------------------------------
 addPost :: CGEnv -> SpecType -> CG SpecType
 --------------------------------------------------------------------------------
-addPost γ (RRTy e r OInv t)
-  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("addPost", x,t)) γ e
-       addC (SubR γ' OInv r) "precondition-oinv" >> return t
+addPost cgenv (RRTy e r OInv rt)
+  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("addPost", x,t)) cgenv e
+       addC (SubR γ' OInv r) "precondition-oinv" >> return rt
 
-addPost γ (RRTy e r OTerm t)
-  = do γ' <- foldM (\γ (x, t) -> γ += ("addPost", x, t)) γ e
-       addC (SubR γ' OTerm r) "precondition-oterm" >> return t
+addPost cgenv (RRTy e r OTerm rt)
+  = do γ' <- foldM (\γ (x, t) -> γ += ("addPost", x, t)) cgenv e
+       addC (SubR γ' OTerm r) "precondition-oterm" >> return rt
 
-addPost γ (RRTy cts _ OCons t)
-  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("splitS", x,t)) γ xts
+addPost cgenv (RRTy cts _ OCons rt)
+  = do γ' <- foldM (\γ (x, t) -> γ `addSEnv` ("splitS", x,t)) cgenv xts
        addC (SubC  γ' t1 t2)  "precondition-ocons"
-       addPost γ t
+       addPost cgenv rt
   where
     (xts, t1, t2) = envToSub cts
-addPost _ t 
-  = return t 
+addPost _ t
+  = return t
 
 --------------------------------------------------------------------------------
 -- | Add Well formedness Constraint
 --------------------------------------------------------------------------------
 addW   :: WfC -> CG ()
 --------------------------------------------------------------------------------
-addW !w = modify $ \s -> s { hsWfs = w : (hsWfs s) }
+addW !w = modify $ \s -> s { hsWfs = w : hsWfs s }
 
 --------------------------------------------------------------------------------
 -- | Add a warning
@@ -93,14 +90,14 @@
 
 -- | Used for annotating holes 
 
-addHole :: Var -> SpecType -> CGEnv -> CG () 
-addHole x t γ 
-  | typedHoles (getConfig γ) = 
-      do  st <- get 
+addHole :: Var -> SpecType -> CGEnv -> CG ()
+addHole x t γ
+  | typedHoles (getConfig γ) =
+      do  st <- get
           modify $ \s -> s {holesMap = M.insert x (hinfo (st, γ)) $ holesMap s}
           -- addWarning $ ErrHole loc ("hole found") (reGlobal env <> reLocal env) x' t 
   | otherwise = return ()
-    where 
+    where
       hinfo = HoleInfo t loc env
       loc   = srcSpan $ cgLoc γ
       env   = mconcat [renv γ, grtys γ, assms γ, intys γ]
@@ -129,7 +126,7 @@
 
 lookupNewType :: Ghc.TyCon -> CG (Maybe SpecType)
 lookupNewType tc
-  = M.lookup tc . newTyEnv <$> get
+  = gets (M.lookup tc . newTyEnv)
 
 
 --------------------------------------------------------------------------------
diff --git a/src/Language/Haskell/Liquid/Constraint/Qualifier.hs b/src/Language/Haskell/Liquid/Constraint/Qualifier.hs
--- a/src/Language/Haskell/Liquid/Constraint/Qualifier.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Qualifier.hs
@@ -1,11 +1,11 @@
 {-# LANGUAGE OverloadedStrings     #-}
-{-# LANGUAGE ViewPatterns          #-}
 {-# LANGUAGE PartialTypeSignatures #-}
 {-# LANGUAGE FlexibleContexts      #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
 
 module Language.Haskell.Liquid.Constraint.Qualifier
-  ( giQuals 
+  ( giQuals
   , useSpcQuals
   )
   where
@@ -19,10 +19,10 @@
 import qualified Language.Fixpoint.Types.Config as FC
 import           Language.Fixpoint.SortCheck
 import           Language.Haskell.Liquid.Types.RefType
-import           Language.Haskell.Liquid.GHC.Misc         (getSourcePos)
+import           Liquid.GHC.Misc         (getSourcePos)
 import           Language.Haskell.Liquid.Misc             (condNull)
 import           Language.Haskell.Liquid.Types.PredType
-import           Language.Haskell.Liquid.GHC.API hiding (Expr, mkQual, panic)
+import           Liquid.GHC.API hiding (Expr, mkQual, panic)
 
 import           Language.Haskell.Liquid.Types
 
@@ -62,7 +62,7 @@
 useAlsQuals i = useQuals i && i `hasOpt` higherOrderFlag && not (needQuals i)
 
 useQuals :: (HasConfig t) => t -> Bool
-useQuals = not . (FC.All == ) . eliminate . getConfig
+useQuals = (FC.All /=) . eliminate . getConfig
 
 needQuals :: (HasConfig t) => t -> Bool
 needQuals = (FC.None == ) . eliminate . getConfig
@@ -106,18 +106,18 @@
 qualifyingBinders :: TargetInfo -> S.HashSet Var
 qualifyingBinders info = S.difference sTake sDrop
   where
-    sTake              = S.fromList $ giDefVars src ++ giUseVars src ++ scrapeVars cfg src 
+    sTake              = S.fromList $ giDefVars src ++ giUseVars src ++ scrapeVars cfg src
     sDrop              = S.fromList $ specAxiomVars info
-    cfg                = getConfig info 
-    src                = giSrc     info 
-    
+    cfg                = getConfig info
+    src                = giSrc     info
+
 -- NOTE: this mines extra, useful qualifiers but causes
 -- a significant increase in running time, so we hide it
 -- behind `--scrape-imports` and `--scrape-used-imports`
 scrapeVars :: Config -> TargetSrc -> [Var]
-scrapeVars cfg src 
-  | cfg `hasOpt` scrapeUsedImports = giUseVars src 
-  | cfg `hasOpt` scrapeImports     = giImpVars src 
+scrapeVars cfg src
+  | cfg `hasOpt` scrapeUsedImports = giUseVars src
+  | cfg `hasOpt` scrapeImports     = giImpVars src
   | otherwise                      = []
 
 specBinders :: TargetInfo -> [(Var, LocSpecType)]
@@ -162,7 +162,7 @@
     goBind x t γ t'           = go (add x t γ) t'
     go γ t@(RVar _ _)         = scrape γ t
     go γ (RAllT _ t _)        = go γ t
-    go γ (RAllP p t)          = go (insertSEnv (pname p) (rTypeSort tce $ (pvarRType p :: RSort)) γ) t
+    go γ (RAllP p t)          = go (insertSEnv (pname p) (rTypeSort tce (pvarRType p :: RSort)) γ) t
     go γ t@(RAppTy t1 t2 _)   = go γ t1 ++ go γ t2 ++ scrape γ t
     go γ (RFun x _ t t' _)    = go γ t ++ goBind x t γ t'
     go γ t@(RApp c ts rs _)   = scrape γ t ++ concatMap (go γ') ts ++ goRefs c γ' rs
@@ -189,7 +189,7 @@
                    , pa                        <- conjuncts ra
                    , not $ isHole    pa
                    , not $ isGradual pa
-                   , notracepp ("refTopQuals: " ++ showpp pa) 
+                   , notracepp ("refTopQuals: " ++ showpp pa)
                      $ isNothing $ checkSorted (srcSpan l) (insertSEnv v so γ') pa
     ]
     ++
diff --git a/src/Language/Haskell/Liquid/Constraint/Relational.hs b/src/Language/Haskell/Liquid/Constraint/Relational.hs
new file mode 100644
--- /dev/null
+++ b/src/Language/Haskell/Liquid/Constraint/Relational.hs
@@ -0,0 +1,791 @@
+{-# LANGUAGE FlexibleContexts           #-}
+{-# LANGUAGE FlexibleInstances          #-}
+{-# LANGUAGE MultiParamTypeClasses      #-}
+{-# LANGUAGE NoMonomorphismRestriction  #-}
+{-# LANGUAGE OverloadedStrings          #-}
+{-# LANGUAGE PatternGuards              #-}
+{-# LANGUAGE ScopedTypeVariables        #-}
+
+-- | This module defines the representation of Subtyping and WF Constraints,
+--   and the code for syntax-directed constraint generation.
+
+module Language.Haskell.Liquid.Constraint.Relational (consAssmRel, consRelTop) where
+
+import           Control.Monad.State
+import           Data.Bifunctor                                 ( Bifunctor(bimap) )
+import qualified Data.HashMap.Strict                            as M
+import qualified Data.List                                      as L
+import           Data.String                                    ( IsString(..) )
+import qualified Language.Fixpoint.Types                        as F
+import qualified Language.Fixpoint.Types.Visitor                as F
+import           Language.Haskell.Liquid.Constraint.Env
+import           Language.Haskell.Liquid.Constraint.Fresh
+import           Language.Haskell.Liquid.Constraint.Monad
+import           Language.Haskell.Liquid.Constraint.Types
+import           Liquid.GHC.API                 ( Alt
+                                                , AltCon(..)
+                                                , Bind(..)
+                                                , CoreBind
+                                                , CoreBndr
+                                                , CoreExpr
+                                                , Expr(..)
+                                                , Type(..)
+                                                , TyVar
+                                                , Var(..))
+import qualified Liquid.GHC.API                as Ghc
+import qualified Liquid.GHC.Misc               as GM
+import           Liquid.GHC.Play               (Subable(sub, subTy))
+import qualified Liquid.GHC.SpanStack          as Sp
+import           Liquid.GHC.TypeRep            ()
+import           Language.Haskell.Liquid.Misc
+import           Language.Haskell.Liquid.Types                  hiding (Def,
+                                                                 Loc, binds,
+                                                                 loc)
+import           System.Console.CmdArgs.Verbosity               (whenLoud)
+import           System.IO.Unsafe                               (unsafePerformIO)
+
+data RelPred
+  = RelPred { fun1 :: Var
+            , fun2 :: Var
+            , args1 :: [(F.Symbol, [F.Symbol])]
+            , args2 :: [(F.Symbol, [F.Symbol])]
+            , prop :: RelExpr
+            } deriving Show
+
+type PrEnv = [RelPred]
+
+consAssmRel :: Config -> TargetInfo -> (PrEnv, CGEnv) -> (Var, Var, LocSpecType, LocSpecType, RelExpr, RelExpr) -> CG (PrEnv, CGEnv)
+consAssmRel _ _ (ψ, γ) (x, y, t, s, _, rp) = traceChk "Assm" x y t s p $ do
+  traceWhenLoud ("ASSUME " ++ F.showpp (fromRelExpr p', p)) $ subUnarySig γ' x t'
+  subUnarySig γ' y s'
+  γ'' <- if base t' && base s'
+    then γ' `addPred` F.subst
+      (F.mkSubst [(resL, F.EVar $ F.symbol x), (resR, F.EVar $ F.symbol y)])
+      (fromRelExpr rp)
+    else return γ'
+  return (RelPred x' y' bs cs rp : ψ, γ'')
+ where
+    p = fromRelExpr rp
+    γ' = γ `setLocation` Sp.Span (GM.fSrcSpan (F.loc t))
+    (x', y') = mkRelCopies x y
+    t' = val t
+    s' = val s
+    (vs, ts) = vargs t'
+    (us, ss) = vargs s'
+    bs = zip vs (fst . vargs <$> ts)
+    cs = zip us (fst . vargs <$> ss)
+    p' = L.foldl (\q (v, u) -> unapplyRelArgsR v u q) rp (zip vs us)
+
+consRelTop :: Config -> TargetInfo -> CGEnv -> PrEnv -> (Var, Var, LocSpecType, LocSpecType, RelExpr, RelExpr) -> CG ()
+consRelTop _ ti γ ψ (x, y, t, s, ra, rp) = traceChk "Init" e d t s p $ do
+  subUnarySig γ' x t'
+  subUnarySig γ' y s'
+  consRelCheckBind γ' ψ e d t' s' ra rp
+  where
+    p = fromRelExpr rp
+    γ' = γ `setLocation` Sp.Span (GM.fSrcSpan (F.loc t))
+    cbs = giCbs $ giSrc ti
+    e = lookupBind x cbs
+    d = lookupBind y cbs
+    t' = removeAbsRef $ val t
+    s' = removeAbsRef $ val s
+
+removeAbsRef :: SpecType -> SpecType
+removeAbsRef (RVar v (MkUReft r _)) 
+  = out
+    where 
+      r' = MkUReft r mempty
+      out = RVar  v r' 
+removeAbsRef (RFun  b i s t (MkUReft r _))  
+  = out
+    where 
+      r' = MkUReft r mempty
+      out = RFun  b i (removeAbsRef s) (removeAbsRef t) r'
+removeAbsRef (RImpF b i s t (MkUReft r _))  
+  = out
+    where 
+      r' = MkUReft r mempty
+      out = RImpF b i (removeAbsRef s) (removeAbsRef t) r'
+removeAbsRef (RAllT b t r)      
+  = RAllT b (removeAbsRef t) r
+removeAbsRef (RAllP p t)        
+  = removeAbsRef (forgetRAllP p t)
+removeAbsRef (RApp  (RTyCon c _ i) as _ (MkUReft r _))   
+  = out
+    where 
+      c' = RTyCon c [] i
+      as' = map removeAbsRef as
+      r' = MkUReft r mempty
+      out = RApp c' as' [] r'
+removeAbsRef (RAllE b a t)      
+  = RAllE b (removeAbsRef a) (removeAbsRef t)
+removeAbsRef (REx   b a t)      
+  = REx   b (removeAbsRef a) (removeAbsRef t)
+removeAbsRef (RAppTy s t r)     
+  = RAppTy (removeAbsRef s) (removeAbsRef t) r
+removeAbsRef (RRTy  e r o t)    
+  = RRTy  e r o (removeAbsRef t)
+removeAbsRef t 
+  = t
+
+--------------------------------------------------------------
+-- Core Checking Rules ---------------------------------------
+--------------------------------------------------------------
+
+resL, resR :: F.Symbol
+resL = fromString "r1"
+resR = fromString "r2"
+
+relSuffixL, relSuffixR :: String
+relSuffixL = "l"
+relSuffixR = "r"
+
+-- recursion rule
+consRelCheckBind :: CGEnv -> PrEnv -> CoreBind -> CoreBind -> SpecType -> SpecType -> RelExpr -> RelExpr -> CG ()
+consRelCheckBind γ ψ b1@(NonRec _ e1) b2@(NonRec _ e2) t1 t2 ra rp
+  | Nothing <- args e1 e2 t1 t2 p =
+  traceChk "Bind NonRec" b1 b2 t1 t2 p $ do
+    γ' <- γ `addPred` a
+    consRelCheck γ' ψ e1 e2 t1 t2 p
+  where
+    a = fromRelExpr ra
+    p = fromRelExpr rp
+
+consRelCheckBind γ ψ (NonRec x1 e1) b2 t1 t2 a p =
+  consRelCheckBind γ ψ (Rec [(x1, e1)]) b2 t1 t2 a p
+
+consRelCheckBind γ ψ b1 (NonRec x2 e2) t1 t2 a p =
+  consRelCheckBind γ ψ b1 (Rec [(x2, e2)]) t1 t2 a p
+
+consRelCheckBind γ ψ b1@(Rec [(f1, e1)]) b2@(Rec [(f2, e2)]) t1 t2 ra rp
+  | Just (xs1, xs2, vs1, vs2, ts1, ts2, qs) <- args e1 e2 t1 t2 p
+  = traceChk "Bind Rec" b1 b2 t1 t2 p $ do
+    forM_ (refts t1 ++ refts t2) (\r -> entlFunReft γ r "consRelCheckBind Rec")
+    let xs' = zipWith mkRelCopies xs1 xs2
+    let (xs1', xs2') = unzip xs'
+    let (e1'', e2'') = L.foldl' subRel (e1', e2') (zip xs1 xs2)
+    γ' <- γ += ("Bind Rec f1", F.symbol f1', t1) >>= (+= ("Bind Rec f2", F.symbol f2', t2))
+    γ'' <- foldM (\γγ (x, t) -> γγ += ("Bind Rec x1", F.symbol x, t)) γ' (zip (xs1' ++ xs2') (ts1 ++ ts2))
+    let vs2xs =  F.subst $ F.mkSubst $ zip (vs1 ++ vs2) $ map (F.EVar . F.symbol) (xs1' ++ xs2')
+    let (ho, fo) = partitionArgs xs1 xs2 ts1 ts2 qs
+    γ''' <- γ'' `addPreds` traceWhenLoud ("PRECONDITION " ++ F.showpp (vs2xs (F.PAnd fo)) ++ "\n" ++
+                                          "ASSUMPTION " ++ F.showpp (vs2xs a))
+                              map vs2xs [F.PAnd fo, a]
+    let p' = unapp rp (zip vs1 vs2)
+    let ψ' = ho ++ ψ
+    consRelCheck γ''' ψ' (xbody e1'') (xbody e2'') (vs2xs $ ret t1) (vs2xs $ ret t2) (vs2xs $ concl (fromRelExpr p'))
+  where
+    a = fromRelExpr ra
+    p = fromRelExpr rp
+    (f1', f2') = mkRelCopies f1 f2
+    (e1', e2') = subRelCopies e1 f1 e2 f2
+    unapp :: RelExpr -> [(F.Symbol, F.Symbol)] -> RelExpr
+    unapp = L.foldl' (\p' (v1, v2) -> unapplyRelArgsR v1 v2 p')
+    subRel (e1'', e2'') (x1, x2) = subRelCopies e1'' x1 e2'' x2
+
+consRelCheckBind _ _ (Rec [(_, e1)]) (Rec [(_, e2)]) t1 t2 _ rp
+  = F.panic $ "consRelCheckBind Rec: exprs, types, and pred should have same number of args " ++
+    show (args e1 e2 t1 t2 p)
+    where
+      p = fromRelExpr rp
+
+consRelCheckBind _ _ b1@(Rec _) b2@(Rec _) _ _ _ _
+  = F.panic $ "consRelCheckBind Rec: multiple binders are not supported " ++ F.showpp (b1, b2)
+
+consRelCheck :: CGEnv -> PrEnv -> CoreExpr -> CoreExpr ->
+  SpecType -> SpecType -> F.Expr -> CG ()
+consRelCheck γ ψ (Tick tt e) d t s p =
+  consRelCheck (γ `setLocation` Sp.Tick tt) ψ e d t s p
+
+consRelCheck γ ψ e (Tick tt d) t s p =
+  consRelCheck (γ `setLocation` Sp.Tick tt) ψ e d t s p
+
+consRelCheck γ ψ l1@(Lam α1 e1) e2 rt1@(RAllT s1 t1 r1) t2 p
+  | Ghc.isTyVar α1
+  = traceChk "Lam Type L" l1 e2 rt1 t2 p $ do
+    entlFunReft γ r1 "consRelCheck Lam Type"
+    γ'  <- γ `extendWithTyVar` α1
+    consRelCheck γ' ψ e1 e2 (sb (s1, α1) t1) t2 p
+  where sb (s, α) = subsTyVarMeet' (ty_var_value s, rVar α)
+
+consRelCheck γ ψ e1 l2@(Lam α2 e2) t1 rt2@(RAllT s2 t2 r2) p
+  | Ghc.isTyVar α2
+  = traceChk "Lam Type" e1 l2 t1 rt2 p $ do
+    entlFunReft γ r2 "consRelCheck Lam Type"
+    γ'  <- γ `extendWithTyVar` α2
+    consRelCheck γ' ψ e1 e2 t1 (sb (s2, α2) t2) p
+  where sb (s, α) = subsTyVarMeet' (ty_var_value s, rVar α)
+
+consRelCheck γ ψ l1@(Lam α1 e1) l2@(Lam α2 e2) rt1@(RAllT s1 t1 r1) rt2@(RAllT s2 t2 r2) p
+  | Ghc.isTyVar α1 && Ghc.isTyVar α2
+  = traceChk "Lam Type" l1 l2 rt1 rt2 p $ do
+    entlFunRefts γ r1 r2 "consRelCheck Lam Type"
+    γ'  <- γ `extendWithTyVar` α1
+    γ'' <- γ' `extendWithTyVar` α2
+    consRelCheck γ'' ψ e1 e2 (sb (s1, α1) t1) (sb (s2, α2) t2) p
+  where sb (s, α) = subsTyVarMeet' (ty_var_value s, rVar α)
+
+consRelCheck γ ψ l1@(Lam x1 e1) l2@(Lam x2 e2) rt1@(RFun v1 _ s1 t1 r1) rt2@(RFun v2 _ s2 t2 r2) pr@(F.PImp q p)
+  = traceChk "Lam Expr" l1 l2 rt1 rt2 pr $ do
+    entlFunRefts γ r1 r2 "consRelCheck Lam Expr"
+    let (pvar1, pvar2) = (F.symbol evar1, F.symbol evar2)
+    let subst = F.subst $ F.mkSubst [(v1, F.EVar pvar1), (v2, F.EVar pvar2)]
+    γ'  <- γ += ("consRelCheck Lam L", pvar1, subst s1)
+    γ'' <- γ' += ("consRelCheck Lam R", pvar2, subst s2)
+    let p'    = unapplyRelArgs v1 v2 p
+    let (ho, fo) = partitionArg x1 x2 s1 s2 q
+    γ''' <- γ'' `addPreds` traceWhenLoud ("PRECONDITION " ++ F.showpp (map subst fo)) map subst fo
+    consRelCheck γ''' (ho ++ ψ) e1' e2' (subst t1) (subst t2) (subst p')
+  where
+    (evar1, evar2) = mkRelCopies x1 x2
+    (e1', e2')     = subRelCopies e1 x1 e2 x2
+
+consRelCheck γ ψ l1@(Let (NonRec x1 d1) e1) l2@(Let (NonRec x2 d2) e2) t1 t2 p
+  = traceChk "Let" l1 l2 t1 t2 p $ do
+    (s1, s2, _) <- consRelSynth γ ψ d1 d2
+    let (evar1, evar2) = mkRelCopies x1 x2
+    let (e1', e2')     = subRelCopies e1 x1 e2 x2
+    γ'  <- γ += ("consRelCheck Let L", F.symbol evar1, s1)
+    γ'' <- γ' += ("consRelCheck Let R", F.symbol evar2, s2)
+    consRelCheck γ'' ψ e1' e2' t1 t2 p
+  
+
+consRelCheck γ ψ l1@(Let (Rec []) e1) l2@(Let (Rec []) e2) t1 t2 p
+  = traceChk "Let Rec Nil" l1 l2 t1 t2 p $ do
+    consRelCheck γ ψ e1 e2 t1 t2 p
+
+consRelCheck γ ψ l1@(Let (Rec ((x1, d1):bs1)) e1) l2@(Let (Rec ((x2, d2):bs2)) e2) t1 t2 p
+  = traceChk "Let Rec Cons" l1 l2 t1 t2 p $ do
+    (s1, s2, _) <- consRelSynth γ ψ d1 d2
+    let (evar1, evar2) = mkRelCopies x1 x2
+    let (e1', e2')     = subRelCopies e1 x1 e2 x2
+    γ'  <- γ += ("consRelCheck Let L", F.symbol evar1, s1)
+    γ'' <- γ' += ("consRelCheck Let R", F.symbol evar2, s2)
+    consRelCheck γ'' ψ (Let (Rec bs1) e1') (Let (Rec bs2) e2') t1 t2 p
+
+consRelCheck γ ψ c1@(Case e1 x1 _ alts1) e2 t1 t2 p =
+  traceChk "Case Async L" c1 e2 t1 t2 p $ do
+    s1 <- consUnarySynth γ e1
+    γ' <- γ += ("consRelCheck Case Async L", x1', s1)
+    forM_ alts1 $ consRelCheckAltAsyncL γ' ψ t1 t2 p x1' s1 e2
+  where
+    x1' = F.symbol $ mkCopyWithSuffix relSuffixL x1
+
+consRelCheck γ ψ e1 c2@(Case e2 x2 _ alts2) t1 t2 p =
+  traceChk "Case Async R" e1 c2 t1 t2 p $ do
+    s2 <- consUnarySynth γ e2
+    γ' <- γ += ("consRelCheck Case Async R", x2', s2)
+    forM_ alts2 $ consRelCheckAltAsyncR γ' ψ t1 t2 p e1 x2' s2
+  where
+    x2' = F.symbol $ mkCopyWithSuffix relSuffixR x2
+
+consRelCheck γ ψ e d t1 t2 p =
+  traceChk "Synth" e d t1 t2 p $ do
+  (s1, s2, qs) <- consRelSynth γ ψ e d
+  let psubst = F.substf (matchFunArgs t1 s1) . F.substf (matchFunArgs t2 s2)
+  consRelSub γ s1 s2 (F.PAnd qs) (psubst p)
+  addC (SubC γ s1 t1) ("consRelCheck (Synth): s1 = " ++ F.showpp s1 ++ " t1 = " ++ F.showpp t1)
+  addC (SubC γ s2 t2) ("consRelCheck (Synth): s2 = " ++ F.showpp s2 ++ " t2 = " ++ F.showpp t2)
+
+consExtAltEnv :: CGEnv -> F.Symbol -> SpecType -> AltCon -> [Var] -> CoreExpr -> String -> CG (CGEnv, CoreExpr)
+consExtAltEnv γ x s c bs e suf = do
+  ct <- ctorTy γ c s
+  unapply γ x s bs (removeAbsRef ct) e suf
+
+consRelCheckAltAsyncL :: CGEnv -> PrEnv -> SpecType -> SpecType -> F.Expr ->
+  F.Symbol -> SpecType -> CoreExpr -> Alt CoreBndr -> CG ()
+consRelCheckAltAsyncL γ ψ t1 t2 p x1 s1 e2 (c, bs1, e1) = do
+  (γ', e1') <- consExtAltEnv γ x1 s1 c bs1 e1 relSuffixL
+  consRelCheck γ' ψ e1' e2 t1 t2 p
+
+consRelCheckAltAsyncR :: CGEnv -> PrEnv -> SpecType -> SpecType -> F.Expr ->
+  CoreExpr -> F.Symbol -> SpecType -> Alt CoreBndr -> CG ()
+consRelCheckAltAsyncR γ ψ t1 t2 p e1 x2 s2 (c, bs2, e2) = do
+  (γ', e2') <- consExtAltEnv γ x2 s2 c bs2 e2 relSuffixR
+  consRelCheck γ' ψ e1 e2' t1 t2 p
+
+ctorTy :: CGEnv -> AltCon -> SpecType -> CG SpecType
+ctorTy γ (DataAlt c) (RApp _ ts _ _)
+  | Just ct <- mbct = refreshTy $ ct `instantiateTys` ts
+  | Nothing <- mbct = F.panic $ "ctorTy: data constructor out of scope" ++ F.showpp c
+  where mbct = γ ?= F.symbol (Ghc.dataConWorkId c)
+ctorTy _ (DataAlt _) t =
+  F.panic $ "ctorTy: type " ++ F.showpp t ++ " doesn't have top-level data constructor"
+ctorTy _ (LitAlt c) _ = return $ uTop <$> literalFRefType c
+ctorTy _ DEFAULT t = return t
+
+unapply :: CGEnv -> F.Symbol -> SpecType -> [Var] -> SpecType -> CoreExpr -> String -> CG (CGEnv, CoreExpr)
+unapply γ y yt (z : zs) (RFun x _ s t _) e suffix = do
+  γ' <- γ += ("unapply arg", evar, s)
+  unapply γ' y yt zs (t `F.subst1` (x, F.EVar evar)) e' suffix
+  where
+    z' = mkCopyWithSuffix suffix z
+    evar = F.symbol z'
+    e' = subVarAndTy z z' e
+unapply _ _ _ (_ : _) t _ _ = F.panic $ "can't unapply type " ++ F.showpp t
+unapply γ y yt [] t e _ = do
+  let yt' = t `F.meet` yt
+  γ' <- γ += ("unapply res", y, yt')
+  return $ traceWhenLoud ("SCRUTINEE " ++ F.showpp (y, yt')) (γ', e)
+
+instantiateTys :: SpecType -> [SpecType] -> SpecType
+instantiateTys = L.foldl' go
+ where
+  go (RAllT α tbody _) t = subsTyVarMeet' (ty_var_value α, t) tbody
+  go tbody             t =
+    F.panic $ "instantiateTys: non-polymorphic type " ++ F.showpp tbody ++ " to instantiate with " ++ F.showpp t
+
+--------------------------------------------------------------
+-- Core Synthesis Rules --------------------------------------
+--------------------------------------------------------------
+
+consRelSynth :: CGEnv -> PrEnv -> CoreExpr -> CoreExpr -> CG (SpecType, SpecType, [F.Expr])
+consRelSynth γ ψ (Tick tt e) d =
+  consRelSynth (γ `setLocation` Sp.Tick tt) ψ e d
+
+consRelSynth γ ψ e (Tick tt d) =
+  consRelSynth (γ `setLocation` Sp.Tick tt) ψ e d
+
+consRelSynth γ ψ a1@(App e1 d1) e2 | Type t1 <- GM.unTickExpr d1 =
+  traceSyn "App Ty L" a1 e2 $ do
+    (ft1', t2, ps) <- consRelSynth γ ψ e1 e2
+    let (α1, ft1, _) = unRAllT ft1' "consRelSynth App Ty L"
+    t1' <- trueTy (typeclass (getConfig γ)) t1
+    return (subsTyVarMeet' (ty_var_value α1, t1') ft1, t2, ps)
+
+consRelSynth γ ψ e1 a2@(App e2 d2) | Type t2 <- GM.unTickExpr d2 =
+  traceSyn "App Ty R" e1 a2 $ do
+    (t1, ft2', ps) <- consRelSynth γ ψ e1 e2
+    let (α2, ft2, _) = unRAllT ft2' "consRelSynth App Ty R"
+    t2' <- trueTy (typeclass (getConfig γ)) t2
+    return (t1, subsTyVarMeet' (ty_var_value α2, t2') ft2, ps)
+
+consRelSynth γ ψ a1@(App e1 d1) a2@(App e2 d2) = traceSyn "App Exp Exp" a1 a2 $ do
+  (ft1, ft2, fps) <- consRelSynth γ ψ e1 e2
+  (t1, t2, ps) <- consRelSynthApp γ ψ ft1 ft2 fps d1 d2
+  return (t1, t2, ps)
+
+consRelSynth γ ψ e d = traceSyn "Unary" e d $ do
+  t <- consUnarySynth γ e >>= refreshTy
+  s <- consUnarySynth γ d >>= refreshTy
+  let ps = lookupRelSig ψ e d t s
+  return (t, s, traceWhenLoud ("consRelSynth Unary synthed preds:" ++ F.showpp ps) ps)
+    
+lookupRelSig :: PrEnv -> CoreExpr -> CoreExpr -> SpecType -> SpecType -> [F.Expr] 
+lookupRelSig ψ (Var x1) (Var x2) t1 t2 = concatMap match ψ
+  where 
+    match :: RelPred -> [F.Expr]
+    match (RelPred f1 f2 bs1 bs2 p) | f1 == x1, f2 == x2 = 
+        let (vs1, ts1') = vargs t1
+            (vs2, ts2') = vargs t2
+            vs1' = concatMap (fst . vargs) ts1'
+            vs2' = concatMap (fst . vargs) ts2'
+            bs1' = concatMap snd bs1
+            bs2' = concatMap snd bs2
+            bs2vs = F.mkSubst $ zip (map fst bs1 ++ map fst bs2 ++ bs1' ++ bs2') $ map F.EVar (vs1 ++ vs2 ++ vs1' ++ vs2')
+          in [F.subst bs2vs (fromRelExpr p)]
+    match _ = []
+lookupRelSig _ _ _ _ _ = []
+
+consRelSynthApp :: CGEnv -> PrEnv -> SpecType -> SpecType ->
+  [F.Expr] -> CoreExpr -> CoreExpr -> CG (SpecType, SpecType, [F.Expr])
+consRelSynthApp γ ψ ft1 ft2 ps e1 (Tick _ e2) =
+  consRelSynthApp γ ψ ft1 ft2 ps e1 e2
+consRelSynthApp γ ψ ft1 ft2 ps (Tick t1 e1) e2 =
+  consRelSynthApp (γ `setLocation` Sp.Tick t1) ψ ft1 ft2 ps e1 e2
+
+consRelSynthApp γ ψ ft1@(RFun v1 _ s1 t1 r1) ft2@(RFun v2 _ s2 t2 r2) ps@[F.PImp q p] d1@(Var x1) d2@(Var x2)
+  = traceSynApp ft1 ft2 ps d1 d2 $ do
+    entlFunRefts γ r1 r2 "consRelSynthApp HO"
+    let qsubst = F.subst $ F.mkSubst [(v1, F.EVar resL), (v2, F.EVar resR)]
+    consRelCheck γ ψ d1 d2 s1 s2 (qsubst q)
+    let subst = F.subst $ F.mkSubst [(v1, F.EVar $ F.symbol x1), (v2, F.EVar $ F.symbol x2)]
+    return (subst t1, subst t2, [(subst . unapplyRelArgs v1 v2) p])
+consRelSynthApp γ ψ ft1@(RFun v1 _ s1 t1 r1) ft2@(RFun v2 _ s2 t2 r2) ps@[] d1@(Var x1) d2@(Var x2)
+  = traceSynApp ft1 ft2 ps d1 d2 $ do
+    entlFunRefts γ r1 r2 "consRelSynthApp FO"
+    consUnaryCheck γ d1 s1
+    consUnaryCheck γ d2 s2
+    (_, _, qs) <- consRelSynth γ ψ d1 d2
+    let subst =
+          F.subst $ F.mkSubst
+            [(v1, F.EVar $ F.symbol x1), (v2, F.EVar $ F.symbol x2)]
+    return (subst t1, subst t2, map subst qs)
+consRelSynthApp _ _ RFun{} RFun{} ps d1@(Var _) d2@(Var _)
+  = F.panic $ "consRelSynthApp: multiple rel sigs not supported " ++ F.showpp (ps, d1, d2)
+consRelSynthApp _ _ RFun{} RFun{} _ d1 d2 =
+  F.panic $ "consRelSynthApp: expected application to variables, got" ++ F.showpp (d1, d2)
+consRelSynthApp _ _ t1 t2 p d1 d2 =
+  F.panic $ "consRelSynthApp: malformed function types or predicate for arguments " ++ F.showpp (t1, t2, p, d1, d2)
+
+--------------------------------------------------------------
+-- Unary Rules -----------------------------------------------
+--------------------------------------------------------------
+
+symbolType :: CGEnv -> Var -> String -> SpecType
+symbolType γ x msg
+  | Just t <- γ ?= F.symbol x = t
+  | otherwise = F.panic $ msg ++ " " ++ F.showpp x ++ " not in scope " ++ F.showpp γ
+
+consUnarySynth :: CGEnv -> CoreExpr -> CG SpecType
+consUnarySynth γ (Tick t e) = consUnarySynth (γ `setLocation` Sp.Tick t) e
+consUnarySynth γ (Var x) = return $ traceWhenLoud ("SELFIFICATION " ++ F.showpp (x, removeAbsRef $ selfify t x)) removeAbsRef $ selfify t x
+  where t = symbolType γ x "consUnarySynth (Var)"
+consUnarySynth _ e@(Lit c) =
+  traceUSyn "Lit" e $ do
+  return $ removeAbsRef $ uRType $ literalFRefType c
+consUnarySynth γ e@(Let _ _) =
+  traceUSyn "Let" e $ do
+  t   <- freshTyType (typeclass (getConfig γ)) LetE e $ Ghc.exprType e
+  addW $ WfC γ t
+  consUnaryCheck γ e t
+  return $ removeAbsRef t
+consUnarySynth γ e'@(App e d) =
+  traceUSyn "App" e' $ do
+  et <- consUnarySynth γ e
+  consUnarySynthApp γ et d
+consUnarySynth γ e'@(Lam α e) | Ghc.isTyVar α =
+                             traceUSyn "LamTyp" e' $ do
+  γ' <- γ `extendWithTyVar` α
+  t' <- consUnarySynth γ' e
+  return $ removeAbsRef $ RAllT (makeRTVar $ rTyVar α) t' mempty
+consUnarySynth γ e@(Lam x d)  =
+  traceUSyn "Lam" e $ do
+  let Ghc.FunTy { ft_arg = s' } = checkFun e $ Ghc.exprType e
+  s  <- freshTyType (typeclass (getConfig γ)) LamE (Var x) s'
+  γ' <- γ += ("consUnarySynth (Lam)", F.symbol x, s)
+  t  <- consUnarySynth γ' d
+  addW $ WfC γ s
+  return $ removeAbsRef $ RFun (F.symbol x) (mkRFInfo $ getConfig γ) s t mempty
+consUnarySynth γ e@(Case _ _ _ alts) =
+  traceUSyn "Case" e $ do
+  t   <- freshTyType (typeclass (getConfig γ)) (caseKVKind alts) e $ Ghc.exprType e
+  addW $ WfC γ t
+  return $ removeAbsRef t
+consUnarySynth _ e@(Cast _ _) = F.panic $ "consUnarySynth is undefined for Cast " ++ F.showpp e
+consUnarySynth _ e@(Type _) = F.panic $ "consUnarySynth is undefined for Type " ++ F.showpp e
+consUnarySynth _ e@(Coercion _) = F.panic $ "consUnarySynth is undefined for Coercion " ++ F.showpp e
+
+caseKVKind :: [Alt Var] -> KVKind
+caseKVKind [(DataAlt _, _, Var _)] = ProjectE
+caseKVKind cs                      = CaseE (length cs)
+
+checkFun :: CoreExpr -> Type -> Type
+checkFun _ t@Ghc.FunTy{} = t
+checkFun e t = F.panic $ "FunTy was expected but got " ++ F.showpp t ++ "\t for expression" ++ F.showpp e
+
+base :: SpecType -> Bool
+base RApp{} = True
+base RVar{} = True
+base _      = False
+
+selfifyExpr :: SpecType -> F.Expr -> Maybe SpecType
+selfifyExpr (RFun v i s t r) f = (\t' -> RFun v i s t' r) <$> selfifyExpr t (F.EApp f (F.EVar v))
+selfifyExpr t e | base t = Just $ t `strengthen` eq e
+  where eq = uTop . F.exprReft
+selfifyExpr _ _ = Nothing
+
+selfify :: F.Symbolic a => SpecType -> a -> SpecType
+selfify t x | base t = t `strengthen` eq x
+  where eq = uTop . F.symbolReft . F.symbol
+selfify t e | Just t' <- selfifyExpr t (F.EVar $ F.symbol e) = t'
+selfify t _ = t
+
+consUnarySynthApp :: CGEnv -> SpecType -> CoreExpr -> CG SpecType
+consUnarySynthApp γ t (Tick y e) = do
+  consUnarySynthApp (γ `setLocation` Sp.Tick y) t e
+consUnarySynthApp γ (RFun x _ s t _) d@(Var y) = do
+  consUnaryCheck γ d s
+  return $ t `F.subst1` (x, F.EVar $ F.symbol y)
+consUnarySynthApp γ (RAllT α t _) (Type s) = do
+    s' <- trueTy (typeclass (getConfig γ)) s
+    return $ subsTyVarMeet' (ty_var_value α, s') t
+consUnarySynthApp _ RFun{} d =
+  F.panic $ "consUnarySynthApp expected Var as a funciton arg, got " ++ F.showpp d
+consUnarySynthApp γ t@(RAllP{}) e
+  = consUnarySynthApp γ (removeAbsRef t) e
+
+consUnarySynthApp _ ft d =
+  F.panic $ "consUnarySynthApp malformed function type " ++ F.showpp ft ++
+            " for argument " ++ F.showpp d
+
+consUnaryCheck :: CGEnv -> CoreExpr -> SpecType -> CG ()
+consUnaryCheck γ (Let (NonRec x d) e) t = do
+  s <- consUnarySynth γ d
+  γ' <- γ += ("consUnaryCheck Let", F.symbol x, s)
+  consUnaryCheck γ' e t
+consUnaryCheck γ e t = do
+  s <- consUnarySynth γ e
+  addC (SubC γ s t) ("consUnaryCheck (Synth): s = " ++ F.showpp s ++ " t = " ++ F.showpp t)
+
+--------------------------------------------------------------
+-- Rel. Predicate Subtyping  ---------------------------------
+--------------------------------------------------------------
+
+consRelSub :: CGEnv -> SpecType -> SpecType -> F.Expr -> F.Expr -> CG ()
+consRelSub γ f1@(RFun g1 _ s1@RFun{} t1 _) f2@(RFun g2 _ s2@RFun{} t2 _)
+             pr1@(F.PImp qr1@F.PImp{} p1)  pr2@(F.PImp qr2@F.PImp{} p2)
+  = traceSub "hof" f1 f2 pr1 pr2 $ do
+    consRelSub γ s1 s2 qr2 qr1
+    γ' <- γ += ("consRelSub HOF", F.symbol g1, s1)
+    γ'' <- γ' += ("consRelSub HOF", F.symbol g2, s2)
+    let psubst = unapplyArg resL g1 <> unapplyArg resR g2
+    consRelSub γ'' t1 t2 (psubst p1) (psubst p2)
+consRelSub γ f1@(RFun g1 _ s1@RFun{} t1 _) f2@(RFun g2 _ s2@RFun{} t2 _)
+             pr1@(F.PAnd [F.PImp qr1@F.PImp{} p1])            pr2@(F.PImp qr2@F.PImp{} p2)
+  = traceSub "hof" f1 f2 pr1 pr2 $ do
+    consRelSub γ s1 s2 qr2 qr1
+    γ' <- γ += ("consRelSub HOF", F.symbol g1, s1)
+    γ'' <- γ' += ("consRelSub HOF", F.symbol g2, s2)
+    let psubst = unapplyArg resL g1 <> unapplyArg resR g2
+    consRelSub γ'' t1 t2 (psubst p1) (psubst p2)
+consRelSub γ f1@(RFun x1 _ s1 e1 _) f2 p1 p2 =
+  traceSub "fun" f1 f2 p1 p2 $ do
+    γ' <- γ += ("consRelSub RFun L", F.symbol x1, s1)
+    let psubst = unapplyArg resL x1
+    consRelSub γ' e1 f2 (psubst p1) (psubst p2)
+consRelSub γ f1 f2@(RFun x2 _ s2 e2 _) p1 p2 =
+  traceSub "fun" f1 f2 p1 p2 $ do
+    γ' <- γ += ("consRelSub RFun R", F.symbol x2, s2)
+    let psubst = unapplyArg resR x2
+    consRelSub γ' f1 e2 (psubst p1) (psubst p2)
+consRelSub γ t1 t2 p1 p2 | isBase t1 && isBase t2 =
+  traceSub "base" t1 t2 p1 p2 $ do
+    rl <- fresh
+    rr <- fresh
+    γ' <- γ += ("consRelSub Base L", rl, t1)
+    γ'' <- γ' += ("consRelSub Base R", rr, t2)
+    let cstr = F.subst (F.mkSubst [(resL, F.EVar rl), (resR, F.EVar rr)]) $ F.PImp p1 p2
+    entl γ'' (traceWhenLoud ("consRelSub Base cstr " ++ F.showpp cstr) cstr) "consRelSub Base"
+consRelSub _ t1@(RHole _) t2@(RHole _) _ _ = F.panic $ "consRelSub is undefined for RHole " ++ show (t1, t2)
+consRelSub _ t1@(RExprArg _) t2@(RExprArg _) _ _ = F.panic $ "consRelSub is undefined for RExprArg " ++ show (t1, t2)
+consRelSub _ t1@REx {} t2@REx {} _ _ = F.panic $ "consRelSub is undefined for REx " ++ show (t1, t2)
+consRelSub _ t1@RAllE {} t2@RAllE {} _ _ = F.panic $ "consRelSub is undefined for RAllE " ++ show (t1, t2)
+consRelSub _ t1@RRTy {} t2@RRTy {} _ _ = F.panic $ "consRelSub is undefined for RRTy " ++ show (t1, t2)
+consRelSub _ t1@RAllP {} t2@RAllP {} _ _ = F.panic $ "consRelSub is undefined for RAllP " ++ show (t1, t2)
+consRelSub _ t1@RAllT {} t2@RAllT {} _ _ = F.panic $ "consRelSub is undefined for RAllT " ++ show (t1, t2)
+consRelSub _ t1@RImpF {} t2@RImpF {} _ _ = F.panic $ "consRelSub is undefined for RImpF " ++ show (t1, t2)
+consRelSub _ t1 t2 _ _ =  F.panic $ "consRelSub is undefined for different types " ++ show (t1, t2)
+
+--------------------------------------------------------------
+-- Helper Definitions ----------------------------------------
+--------------------------------------------------------------
+
+isFuncPred :: F.Expr -> Bool
+isFuncPred (F.PImp _ _) = True
+isFuncPred _            = False
+
+partitionArg :: Var -> Var -> SpecType -> SpecType -> F.Expr -> (PrEnv, [F.Expr])
+partitionArg x1 x2 s1 s2 q = partitionArgs [x1] [x2] [s1] [s2] [q]
+
+partitionArgs :: [Var] -> [Var] -> [SpecType] -> [SpecType] -> [F.Expr] -> (PrEnv, [F.Expr])
+partitionArgs xs1 xs2 ts1 ts2 qs = (map toRel ho, map toUnary fo)
+ where
+  (ho, fo) = L.partition (isFuncPred . toUnary) (zip5 xs1 xs2 ts1 ts2 qs)
+  toRel (f1, f2, t1, t2, q) =
+    let (vs1, ts1') = vargs t1
+    in  let (vs2, ts2') = vargs t2
+        in  let bs1 = zip vs1 (fst . vargs <$> ts1')
+            in  let bs2 = zip vs2 (fst . vargs <$> ts2')
+                in  let rp = RelPred f1 f2 bs1 bs2 $ ERBasic q
+                    in traceWhenLoud ("partitionArgs toRel: " ++ F.showpp (f1, f2, bs1, bs2, q)) rp
+  toUnary (_, _, _, _, q) = q
+
+unRAllT :: SpecType -> String -> (RTVU RTyCon RTyVar, SpecType, RReft)
+unRAllT (RAllT α2 ft2 r2) _ = (α2, ft2, r2)
+unRAllT t msg = F.panic $ msg ++ ": expected RAllT, got: " ++ F.showpp t
+
+forgetRAllP :: PVU RTyCon RTyVar -> SpecType -> SpecType
+forgetRAllP _ t = t
+
+args :: CoreExpr -> CoreExpr -> SpecType -> SpecType -> F.Expr ->
+  Maybe ([Var], [Var], [F.Symbol], [F.Symbol], [SpecType], [SpecType], [F.Expr])
+args e1 e2 t1 t2 ps
+  | xs1 <- xargs e1, xs2 <- xargs e2,
+    (vs1, ts1) <- vargs t1, (vs2, ts2) <- vargs t2,
+    qs  <- prems ps,
+    all (length qs ==) [length xs1, length xs2, length vs1, length vs2, length ts1, length ts2]
+  = Just (xs1, xs2, vs1, vs2, ts1, ts2, qs)
+args e1 e2 t1 t2 ps = traceWhenLoud ("args guard" ++ F.showpp (xargs e1, xargs e2, vargs t1, vargs t2, prems ps)) Nothing
+
+xargs :: CoreExpr -> [Var]
+xargs (Tick _ e) = xargs e
+xargs (Lam  x e) | Ghc.isTyVar x = xargs e
+xargs (Lam  x e) = x : xargs e
+xargs _          = []
+
+xbody :: CoreExpr -> CoreExpr
+xbody (Tick _ e) = xbody e
+xbody (Lam  _ e) = xbody e
+xbody e          = e
+
+refts :: SpecType -> [RReft]
+refts (RAllT _ t r ) = r : refts t
+refts (RFun _ _ _ t r) = r : refts t
+refts _              = []
+
+vargs :: SpecType -> ([F.Symbol], [SpecType])
+vargs (RAllT _ t _ ) = vargs t
+vargs (RFun v _ s t _) = bimap (v :) (s :) $ vargs t
+vargs _              = ([], [])
+
+ret :: SpecType -> SpecType
+ret (RAllT _ t _ ) = ret t
+ret (RFun _ _ _ t _) = ret t
+ret t              = t
+
+prems :: F.Expr -> [F.Expr]
+prems (F.PImp q p) = q : prems p
+prems _            = []
+
+concl :: F.Expr -> F.Expr
+concl (F.PImp _ p) = concl p
+concl p            = p
+
+extendWithTyVar :: CGEnv -> TyVar -> CG CGEnv
+extendWithTyVar γ a
+  | isValKind (Ghc.tyVarKind a)
+  = γ += ("extendWithTyVar", F.symbol a, kindToRType $ Ghc.tyVarKind a)
+  | otherwise
+  = return γ
+
+matchFunArgs :: SpecType -> SpecType -> F.Symbol -> F.Expr
+matchFunArgs (RAllT _ t1 _) t2 x = matchFunArgs t1 t2 x
+matchFunArgs t1 (RAllT _ t2 _) x = matchFunArgs t1 t2 x
+matchFunArgs (RFun x1 _ _ t1 _) (RFun x2 _ _ t2 _) x =
+  if x == x1 then F.EVar x2 else matchFunArgs t1 t2 x
+matchFunArgs t1 t2 x | isBase t1 && isBase t2 = F.EVar x
+matchFunArgs t1 t2 _ = F.panic $ "matchFunArgs undefined for " ++ F.showpp (t1, t2)
+
+entl :: CGEnv -> F.Expr -> String -> CG ()
+entl γ p = addC (SubR γ OCons $ uReft (F.vv_, F.PIff (F.EVar F.vv_) p))
+
+entlFunReft :: CGEnv -> RReft -> String -> CG ()
+entlFunReft γ r msg = do
+  entl γ (F.reftPred $ ur_reft r) $ "entlFunRefts " ++ msg
+
+entlFunRefts :: CGEnv -> RReft -> RReft -> String -> CG ()
+entlFunRefts γ r1 r2 msg = do
+  entlFunReft γ r1 $ msg ++ " L"
+  entlFunReft γ r2 $ msg ++ " R"
+
+subRelCopies :: CoreExpr -> Var -> CoreExpr -> Var -> (CoreExpr, CoreExpr)
+subRelCopies e1 x1 e2 x2 = (subVarAndTy x1 evar1 e1, subVarAndTy x2 evar2 e2)
+  where (evar1, evar2) = mkRelCopies x1 x2
+
+subVarAndTy :: Var -> Var -> CoreExpr -> CoreExpr
+subVarAndTy x v = subTy (M.singleton x $ TyVarTy v) . sub (M.singleton x $ Var v)
+
+mkRelCopies :: Var -> Var -> (Var, Var)
+mkRelCopies x1 x2 = (mkCopyWithSuffix relSuffixL x1, mkCopyWithSuffix relSuffixR x2)
+
+mkCopyWithName :: String -> Var -> Var
+mkCopyWithName s v =
+  Ghc.setVarName v $ Ghc.mkSystemName (Ghc.getUnique v) (Ghc.mkVarOcc s)
+
+mkCopyWithSuffix :: String -> Var -> Var
+mkCopyWithSuffix s v = mkCopyWithName (Ghc.getOccString v ++ s) v
+
+lookupBind :: Var -> [CoreBind] -> CoreBind
+lookupBind x bs = case lookup x (concatMap binds bs) of
+  Nothing -> F.panic $ "Not found definition for " ++ show x
+  Just e  -> e
+ where
+  binds b@(NonRec x' _) = [ (x', b) ]
+  binds   (Rec bs'    ) = [ (x', Rec [(x',e)]) | (x',e) <- bs' ]
+
+subUnarySig :: CGEnv -> Var -> SpecType -> CG ()
+subUnarySig γ x tRel =
+  forM_ mkargs $ \(rt, ut) -> addC (SubC γ ut rt) $ "subUnarySig tUn = " ++ F.showpp ut ++ " tRel = " ++ F.showpp rt
+  where
+    mkargs = zip (snd $ vargs tRel) (snd $ vargs tUn)
+    tUn = symbolType γ x $ "subUnarySig " ++ F.showpp x
+
+addPred :: CGEnv -> F.Expr -> CG CGEnv
+addPred γ p = extendWithExprs γ [p]
+
+addPreds :: CGEnv -> [F.Expr] -> CG CGEnv
+addPreds = extendWithExprs
+
+extendWithExprs :: CGEnv -> [F.Expr] -> CG CGEnv
+extendWithExprs γ ps = do
+  dummy <- fresh
+  let reft = uReft (F.vv_, F.PAnd ps)
+  γ += ("extend with predicate env", dummy, RVar (symbolRTyVar F.dummySymbol) reft)
+
+unapplyArg :: F.Symbol -> F.Symbol -> F.Expr -> F.Expr
+unapplyArg f y e = F.mapExpr sb e
+  where
+    sb :: F.Expr -> F.Expr
+    sb (F.EApp (F.EVar r) (F.EVar x))
+      | r == f && x == y = F.EVar r
+    sb e' = e'
+
+unapplyRelArgs :: F.Symbol -> F.Symbol -> F.Expr -> F.Expr
+unapplyRelArgs x1 x2 = unapplyArg resL x1 . unapplyArg resR x2
+
+unapplyRelArgsR :: F.Symbol -> F.Symbol -> RelExpr -> RelExpr
+unapplyRelArgsR x1 x2 (ERBasic e) = ERBasic (unapplyRelArgs x1 x2 e)
+unapplyRelArgsR x1 x2 (ERChecked e re) = ERChecked (unapplyRelArgs x1 x2 e) (unapplyRelArgsR x1 x2 re)
+unapplyRelArgsR x1 x2 (ERUnChecked e re) = ERUnChecked (unapplyRelArgs x1 x2 e) (unapplyRelArgsR x1 x2 re)
+
+--------------------------------------------------------------
+-- RelExpr & F.Expr ------------------------------------------
+--------------------------------------------------------------
+
+fromRelExpr :: RelExpr -> F.Expr
+fromRelExpr (ERBasic e) = e
+fromRelExpr (ERChecked a b) = F.PImp a (fromRelExpr b)
+fromRelExpr (ERUnChecked a b) = F.PImp a (fromRelExpr b)
+
+--------------------------------------------------------------
+-- Debug -----------------------------------------------------
+--------------------------------------------------------------
+
+
+traceSub :: (PPrint t, PPrint s, PPrint p, PPrint q) => String -> t -> s -> p -> q -> a -> a
+traceSub msg t s p q = traceWhenLoud (msg ++ " RelSub\n"
+                      ++ "t: " ++ F.showpp t ++ "\n\n"
+                      ++ "s: " ++ F.showpp s ++ "\n\n"
+                      ++ "p: " ++ F.showpp p ++ "\n\n"
+                      ++ "q: " ++ F.showpp q)
+
+
+traceChk
+  :: (PPrint e, PPrint d, PPrint t, PPrint s, PPrint p)
+  => String -> e -> d -> t -> s -> p -> a -> a
+traceChk expr = trace (expr ++ " To CHECK")
+
+traceSyn
+  :: (PPrint e, PPrint d, PPrint a, PPrint b, PPrint c)
+  => String -> e -> d -> CG (a, b, c) -> CG (a, b, c)
+traceSyn expr e d cg
+  = do
+    (a, b, c) <- cg
+    trace (expr ++ " To SYNTH") e d a b c cg
+
+traceSynApp
+  :: (PPrint e, PPrint d, PPrint a, PPrint b, PPrint c)
+  => e -> d -> a -> b -> c -> t -> t
+traceSynApp = trace "SYNTH APP TO "
+
+traceUSyn
+  :: (PPrint e, PPrint a)
+  => String -> e -> CG a -> CG a
+traceUSyn expr e cg = do
+  t <- cg
+  trace (expr ++ " To SYNTH UNARY") e dummy t dummy dummy cg
+  where dummy = F.PTrue
+
+trace
+  :: (PPrint e, PPrint d, PPrint t, PPrint s, PPrint p)
+  => String -> e -> d -> t -> s -> p -> a -> a
+trace msg e d t s p = traceWhenLoud (msg ++ "\n"
+                      ++ "e: " ++ F.showpp e ++ "\n\n"
+                      ++ "d: " ++ F.showpp d ++ "\n\n"
+                      ++ "t: " ++ F.showpp t ++ "\n\n"
+                      ++ "s: " ++ F.showpp s ++ "\n\n"
+                      ++ "p: " ++ F.showpp p)
+
+traceWhenLoud :: String -> a -> a
+traceWhenLoud s a = unsafePerformIO $ whenLoud (putStrLn s) >> return a
diff --git a/src/Language/Haskell/Liquid/Constraint/Split.hs b/src/Language/Haskell/Liquid/Constraint/Split.hs
--- a/src/Language/Haskell/Liquid/Constraint/Split.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Split.hs
@@ -1,8 +1,9 @@
-{-# LANGUAGE ImplicitParams        #-}
 {-# LANGUAGE OverloadedStrings     #-}
 {-# LANGUAGE PartialTypeSignatures #-}
 {-# LANGUAGE FlexibleContexts      #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 --------------------------------------------------------------------------------
 -- | Constraint Splitting ------------------------------------------------------
 --------------------------------------------------------------------------------
@@ -28,9 +29,9 @@
 
 import           Text.PrettyPrint.HughesPJ hiding (first, parens)
 
-import           Data.Maybe          (fromMaybe) 
+import           Data.Maybe          (fromMaybe)
 import           Control.Monad
-import           Control.Monad.State (get)
+import           Control.Monad.State (gets)
 import qualified Control.Exception as Ex
 
 import qualified Language.Fixpoint.Types            as F
@@ -103,7 +104,7 @@
         return $ ws ++ ws'
 
 splitW (WfC γ (RRTy _ _ _ t))
-  = splitW (WfC γ t) 
+  = splitW (WfC γ t)
 
 splitW (WfC _ t)
   = panic Nothing $ "splitW cannot handle: " ++ showpp t
@@ -122,7 +123,7 @@
 bsplitW :: CGEnv -> SpecType -> CG [FixWfC]
 bsplitW γ t =
   do temp  <- getTemplates
-     isHO  <- allowHO   <$> get
+     isHO  <- gets allowHO
      return $ bsplitW' γ t temp isHO
 
 bsplitW' :: (PPrint r, F.Reftable r, SubsTy RTyVar RSort r, F.Reftable (RTProp RTyCon RTyVar r))
@@ -245,7 +246,7 @@
        cs' <- splitC allowTC $ SubC γ' t1 (F.subst su t2'')
        return (cs ++ cs')
   where
-    t2'' = subsTyVar_meet' (ty_var_value α2, RVar (ty_var_value α1) mempty) t2
+    t2'' = subsTyVarMeet' (ty_var_value α2, RVar (ty_var_value α1) mempty) t2
     su = case (rTVarToBind α1, rTVarToBind α2) of
           (Just (x1, _), Just (x2, _)) -> F.mkSubst [(x1, F.EVar x2)]
           _                            -> F.mkSubst []
@@ -253,10 +254,10 @@
 splitC allowTC (SubC _ (RApp c1 _ _ _) (RApp c2 _ _ _)) | (if allowTC then isEmbeddedDict else isClass) c1 && c1 == c2
   = return []
 
-splitC _ (SubC γ t1@(RApp _ _ _ _) t2@(RApp _ _ _ _))
+splitC _ (SubC γ t1@RApp{} t2@RApp{})
   = do (t1',t2') <- unifyVV t1 t2
        cs    <- bsplitC γ t1' t2'
-       γ'    <- if (bscope (getConfig γ)) then γ `extendEnvWithVV` t1' else return γ
+       γ'    <- if bscope (getConfig γ) then γ `extendEnvWithVV` t1' else return γ
        let RApp c t1s r1s _ = t1'
        let RApp _ t2s r2s _ = t2'
        let isapplied = True -- TC.tyConArity (rtc_tc c) == length t1s
@@ -289,9 +290,9 @@
     src = getLocation γ
     g   = reLocal $ renv γ
 
-traceTy :: SpecType -> String 
+traceTy :: SpecType -> String
 traceTy (RVar v _)      = parens ("RVar " ++ showpp v)
-traceTy (RApp c ts _ _) = parens ("RApp " ++ showpp c ++ unwords (traceTy <$> ts)) 
+traceTy (RApp c ts _ _) = parens ("RApp " ++ showpp c ++ unwords (traceTy <$> ts))
 traceTy (RAllP _ t)     = parens ("RAllP " ++ traceTy t)
 traceTy (RAllT _ t _)   = parens ("RAllT " ++ traceTy t)
 traceTy (RImpF _ _ t t' _) = parens ("RImpF " ++ parens (traceTy t) ++ parens (traceTy t'))
@@ -316,7 +317,7 @@
                     -> [Variance]
                     -> CG [FixSubC]
 splitsCWithVariance γ t1s t2s variants
-  = concatMapM (\(t1, t2, v) -> splitfWithVariance (\s1 s2 -> (splitC (typeclass (getConfig γ)) (SubC γ s1 s2))) t1 t2 v) (zip3 t1s t2s variants)
+  = concatMapM (\(t1, t2, v) -> splitfWithVariance (\s1 s2 -> splitC (typeclass (getConfig γ)) (SubC γ s1 s2)) t1 t2 v) (zip3 t1s t2s variants)
 
 rsplitsCWithVariance :: Bool
                      -> CGEnv
@@ -336,7 +337,7 @@
         -> CG [F.SubC Cinfo]
 bsplitC γ t1 t2 = do
   temp   <- getTemplates
-  isHO   <- allowHO   <$> get
+  isHO   <- gets allowHO
   t1'    <- addLhsInv γ <$> refreshVV t1
   return  $ bsplitC' γ t1' t2 temp isHO
 
@@ -363,12 +364,13 @@
     γ'  = feBinds $ fenv γ
     r1' = rTypeSortedReft' γ tem t1
     r2' = rTypeSortedReft' γ tem t2
-    ci  = \sr -> Ci src (err sr) (cgVar γ)
     tag = getTag γ
-    err = \sr -> Just $ fromMaybe (ErrSubType src (text "subtype") Nothing g t1 (replaceTop t2 sr)) (cerr γ)
     src = getLocation γ
     g   = reLocal $ renv γ
 
+    ci sr  = Ci src (err sr) (cgVar γ)
+    err sr = Just $ fromMaybe (ErrSubType src (text "subtype") Nothing g t1 (replaceTop t2 sr)) (cerr γ)
+
 mkSubC :: F.IBindEnv -> F.SortedReft -> F.SortedReft -> F.Tag -> (F.SortedReft -> a) -> [F.SubC a]
 mkSubC g sr1 sr2 tag ci = concatMap (\sr2' -> F.subC g sr1 sr2' Nothing tag (ci sr2')) (splitSortedReft sr2)
 
@@ -393,12 +395,12 @@
     F.Reft (vr,p)         = r
 
 unifyVV :: SpecType -> SpecType -> CG (SpecType, SpecType)
-unifyVV t1@(RApp _ _ _ _) t2@(RApp _ _ _ _)
-  = do vv     <- (F.vv . Just) <$> fresh
-       return  $ (shiftVV t1 vv,  (shiftVV t2 vv) )
+unifyVV t1@RApp{} t2@RApp{}
+  = do vv <- F.vv . Just <$> fresh
+       return (shiftVV t1 vv, shiftVV t2 vv)
 
 unifyVV _ _
-  = panic Nothing $ "Constraint.Generate.unifyVV called on invalid inputs"
+  = panic Nothing "Constraint.Generate.unifyVV called on invalid inputs"
 
 rsplitC :: CGEnv
         -> SpecProp
@@ -420,7 +422,7 @@
 -- | Reftypes from F.Fixpoint Expressions --------------------------------------
 --------------------------------------------------------------------------------
 forallExprRefType     :: CGEnv -> SpecType -> SpecType
-forallExprRefType γ t = t `strengthen` (uTop r')
+forallExprRefType γ t = t `strengthen` uTop r'
   where
     r'                = fromMaybe mempty $ forallExprReft γ r
     r                 = F.sr_reft $ rTypeSortedReft (emb γ) t
@@ -465,4 +467,4 @@
 -- | Constraint Generation Panic -----------------------------------------------
 --------------------------------------------------------------------------------
 panicUnbound :: (PPrint x) => CGEnv -> x -> a
-panicUnbound γ x = Ex.throw $ (ErrUnbound (getLocation γ) (F.pprint x) :: Error)
+panicUnbound γ x = Ex.throw (ErrUnbound (getLocation γ) (F.pprint x) :: Error)
diff --git a/src/Language/Haskell/Liquid/Constraint/ToFixpoint.hs b/src/Language/Haskell/Liquid/Constraint/ToFixpoint.hs
--- a/src/Language/Haskell/Liquid/Constraint/ToFixpoint.hs
+++ b/src/Language/Haskell/Liquid/Constraint/ToFixpoint.hs
@@ -1,4 +1,7 @@
 {-# LANGUAGE FlexibleContexts          #-}
+
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Constraint.ToFixpoint
   ( cgInfoFInfo
   , fixConfig
@@ -7,8 +10,8 @@
   ) where
 
 import           Prelude hiding (error)
-import qualified Language.Haskell.Liquid.GHC.API as Ghc
-import           Language.Haskell.Liquid.GHC.API (Var, Id, TyCon)
+import qualified Liquid.GHC.API as Ghc
+import           Liquid.GHC.API (Var, Id, TyCon)
 import qualified Language.Fixpoint.Types.Config as FC
 import           System.Console.CmdArgs.Default (def)
 import qualified Language.Fixpoint.Types        as F
@@ -23,7 +26,7 @@
 -- imports for AxiomEnv
 import qualified Language.Haskell.Liquid.UX.Config as Config
 import           Language.Haskell.Liquid.UX.DiffCheck (coreDefs, coreDeps, dependsOn, Def(..))
-import qualified Language.Haskell.Liquid.GHC.Misc  as GM -- (simplesymbol)
+import qualified Liquid.GHC.Misc  as GM -- (simplesymbol)
 import qualified Data.List                         as L
 import qualified Data.HashMap.Strict               as M
 import qualified Data.HashSet                      as S
@@ -47,14 +50,16 @@
   , FC.elimBound                = elimBound         cfg
   , FC.allowHO                  = higherOrderFlag   cfg
   , FC.allowHOqs                = higherorderqs     cfg
-  , FC.smtTimeout               = smtTimeout        cfg 
+  , FC.smtTimeout               = smtTimeout        cfg
   , FC.stringTheory             = stringTheory      cfg
   , FC.gradual                  = gradual           cfg
   , FC.ginteractive             = ginteractive       cfg
   , FC.noslice                  = noslice           cfg
   , FC.rewriteAxioms            = Config.allowPLE   cfg
+  , FC.pleWithUndecidedGuards   = Config.pleWithUndecidedGuards cfg
   , FC.etaElim                  = not (exactDC cfg) && extensionality cfg -- SEE: https://github.com/ucsd-progsys/liquidhaskell/issues/1601
-  , FC.extensionality           = extensionality    cfg 
+  , FC.extensionality           = extensionality    cfg
+  , FC.interpreter              = interpreter    cfg
   , FC.oldPLE                   = oldPLE cfg
   , FC.rwTerminationCheck       = rwTerminationCheck cfg
   , FC.noLazyPLE                = noLazyPLE cfg
@@ -88,18 +93,18 @@
 
 makeAxiomEnvironment :: TargetInfo -> [(Var, SpecType)] -> M.HashMap F.SubcId (F.SubC Cinfo) -> F.AxiomEnv
 makeAxiomEnvironment info xts fcs
-  = F.AEnv eqs  
+  = F.AEnv eqs
            (concatMap makeSimplify xts)
            (doExpand sp cfg <$> fcs)
            (makeRewrites info <$> fcs)
   where
     eqs      = if oldPLE cfg
                 then makeEquations (typeclass cfg) sp ++ map (uncurry $ specTypeEq emb) xts
-                else axioms  
+                else axioms
     emb      = gsTcEmbeds (gsName sp)
     cfg      = getConfig  info
     sp       = giSpec     info
-    axioms   = gsMyAxioms refl ++ gsImpAxioms refl 
+    axioms   = gsMyAxioms refl ++ gsImpAxioms refl
     refl     = gsRefl sp
 
 
@@ -119,7 +124,7 @@
         Nothing ->
           Mb.listToMaybe $ do
             D s e v <- coreDefs $ giCbs $ giSrc info
-            let (Ghc.RealSrcSpan cc _) = (ci_loc $ F.sinfo sub)
+            let (Ghc.RealSrcSpan cc _) = ci_loc $ F.sinfo sub
             guard $ s <= Ghc.srcSpanStartLine cc && e >= Ghc.srcSpanEndLine cc
             return v
 
@@ -160,9 +165,9 @@
       []
   where
     tres = ty_res tRep
-    tRep = toRTypeRep $ val t 
-  
-makeRewriteOne :: (F.TCEmb TyCon) -> (Var, LocSpecType) -> [F.AutoRewrite]
+    tRep = toRTypeRep $ val t
+
+makeRewriteOne :: F.TCEmb TyCon -> (Var, LocSpecType) -> [F.AutoRewrite]
 makeRewriteOne tce (_, t)
   = [rw | (lhs, rhs) <- refinementEQs t , rw <- rewrites lhs rhs ]
   where
@@ -178,16 +183,15 @@
       (sym, arg) <- zip (ty_binds tRep) (ty_args tRep)
       let e = maybe F.PTrue (F.reftPred . F.toReft) (stripRTypeBase arg)
       return $ F.RR (rTypeSort tce arg) (F.Reft (sym, e))
-       
-    tRep = toRTypeRep $ val t 
 
+    tRep = toRTypeRep $ val t
+
 _isClassOrDict :: Id -> Bool
-_isClassOrDict x = F.tracepp ("isClassOrDict: " ++ F.showpp x) 
-                    $ (hasClassArg x || GM.isDictionary x || Mb.isJust (Ghc.isClassOpId_maybe x))
+_isClassOrDict x = F.tracepp ("isClassOrDict: " ++ F.showpp x) (hasClassArg x || GM.isDictionary x || Mb.isJust (Ghc.isClassOpId_maybe x))
 
 hasClassArg :: Id -> Bool
-hasClassArg x = F.tracepp msg $ (GM.isDataConId x && any Ghc.isClassPred (t:ts'))
-  where 
+hasClassArg x = F.tracepp msg (GM.isDataConId x && any Ghc.isClassPred (t:ts'))
+  where
     msg       = "hasClassArg: " ++ showpp (x, t:ts')
     (ts, t)   = Ghc.splitFunTys . snd . Ghc.splitForAllTys . Ghc.varType $ x
     ts'       = map Ghc.irrelevantMult ts
@@ -217,8 +221,8 @@
 makeSimplify :: (Var, SpecType) -> [F.Rewrite]
 makeSimplify (x, t)
   | not (GM.isDataConId x)
-  = [] 
-  | otherwise 
+  = []
+  | otherwise
   = go $ specTypeToResultRef (F.eApps (F.EVar $ F.symbol x) (F.EVar <$> ty_binds (toRTypeRep t))) t
   where
     go (F.PAnd es) = concatMap go es
@@ -226,13 +230,13 @@
     go (F.PAtom eq (F.EApp (F.EVar f) dc) bd)
       | eq `elem` [F.Eq, F.Ueq]
       , (F.EVar dc, xs) <- F.splitEApp dc
-      , dc == F.symbol x 
+      , dc == F.symbol x
       , all isEVar xs
       = [F.SMeasure f dc (fromEVar <$> xs) bd]
 
     go (F.PIff (F.EApp (F.EVar f) dc) bd)
       | (F.EVar dc, xs) <- F.splitEApp dc
-      , dc == F.symbol x 
+      , dc == F.symbol x
       , all isEVar xs
       = [F.SMeasure f dc (fromEVar <$> xs) bd]
 
@@ -258,12 +262,12 @@
 
 makeEquations :: Bool -> TargetSpec -> [F.Equation]
 makeEquations allowTC sp = [ F.mkEquation f xts (equationBody allowTC (F.EVar f) xArgs e mbT) t
-                      | F.Equ f xts e t _ <- axioms 
+                      | F.Equ f xts e t _ <- axioms
                       , let xArgs          = F.EVar . fst <$> xts
                       , let mbT            = if null xArgs then Nothing else M.lookup f sigs
                    ]
   where
-    axioms       = gsMyAxioms refl ++ gsImpAxioms refl 
+    axioms       = gsMyAxioms refl ++ gsImpAxioms refl
     refl         = gsRefl sp
     sigs         = M.fromList [ (GM.simplesymbol v, t) | (v, t) <- gsTySigs (gsSig sp) ]
 
@@ -293,9 +297,9 @@
     okClass = all (F.isTauto . snd) cls
     okArgs  = all okArg ts
 
-    okArg (RVar _ _)       = True
-    okArg t@(RApp _ _ _ _) = F.isTauto (t{rt_reft = mempty})
-    okArg _                = False
+    okArg (RVar _ _) = True
+    okArg t@RApp{}   = F.isTauto (t{rt_reft = mempty})
+    okArg _          = False
 
 
     su           = F.mkSubst $ zip xs es
diff --git a/src/Language/Haskell/Liquid/Constraint/Types.hs b/src/Language/Haskell/Liquid/Constraint/Types.hs
--- a/src/Language/Haskell/Liquid/Constraint/Types.hs
+++ b/src/Language/Haskell/Liquid/Constraint/Types.hs
@@ -1,10 +1,9 @@
 {-# LANGUAGE OverloadedStrings    #-}
 {-# LANGUAGE FlexibleContexts     #-}
 {-# LANGUAGE TupleSections        #-}
-{-# LANGUAGE EmptyDataDecls       #-}
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
 
 module Language.Haskell.Liquid.Constraint.Types
   ( -- * Constraint Generation Monad
@@ -58,16 +57,16 @@
   ) where
 
 import Prelude hiding (error)
-import           Text.PrettyPrint.HughesPJ hiding ((<>)) 
+import           Text.PrettyPrint.HughesPJ hiding ((<>))
 import qualified Data.HashMap.Strict as M
 import qualified Data.HashSet        as S
 import qualified Data.List           as L
 import           Control.DeepSeq
-import           Data.Maybe               (catMaybes, isJust)
+import           Data.Maybe               (isJust, mapMaybe)
 import           Control.Monad.State
 
-import           Language.Haskell.Liquid.GHC.SpanStack
-import           Language.Haskell.Liquid.GHC.API    as Ghc hiding ( (<+>)
+import           Liquid.GHC.SpanStack
+import           Liquid.GHC.API    as Ghc hiding ( (<+>)
                                                                   , vcat
                                                                   , parens
                                                                   , ($+$)
@@ -104,7 +103,7 @@
   , tgKey  :: !(Maybe Tg.TagKey)                     -- ^ Current top-level binder
   , trec   :: !(Maybe (M.HashMap F.Symbol SpecType)) -- ^ Type of recursive function with decreasing constraints
   , lcb    :: !(M.HashMap F.Symbol CoreExpr)         -- ^ Let binding that have not been checked (c.f. LAZYVARs)
-  , forallcb :: !(M.HashMap Var F.Expr)              -- ^ Polymorhic let bindings 
+  , forallcb :: !(M.HashMap Var F.Expr)              -- ^ Polymorhic let bindings
   , holes  :: !HEnv                                  -- ^ Types with holes, will need refreshing
   , lcs    :: !LConstraint                           -- ^ Logical Constraints
   , cerr   :: !(Maybe (TError SpecType))             -- ^ error that should be reported at the user
@@ -115,7 +114,7 @@
 instance HasConfig CGEnv where
   getConfig = getConfig . cgInfo
 
-data LConstraint = LC [[(F.Symbol, SpecType)]]
+newtype LConstraint = LC [[(F.Symbol, SpecType)]]
 
 instance Monoid LConstraint where
   mempty  = LC []
@@ -151,15 +150,15 @@
 data WfC      = WfC  !CGEnv !SpecType
               -- deriving (Data, Typeable)
 
-type FixSubC  = F.SubC Cinfo
-type FixWfC   = F.WfC Cinfo
-
+type FixSubC    = F.SubC Cinfo
+type FixWfC     = F.WfC Cinfo
+type FixBindEnv = F.BindEnv Cinfo
 
 subVar :: FixSubC -> Maybe Var
 subVar = ci_var . F.sinfo
 
 instance PPrint SubC where
-  pprintTidy k c@(SubC {}) =
+  pprintTidy k c@SubC {} =
     "The environment:"
     $+$
     ""
@@ -178,7 +177,7 @@
                    , "<:"
                    , pprintTidy k (rhs c) ]
 
-  pprintTidy k c@(SubR {}) =
+  pprintTidy k c@SubR {} =
     "The environment:"
     $+$
     ""
@@ -203,24 +202,24 @@
 --------------------------------------------------------------------------------
 -- | Generation: Types ---------------------------------------------------------
 --------------------------------------------------------------------------------
-data CGInfo = CGInfo 
+data CGInfo = CGInfo
   { fEnv       :: !(F.SEnv F.Sort)             -- ^ top-level fixpoint env
   , hsCs       :: ![SubC]                      -- ^ subtyping constraints over RType
   , hsWfs      :: ![WfC]                       -- ^ wellformedness constraints over RType
   , fixCs      :: ![FixSubC]                   -- ^ subtyping over Sort (post-splitting)
   , fixWfs     :: ![FixWfC]                    -- ^ wellformedness constraints over Sort (post-splitting)
   , freshIndex :: !Integer                     -- ^ counter for generating fresh KVars
-  , binds      :: !F.BindEnv                   -- ^ set of environment binders
+  , binds      :: !FixBindEnv                   -- ^ set of environment binders
   , ebinds     :: ![F.BindId]                  -- ^ existentials
   , annotMap   :: !(AnnInfo (Annot SpecType))  -- ^ source-position annotation map
   , holesMap   :: !(M.HashMap Var (HoleInfo (CGInfo, CGEnv) SpecType))    -- ^ information for ghc hole expressions
   , tyConInfo  :: !TyConMap                    -- ^ information about type-constructors
-  , specDecr   :: ![(Var, [Int])]              -- ^ ^ Lexicographic order of decreasing args (DEPRECATED) 
+  , specDecr   :: ![(Var, [Int])]              -- ^ ^ Lexicographic order of decreasing args (DEPRECATED)
   , newTyEnv   :: !(M.HashMap Ghc.TyCon SpecType)        -- ^ Mapping of new type type constructors with their refined types.
   , termExprs  :: !(M.HashMap Var [F.Located F.Expr])   -- ^ Terminating Metrics for Recursive functions
   , specLVars  :: !(S.HashSet Var)             -- ^ Set of variables to ignore for termination checking
   , specLazy   :: !(S.HashSet Var)             -- ^ "Lazy binders", skip termination checking
-  , specTmVars :: !(S.HashSet Var)             -- ^ Binders that FAILED struct termination check that MUST be checked 
+  , specTmVars :: !(S.HashSet Var)             -- ^ Binders that FAILED struct termination check that MUST be checked
   , autoSize   :: !(S.HashSet Ghc.TyCon)        -- ^ ? FIX THIS
   , tyConEmbed :: !(F.TCEmb Ghc.TyCon)          -- ^ primitive Sorts into which TyCons should be embedded
   , kuts       :: !F.Kuts                      -- ^ Fixpoint Kut variables (denoting "back-edges"/recursive KVars)
@@ -229,6 +228,7 @@
   , cgConsts   :: !(F.SEnv F.Sort)             -- ^ Distinct constant symbols in the refinement logic
   , cgADTs     :: ![F.DataDecl]                -- ^ ADTs extracted from Haskell 'data' definitions
   , tcheck     :: !Bool                        -- ^ Check Termination (?)
+  , cgiTypeclass :: !Bool                      -- ^ Enable typeclass support
   , pruneRefs  :: !Bool                        -- ^ prune unsorted refinements
   , logErrors  :: ![Error]                     -- ^ Errors during constraint generation
   , kvProf     :: !KVProf                      -- ^ Profiling distribution of KVars
@@ -242,12 +242,12 @@
 
 
 getTemplates :: CG F.Templates
-getTemplates = do 
-  fg     <- pruneRefs <$> get
-  ts     <- unsorted  <$> get
-  return $ if fg then F.anything else ts 
-       
+getTemplates = do
+  fg    <- gets pruneRefs
+  ts    <- gets unsorted
+  return $ if fg then F.anything else ts
 
+
 instance PPrint CGInfo where
   pprintTidy = pprCGInfo
 
@@ -320,7 +320,7 @@
 lookupRInv (RApp c ts _ _) m
   = case M.lookup c m of
       Nothing   -> Nothing
-      Just invs -> Just (catMaybes $ goodInvs ts <$> invs)
+      Just invs -> Just (mapMaybe (goodInvs ts) invs)
 lookupRInv _ _
   = Nothing
 
@@ -340,7 +340,7 @@
 addRInv :: RTyConInv -> (Var, SpecType) -> (Var, SpecType)
 addRInv m (x, t)
   | x `elem` ids , Just invs <- lookupRInv (res t) m
-  = (x, addInvCond t (mconcat $ catMaybes (stripRTypeBase <$> invs)))
+  = (x, addInvCond t (mconcat $ mapMaybe stripRTypeBase invs))
   | otherwise
   = (x, t)
    where
@@ -378,7 +378,7 @@
         | otherwise
         = True
     binds (NonRec x _) = [x]
-    binds (Rec xes)    = fst $ unzip xes
+    binds (Rec xes)    = map fst xes
 
 restoreInvariant :: CGEnv -> RTyConInv -> CGEnv
 restoreInvariant γ is = γ {invs = is}
diff --git a/src/Language/Haskell/Liquid/GHC/API.hs b/src/Language/Haskell/Liquid/GHC/API.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/API.hs
+++ /dev/null
@@ -1,871 +0,0 @@
-{-| This module re-exports a bunch of the GHC API.
-
-The intended use of this module is to shelter LiquidHaskell from changes to the GHC API, so this is the
-/only/ module LiquidHaskell should import when trying to access any ghc-specific functionality.
-
---}
-
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE DeriveFunctor #-}
-{-# LANGUAGE DeriveFoldable #-}
-{-# LANGUAGE DeriveTraversable #-}
-{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE PatternSynonyms #-}
-{-# LANGUAGE EmptyDataDecls #-}
-{-# LANGUAGE ViewPatterns #-}
-{-# LANGUAGE TupleSections #-}
-{-# LANGUAGE DeriveDataTypeable #-}
-{-# LANGUAGE BangPatterns #-}
-
-module Language.Haskell.Liquid.GHC.API (
-    module Ghc
-  , module StableModule
-
--- Specific exports for 8.6.5
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)
-  , pattern Bndr
-  , pattern LitString
-  , pattern LitFloat
-  , pattern LitDouble
-  , pattern LitChar
-  , VarBndr
-#endif
-#endif
-
--- Specific exports for 8.6.5 and 8.8.x
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-  , AnonArgFlag(..)
-  , pattern FunTy
-  , pattern AnonTCB
-  , ft_af, ft_mult, ft_arg, ft_res
-  , bytesFS
-  , mkFunTy
-  , isEvVarType
-  , isEqPrimPred
-  , noExtField
-  , Mult
-  , pattern Many
-#endif
-#endif
-
-  , tyConRealArity
-  , dataConExTyVars
-
--- Specific exports for 8.8.x
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,8,1,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-  , isEqPred
-#endif
-#endif
-
--- Specific exports for 8.10.x
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) && !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-  , Mult
-  , pattern Many
-  , pattern FunTy
-  , mkFunTy
-  , ft_af, ft_mult, ft_arg, ft_res
-#endif
-#endif
-
--- Shared exports for GHC < 9
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-  , pattern RealSrcSpan
-  , pattern UnhelpfulSpan
-  , UnhelpfulSpanReason(..)
-  , scaledThing
-  , Scaled(..)
-  , mkScaled
-  , irrelevantMult
-  , dataConInstArgTys
-  , dataConOrigArgTys
-  , dataConRepArgTys
-  , mkLocalVar
-  , DataConAppContext(..)
-  , deepSplitProductType_maybe
-  , splitFunTys
-  , mkUserLocal
-  , dataConWrapperType
-  , apiAnnComments
-  , getDependenciesModuleNames
-  , GenWithIsBoot(..)
-  , ModuleNameWithIsBoot
-  , IsBootInterface
-  , isBootSummary
-  , mkIntExprInt
-  , dataConFullSig
-#endif
-#endif
-
--- Specific exports for 9.x
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-  , fsToUnitId
-  , moduleUnitId
-  , thisPackage
-  , renderWithStyle
-  , mkUserStyle
-  , pattern LitNumber
-  , dataConSig
-  , getDependenciesModuleNames
-  , gcatch
-#endif
-#endif
-
-  ) where
-
-import           Language.Haskell.Liquid.GHC.API.StableModule      as StableModule
-import           GHC                                               as Ghc hiding ( Warning
-                                                                                 , SrcSpan(RealSrcSpan, UnhelpfulSpan)
-                                                                                 , exprType
-                                                                                 , dataConInstArgTys
-                                                                                 )
-
--- Shared imports for GHC < 9
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-
-import CoreFVs                  as Ghc (exprFreeVarsList)
-import OccurAnal                as Ghc (occurAnalysePgm)
-import Annotations              as Ghc
-import ApiAnnotation            as Ghc
-import Avail                    as Ghc
-import Bag                      as Ghc
-import BasicTypes               as Ghc
-import Class                    as Ghc
-import CoAxiom                  as Ghc
-import Coercion                 as Ghc
-import ConLike                  as Ghc
-import CoreLint                 as Ghc hiding (dumpIfSet)
-import CoreMonad                as Ghc (CoreToDo(..))
-import CoreSubst                as Ghc (deShadowBinds, substExpr, emptySubst, extendCvSubst)
-import CoreSyn                  as Ghc hiding (AnnExpr, AnnExpr' (..), AnnRec, AnnCase)
-import CoreUtils                as Ghc (exprType)
-import CostCentre               as Ghc
-import Data.Map.Strict (Map)
-import DataCon                  as Ghc hiding (dataConInstArgTys, dataConOrigArgTys, dataConRepArgTys, dataConFullSig)
-import qualified DataCon        as Ghc
-import Digraph                  as Ghc
-import DriverPhases             as Ghc (Phase(StopLn))
-import DriverPipeline           as Ghc hiding (P, getLocation)
-import DsMonad                  as Ghc
-import DynFlags                 as Ghc
-import ErrUtils                 as Ghc
-import FamInst                  as Ghc
-import FamInstEnv               as Ghc hiding (pprFamInst)
-import Finder                   as Ghc
-import ForeignCall              (CType)
-import GHC                      as Ghc (SrcSpan)
-import GhcMonad                 as Ghc (withSession)
-import GhcPlugins               as Ghc (deserializeWithData , fromSerialized , toSerialized, extendIdSubst)
-import HscMain                  as Ghc
-import HscTypes                 as Ghc hiding (IsBootInterface, isBootSummary)
-import Id                       as Ghc hiding (lazySetIdInfo, setIdExported, setIdNotExported, mkUserLocal)
-import IdInfo                   as Ghc
-import IfaceSyn                 as Ghc
-import InstEnv                  as Ghc
-import Literal                  as Ghc
-import MkCore                   as Ghc hiding (mkIntExprInt)
-import MkId                     (mkDataConWorkId)
-import Module                   as Ghc
-import Name                     as Ghc hiding (varName)
-import NameEnv                  (lookupNameEnv_NF)
-import NameSet                  as Ghc
-import Outputable               as Ghc hiding ((<>))
-import Pair                     as Ghc
-import Panic                    as Ghc
-import Plugins                  as Ghc (defaultPlugin, Plugin(..), CommandLineOption, purePlugin)
-import PrelInfo                 as Ghc
-import PrelNames                as Ghc hiding (wildCardName)
-import RdrName                  as Ghc
-import SrcLoc                   as Ghc hiding (RealSrcSpan, SrcSpan(UnhelpfulSpan))
-import TcRnDriver               as Ghc
-import TcRnMonad                as Ghc hiding (getGHCiMonad)
-import TcRnTypes                as Ghc
-import TysPrim                  as Ghc
-import TysWiredIn               as Ghc
-import Unify                    as Ghc
-import UniqDFM                  as Ghc
-import UniqFM                   as Ghc
-import UniqSet                  as Ghc
-import UniqSupply               as Ghc
-import Unique                   as Ghc
-import Var                      as Ghc hiding (mkLocalVar)
-import VarEnv                   as Ghc
-import VarSet                   as  Ghc
-import qualified                SrcLoc
-import qualified Data.Bifunctor as Bi
-import qualified Data.Data      as Data
-import qualified DataCon        as Ghc
-import qualified GhcMake
-import qualified HscTypes       as Ghc
-import qualified Id             as Ghc
-import qualified MkCore         as Ghc
-import qualified Var            as Ghc
-import qualified WwLib          as Ghc
-import           RnExpr         as Ghc (rnLExpr)
-import           TcExpr         as Ghc (tcInferSigma)
-import           TcBinds        as Ghc (tcValBinds)
-import           Inst           as Ghc (deeplyInstantiate)
-import           TcSimplify     as Ghc ( simplifyInfer, simplifyInteractive
-                                       , InferMode (..))
-import           TcHsSyn        as Ghc (zonkTopLExpr)
-import           TcEvidence     as Ghc ( TcEvBinds (EvBinds))
-import           DsExpr         as Ghc (dsLExpr)
-#endif
-#endif
-
---
--- Compatibility layer for different GHC versions.
---
-
---
--- Specific imports for GHC 8.6.5
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)
-
-import qualified Literal as Lit
-import FastString        as Ghc hiding (bytesFS, LitString)
-import TcType            as Ghc hiding (typeKind, mkFunTy)
-import Type              as Ghc hiding (typeKind, mkFunTy, splitFunTys, extendCvSubst)
-import qualified Type    as Ghc
-import qualified Var     as Var
-import qualified GHC.Real
--- import PrelNames      (eqPrimTyConKey, eqReprPrimTyConKey, gHC_REAL, varQual_RDR)
-#endif
-#endif
-
---
--- Specific imports for GHC 8.6.5 & 8.8.x
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-
-import                   Binary
-import                   Data.ByteString (ByteString)
-import                   Data.Data (Data)
-import Kind              as Ghc
-import TyCoRep           as Ghc hiding (Type (FunTy), mkFunTy, extendCvSubst)
-import TyCon             as Ghc hiding (mkAnonTyConBinders, TyConBndrVis(AnonTCB))
-import qualified TyCoRep as Ty hiding (extendCvSubst)
-import qualified TyCon   as Ty
-import Platform as Ghc
-import qualified HsExtension
--- import PrelNames      (eqPrimTyConKey, eqReprPrimTyConKey, gHC_REAL, varQual_RDR)
-
-#endif
-#endif
-
---
--- Specific imports for 8.8.x
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,8,1,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-
-import FastString           as Ghc hiding (bytesFS)
-import TcType               as Ghc hiding (typeKind, mkFunTy, isEqPred)
-import Type                 as Ghc hiding (typeKind, mkFunTy, isEvVarType, isEqPred, splitFunTys, extendCvSubst)
-import qualified Type       as Ghc
-import qualified Type       as Ghc (isEvVarType)
-import qualified PrelNames  as Ghc
-import Data.Foldable        (asum)
--- import PrelNames      (eqPrimTyConKey, eqReprPrimTyConKey, gHC_REAL, varQual_RDR)
-#endif
-#endif
-
---
--- Specific imports for GHC 8.10
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) && !MIN_VERSION_GLASGOW_HASKELL (9,0,0,0)
-import DynFlags          as  Ghc (targetPlatform)
-import GHC.Platform      as  Ghc (Platform)
-import Type              as  Ghc hiding (typeKind , isPredTy, splitFunTys, extendCvSubst)
-import qualified Type    as  Ghc hiding (extendCvSubst)
-import TyCon             as  Ghc
-import qualified TyCoRep as  Ty
-import TcType            as  Ghc
-import TyCoRep           as  Ghc hiding (Type (FunTy), mkFunTy, ft_arg, ft_res, ft_af)
-import FastString        as  Ghc
-import Predicate      as Ghc (getClassPredTys_maybe, isEvVarType, getClassPredTys, isDictId)
-import TcOrigin       as Ghc (lexprCtOrigin)
-import Data.Foldable  (asum)
-import Util           (lengthIs)
--- import PrelNames      (eqPrimTyConKey, eqReprPrimTyConKey, gHC_REAL, varQual_RDR)
-#endif
-#endif
-
---
--- Specific imports for GHC 9
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0) && !MIN_VERSION_GLASGOW_HASKELL (9,1,0,0)
-
-import Optics
-import qualified Control.Monad.Catch as Ex
-
-import Data.Foldable                  (asum)
-import GHC.Builtin.Names              as Ghc
-import GHC.Builtin.Types              as Ghc
-import GHC.Builtin.Types.Prim         as Ghc
-import GHC.Builtin.Utils              as Ghc
-import GHC.Core                       as Ghc hiding (AnnExpr, AnnExpr' (..), AnnRec, AnnCase)
-import GHC.Core.Class                 as Ghc
-import GHC.Core.Coercion              as Ghc
-import GHC.Core.Coercion.Axiom        as Ghc
-import GHC.Core.ConLike               as Ghc
-import GHC.Core.DataCon               as Ghc
-import GHC.Core.FamInstEnv            as Ghc hiding (pprFamInst)
-import GHC.Core.InstEnv               as Ghc
-import GHC.Core.Lint                  as Ghc hiding (dumpIfSet)
-import GHC.Core.Make                  as Ghc
-import GHC.Core.Opt.Monad             as Ghc (CoreToDo(..))
-import GHC.Core.Opt.WorkWrap.Utils    as Ghc
-import GHC.Core.Predicate             as Ghc (getClassPredTys_maybe, getClassPredTys, isEvVarType, isEqPrimPred, isEqPred, isClassPred, isDictId)
-import GHC.Core.Subst                 as Ghc (deShadowBinds, emptySubst, extendCvSubst)
-import GHC.Core.TyCo.Rep              as Ghc hiding (extendCvSubst)
-import GHC.Core.TyCon                 as Ghc
-import GHC.Core.Type                  as Ghc hiding (typeKind , isPredTy, extendCvSubst, linear)
-import GHC.Core.Unify                 as Ghc
-import GHC.Core.Utils                 as Ghc (exprType)
-import GHC.Data.Bag                   as Ghc
-import GHC.Data.FastString            as Ghc
-import GHC.Data.Graph.Directed        as Ghc
-import GHC.Data.Pair                  as Ghc
-import GHC.Driver.Finder              as Ghc
-import GHC.Driver.Main                as Ghc
-import GHC.Driver.Phases              as Ghc (Phase(StopLn))
-import GHC.Driver.Pipeline            as Ghc (compileFile)
-import GHC.Driver.Session             as Ghc
-import GHC.Driver.Types               as Ghc
-import GHC.Driver.Monad               as Ghc (withSession)
-import GHC.HsToCore.Monad             as Ghc
-import GHC.Iface.Syntax               as Ghc
-import GHC.Plugins                    as Ghc ( deserializeWithData
-                                             , fromSerialized
-                                             , toSerialized
-                                             , defaultPlugin
-                                             , Plugin(..)
-                                             , CommandLineOption
-                                             , purePlugin
-                                             , extendIdSubst
-                                             , substExpr
-                                             )
-import GHC.Tc.Instance.Family         as Ghc
-import GHC.Tc.Module                  as Ghc
-import GHC.Tc.Types                   as Ghc
-import GHC.Tc.Utils.Monad             as Ghc hiding (getGHCiMonad)
-import GHC.Tc.Utils.TcType            as Ghc (tcSplitDFunTy, tcSplitMethodTy)
-import GHC.Types.Annotations          as Ghc
-import GHC.Types.Avail                as Ghc
-import GHC.Types.Basic                as Ghc
-import GHC.Types.CostCentre           as Ghc
-import GHC.Types.Id                   as Ghc hiding (lazySetIdInfo, setIdExported, setIdNotExported)
-import GHC.Types.Id.Info              as Ghc
-import GHC.Types.Literal              as Ghc hiding (LitNumber)
-import GHC.Types.Name                 as Ghc hiding (varName, isWiredIn)
-import GHC.Types.Name.Reader          as Ghc
-import GHC.Types.Name.Set             as Ghc
-import GHC.Types.SrcLoc               as Ghc
-import GHC.Types.Unique               as Ghc
-import GHC.Types.Unique.DFM           as Ghc
-import GHC.Types.Unique.FM            as Ghc
-import GHC.Types.Unique.Set           as Ghc
-import GHC.Types.Unique.Supply        as Ghc
-import GHC.Types.Var                  as Ghc
-import GHC.Types.Var.Env              as Ghc
-import GHC.Types.Var.Set              as Ghc
-import GHC.Unit.Module                as Ghc
-import GHC.Utils.Error                as Ghc
-import GHC.Utils.Outputable           as Ghc hiding ((<>), renderWithStyle, mkUserStyle)
-import GHC.Utils.Panic                as Ghc
-import qualified GHC.Types.Literal    as Ghc
-import qualified GHC.Utils.Outputable as Ghc
-import GHC.Tc.Types.Origin            as Ghc (lexprCtOrigin)
-import GHC.Rename.Expr                as Ghc (rnLExpr)
-import GHC.Tc.Gen.Expr                as Ghc (tcInferSigma, tcInferRho)
-import GHC.Tc.Gen.Bind                as Ghc (tcValBinds)
-import GHC.Tc.Solver                  as Ghc
-import GHC.Tc.Utils.Zonk              as Ghc
-import GHC.Core.FVs                   as Ghc (exprFreeVarsList)
-import GHC.Tc.Types.Evidence          as Ghc
-import GHC.HsToCore.Expr              as Ghc
-import GHC.Core.Predicate             as Ghc (mkClassPred)
-import GHC.Core.Opt.OccurAnal         as Ghc
-#endif
-#endif
-
---
--- Compat shim for GHC < 9 (shared parts)
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-
-data BufSpan
-
-pattern RealSrcSpan :: SrcLoc.RealSrcSpan -> Maybe BufSpan -> SrcLoc.SrcSpan
-pattern RealSrcSpan rss mbSpan <- ((,Nothing) -> (SrcLoc.RealSrcSpan rss, mbSpan))
-  where
-    RealSrcSpan rss _mbSpan = SrcLoc.RealSrcSpan rss
-
-data UnhelpfulSpanReason
-  = UnhelpfulNoLocationInfo
-  | UnhelpfulWiredIn
-  | UnhelpfulInteractive
-  | UnhelpfulGenerated
-  | UnhelpfulOther !FastString
-  deriving (Eq, Show)
-
-pattern UnhelpfulSpan :: UnhelpfulSpanReason -> SrcLoc.SrcSpan
-pattern UnhelpfulSpan reason <- (toUnhelpfulReason -> Just reason)
-  where
-    UnhelpfulSpan reason = SrcLoc.UnhelpfulSpan (fromUnhelpfulReason reason)
-
-fromUnhelpfulReason :: UnhelpfulSpanReason -> FastString
-fromUnhelpfulReason = \case
-  UnhelpfulNoLocationInfo -> fsLit "UnhelpfulNoLocationInfo"
-  UnhelpfulWiredIn        -> fsLit "UnhelpfulWiredIn"
-  UnhelpfulInteractive    -> fsLit "UnhelpfulInteractive"
-  UnhelpfulGenerated      -> fsLit "UnhelpfulGenerated"
-  UnhelpfulOther fs       -> fs
-
-toUnhelpfulReason :: SrcLoc.SrcSpan -> Maybe UnhelpfulSpanReason
-toUnhelpfulReason (SrcLoc.RealSrcSpan _) = Nothing
-toUnhelpfulReason (SrcLoc.UnhelpfulSpan fs) = Just $ case unpackFS fs of
-  "UnhelpfulNoLocationInfo" -> UnhelpfulNoLocationInfo
-  "UnhelpfulWiredIn"        -> UnhelpfulWiredIn
-  "UnhelpfulInteractive"    -> UnhelpfulInteractive
-  "UnhelpfulGenerated"      -> UnhelpfulGenerated
-  _                         -> UnhelpfulOther fs
-
--- Backporting multiplicity
-
-data Scaled a = Scaled Mult a
-  deriving (Data.Data)
-
-instance (Outputable a) => Outputable (Scaled a) where
-   ppr (Scaled _cnt t) = ppr t
-
-irrelevantMult :: Scaled a -> a
-irrelevantMult = scaledThing
-
-mkScaled :: Mult -> a -> Scaled a
-mkScaled = Scaled
-
-scaledThing :: Scaled a -> a
-scaledThing (Scaled _ t) = t
-
-type Mult = Type
-
-pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
-pcDataCon n univs tys tycon = data_con
-  where
-    data_con = mkDataCon n
-                         False
-                         (mkPrelTyConRepName n)
-                         (map (const (HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict)) tys)
-                         []
-                         univs
-                         []
-                         (error "[TyVarBinder]")
-                         []
-                         []
-                         tys
-                         (mkTyConApp tycon (mkTyVarTys univs))
-                         NoRRI
-                         tycon
-                         (lookupNameEnv_NF (mkTyConTagMap tycon) n)
-                         []
-                         (mkDataConWorkId (mkDataConWorkerName data_con (dataConWorkerUnique (nameUnique n))) data_con)
-                         NoDataConRep
-
-
-mkDataConWorkerName :: DataCon -> Unique -> Name
-mkDataConWorkerName data_con wrk_key =
-    mkWiredInName modu wrk_occ wrk_key
-                  (AnId (dataConWorkId data_con)) UserSyntax
-  where
-    modu    = nameModule dc_name
-    dc_name = dataConName data_con
-    dc_occ  = nameOccName dc_name
-    wrk_occ = mkDataConWorkerOcc dc_occ
-
-pcTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
-pcTyCon name cType tyvars cons
-  = mkAlgTyCon name
-                (mkAnonTyConBinders VisArg tyvars)
-                liftedTypeKind
-                (map (const Representational) tyvars)
-                cType
-                []              -- No stupid theta
-                (mkDataTyConRhs cons)
-                (VanillaAlgTyCon (mkPrelTyConRepName name))
-                False           -- Not in GADT syntax
-
-
-mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
-mkWiredInDataConName built_in modu fs unique datacon
-  = mkWiredInName modu (mkDataOccFS fs) unique
-                  (AConLike (RealDataCon datacon))    -- Relevant DataCon
-                  built_in
-
-multiplicityTyConKey :: Unique
-multiplicityTyConKey = mkPreludeTyConUnique 192
-
-multiplicityTyConName :: Name
-multiplicityTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Multiplicity")
-                          multiplicityTyConKey multiplicityTyCon
-
-manyDataConName :: Name
-manyDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "Many") manyDataConKey manyDataCon
-
-multiplicityTyCon :: TyCon
-multiplicityTyCon = pcTyCon multiplicityTyConName Nothing [] [manyDataCon]
-
-manyDataCon :: DataCon
-manyDataCon = pcDataCon manyDataConName [] [] multiplicityTyCon
-
-manyDataConKey :: Unique
-manyDataConKey = mkPreludeDataConUnique 116
-
-manyDataConTy :: Type
-manyDataConTy = mkTyConTy manyDataConTyCon
-
-manyDataConTyCon :: TyCon
-manyDataConTyCon = promoteDataCon manyDataCon
-
-pattern Many :: Mult
-pattern Many <- (isManyDataConTy -> True)
-  where Many = manyDataConTy
-
-isManyDataConTy :: Mult -> Bool
-isManyDataConTy ty
-  | Just tc <- tyConAppTyCon_maybe ty
-  = tc `hasKey` manyDataConKey
-isManyDataConTy _ = False
-
---
--- Dependencies and Boot
---
-type IsBootInterface = GhcMake.IsBoot
-
--- | This data type just pairs a value 'mod' with an IsBootInterface flag. In
--- practice, 'mod' is usually a @Module@ or @ModuleName@'.
-data GenWithIsBoot mod = GWIB
-  { gwib_mod :: mod
-  , gwib_isBoot :: IsBootInterface
-  } deriving ( Eq, Ord, Show
-             , Functor, Foldable, Traversable
-             )
-
-type ModuleNameWithIsBoot = GenWithIsBoot ModuleName
-
-isBootSummary :: ModSummary -> IsBootInterface
-isBootSummary ms = case Ghc.isBootSummary ms of
-  True  -> GhcMake.IsBoot
-  False -> GhcMake.NotBoot
-
-getDependenciesModuleNames :: Dependencies -> [ModuleNameWithIsBoot]
-getDependenciesModuleNames = map f . dep_mods
-  where
-    f :: (ModuleName, Bool) -> ModuleNameWithIsBoot
-    f (modName, b) = let isBoot = if b then GhcMake.IsBoot else GhcMake.NotBoot in GWIB modName isBoot
-
-dataConInstArgTys :: DataCon -> [Type] -> [Scaled Type]
-dataConInstArgTys dc tys = map (mkScaled Many) (Ghc.dataConInstArgTys dc tys)
-
-dataConOrigArgTys :: DataCon -> [Scaled Type]
-dataConOrigArgTys dc = map (mkScaled Many) (Ghc.dataConOrigArgTys dc)
-
-dataConRepArgTys :: DataCon -> [Scaled Type]
-dataConRepArgTys dc = map (mkScaled Many) (Ghc.dataConRepArgTys dc)
-
-mkLocalVar :: IdDetails -> Name -> Mult -> Type -> IdInfo -> Id
-mkLocalVar idDetails name _ ty info = Ghc.mkLocalVar idDetails name ty info
-
-mkUserLocal :: OccName -> Unique -> Mult -> Type -> SrcSpan -> Id
-mkUserLocal occName u _mult ty srcSpan = Ghc.mkUserLocal occName u ty srcSpan
-
-dataConWrapperType :: DataCon -> Type
-dataConWrapperType = dataConUserType
-
--- WWlib
-
-data DataConAppContext
-  = DataConAppContext
-  { dcac_dc      :: !DataCon
-  , dcac_tys     :: ![Type]
-  , dcac_arg_tys :: ![(Scaled Type, StrictnessMark)]
-  , dcac_co      :: !Coercion
-  }
-
-deepSplitProductType_maybe :: FamInstEnvs -> Type -> Maybe DataConAppContext
-deepSplitProductType_maybe famInstEnv ty = do
-  (dc, tys, tysWithStricts, co) <- Ghc.deepSplitProductType_maybe famInstEnv ty
-  pure $ DataConAppContext dc tys (map (Bi.first (mkScaled Many)) tysWithStricts) co
-
-splitFunTys :: Type -> ([Scaled Type], Type)
-splitFunTys ty = Bi.first (map (mkScaled Many)) $ Ghc.splitFunTys ty
-
-apiAnnComments :: (Map ApiAnnKey [SrcSpan], Map SrcSpan [Located AnnotationComment])
-               -> Map SrcSpan [Located AnnotationComment]
-apiAnnComments = snd
-
-mkIntExprInt :: Platform -> Int -> CoreExpr
-mkIntExprInt _ int = Ghc.mkIntExprInt unsafeGlobalDynFlags int
-
-dataConFullSig :: DataCon -> ([TyVar], [TyCoVar], [EqSpec], ThetaType, [Scaled Type], Type)
-dataConFullSig dc =
-  let (tyvars, tycovars, eqspecs, theta, tys, ty) = Ghc.dataConFullSig dc
-  in  (tyvars, tycovars, eqspecs, theta, map (mkScaled Many) tys, ty)
-
-
-#endif
-#endif
-
---
--- Compat shim for GHC 8.6.5
-
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)
-
-pattern LitString :: ByteString -> Lit.Literal
-pattern LitString bs <- Lit.MachStr bs where
-    LitString bs = Lit.MachStr bs
-
-pattern LitFloat :: GHC.Real.Ratio Integer -> Lit.Literal
-pattern LitFloat f <- Lit.MachFloat f where
-    LitFloat f = Lit.MachFloat f
-
-pattern LitDouble :: GHC.Real.Ratio Integer -> Lit.Literal
-pattern LitDouble d <- Lit.MachDouble d where
-    LitDouble d = Lit.MachDouble d
-
-pattern LitChar :: Char -> Lit.Literal
-pattern LitChar c <- Lit.MachChar c where
-    LitChar c = Lit.MachChar c
-
-pattern Bndr :: var -> argf -> Var.TyVarBndr var argf
-pattern Bndr var argf <- TvBndr var argf where
-    Bndr var argf = TvBndr var argf
-
-type VarBndr = TyVarBndr
-
-isEqPrimPred :: Type -> Bool
-isEqPrimPred = Ghc.isPredTy
-
--- See NOTE [isEvVarType].
-isEvVarType :: Type -> Bool
-isEvVarType = Ghc.isPredTy
-
-tyConRealArity :: TyCon -> Int
-tyConRealArity = tyConArity
-
-#endif
-#endif
-
---
--- Compat shim for GHC-8.6.5 and GHC-8.8.x
---
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-
--- | The non-dependent version of 'ArgFlag'.
-
--- Appears here partly so that it's together with its friend ArgFlag,
--- but also because it is used in IfaceType, rather early in the
--- compilation chain
--- See Note [AnonArgFlag vs. ForallVisFlag]
-data AnonArgFlag
-  = VisArg    -- ^ Used for @(->)@: an ordinary non-dependent arrow.
-              --   The argument is visible in source code.
-  | InvisArg  -- ^ Used for @(=>)@: a non-dependent predicate arrow.
-              --   The argument is invisible in source code.
-  deriving (Eq, Ord, Data)
-
-instance Outputable AnonArgFlag where
-  ppr VisArg   = text "[vis]"
-  ppr InvisArg = text "[invis]"
-
-instance Binary AnonArgFlag where
-  put_ bh VisArg   = putByte bh 0
-  put_ bh InvisArg = putByte bh 1
-
-  get bh = do
-    h <- getByte bh
-    case h of
-      0 -> return VisArg
-      _ -> return InvisArg
-
-mkAnonTyConBinders :: AnonArgFlag -> [TyVar] -> [TyConBinder]
-mkAnonTyConBinders _ = Ty.mkAnonTyConBinders
-
-bytesFS :: FastString -> ByteString
-bytesFS = fastStringToByteString
-
-mkFunTy :: AnonArgFlag -> Mult -> Type -> Type -> Type
-mkFunTy _ _ = Ty.FunTy
-
-pattern FunTy :: AnonArgFlag -> Mult -> Type -> Type -> Type
-pattern FunTy { ft_af, ft_mult, ft_arg, ft_res } <- ((VisArg,Many,) -> (ft_af, ft_mult, Ty.FunTy ft_arg ft_res)) where
-    FunTy _ft_af _ft_mult ft_arg ft_res = Ty.FunTy ft_arg ft_res
-
-pattern AnonTCB :: AnonArgFlag -> Ty.TyConBndrVis
-pattern AnonTCB af <- ((VisArg,) -> (af, Ty.AnonTCB)) where
-    AnonTCB _af = Ty.AnonTCB
-
-noExtField :: NoExt
-noExtField = NoExt
-
-#endif
-
--- Compat shim for GHC 8.8.x
-
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,8,1,0) && !MIN_VERSION_GLASGOW_HASKELL(8,10,1,0)
-
-isEqPrimPred :: Type -> Bool
-isEqPrimPred ty
-  | Just tc <- tyConAppTyCon_maybe ty
-  = tc `hasKey` Ghc.eqPrimTyConKey || tc `hasKey` Ghc.eqReprPrimTyConKey
-  | otherwise
-  = False
-
-isEqPred :: Type -> Bool
-isEqPred ty
-  | Just tc <- tyConAppTyCon_maybe ty
-  , Just cls <- tyConClass_maybe tc
-  = cls `hasKey` Ghc.eqTyConKey || cls `hasKey` Ghc.heqTyConKey
-  | otherwise
-  = False
-
--- See NOTE [isEvVarType].
-isEvVarType :: Type -> Bool
-isEvVarType = Ghc.isEvVarType
-
-#endif
-#endif
-
-{- | [NOTE:tyConRealArity]
-
-The semantics of 'tyConArity' changed between GHC 8.6.5 and GHC 8.10, mostly due to the
-Visible Dependent Quantification (VDQ). As a result, given the following:
-
-data family EntityField record :: * -> *
-
-Calling `tyConArity` on this would yield @2@ for 8.6.5 but @1@ an 8.10, so we try to backport
-the old behaviour in 8.10 by \"looking\" at the 'Kind' of the input 'TyCon' and trying to recursively
-split the type apart with either 'splitFunTy_maybe' or 'splitForAllTy_maybe'.
-
--}
-
-{- | [NOTE:isEvVarType]
-
-For GHC < 8.8.1 'isPredTy' is effectively the same as the new 'isEvVarType', which covers the cases
-for coercion types and \"normal\" type coercions. The 8.6.5 version of 'isPredTy' had a special case to
-handle a 'TyConApp' in the case of type equality (i.e. ~ ) which was removed in the implementation
-for 8.8.1, which essentially calls 'tcIsConstraintKind' straight away.
--}
-
---
--- Support for GHC >= 8.8
---
-
-#if MIN_VERSION_GLASGOW_HASKELL(8,8,1,0) && !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-
--- See NOTE [tyConRealArity].
-tyConRealArity :: TyCon -> Int
-tyConRealArity tc = go 0 (tyConKind tc)
-  where
-    go :: Int -> Kind -> Int
-    go !acc k =
-      case asum [fmap snd (splitFunTy_maybe k), fmap snd (splitForAllTy_maybe k)] of
-        Nothing -> acc
-        Just ks -> go (acc + 1) ks
-
-dataConExTyVars :: DataCon -> [TyVar]
-dataConExTyVars = dataConExTyCoVars
-
-#endif
-
---
--- Compat shim for 8.10.x
---
-
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) && !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-pattern FunTy :: AnonArgFlag -> Mult -> Type -> Type -> Type
-pattern FunTy { ft_af, ft_mult, ft_arg, ft_res } <- ((Many,) -> (ft_mult, Ty.FunTy ft_af ft_arg ft_res)) where
-    FunTy ft_af _ft_mult ft_arg ft_res = Ty.FunTy ft_af ft_arg ft_res
-
-mkFunTy :: AnonArgFlag -> Mult -> Type -> Type -> Type
-mkFunTy af _ arg res = Ty.FunTy af arg res
-#endif
-
---
--- Compat shim for 9.0.x
-
-#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-
--- 'fsToUnitId' is gone in GHC 9, but we can bring code it in terms of 'fsToUnit' and 'toUnitId'.
-fsToUnitId :: FastString -> UnitId
-fsToUnitId = toUnitId . fsToUnit
-
-moduleUnitId :: Module -> UnitId
-moduleUnitId = toUnitId . moduleUnit
-
-thisPackage :: DynFlags -> UnitId
-thisPackage = toUnitId . homeUnit
-
--- See NOTE [tyConRealArity].
-tyConRealArity :: TyCon -> Int
-tyConRealArity tc = go 0 (tyConKind tc)
-  where
-    go :: Int -> Kind -> Int
-    go !acc k =
-      case asum [fmap (view _3) (splitFunTy_maybe k), fmap snd (splitForAllTy_maybe k)] of
-        Nothing -> acc
-        Just ks -> go (acc + 1) ks
-
-dataConExTyVars :: DataCon -> [TyVar]
-dataConExTyVars = dataConExTyCoVars
-
-getDependenciesModuleNames :: Dependencies -> [ModuleNameWithIsBoot]
-getDependenciesModuleNames = dep_mods
-
-renderWithStyle :: DynFlags -> SDoc -> PprStyle -> String
-renderWithStyle dynflags sdoc style = Ghc.renderWithStyle (Ghc.initSDocContext dynflags style) sdoc
-
-mkUserStyle :: DynFlags -> PrintUnqualified -> Depth -> PprStyle
-mkUserStyle _ = Ghc.mkUserStyle
-
---
--- Literal
---
-
--- In GHC 9 'LitNumber' doesn't have the extra 3rd argument, so we simply ignore it in the construction.
-
-pattern LitNumber :: Ghc.LitNumType -> Integer -> Ghc.Type -> Ghc.Literal
-pattern LitNumber numType integer ty <- ((intPrimTy,) -> (ty, Ghc.LitNumber numType integer))
-  where
-    LitNumber numType integer _ = Ghc.LitNumber numType integer
-
--- This function is gone in GHC 9.
-dataConSig :: DataCon -> ([TyCoVar], ThetaType, [Type], Type)
-dataConSig dc
-  = (dataConUnivAndExTyCoVars dc, dataConTheta dc, map irrelevantMult $ dataConOrigArgTys dc, dataConOrigResTy dc)
-
-gcatch :: (Ex.MonadCatch m, Exception e) => m a -> (e -> m a) -> m a
-gcatch = Ex.catch
-
-#endif
-
---
--- End of compatibility shim.
---
-#endif
diff --git a/src/Language/Haskell/Liquid/GHC/API/StableModule.hs b/src/Language/Haskell/Liquid/GHC/API/StableModule.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/API/StableModule.hs
+++ /dev/null
@@ -1,101 +0,0 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE DeriveGeneric #-}
-module Language.Haskell.Liquid.GHC.API.StableModule (
-    StableModule
-  -- * Constructing a 'StableModule'
-  , mkStableModule
-  -- * Converting a 'StableModule' into a standard 'Module'
-  , unStableModule
-  -- * Utility functions
-  , toStableModule
-  , renderModule
-  ) where
-
-import qualified GHC
-
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-import qualified Module as GHC
-#else
-import qualified GHC.Unit.Types as GHC
-import qualified GHC.Unit.Module as GHC
-#endif
-#endif
-
-import           Data.Hashable
-import           GHC.Generics            hiding (to, moduleName)
-import           Data.Binary
-
--- | A newtype wrapper around a 'Module' which:
---
--- * Allows a 'Module' to be serialised (i.e. it has a 'Binary' instance)
--- * It tries to use stable comparison and equality under the hood.
---
-newtype StableModule =
-  StableModule { unStableModule :: GHC.Module }
-  deriving Generic
-
--- | Converts a 'Module' into a 'StableModule'.
-toStableModule :: GHC.Module -> StableModule
-toStableModule = StableModule
-
-moduleUnitId :: GHC.Module -> GHC.UnitId
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-moduleUnitId = GHC.moduleUnitId
-#else
-moduleUnitId = GHC.toUnitId . GHC.moduleUnit
-#endif
-#endif
-
-renderModule :: GHC.Module -> String
-renderModule m =    "Module { unitId = " <> (GHC.unitIdString . moduleUnitId $ m)
-                 <> ", name = " <> show (GHC.moduleName m)
-                 <> " }"
-
--- These two orphans originally lived inside module 'Language.Haskell.Liquid.Types.Types'.
-instance Hashable GHC.ModuleName where
-  hashWithSalt i = hashWithSalt i . show
-
-instance Show GHC.ModuleName where
-  show = GHC.moduleNameString
-
-instance Hashable StableModule where
-  hashWithSalt s (StableModule mdl) = hashWithSalt s (GHC.moduleStableString mdl)
-
-instance Ord StableModule where
-  (StableModule m1) `compare` (StableModule m2) = GHC.stableModuleCmp m1 m2
-
-instance Eq StableModule where
-  (StableModule m1) == (StableModule m2) = (m1 `GHC.stableModuleCmp` m2) == EQ
-
-instance Show StableModule where
-    show (StableModule mdl) = "Stable" ++ renderModule mdl
-
-instance Binary StableModule where
-
-    put (StableModule mdl) = do
-      put (GHC.unitIdString . moduleUnitId $ mdl)
-      put (GHC.moduleNameString . GHC.moduleName $ mdl)
-
-    get = do
-      uidStr <- get
-      mnStr  <- get
-      pure $ mkStableModule (GHC.stringToUnitId uidStr) (GHC.mkModuleName mnStr)
-
---
--- Compat shim layer
---
-
--- | Creates a new 'StableModule' out of a 'ModuleName' and a 'UnitId'.
-mkStableModule :: GHC.UnitId -> GHC.ModuleName -> StableModule
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-mkStableModule uid modName = StableModule (GHC.mkModule uid modName)
-#else
-mkStableModule uid modName =
-  let realUnit = GHC.RealUnit $ GHC.Definite uid
-  in StableModule (GHC.Module realUnit modName)
-#endif
-#endif
-
diff --git a/src/Language/Haskell/Liquid/GHC/GhcMonadLike.hs b/src/Language/Haskell/Liquid/GHC/GhcMonadLike.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/GhcMonadLike.hs
+++ /dev/null
@@ -1,336 +0,0 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE RecordWildCards #-}
-{-# LANGUAGE TypeSynonymInstances #-}
-{-# LANGUAGE FlexibleInstances #-}
--- | This module introduces a \"lighter\" "GhcMonad" typeclass which doesn't require an instance of
--- 'ExceptionMonad', and can therefore be used for both 'CoreM' and 'Ghc'.
---
-
-module Language.Haskell.Liquid.GHC.GhcMonadLike (
-  -- * Types and type classes
-    HasHscEnv
-  , GhcMonadLike
-  , ModuleInfo
-  , TypecheckedModule(..)
-
-  -- * Functions and typeclass methods
-
-  , askHscEnv
-  , getModuleGraph
-  , getModSummary
-  , lookupModSummary
-  , lookupGlobalName
-  , lookupName
-  , modInfoLookupName
-  , moduleInfoTc
-  , parseModule
-  , typecheckModule
-  , desugarModule
-  , findModule
-  , lookupModule
-  , isBootInterface
-  , apiComments
-  ) where
-
-import Control.Monad
-import Control.Monad.IO.Class
-import Control.Exception (throwIO)
-
-import Data.IORef (readIORef)
-
-import qualified Language.Haskell.Liquid.GHC.API   as Ghc
-import           Language.Haskell.Liquid.GHC.API   hiding ( ModuleInfo
-                                                          , findModule
-                                                          , desugarModule
-                                                          , typecheckModule
-                                                          , parseModule
-                                                          , lookupName
-                                                          , lookupGlobalName
-                                                          , getModSummary
-                                                          , getModuleGraph
-                                                          , modInfoLookupName
-                                                          , lookupModule
-                                                          , TypecheckedModule
-                                                          , tm_parsed_module
-                                                          , tm_renamed_source
-                                                          )
-
--- Shared imports for GHC < 9
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-import qualified CoreMonad
-import qualified EnumSet
-import Maybes
-import GhcMake
-import Exception (ExceptionMonad)
-#else
-import GHC.Data.Maybe
-import GHC.Driver.Make
-import GHC.Utils.Exception (ExceptionMonad)
-import qualified GHC.Core.Opt.Monad as CoreMonad
-import qualified GHC.Data.EnumSet as EnumSet
-#endif
-#endif
-
-import qualified Data.Map.Strict as M
-import Optics
-
-class HasHscEnv m where
-  askHscEnv :: m HscEnv
-
-instance HasHscEnv CoreMonad.CoreM where
-  askHscEnv = CoreMonad.getHscEnv
-
-instance HasHscEnv Ghc where
-  askHscEnv = getSession
-
-instance HasHscEnv (IfM lcl) where
-  askHscEnv = getTopEnv
-
-instance HasHscEnv TcM where
-  askHscEnv = env_top <$> getEnv
-
-instance HasHscEnv Hsc where
-  askHscEnv = Hsc $ \e w -> pure (e, w)
-
-instance (ExceptionMonad m, HasHscEnv m) => HasHscEnv (GhcT m) where
-  askHscEnv = getSession
-
--- | A typeclass which is /very/ similar to the existing 'GhcMonad', but it doesn't impose a
--- 'ExceptionMonad' constraint.
-class (Functor m, MonadIO m, HasHscEnv m, HasDynFlags m) => GhcMonadLike m
-
-instance GhcMonadLike CoreMonad.CoreM
-instance GhcMonadLike Ghc
-instance GhcMonadLike (IfM lcl)
-instance GhcMonadLike TcM
-instance GhcMonadLike Hsc
-instance (ExceptionMonad m, GhcMonadLike m) => GhcMonadLike (GhcT m)
-
--- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
-getModuleGraph :: GhcMonadLike m => m ModuleGraph
-getModuleGraph = liftM hsc_mod_graph askHscEnv
-
--- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
-getModSummary :: GhcMonadLike m => ModuleName -> m ModSummary
-getModSummary mdl = do
-   mg <- liftM hsc_mod_graph askHscEnv
-   let mods_by_name = [ ms | ms <- mgModSummaries mg
-                      , ms_mod_name ms == mdl
-                      , not (isBootInterface . isBootSummary $ ms) ]
-   case mods_by_name of
-     [] -> do dflags <- getDynFlags
-              liftIO $ throwIO $ mkApiErr dflags (text "Module not part of module graph")
-     [ms] -> return ms
-     multiple -> do dflags <- getDynFlags
-                    liftIO $ throwIO $ mkApiErr dflags (text "getModSummary is ambiguous: " <+> ppr multiple)
-
-
--- Converts a 'IsBootInterface' into a 'Bool'.
-isBootInterface :: IsBootInterface -> Bool
-isBootInterface IsBoot  = True
-isBootInterface NotBoot = False
-
-lookupModSummary :: GhcMonadLike m => ModuleName -> m (Maybe ModSummary)
-lookupModSummary mdl = do
-   mg <- liftM hsc_mod_graph askHscEnv
-   let mods_by_name = [ ms | ms <- mgModSummaries mg
-                      , ms_mod_name ms == mdl
-                      , not (isBootInterface . isBootSummary $ ms) ]
-   case mods_by_name of
-     [ms] -> pure (Just ms)
-     _    -> pure Nothing
-
--- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
-lookupGlobalName :: GhcMonadLike m => Name -> m (Maybe TyThing)
-lookupGlobalName name = do
-  hsc_env <- askHscEnv
-  liftIO $ lookupTypeHscEnv hsc_env name
-
--- NOTE(adn) Taken from the GHC API, adapted to work for a 'GhcMonadLike' monad.
-lookupName :: GhcMonadLike m => Name -> m (Maybe TyThing)
-lookupName name = do
-  hsc_env <- askHscEnv
-  liftIO $ hscTcRcLookupName hsc_env name
-
--- | Our own simplified version of 'ModuleInfo' to overcome the fact we cannot construct the \"original\"
--- one as the constructor is not exported, and 'getHomeModuleInfo' and 'getPackageModuleInfo' are not
--- exported either, so we had to backport them as well.
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-
--- For GHC < 9, UniqFM has a single parameter.
-data ModuleInfo = ModuleInfo { minf_type_env :: UniqFM TyThing }
-#else
--- For GHC >= 9, UniqFM has two parameters.
--- just fine.
-data ModuleInfo = ModuleInfo { minf_type_env :: UniqFM Name TyThing }
-#endif
-#endif
-
-modInfoLookupName :: GhcMonadLike m
-                  => ModuleInfo
-                  -> Name
-                  -> m (Maybe TyThing)
-modInfoLookupName minf name = do
-  hsc_env <- askHscEnv
-  case lookupTypeEnv (minf_type_env minf) name of
-    Just tyThing -> return (Just tyThing)
-    Nothing      -> do
-      eps   <- liftIO $ readIORef (hsc_EPS hsc_env)
-      return $! lookupType (hsc_dflags hsc_env) (hsc_HPT hsc_env) (eps_PTE eps) name
-
-moduleInfoTc :: GhcMonadLike m => ModSummary -> TcGblEnv -> m ModuleInfo
-moduleInfoTc ms tcGblEnv = do
-  hsc_env <- askHscEnv
-  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
-  details <- md_types <$> liftIO (makeSimpleDetails hsc_env_tmp tcGblEnv)
-  pure ModuleInfo { minf_type_env = details }
-
---
--- Parsing, typechecking and desugaring a module
---
-parseModule :: GhcMonadLike m => ModSummary -> m ParsedModule
-parseModule ms = do
-  hsc_env <- askHscEnv
-  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
-  hpm <- liftIO $ hscParse hsc_env_tmp ms
-  return (ParsedModule ms (hpm_module hpm) (hpm_src_files hpm)
-                           (hpm_annotations hpm))
-
--- | Our own simplified version of 'TypecheckedModule'.
-data TypecheckedModule = TypecheckedModule { 
-    tm_parsed_module  :: ParsedModule
-  , tm_renamed_source :: Maybe RenamedSource
-  , tm_mod_summary    :: ModSummary
-  , tm_gbl_env        :: TcGblEnv
-  }
-
-typecheckModule :: GhcMonadLike m => ParsedModule -> m TypecheckedModule
-typecheckModule pmod = do
-  -- Suppress all the warnings, so that they won't be printed (which would result in them being
-  -- printed twice, one by GHC and once here).
-  let ms = pm_mod_summary pmod
-  hsc_env <- askHscEnv
-  let dynFlags' = ms_hspp_opts ms
-  let hsc_env_tmp = hsc_env { hsc_dflags = dynFlags' { warningFlags = EnumSet.empty } }
-  (tc_gbl_env, rn_info)
-        <- liftIO $ hscTypecheckRename hsc_env_tmp ms $
-                       HsParsedModule { hpm_module = parsedSource pmod,
-                                        hpm_src_files = pm_extra_src_files pmod,
-                                        hpm_annotations = pm_annotations pmod }
-  return TypecheckedModule {
-      tm_parsed_module  = pmod
-    , tm_renamed_source = rn_info
-    , tm_mod_summary    = ms
-    , tm_gbl_env        = tc_gbl_env
-    }
-
-{- | [NOTE:ghc810]
-Something changed in the GHC bowels such that the 'hscTarget' that the 'ModSummary' was inheriting
-was /not/ the one we were setting in 'configureDynFlags'. This is important, because if the 'hscTarget'
-is not 'HscInterpreted' or 'HscNothing', the call to 'targetRetainsAllBindings' will yield 'False'. This
-function is used internally by GHC to do dead-code-elimination and to mark functions as "exported" or not.
-Therefore, the 'CoreBind's passed to LiquidHaskell would be different between GHC 8.6.5 and GHC 8.10.
--}
-
-class IsTypecheckedModule t where
-  tmParsedModule :: Lens'  t ParsedModule
-  tmModSummary   :: Lens'  t ModSummary
-  tmGblEnv       :: Getter t TcGblEnv
-
-instance IsTypecheckedModule TypecheckedModule where
-  tmParsedModule = lens tm_parsed_module (\s x -> s { tm_parsed_module = x })
-  tmModSummary   = lens tm_mod_summary   (\s x -> s { tm_mod_summary = x })
-  tmGblEnv       = to tm_gbl_env
-
-instance IsTypecheckedModule Ghc.TypecheckedModule where
-  tmParsedModule = lens Ghc.tm_parsed_module (\s x -> s { Ghc.tm_parsed_module = x })
-  tmModSummary   = lens (pm_mod_summary . Ghc.tm_parsed_module)
-                        (\s x -> over tmParsedModule (\pm -> pm { Ghc.pm_mod_summary = x }) s )
-  tmGblEnv       = to (fst . Ghc.tm_internals_)
-
--- | Desugar a typechecked module.
-desugarModule :: (GhcMonadLike m, IsTypecheckedModule t) => ModSummary -> t -> m ModGuts
-desugarModule originalModSum typechecked = do
-  -- See [NOTE:ghc810] on why we override the dynFlags here before calling 'desugarModule'.
-  dynFlags          <- getDynFlags
-  let modSum         = originalModSum { ms_hspp_opts = dynFlags }
-  let parsedMod'     = (view tmParsedModule typechecked) { pm_mod_summary = modSum }
-  let typechecked'   = set tmParsedModule parsedMod' typechecked
-
-  hsc_env <- askHscEnv
-  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts (view tmModSummary typechecked') }
-  liftIO $ hscDesugar hsc_env_tmp (view tmModSummary typechecked') (view tmGblEnv typechecked')
-
--- | Takes a 'ModuleName' and possibly a 'UnitId', and consults the
--- filesystem and package database to find the corresponding 'Module',
--- using the algorithm that is used for an @import@ declaration.
-findModule :: GhcMonadLike m => ModuleName -> Maybe FastString -> m Module
-findModule mod_name maybe_pkg = do
-  hsc_env <- askHscEnv
-  let
-    dflags   = hsc_dflags hsc_env
-    this_pkg = thisPackage dflags
-  --
-  case maybe_pkg of
-    Just pkg | fsToUnitId pkg /= this_pkg && pkg /= fsLit "this" -> liftIO $ do
-      res <- findImportedModule hsc_env mod_name maybe_pkg
-      case res of
-        Found _ m -> return m
-        err       -> throwOneError $ noModError dflags noSrcSpan mod_name err
-    _otherwise -> do
-      home <- lookupLoadedHomeModule mod_name
-      case home of
-        Just m  -> return m
-        Nothing -> liftIO $ do
-           res <- findImportedModule hsc_env mod_name maybe_pkg
-           case res of
-             Found loc m | moduleUnitId m /= this_pkg -> return m
-                         | otherwise -> modNotLoadedError dflags m loc
-             err -> throwOneError $ noModError dflags noSrcSpan mod_name err
-
-
-lookupLoadedHomeModule :: GhcMonadLike m => ModuleName -> m (Maybe Module)
-lookupLoadedHomeModule mod_name = do
-  hsc_env <- askHscEnv
-  case lookupHpt (hsc_HPT hsc_env) mod_name of
-    Just mod_info      -> return (Just (mi_module (hm_iface mod_info)))
-    _not_a_home_module -> return Nothing
-
-
-modNotLoadedError :: DynFlags -> Module -> ModLocation -> IO a
-modNotLoadedError dflags m loc = throwGhcExceptionIO $ CmdLineError $ showSDoc dflags $
-   text "module is not loaded:" <+>
-   quotes (ppr (moduleName m)) <+>
-   parens (text (expectJust "modNotLoadedError" (ml_hs_file loc)))
-
-
-lookupModule :: GhcMonadLike m => ModuleName -> Maybe FastString -> m Module
-lookupModule mod_name (Just pkg) = findModule mod_name (Just pkg)
-lookupModule mod_name Nothing = do
-  hsc_env <- askHscEnv
-  home <- lookupLoadedHomeModule mod_name
-  case home of
-    Just m  -> return m
-    Nothing -> liftIO $ do
-      res <- findExposedPackageModule hsc_env mod_name Nothing
-      case res of
-        Found _ m -> return m
-        err       -> throwOneError $ noModError (hsc_dflags hsc_env) noSrcSpan mod_name err
-
--- Compatibility shim to extract the comments out of an 'ApiAnns', as modern GHCs now puts the
--- comments (i.e. Haskell comments) in a different field ('apiAnnRogueComments').
-apiComments :: ApiAnns -> [Ghc.Located AnnotationComment]
-apiComments apiAnns =
-  let comments = concat . M.elems . apiAnnComments $ apiAnns
-  in
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-      comments
-#else
-     map toRealSrc $ mappend comments (apiAnnRogueComments apiAnns)
-  where
-    toRealSrc (L x e) = L (RealSrcSpan x Nothing) e
-#endif
-#endif
diff --git a/src/Language/Haskell/Liquid/GHC/Interface.hs b/src/Language/Haskell/Liquid/GHC/Interface.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Interface.hs
+++ /dev/null
@@ -1,1058 +0,0 @@
-{-# LANGUAGE CPP                        #-}
-{-# LANGUAGE NoMonomorphismRestriction  #-}
-{-# LANGUAGE LambdaCase                 #-}
-{-# LANGUAGE TypeSynonymInstances       #-}
-{-# LANGUAGE FlexibleContexts           #-}
-{-# LANGUAGE FlexibleInstances          #-}
-{-# LANGUAGE TupleSections              #-}
-{-# LANGUAGE ScopedTypeVariables        #-}
-{-# LANGUAGE OverloadedStrings          #-}
-{-# LANGUAGE PartialTypeSignatures      #-}
-{-# LANGUAGE TypeFamilies               #-}
-{-# LANGUAGE ViewPatterns               #-}
-
-module Language.Haskell.Liquid.GHC.Interface (
-
-  -- * Determine the build-order for target files
-   realTargets
-
-  , getInterfaceDynFlags
-
-  -- * Extract all information needed for verification
-  , getTargetInfos
-  , runLiquidGhc
-
-  -- * Printer
-  , pprintCBs
-
-  -- * predicates
-  -- , isExportedVar
-  -- , exportedVars
-
-  -- * Internal exports (provisional)
-  , extractSpecComments
-  , extractSpecQuotes'
-  , makeLogicMap
-  , classCons
-  , derivedVars
-  , importVars
-  , makeGhcSrc
-  , allImports
-  , qualifiedImports
-  , modSummaryHsFile
-  , makeFamInstEnv
-  , findAndParseSpecFiles
-  , parseSpecFile
-  , noTerm
-  , clearSpec
-  , checkFilePragmas
-  , keepRawTokenStream
-  , ignoreInline
-  , lookupTyThings
-  , availableTyCons
-  , availableVars
-  , updLiftedSpec
-  , loadDependenciesOf
-  ) where
-
-import Prelude hiding (error)
-
-import GHC.Paths (libdir)
-import GHC.Serialized
-
-import           Language.Haskell.Liquid.GHC.GhcMonadLike (isBootInterface)
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding ( text
-                                                               , (<+>)
-                                                               , panic
-                                                               , vcat
-                                                               , showPpr
-                                                               , isHomeModule
-                                                               , Target
-                                                               , Located
-                                                               )
-import qualified Language.Haskell.Liquid.GHC.API as Ghc
-import qualified Language.Haskell.Liquid.GHC.API as O
-import GHC.LanguageExtensions
-
-import Control.Exception
-import Control.Monad
-
-import Data.Bifunctor
-import Data.Data
-import Data.List hiding (intersperse)
-import Data.Maybe
-
-import Data.Generics.Aliases (mkT)
-import Data.Generics.Schemes (everywhere)
-
-import qualified Data.HashSet        as S
-import qualified Data.HashMap.Strict as HM
-
-import System.Console.CmdArgs.Verbosity hiding (Loud)
-import System.Directory
-import System.FilePath
-import System.IO
-import System.IO.Temp
-import Text.Megaparsec.Error
-import Text.PrettyPrint.HughesPJ        hiding (first, (<>))
-import Language.Fixpoint.Types          hiding (panic, Error, Result, Expr)
-import qualified Language.Fixpoint.Misc as Misc
-import Language.Haskell.Liquid.Bare
-import Language.Haskell.Liquid.GHC.Misc
-import Language.Haskell.Liquid.GHC.Types (MGIModGuts(..), miModGuts)
-import Language.Haskell.Liquid.GHC.Play
-import qualified Language.Haskell.Liquid.GHC.GhcMonadLike as GhcMonadLike
-import Language.Haskell.Liquid.GHC.GhcMonadLike (GhcMonadLike, askHscEnv)
-import Language.Haskell.Liquid.WiredIn (isDerivedInstance) 
-import qualified Language.Haskell.Liquid.Measure  as Ms
-import qualified Language.Haskell.Liquid.Misc     as Misc
-import Language.Haskell.Liquid.Parse
-import Language.Haskell.Liquid.Transforms.ANF
-import Language.Haskell.Liquid.Types hiding (Spec)
--- import Language.Haskell.Liquid.Types.PrettyPrint
--- import Language.Haskell.Liquid.Types.Visitors
-import Language.Haskell.Liquid.UX.CmdLine
-import Language.Haskell.Liquid.UX.QuasiQuoter
-import Language.Haskell.Liquid.UX.Tidy
-import Language.Fixpoint.Utils.Files
-
-import Optics
-
-import qualified Debug.Trace as Debug 
-
-
---------------------------------------------------------------------------------
-{- | @realTargets mE cfg targets@ uses `Interface.configureGhcTargets` to 
-     return a list of files
-
-       [i1, i2, ... ] ++ [f1, f2, ...]
-
-     1. Where each file only (transitively imports) PRECEDIING ones; 
-     2. `f1..` are a permutation of the original `targets`;
-     3. `i1..` either don't have "fresh" .bspec files. 
-
- -}
---------------------------------------------------------------------------------
-realTargets :: Maybe HscEnv -> Config -> [FilePath] -> IO [FilePath] 
-realTargets  mbEnv cfg tgtFs 
-  | noCheckImports cfg = return tgtFs
-  | otherwise          = do 
-    incDir   <- Misc.getIncludeDir 
-    allFs    <- orderTargets mbEnv cfg tgtFs
-    let srcFs = filter (not . Misc.isIncludeFile incDir) allFs
-    realFs   <- filterM check srcFs
-    dir      <- getCurrentDirectory
-    return      (makeRelative dir <$> realFs)
-  where 
-    check f    = not <$> skipTarget tgts f 
-    tgts       = S.fromList tgtFs
-
-getInterfaceDynFlags :: Maybe HscEnv -> Config -> IO DynFlags
-getInterfaceDynFlags mbEnv cfg = runLiquidGhc mbEnv cfg $ getSessionDynFlags
-
-orderTargets :: Maybe HscEnv -> Config -> [FilePath] -> IO [FilePath] 
-orderTargets mbEnv cfg tgtFiles = runLiquidGhc mbEnv cfg $ do 
-  homeModules <- configureGhcTargets tgtFiles
-  return         (modSummaryHsFile <$> mgModSummaries homeModules)
-
-
-skipTarget :: S.HashSet FilePath -> FilePath -> IO Bool
-skipTarget tgts f 
-  | S.member f tgts = return False          -- Always check target file 
-  | otherwise       = hasFreshBinSpec f     -- But skip an import with fresh .bspec
-
-hasFreshBinSpec :: FilePath -> IO Bool
-hasFreshBinSpec srcF = do 
-  let specF = extFileName BinSpec srcF
-  srcMb    <- Misc.lastModified srcF 
-  specMb   <- Misc.lastModified specF 
-  case (srcMb, specMb) of 
-    (Just srcT, Just specT) -> return (srcT < specT)
-    _                       -> return False
-
-
-
---------------------------------------------------------------------------------
--- | GHC Interface Pipeline ----------------------------------------------------
---------------------------------------------------------------------------------
-
-getTargetInfos :: Maybe HscEnv -> Config -> [FilePath] -> IO ([TargetInfo], HscEnv)
-getTargetInfos hscEnv cfg tgtFiles' = do
-  tgtFiles <- mapM canonicalizePath tgtFiles'
-  _        <- mapM checkFilePresent tgtFiles
-  _        <- mapM_ createTempDirectoryIfMissing tgtFiles
-  logicMap <- liftIO makeLogicMap
-  runLiquidGhc hscEnv cfg (getTargetInfos' cfg logicMap tgtFiles)
-
-checkFilePresent :: FilePath -> IO ()
-checkFilePresent f = do
-  b <- doesFileExist f
-  unless b $ panic Nothing ("Cannot find file: " ++ f)
-
-getTargetInfos' :: Config -> LogicMap -> [FilePath] -> Ghc ([TargetInfo], HscEnv)
-getTargetInfos' cfg logicMap tgtFiles = do
-  _           <- compileCFiles cfg
-  homeModules <- configureGhcTargets tgtFiles
-  depGraph    <- buildDepGraph homeModules
-  ghcInfos    <- processModules cfg logicMap tgtFiles depGraph homeModules
-  hscEnv      <- getSession
-  return (ghcInfos, hscEnv)
-
-createTempDirectoryIfMissing :: FilePath -> IO ()
-createTempDirectoryIfMissing tgtFile = Misc.tryIgnore "create temp directory" $
-  createDirectoryIfMissing False $ tempDirectory tgtFile
-
---------------------------------------------------------------------------------
--- | GHC Configuration & Setup -------------------------------------------------
---------------------------------------------------------------------------------
-runLiquidGhc :: Maybe HscEnv -> Config -> Ghc a -> IO a
-runLiquidGhc hscEnv cfg act =
-  withSystemTempDirectory "liquid" $ \tmp ->
-    runGhc (Just libdir) $ do
-      maybe (return ()) setSession hscEnv
-      df <- configureDynFlags cfg tmp
-      prettyPrintGhcErrors df act
-
-updateIncludePaths :: DynFlags -> [FilePath] -> IncludeSpecs 
-updateIncludePaths df ps = addGlobalInclude (includePaths df) ps 
-
-configureDynFlags :: Config -> FilePath -> Ghc DynFlags
-configureDynFlags cfg tmp = do
-  df <- getSessionDynFlags
-  (df',_,_) <- parseDynamicFlags df $ map noLoc $ ghcOptions cfg
-  loud <- liftIO isLoud
-  let df'' = df' { importPaths  = nub $ idirs cfg ++ importPaths df'
-                 , libraryPaths = nub $ idirs cfg ++ libraryPaths df'
-                 , includePaths = updateIncludePaths df' (idirs cfg) -- addGlobalInclude (includePaths df') (idirs cfg) 
-                 , packageFlags = ExposePackage ""
-                                                (PackageArg "ghc-prim")
-                                                (ModRenaming True [])
-                                : (packageFlags df')
-
-                 , debugLevel   = 1               -- insert SourceNotes
-                 -- , profAuto     = ProfAutoCalls
-                 , ghcLink      = LinkInMemory
-                 , hscTarget    = HscInterpreted
-                 , ghcMode      = CompManager
-                 -- prevent GHC from printing anything, unless in Loud mode
-                 , log_action   = if loud
-                                    then defaultLogAction
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-                                    else \_ _ _ _ _ _ -> return ()
-#else
-                                    else \_ _ _ _ _   -> return ()
-#endif
-#endif
-                 -- redirect .hi/.o/etc files to temp directory
-                 , objectDir    = Just tmp
-                 , hiDir        = Just tmp
-                 , stubDir      = Just tmp
-                 } `gopt_set` Opt_ImplicitImportQualified
-                   `gopt_set` Opt_PIC
-                   `gopt_set` Opt_DeferTypedHoles
-                   `xopt_set` MagicHash
-                   `xopt_set` DeriveGeneric
-                   `xopt_set` StandaloneDeriving
-  _ <- setSessionDynFlags df''
-  return df''
-
-configureGhcTargets :: [FilePath] -> Ghc ModuleGraph
-configureGhcTargets tgtFiles = do
-  targets         <- mapM (`guessTarget` Nothing) tgtFiles
-  _               <- setTargets targets
-  moduleGraph     <- depanal [] False -- see [NOTE:DROP-BOOT-FILES]
-
-  let homeModules  = filter (not . isBootInterface . isBootSummary) $
-                     flattenSCCs $ topSortModuleGraph False moduleGraph Nothing
-  let homeNames    = moduleName . ms_mod <$> homeModules
-  _               <- setTargetModules homeNames
-  liftIO $ whenLoud $ print    ("Module Dependencies", homeNames)
-  return $ mkModuleGraph homeModules
-
-setTargetModules :: [ModuleName] -> Ghc ()
-setTargetModules modNames = setTargets $ mkTarget <$> modNames
-  where
-    mkTarget modName = Ghc.Target (TargetModule modName) True Nothing
-
-compileCFiles :: Config -> Ghc ()
-compileCFiles cfg = do
-  df  <- getSessionDynFlags
-  _   <- setSessionDynFlags $
-           df { includePaths = updateIncludePaths df (idirs cfg) 
-              , importPaths  = nub $ idirs cfg ++ importPaths df
-              , libraryPaths = nub $ idirs cfg ++ libraryPaths df }
-  hsc <- getSession
-  os  <- mapM (\x -> liftIO $ compileFile hsc StopLn (x,Nothing)) (nub $ cFiles cfg)
-  df  <- getSessionDynFlags
-  void $ setSessionDynFlags $ df { ldInputs = nub $ map (FileOption "") os ++ ldInputs df }
-
-{- | [NOTE:DROP-BOOT-FILES] Drop hs-boot files from the graph.
-      We do it manually rather than using the flag to topSortModuleGraph
-      because otherwise the order of mutually recursive modules depends
-      on the modulename, e.g. given
-
-      Bar.hs --> Foo.hs --> Bar.hs-boot
-
-      we'll get
-      
-      [Bar.hs, Foo.hs]
-    
-      which is backwards..
- -}
---------------------------------------------------------------------------------
--- Home Module Dependency Graph ------------------------------------------------
---------------------------------------------------------------------------------
-
-type DepGraph = Graph DepGraphNode
-type DepGraphNode = Node Module ()
-
-reachableModules :: DepGraph -> Module -> [Module]
-reachableModules depGraph mod =
-  node_key <$> tail (reachableG depGraph (DigraphNode () mod []))
-
-buildDepGraph :: ModuleGraph -> Ghc DepGraph
-buildDepGraph homeModules =
-  graphFromEdgedVerticesOrd <$> mapM mkDepGraphNode (mgModSummaries homeModules)
-
-mkDepGraphNode :: ModSummary -> Ghc DepGraphNode
-mkDepGraphNode modSummary = 
-  DigraphNode () (ms_mod modSummary) <$> (filterM isHomeModule =<< modSummaryImports modSummary)
-
-isHomeModule :: GhcMonadLike m => Module -> m Bool
-isHomeModule mod = do
-  homePkg <- thisPackage <$> getDynFlags
-  return   $ moduleUnitId mod == homePkg
-
-modSummaryImports :: GhcMonadLike m => ModSummary -> m [Module]
-modSummaryImports modSummary =
-  mapM (importDeclModule (ms_mod modSummary))
-       (ms_textual_imps modSummary)
-
-importDeclModule :: GhcMonadLike m => Module -> (Maybe FastString,  Ghc.Located ModuleName) -> m Module
-importDeclModule fromMod (pkgQual, locModName) = do
-  hscEnv <- askHscEnv
-  let modName = unLoc locModName
-  result <- liftIO $ findImportedModule hscEnv modName pkgQual
-  case result of
-    Ghc.Found _ mod -> return mod
-    _ -> do
-      dflags <- getDynFlags
-      liftIO $ throwGhcExceptionIO $ ProgramError $
-        O.showPpr dflags (moduleName fromMod) ++ ": " ++
-        O.showSDoc dflags (cannotFindModule dflags modName result)
-
---------------------------------------------------------------------------------
--- | Extract Ids ---------------------------------------------------------------
---------------------------------------------------------------------------------
-
-classCons :: Maybe [ClsInst] -> [Id]
-classCons Nothing   = []
-classCons (Just cs) = concatMap (dataConImplicitIds . head . tyConDataCons . classTyCon . is_cls) cs
-
-derivedVars :: Config -> MGIModGuts -> [Var]  
-derivedVars cfg mg  = concatMap (dFunIdVars cbs . is_dfun) derInsts 
-  where 
-    derInsts        
-      | checkDer    = insts 
-      | otherwise   = filter isDerivedInstance insts
-    insts           = mgClsInstances mg 
-    checkDer        = checkDerived cfg
-    cbs             = mgi_binds mg
-               
-
-mgClsInstances :: MGIModGuts -> [ClsInst]
-mgClsInstances = fromMaybe [] . mgi_cls_inst 
-
-dFunIdVars :: CoreProgram -> DFunId -> [Id]
-dFunIdVars cbs fd  = notracepp msg $ concatMap bindersOf cbs' ++ deps
-  where
-    msg            = "DERIVED-VARS-OF: " ++ showpp fd
-    cbs'           = filter f cbs
-    f (NonRec x _) = eqFd x
-    f (Rec xes)    = any eqFd (fst <$> xes)
-    eqFd x         = varName x == varName fd
-    deps           = concatMap unfoldDep unfolds
-    unfolds        = unfoldingInfo . idInfo <$> concatMap bindersOf cbs'
-
-unfoldDep :: Unfolding -> [Id]
-unfoldDep (DFunUnfolding _ _ e)       = concatMap exprDep e
-unfoldDep CoreUnfolding {uf_tmpl = e} = exprDep e
-unfoldDep _                           = []
-
-exprDep :: CoreExpr -> [Id]
-exprDep = freeVars S.empty
-
-importVars :: CoreProgram -> [Id]
-importVars = freeVars S.empty
-
-_definedVars :: CoreProgram -> [Id]
-_definedVars = concatMap defs
-  where
-    defs (NonRec x _) = [x]
-    defs (Rec xes)    = map fst xes
-
---------------------------------------------------------------------------------
--- | Per-Module Pipeline -------------------------------------------------------
---------------------------------------------------------------------------------
-
-type SpecEnv = ModuleEnv (ModName, Ms.BareSpec)
-
-processModules :: Config -> LogicMap -> [FilePath] -> DepGraph -> ModuleGraph -> Ghc [TargetInfo]
-processModules cfg logicMap tgtFiles depGraph homeModules = do
-  -- DO NOT DELETE: liftIO $ putStrLn $ "Process Modules: TargetFiles = " ++ show tgtFiles
-  catMaybes . snd <$> Misc.mapAccumM go emptyModuleEnv (mgModSummaries homeModules)
-  where                                             
-    go = processModule cfg logicMap (S.fromList tgtFiles) depGraph
-
-processModule :: Config -> LogicMap -> S.HashSet FilePath -> DepGraph -> SpecEnv -> ModSummary
-              -> Ghc (SpecEnv, Maybe TargetInfo)
-processModule cfg logicMap tgtFiles depGraph specEnv modSummary = do
-  let mod              = ms_mod modSummary
-  -- DO-NOT-DELETE _                <- liftIO $ whenLoud $ putStrLn $ "Process Module: " ++ showPpr (moduleName mod)
-  file                <- liftIO $ canonicalizePath $ modSummaryHsFile modSummary
-  let isTarget         = file `S.member` tgtFiles
-  _                   <- loadDependenciesOf $ moduleName mod
-  parsed              <- parseModule $ keepRawTokenStream modSummary
-  let specComments     = extractSpecComments (pm_annotations parsed)
-  typechecked         <- typecheckModule $ ignoreInline parsed
-  let specQuotes       = extractSpecQuotes typechecked
-  _                   <- loadModule' typechecked
-  (modName, commSpec) <- either throw return $ hsSpecificationP (moduleName mod) specComments specQuotes
-
-  liftedSpec          <- liftIO $ if isTarget || null specComments then return Nothing else loadLiftedSpec cfg file 
-  let bareSpec         = updLiftedSpec commSpec liftedSpec
-  _                   <- checkFilePragmas $ Ms.pragmas bareSpec
-  let specEnv'         = extendModuleEnv specEnv mod (modName, noTerm bareSpec)
-  (specEnv', ) <$> if isTarget
-                     then Just <$> processTargetModule cfg logicMap depGraph specEnv file typechecked bareSpec
-                     else return Nothing
-
-updLiftedSpec :: Ms.BareSpec -> Maybe Ms.BareSpec -> Ms.BareSpec 
-updLiftedSpec s1 Nothing   = s1 
-updLiftedSpec s1 (Just s2) = (clearSpec s1) `mappend` s2 
-
-clearSpec :: Ms.BareSpec -> Ms.BareSpec
-clearSpec s = s { sigs = [], asmSigs = [], aliases = [], ealiases = [], qualifiers = [], dataDecls = [] }
-
-keepRawTokenStream :: ModSummary -> ModSummary
-keepRawTokenStream modSummary = modSummary
-  { ms_hspp_opts = ms_hspp_opts modSummary `gopt_set` Opt_KeepRawTokenStream }
-
-loadDependenciesOf :: GhcMonad m => ModuleName -> m ()
-loadDependenciesOf modName = do
-  loadResult <- load $ LoadDependenciesOf modName
-  when (failed loadResult) $ liftIO $ throwGhcExceptionIO $ ProgramError $
-   "Failed to load dependencies of module " ++ showPpr modName
-
-loadModule' :: TypecheckedModule -> Ghc TypecheckedModule
-loadModule' tm = loadModule tm'
-  where
-    pm   = tm_parsed_module tm
-    ms   = pm_mod_summary pm
-    df   = ms_hspp_opts ms
-    df'  = df { hscTarget = HscNothing, ghcLink = NoLink }
-    ms'  = ms { ms_hspp_opts = df' }
-    pm'  = pm { pm_mod_summary = ms' }
-    tm'  = tm { tm_parsed_module = pm' }
-
-
-
-
-      -- -- we should be able to setContext regardless of whether
-      -- -- we use the ghc api. However, ghc will complain
-      -- -- if the filename does not match the module name
-      -- when (typeclass cfg) $ do
-      --   Ghc.setContext [iimport |(modName, _) <- allSpecs legacyBareSpec,
-      --                   let iimport = if isTarget modName
-      --                                 then Ghc.IIModule (getModName modName)
-      --                                 else Ghc.IIDecl (Ghc.simpleImportDecl (getModName modName))]
-      --   void $ Ghc.execStmt
-      --     "let {infixr 1 ==>; True ==> False = False; _ ==> _ = True}"
-      --     Ghc.execOptions
-      --   void $ Ghc.execStmt
-      --     "let {infixr 1 <=>; True <=> False = False; _ <=> _ = True}"
-      --     Ghc.execOptions
-      --   void $ Ghc.execStmt
-      --     "let {infix 4 ==; (==) :: a -> a -> Bool; _ == _ = undefined}"
-      --     Ghc.execOptions
-      --   void $ Ghc.execStmt
-      --     "let {infix 4 /=; (/=) :: a -> a -> Bool; _ /= _ = undefined}"
-      --     Ghc.execOptions
-      --   void $ Ghc.execStmt
-      --     "let {infixl 7 /; (/) :: Num a => a -> a -> a; _ / _ = undefined}"
-      --     Ghc.execOptions        
-      --   void $ Ghc.execStmt
-      --     "let {len :: [a] -> Int; len _ = undefined}"
-      --     Ghc.execOptions        
-processTargetModule :: Config -> LogicMap -> DepGraph -> SpecEnv -> FilePath -> TypecheckedModule -> Ms.BareSpec
-                    -> Ghc TargetInfo
-processTargetModule cfg0 logicMap depGraph specEnv file typechecked bareSpec = do
-  withPragmas cfg0 file (Ms.pragmas bareSpec) $ \cfg -> do
-    let modSum    = pm_mod_summary (tm_parsed_module typechecked)
-    ghcSrc       <- makeGhcSrc    cfg file     typechecked modSum
-    dependencies <- makeDependencies cfg depGraph specEnv modSum bareSpec
-
-    let targetSrc = view targetSrcIso ghcSrc
-    dynFlags <- getDynFlags
-  -- set up the interactive context
-    when (typeclass cfg) $
-      loadContext (view bareSpecIso bareSpec) dependencies targetSrc
-    (msgs, specM) <- Ghc.withSession $ \hsc_env -> liftIO $ runTcInteractive hsc_env
-      (makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies)
-    case specM of
-      Nothing -> panic Nothing  $ O.showSDoc dynFlags $ O.sep (Ghc.pprErrMsgBagWithLoc (snd msgs))
-      Just spec ->
-        case spec of
-          Left diagnostics -> do
-            mapM_ (liftIO . printWarning dynFlags) (allWarnings diagnostics)
-            throw (allErrors diagnostics)
-          Right (warns, targetSpec, liftedSpec) -> do
-            mapM_ (liftIO . printWarning dynFlags) warns
-            -- The call below is temporary, we should really load & save directly 'LiftedSpec's.
-            _          <- liftIO $ saveLiftedSpec (_giTarget ghcSrc) (unsafeFromLiftedSpec liftedSpec)
-            return      $ TargetInfo targetSrc targetSpec
-
-  -- cfg          <- liftIO $ withPragmas cfg0 file (Ms.pragmas bareSpec)
-  -- let modSum    = pm_mod_summary (tm_parsed_module typechecked)
-  -- ghcSrc       <- makeGhcSrc    cfg file     typechecked modSum
-  -- dependencies <- makeDependencies cfg depGraph specEnv modSum bareSpec
-
-  -- let targetSrc = view targetSrcIso ghcSrc
-  -- dynFlags <- getDynFlags
-  -- -- set up the interactive context
-  -- when (typeclass cfg) $
-  --   loadContext (view bareSpecIso bareSpec) dependencies targetSrc
-  -- (msgs, specM) <- Ghc.withSession $ \hsc_env -> liftIO $ runTcInteractive hsc_env
-  --   (makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies)
-  -- case specM of
-  --   Nothing -> panic Nothing  $ O.showSDoc dynFlags $ O.sep (Ghc.pprErrMsgBagWithLoc (snd msgs))
-  --   Just spec ->
-  --     case spec of
-  --       Left diagnostics -> do
-  --         mapM_ (liftIO . printWarning dynFlags) (allWarnings diagnostics)
-  --         throw (allErrors diagnostics)
-  --       Right (warns, targetSpec, liftedSpec) -> do
-  --         mapM_ (liftIO . printWarning dynFlags) warns
-      
-  --     -- makeTargetSpec cfg logicMap targetSrc (view bareSpecIso bareSpec) dependencies >>= \case
-  --     --   Left  validationErrors -> Bare.checkThrow (Left validationErrors)
-  --     --   Right (targetSpec, liftedSpec) -> do
-      
-  --     -- The call below is temporary, we should really load & save directly 'LiftedSpec's.
-  --         _          <- liftIO $ saveLiftedSpec (_giTarget ghcSrc) (unsafeFromLiftedSpec liftedSpec)
-  --         return      $ TargetInfo targetSrc targetSpec
-
-
-loadContext :: BareSpec -> TargetDependencies -> TargetSrc -> Ghc ()
-loadContext bareSpec dependencies targetSrc = do
-  Ghc.setContext $ [Ghc.IIModule (getModName modName) |(modName, _) <- allSpecs legacyBareSpec,
-                    isTarget modName]
-
-  where
-    toLegacyDep :: (StableModule, LiftedSpec) -> (ModName, Ms.BareSpec)
-    toLegacyDep (sm, ls) = (ModName SrcImport (Ghc.moduleName . unStableModule $ sm), unsafeFromLiftedSpec ls)
-
-    toLegacyTarget :: Ms.BareSpec -> (ModName, Ms.BareSpec)
-    toLegacyTarget validatedSpec = (giTargetMod targetSrc, validatedSpec)
-
-    legacyDependencies :: [(ModName, Ms.BareSpec)]
-    legacyDependencies = map toLegacyDep . HM.toList . getDependencies $ dependencies
-
-    allSpecs :: Ms.BareSpec -> [(ModName, Ms.BareSpec)]
-    allSpecs validSpec = toLegacyTarget validSpec : legacyDependencies
-
-    -- legacyBareSpec :: Spec LocBareType F.LocSymbol
-    legacyBareSpec = review bareSpecIso bareSpec
-
----------------------------------------------------------------------------------------
--- | @makeGhcSrc@ builds all the source-related information needed for consgen 
----------------------------------------------------------------------------------------
-
-makeGhcSrc :: Config -> FilePath -> TypecheckedModule -> ModSummary -> Ghc GhcSrc 
-makeGhcSrc cfg file typechecked modSum = do
-  modGuts'          <- GhcMonadLike.desugarModule modSum typechecked
-
-  let modGuts        = makeMGIModGuts modGuts'
-  hscEnv            <- getSession
-  coreBinds         <- liftIO $ anormalize cfg hscEnv modGuts'
-  _                 <- liftIO $ whenNormal $ Misc.donePhase Misc.Loud "A-Normalization"
-  let dataCons       = concatMap (map dataConWorkId . tyConDataCons) (mgi_tcs modGuts)
-  (fiTcs, fiDcs)    <- makeFamInstEnv <$> liftIO (getFamInstances hscEnv)
-  things            <- lookupTyThings hscEnv modSum (fst $ tm_internals_ typechecked)
-
-  availableTcs      <- availableTyCons hscEnv modSum (fst $ tm_internals_ typechecked) (mg_exports modGuts')
-
-  let impVars        = importVars coreBinds ++ classCons (mgi_cls_inst modGuts)
-  incDir            <- liftIO $ Misc.getIncludeDir
-
-  --liftIO $ do
-  --  print $ "_gsTcs   => " ++ show (nub $ (mgi_tcs      modGuts) ++ availableTcs)
-  --  print $ "_gsFiTcs => " ++ show fiTcs
-  --  print $ "_gsFiDcs => " ++ show fiDcs
-  --  print $ "dataCons => " ++ show dataCons
-  --  print $ "defVars  => " ++ show (dataCons ++ (letVars coreBinds))
-
-  return $ Src 
-    { _giIncDir    = incDir 
-    , _giTarget    = file
-    , _giTargetMod = ModName Target (moduleName (ms_mod modSum))
-    , _giCbs       = coreBinds
-    , _giImpVars   = impVars 
-    , _giDefVars   = dataCons ++ (letVars coreBinds) 
-    , _giUseVars   = readVars coreBinds
-    , _giDerVars   = S.fromList (derivedVars cfg modGuts) 
-    , _gsExports   = mgi_exports  modGuts 
-    , _gsTcs       = nub $ (mgi_tcs      modGuts) ++ availableTcs
-    , _gsCls       = mgi_cls_inst modGuts 
-    , _gsFiTcs     = fiTcs 
-    , _gsFiDcs     = fiDcs
-    , _gsPrimTcs   = Ghc.primTyCons
-    , _gsQualImps  = qualifiedImports (maybe mempty (view _2) (tm_renamed_source typechecked))
-    , _gsAllImps   = allImports       (maybe mempty (view _2) (tm_renamed_source typechecked))
-    , _gsTyThings  = [ t | (_, Just t) <- things ] 
-    }
-
-_impThings :: [Var] -> [TyThing] -> [TyThing]
-_impThings vars  = filter ok
-  where
-    vs          = S.fromList vars 
-    ok (AnId x) = S.member x vs  
-    ok _        = True 
-
-allImports :: [LImportDecl GhcRn] -> S.HashSet Symbol 
-allImports = \case
-  []-> Debug.trace "WARNING: Missing RenamedSource" mempty 
-  imps -> S.fromList (symbol . unLoc . ideclName . unLoc <$> imps)
-
-qualifiedImports :: [LImportDecl GhcRn] -> QImports 
-qualifiedImports = \case
-  []   -> Debug.trace "WARNING: Missing RenamedSource" (qImports mempty) 
-  imps -> qImports [ (qn, n) | i         <- imps
-                                          , let decl   = unLoc i
-                                          , let m      = unLoc (ideclName decl)  
-                                          , qm        <- maybeToList (unLoc <$> ideclAs decl) 
-                                          , let [n,qn] = symbol <$> [m, qm] 
-                                          ]
-
-qImports :: [(Symbol, Symbol)] -> QImports 
-qImports qns  = QImports 
-  { qiNames   = Misc.group qns 
-  , qiModules = S.fromList (snd <$> qns) 
-  }
-
-
----------------------------------------------------------------------------------------
--- | @lookupTyThings@ grabs all the @Name@s and associated @TyThing@ known to GHC 
---   for this module; we will use this to create our name-resolution environment 
---   (see `Bare.Resolve`)                                          
----------------------------------------------------------------------------------------
-lookupTyThings :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> m [(Name, Maybe TyThing)]
-lookupTyThings hscEnv modSum tcGblEnv = forM names (lookupTyThing hscEnv modSum tcGblEnv)
-  where
-    names :: [Ghc.Name] 
-    names  = liftM2 (++)
-             (fmap Ghc.gre_name . Ghc.globalRdrEnvElts . tcg_rdr_env)
-             (fmap is_dfun_name . tcg_insts) tcGblEnv
--- | Lookup a single 'Name' in the GHC environment, yielding back the 'Name' alongside the 'TyThing',
--- if one is found.
-lookupTyThing :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> Name -> m (Name, Maybe TyThing)
-lookupTyThing hscEnv modSum tcGblEnv n = do
-  mi  <- GhcMonadLike.moduleInfoTc modSum tcGblEnv
-  tt1 <-          GhcMonadLike.lookupName      n
-  tt2 <- liftIO $ Ghc.hscTcRcLookupName hscEnv n
-  tt3 <-          GhcMonadLike.modInfoLookupName mi n
-  tt4 <-          GhcMonadLike.lookupGlobalName n
-  return (n, Misc.firstMaybes [tt1, tt2, tt3, tt4])
-
-availableTyThings :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [TyThing]
-availableTyThings hscEnv modSum tcGblEnv avails = fmap (catMaybes . mconcat) $ forM avails $ \a -> do
-  results <- case a of
-    Avail n        -> pure <$> lookupTyThing hscEnv modSum tcGblEnv n
-    AvailTC n ns _ -> forM (n : ns) $ lookupTyThing hscEnv modSum tcGblEnv
-  pure . map snd $ results
-
--- | Returns all the available (i.e. exported) 'TyCon's (type constructors) for the input 'Module'.
-availableTyCons :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [Ghc.TyCon]
-availableTyCons hscEnv modSum tcGblEnv avails = 
-  fmap (\things -> [tyCon | (ATyCon tyCon) <- things]) (availableTyThings hscEnv modSum tcGblEnv avails)
-
--- | Returns all the available (i.e. exported) 'Var's for the input 'Module'.
-availableVars :: GhcMonadLike m => HscEnv -> ModSummary -> TcGblEnv -> [AvailInfo] -> m [Ghc.Var]
-availableVars hscEnv modSum tcGblEnv avails = 
-  fmap (\things -> [var | (AnId var) <- things]) (availableTyThings hscEnv modSum tcGblEnv avails)
-
--- lookupTyThings :: HscEnv -> TypecheckedModule -> MGIModGuts -> Ghc [(Name, Maybe TyThing)] 
--- lookupTyThings hscEnv tcm mg =
---   forM (mgNames mg ++ instNames mg) $ \n -> do 
---     tt1 <-          lookupName                   n 
---     tt2 <- liftIO $ Ghc.hscTcRcLookupName hscEnv n 
---     tt3 <-          modInfoLookupName mi         n 
---     tt4 <-          lookupGlobalName             n 
---     return (n, Misc.firstMaybes [tt1, tt2, tt3, tt4])
---     where 
---       mi = tm_checked_module_info tcm
-
-
--- lookupName        :: GhcMonad m => Name -> m (Maybe TyThing) 
--- hscTcRcLookupName :: HscEnv -> Name -> IO (Maybe TyThing)
--- modInfoLookupName :: GhcMonad m => ModuleInfo -> Name -> m (Maybe TyThing)  
--- lookupGlobalName  :: GhcMonad m => Name -> m (Maybe TyThing)  
-
-_dumpTypeEnv :: TypecheckedModule -> IO () 
-_dumpTypeEnv tm = do 
-  print "DUMP-TYPE-ENV"
-  print (showpp <$> tcmTyThings tm)
-
-tcmTyThings :: TypecheckedModule -> Maybe [Name] 
-tcmTyThings 
-  = id 
-  -- typeEnvElts 
-  -- . tcg_type_env . fst 
-  -- . md_types . snd
-  -- . tm_internals_
-  . modInfoTopLevelScope
-  . tm_checked_module_info
-
-
-_dumpRdrEnv :: HscEnv -> MGIModGuts -> IO () 
-_dumpRdrEnv _hscEnv modGuts = do 
-  print "DUMP-RDR-ENV" 
-  print (mgNames modGuts)
-  -- print (hscNames hscEnv) 
-  -- print (mgDeps modGuts) 
-  where 
-    _mgDeps   = Ghc.dep_mods . mgi_deps 
-    _hscNames = fmap showPpr . Ghc.ic_tythings . Ghc.hsc_IC
-
-mgNames :: MGIModGuts -> [Ghc.Name] 
-mgNames  = fmap Ghc.gre_name . Ghc.globalRdrEnvElts .  mgi_rdr_env 
-
----------------------------------------------------------------------------------------
--- | @makeDependencies@ loads BareSpec for target and imported modules 
--- /IMPORTANT(adn)/: We \"cheat\" a bit by creating a 'Module' out the 'ModuleName' we 
--- parse from the spec, and convert the former into a 'StableModule' for the purpose
--- of dependency tracking. This means, in practice, that all the \"wired-in-prelude\"
--- specs will share the same `UnitId`, which for the sake of the executable is an
--- acceptable compromise, as long as we don't create duplicates.
----------------------------------------------------------------------------------------
-makeDependencies :: Config -> DepGraph -> SpecEnv -> ModSummary -> Ms.BareSpec 
-                 -> Ghc TargetDependencies
-makeDependencies cfg depGraph specEnv modSum _ = do 
-  let paths     = S.fromList $ idirs cfg ++ importPaths (ms_hspp_opts modSum)
-  _            <- liftIO $ whenLoud $ putStrLn $ "paths = " ++ show paths
-  let reachable = reachableModules depGraph (ms_mod modSum)
-  specSpecs    <- findAndParseSpecFiles cfg paths modSum reachable
-  let homeSpecs = cachedBareSpecs specEnv reachable
-
-  -- NOTE:(adn) Unfortunately for the executable we might have 3 different 'Prelude' specs
-  -- (one for the Prelude functions, one for the Real/NonReal and one for the PatErr, so we
-  -- cannot really assume all the module names will be disjointed. As a result we have to
-  -- hack our way around this by replacing the 'UnitId' with some unique enumeration, at
-  -- least unique in this local scope.
-
-  let combine ix (mn, sp) = ((mn, ix), sp)
-  let impSpecs  = map (bimap mkStableModule (view liftedSpecGetter)) (zipWith combine [0..] (specSpecs ++ homeSpecs))
-
-  return        $ TargetDependencies $ HM.fromList impSpecs
-  where
-    mkStableModule :: (ModName, Int) -> StableModule
-    mkStableModule (modName, ix) =
-      Ghc.mkStableModule (fakeUnitId (moduleUnitId targetModule) ix) (getModName modName)
-
-    fakeUnitId :: UnitId -> Int -> UnitId
-    fakeUnitId uid ix = stringToUnitId $ unitIdString uid ++ show ix
-
-    targetModule :: Module
-    targetModule = ms_mod modSum
-
-modSummaryHsFile :: ModSummary -> FilePath
-modSummaryHsFile modSummary =
-  fromMaybe
-    (panic Nothing $
-      "modSummaryHsFile: missing .hs file for " ++
-      showPpr (ms_mod modSummary))
-    (ml_hs_file $ ms_location modSummary)
-
-cachedBareSpecs :: SpecEnv -> [Module] -> [(ModName, Ms.BareSpec)]
-cachedBareSpecs specEnv mods = lookupBareSpec <$> mods
-  where
-    lookupBareSpec m         = fromMaybe (err m) (lookupModuleEnv specEnv m)
-    err m                    = impossible Nothing ("lookupBareSpec: missing module " ++ showPpr m)
-
-checkFilePragmas :: GhcMonadLike m => [Located String] -> m ()
-checkFilePragmas = Misc.applyNonNull (return ()) throw . mapMaybe err
-  where
-    err pragma
-      | check (val pragma) = Just (ErrFilePragma $ fSrcSpan pragma :: Error)
-      | otherwise          = Nothing
-    check pragma           = any (`isPrefixOf` pragma) bad
-    bad =
-      [ "-i", "--idirs"
-      , "-g", "--ghc-option"
-      , "--c-files", "--cfiles"
-      ]
-
---------------------------------------------------------------------------------
--- | Family instance information
---------------------------------------------------------------------------------
-makeFamInstEnv :: [FamInst] -> ([Ghc.TyCon], [(Symbol, DataCon)])
-makeFamInstEnv famInsts =
-  let fiTcs = [ tc            | FamInst { fi_flavor = DataFamilyInst tc } <- famInsts ]
-      fiDcs = [ (symbol d, d) | tc <- fiTcs, d <- tyConDataCons tc ]
-  in (fiTcs, fiDcs)
-
-getFamInstances :: HscEnv -> IO [FamInst]
-getFamInstances env = do
-  (_, Just (pkg_fie, home_fie)) <- runTcInteractive env tcGetFamInstEnvs
-  return $ famInstEnvElts home_fie ++ famInstEnvElts pkg_fie
- 
---------------------------------------------------------------------------------
--- | Extract Specifications from GHC -------------------------------------------
---------------------------------------------------------------------------------
-extractSpecComments :: ApiAnns -> [(SourcePos, String)]
-extractSpecComments = mapMaybe extractSpecComment . GhcMonadLike.apiComments
-
--- | 'extractSpecComment' pulls out the specification part from a full comment
---   string, i.e. if the string is of the form:
---   1. '{-@ S @-}' then it returns the substring 'S',
---   2. '{-@ ... -}' then it throws a malformed SPECIFICATION ERROR, and
---   3. Otherwise it is just treated as a plain comment so we return Nothing.
-
-extractSpecComment :: Ghc.Located AnnotationComment -> Maybe (SourcePos, String)
-extractSpecComment (Ghc.L sp (AnnBlockComment text))
-  | isPrefixOf "{-@" text && isSuffixOf "@-}" text          -- valid   specification
-  = Just (offsetPos, take (length text - 6) $ drop 3 text)
-  | isPrefixOf "{-@" text                                   -- invalid specification
-  = uError $ ErrParseAnn sp "A valid specification must have a closing '@-}'."
-  where
-    offsetPos = case srcSpanSourcePos sp of
-      SourcePos file line col -> safeSourcePos file (unPos line) (unPos col + 3)
-extractSpecComment _ = Nothing
-
-extractSpecQuotes :: TypecheckedModule -> [BPspec]
-extractSpecQuotes = 
-  extractSpecQuotes' (ms_mod . pm_mod_summary . tm_parsed_module) 
-                     (tcg_anns . fst . tm_internals_)
-
-extractSpecQuotes' :: (a -> Module) -> (a -> [Annotation]) -> a -> [BPspec]
-extractSpecQuotes' thisModule getAnns a = mapMaybe extractSpecQuote anns
-  where
-    anns = map ann_value $
-           filter (isOurModTarget . ann_target) $
-           getAnns a
-
-    isOurModTarget (ModuleTarget mod1) = mod1 == thisModule a
-    isOurModTarget _ = False
-
-extractSpecQuote :: AnnPayload -> Maybe BPspec
-extractSpecQuote payload = 
-  case fromSerialized deserializeWithData payload of
-    Nothing -> Nothing
-    Just qt -> Just $ refreshSymbols $ liquidQuoteSpec qt
-
-refreshSymbols :: Data a => a -> a
-refreshSymbols = everywhere (mkT refreshSymbol)
-
-refreshSymbol :: Symbol -> Symbol
-refreshSymbol = symbol . symbolText
-
---------------------------------------------------------------------------------
--- | Finding & Parsing Files ---------------------------------------------------
---------------------------------------------------------------------------------
-
--- | Handle Spec Files ---------------------------------------------------------
-
-findAndParseSpecFiles :: GhcMonadLike m
-                      => Config
-                      -> S.HashSet FilePath
-                      -> ModSummary
-                      -> [Module]
-                      -> m [(ModName, Ms.BareSpec)]
-findAndParseSpecFiles cfg paths modSummary reachable = do
-  modGraph <- GhcMonadLike.getModuleGraph
-  impSumms <- mapM GhcMonadLike.getModSummary (moduleName <$> reachable)
-  imps''   <- nub . concat <$> mapM modSummaryImports (modSummary : impSumms)
-  imps'    <- filterM ((not <$>) . isHomeModule) imps''
-  let imps  = m2s <$> imps'
-  fs'      <- liftIO $ moduleFiles modGraph Spec paths imps
-  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps'': "  ++ show (m2s <$> imps''))
-  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps' : "  ++ show (m2s <$> imps'))
-  -- liftIO  $ whenLoud  $ print ("moduleFiles-imps  : "  ++ show imps)
-  -- liftIO  $ whenLoud  $ print ("moduleFiles-Paths : "  ++ show paths)
-  -- liftIO  $ whenLoud  $ print ("moduleFiles-Specs : "  ++ show fs')
-  patSpec  <- liftIO $ getPatSpec  modGraph paths $ totalityCheck cfg
-  rlSpec   <- liftIO $ getRealSpec modGraph paths $ not (linear cfg)
-  let fs    = patSpec ++ rlSpec ++ fs'
-  liftIO $ transParseSpecs modGraph paths mempty mempty fs
-  where
-    m2s = moduleNameString . moduleName
-
-getPatSpec :: ModuleGraph -> S.HashSet FilePath -> Bool -> IO [FilePath]
-getPatSpec modGraph paths totalitycheck
- | totalitycheck = moduleFiles modGraph Spec paths [patErrorName]
- | otherwise     = return []
- where
-  patErrorName   = "PatErr"
-
-getRealSpec :: ModuleGraph -> S.HashSet FilePath -> Bool -> IO [FilePath]
-getRealSpec modGraph paths freal
-  | freal     = moduleFiles modGraph Spec paths [realSpecName]
-  | otherwise = moduleFiles modGraph Spec paths [notRealSpecName]
-  where
-    realSpecName    = "Real"
-    notRealSpecName = "NotReal"
-
-transParseSpecs :: ModuleGraph
-                -> S.HashSet FilePath
-                -> S.HashSet FilePath 
-                -> [(ModName, Ms.BareSpec)]
-                -> [FilePath]
-                -> IO [(ModName, Ms.BareSpec)]
-transParseSpecs _ _ _ specs [] = return specs
-transParseSpecs modGraph paths seenFiles specs newFiles = do
-  -- liftIO $ print ("TRANS-PARSE-SPECS", seenFiles, newFiles)
-  newSpecs      <- liftIO $ mapM parseSpecFile newFiles
-  impFiles      <- moduleFiles modGraph Spec paths $ specsImports newSpecs
-  let seenFiles' = seenFiles `S.union` S.fromList newFiles
-  let specs'     = specs ++ map (second noTerm) newSpecs
-  let newFiles'  = filter (not . (`S.member` seenFiles')) impFiles
-  transParseSpecs modGraph paths seenFiles' specs' newFiles'
-  where
-    specsImports ss = nub $ concatMap (map symbolString . Ms.imports . snd) ss
-
-noTerm :: Ms.BareSpec -> Ms.BareSpec
-noTerm spec = spec { Ms.decr = mempty, Ms.lazy = mempty, Ms.termexprs = mempty }
-
--- | Parse a spec file by path.
---
--- On a parse error, we fail.
---
--- TODO, Andres: It would be better to fail more systematically, but currently we
--- seem to have an option between throwing an error which will be reported badly,
--- or printing the error ourselves.
---
-parseSpecFile :: FilePath -> IO (ModName, Ms.BareSpec)
-parseSpecFile file = do
-  contents <- Misc.sayReadFile file
-  case specSpecificationP file contents of
-    Left peb -> do
-      hPutStrLn stderr (errorBundlePretty peb)
-      panic Nothing "parsing spec file failed"
-    Right x  -> pure x
-
--- Find Hquals Files -----------------------------------------------------------
-
--- _moduleHquals :: MGIModGuts
---              -> [FilePath]
---              -> FilePath
---              -> [String]
---              -> [FilePath]
---              -> Ghc [FilePath]
--- _moduleHquals mgi paths target imps incs = do
---   hqs   <- specIncludes Hquals paths incs
---   hqs'  <- moduleFiles Hquals paths (mgi_namestring mgi : imps)
---   hqs'' <- liftIO $ filterM doesFileExist [extFileName Hquals target]
---   return $ Misc.sortNub $ hqs'' ++ hqs ++ hqs'
-
--- Find Files for Modules ------------------------------------------------------
-
-moduleFiles :: ModuleGraph -> Ext -> S.HashSet FilePath -> [String] -> IO [FilePath]
-moduleFiles modGraph ext paths names = catMaybes <$> mapM (moduleFile modGraph ext paths) names
-
-moduleFile :: ModuleGraph -> Ext -> S.HashSet FilePath -> String -> IO (Maybe FilePath)
-moduleFile modGraph ext (S.toList -> paths) name
-  | ext `elem` [Hs, LHs] = do
-    let graph = mgModSummaries modGraph
-    case find (\m -> not (isBootInterface . isBootSummary $ m) &&
-                     name == moduleNameString (ms_mod_name m)) graph of
-      Nothing -> getFileInDirs (extModuleName name ext) paths
-      Just ms -> return $ normalise <$> ml_hs_file (ms_location ms)
-  | otherwise = getFileInDirs (extModuleName name ext) paths
-
-
---------------------------------------------------------------------------------
--- Assemble Information for Spec Extraction ------------------------------------
---------------------------------------------------------------------------------
-
-makeMGIModGuts :: ModGuts -> MGIModGuts
-makeMGIModGuts modGuts = miModGuts deriv modGuts
-  where
-    deriv   = Just $ instEnvElts $ mg_inst_env modGuts
-
-makeLogicMap :: IO LogicMap
-makeLogicMap = do
-  lg    <- Misc.getCoreToLogicPath
-  lspec <- Misc.sayReadFile lg
-  case parseSymbolToLogic lg lspec of
-    Left peb -> do
-      hPutStrLn stderr (errorBundlePretty peb)
-      panic Nothing "makeLogicMap failed"
-    Right lm -> return (lm <> listLMap)
-
-listLMap :: LogicMap -- TODO-REBARE: move to wiredIn
-listLMap  = toLogicMap [ (dummyLoc nilName , []     , hNil)
-                       , (dummyLoc consName, [x, xs], hCons (EVar <$> [x, xs])) ]
-  where
-    x     = "x"
-    xs    = "xs"
-    hNil  = mkEApp (dcSym Ghc.nilDataCon ) []
-    hCons = mkEApp (dcSym Ghc.consDataCon)
-    dcSym = dummyLoc . dropModuleUnique . symbol
-
-
-
---------------------------------------------------------------------------------
--- | Pretty Printing -----------------------------------------------------------
---------------------------------------------------------------------------------
-
-instance PPrint TargetSpec where
-  pprintTidy k spec = vcat
-    [ "******* Target Variables ********************"
-    , pprintTidy k $ gsTgtVars (gsVars spec)
-    , "******* Type Signatures *********************"
-    , pprintLongList k (gsTySigs (gsSig spec))
-    , "******* Assumed Type Signatures *************"
-    , pprintLongList k (gsAsmSigs (gsSig spec))
-    , "******* DataCon Specifications (Measure) ****"
-    , pprintLongList k (gsCtors (gsData spec))
-    , "******* Measure Specifications **************"
-    , pprintLongList k (gsMeas (gsData spec))       ]
-
-instance PPrint TargetInfo where
-  pprintTidy k info = vcat
-    [ -- "*************** Imports *********************"
-      -- , intersperse comma $ text <$> imports info
-      -- , "*************** Includes ********************"
-      -- , intersperse comma $ text <$> includes info
-      "*************** Imported Variables **********"
-    , pprDoc $ _giImpVars (review targetSrcIso $ giSrc info)
-    , "*************** Defined Variables ***********"
-    , pprDoc $ _giDefVars (review targetSrcIso $ giSrc info)
-    , "*************** Specification ***************"
-    , pprintTidy k $ giSpec info
-    , "*************** Core Bindings ***************"
-    , pprintCBs $ _giCbs (review targetSrcIso $ giSrc info) ]
-
--- RJ: the silly guards below are to silence the unused-var checker
-pprintCBs :: [CoreBind] -> Doc
-pprintCBs
-  | otherwise = pprintCBsTidy
-  | otherwise = pprintCBsVerbose
-  where
-    pprintCBsTidy    = pprDoc . tidyCBs
-    pprintCBsVerbose = text . O.showSDocDebug unsafeGlobalDynFlags . O.ppr . tidyCBs
-
-instance Show TargetInfo where
-  show = showpp
-
-instance PPrint TargetVars where
-  pprintTidy _ AllVars   = text "All Variables"
-  pprintTidy k (Only vs) = text "Only Variables: " <+> pprintTidy k vs
-
-------------------------------------------------------------------------
--- Dealing with Errors ---------------------------------------------------
-------------------------------------------------------------------------
-
-instance Result SourceError where
-  result = (`Crash` "Invalid Source") . sourceErrors ""
diff --git a/src/Language/Haskell/Liquid/GHC/Logging.hs b/src/Language/Haskell/Liquid/GHC/Logging.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Logging.hs
+++ /dev/null
@@ -1,73 +0,0 @@
-{- | This module exposes variations over the standard GHC's logging functions to work with the 'Doc'
-     type from the \"pretty\" package. We would like LiquidHaskell to emit diagnostic messages using the very
-     same GHC machinery, so that IDE-like programs (e.g. \"ghcid\", \"ghcide\" etc) would be able to
-     correctly show errors and warnings to the users, in ther editors.
-
-     Unfortunately, this is not possible to do out of the box because LiquidHaskell uses the 'Doc' type from
-     the \"pretty\" package but GHC uses (for historical reasons) its own version. Due to the fact none of
-     the constructors are exported, we simply cannot convert between the two types effortlessly, but we have
-     to pay the price of a pretty-printing \"roundtrip\".
--}
-
-{-# LANGUAGE CPP #-}
-
-module Language.Haskell.Liquid.GHC.Logging (
-    fromPJDoc
-  , putWarnMsg
-  , putErrMsg
-  , mkLongErrAt
-  ) where
-
-import qualified Language.Haskell.Liquid.GHC.API as GHC
-import qualified Text.PrettyPrint.HughesPJ as PJ
-
--- Unfortunately we need the import below to bring in scope 'PPrint' instances.
-import Language.Haskell.Liquid.Types.Errors ()
-
-fromPJDoc :: PJ.Doc -> GHC.SDoc
-fromPJDoc = GHC.text . PJ.render
-
--- | Like the original 'putLogMsg', but internally converts the input 'Doc' (from the \"pretty\" library)
--- into GHC's internal 'SDoc'.
-putLogMsg :: GHC.DynFlags
-          -> GHC.WarnReason
-          -> GHC.Severity
-          -> GHC.SrcSpan
-          -> Maybe GHC.PprStyle
-          -> PJ.Doc
-          -> IO ()
-putLogMsg dynFlags reason sev srcSpan _mbStyle =
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
- GHC.putLogMsg dynFlags reason sev srcSpan style' . GHC.text . PJ.render
-   where
-    style' :: GHC.PprStyle
-    style' = case _mbStyle of
-               Nothing  -> defaultErrStyle dynFlags
-               Just sty -> sty
-#else
-  GHC.putLogMsg dynFlags reason sev srcSpan . GHC.text . PJ.render
-#endif
-#endif
-
-
-defaultErrStyle :: GHC.DynFlags -> GHC.PprStyle
-defaultErrStyle _dynFlags =
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-  GHC.defaultErrStyle _dynFlags
-#else
-  GHC.defaultErrStyle
-#endif
-#endif
-
-putWarnMsg :: GHC.DynFlags -> GHC.SrcSpan -> PJ.Doc -> IO ()
-putWarnMsg dynFlags srcSpan doc =
-  putLogMsg dynFlags GHC.NoReason GHC.SevWarning srcSpan (Just $ defaultErrStyle dynFlags) doc
-
-putErrMsg :: GHC.DynFlags -> GHC.SrcSpan -> PJ.Doc -> IO ()
-putErrMsg dynFlags srcSpan doc = putLogMsg dynFlags GHC.NoReason GHC.SevError srcSpan Nothing doc
-
--- | Like GHC's 'mkLongErrAt', but it builds the final 'ErrMsg' out of two \"HughesPJ\"'s 'Doc's.
-mkLongErrAt :: GHC.SrcSpan -> PJ.Doc -> PJ.Doc -> GHC.TcRn GHC.ErrMsg
-mkLongErrAt srcSpan msg extra = GHC.mkLongErrAt srcSpan (fromPJDoc msg) (fromPJDoc extra)
diff --git a/src/Language/Haskell/Liquid/GHC/Misc.hs b/src/Language/Haskell/Liquid/GHC/Misc.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Misc.hs
+++ /dev/null
@@ -1,1141 +0,0 @@
-{-# LANGUAGE CPP                       #-}
-{-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE FlexibleInstances         #-}
-{-# LANGUAGE FlexibleContexts          #-}
-{-# LANGUAGE GADTs                     #-}
-{-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE RankNTypes                #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
-{-# LANGUAGE UndecidableInstances      #-}
-{-# LANGUAGE ViewPatterns              #-}
-{-# LANGUAGE PatternSynonyms           #-}
-
--- | This module contains a wrappers and utility functions for
--- accessing GHC module information. It should NEVER depend on
--- ANY module inside the Language.Haskell.Liquid.* tree.
-
-module Language.Haskell.Liquid.GHC.Misc where
-
-import           Data.String
-import qualified Data.List as L
-import           Debug.Trace
-
-import           Prelude                                    hiding (error)
-import           Language.Haskell.Liquid.GHC.API            as Ghc hiding ( L
-                                                                          , sourceName
-                                                                          , showPpr
-                                                                          , showSDocDump
-                                                                          , panic
-                                                                          , showSDoc
-                                                                          )
-import qualified Language.Haskell.Liquid.GHC.API            as Ghc (GenLocated (L), showSDoc, panic, showSDocDump)
-
-
-import           Data.Char                                  (isLower, isSpace, isUpper)
-import           Data.Maybe                                 (isJust, fromMaybe, fromJust, maybeToList)
-import           Data.Hashable
-import qualified Data.HashSet                               as S
-import qualified Data.Map.Strict                            as OM
-import           Control.Monad.State                        (evalState, get, modify)
-
-import qualified Data.Text.Encoding.Error                   as TE
-import qualified Data.Text.Encoding                         as T
-import qualified Data.Text                                  as T
-import           Control.Arrow                              (second)
-import           Control.Monad                              ((>=>), foldM)
-import qualified Text.PrettyPrint.HughesPJ                  as PJ
-import           Language.Fixpoint.Types                    hiding (L, panic, Loc (..), SrcSpan, Constant, SESearch (..))
-import qualified Language.Fixpoint.Types                    as F
-import           Language.Fixpoint.Misc                     (safeHead, safeLast, errorstar) -- , safeLast, safeInit)
-import           Language.Haskell.Liquid.Misc               (keyDiff) 
-import           Control.DeepSeq
-import           Language.Haskell.Liquid.Types.Errors
-
-
-isAnonBinder :: Ghc.TyConBinder -> Bool
-isAnonBinder (Bndr _ (AnonTCB _)) = True
-isAnonBinder (Bndr _ _)           = False
-
-mkAlive :: Var -> Id
-mkAlive x
-  | isId x && isDeadOcc (idOccInfo x)
-  = setIdInfo x (setOccInfo (idInfo x) noOccInfo)
-  | otherwise
-  = x
-
-
---------------------------------------------------------------------------------
--- | Encoding and Decoding Location --------------------------------------------
---------------------------------------------------------------------------------
-srcSpanTick :: Module -> SrcSpan -> Tickish a
-srcSpanTick m sp = ProfNote (AllCafsCC m sp) False True
-
-tickSrcSpan ::  Outputable a => Tickish a -> SrcSpan
-tickSrcSpan (ProfNote cc _ _) = cc_loc cc
-tickSrcSpan (SourceNote ss _) = RealSrcSpan ss Nothing
-tickSrcSpan _                 = noSrcSpan
-
---------------------------------------------------------------------------------
--- | Generic Helpers for Accessing GHC Innards ---------------------------------
---------------------------------------------------------------------------------
-
--- FIXME: reusing uniques like this is really dangerous
-stringTyVar :: String -> TyVar
-stringTyVar s = mkTyVar name liftedTypeKind
-  where 
-    name      = mkInternalName (mkUnique 'x' 24)  occ noSrcSpan
-    occ       = mkTyVarOcc s
-
--- FIXME: reusing uniques like this is really dangerous
-stringVar :: String -> Type -> Var
-stringVar s t = mkLocalVar VanillaId name Many t vanillaIdInfo
-   where
-      name = mkInternalName (mkUnique 'x' 25) occ noSrcSpan
-      occ  = mkVarOcc s
-
--- FIXME: plugging in dummy type like this is really dangerous
-maybeAuxVar :: Symbol -> Maybe Var
-maybeAuxVar s
-  | isMethod sym = Just sv
-  | otherwise = Nothing 
-  where (_, uid) = splitModuleUnique s
-        sym = dropModuleNames s
-        sv = mkExportedLocalId VanillaId name anyTy 
-        -- 'x' is chosen for no particular reason..
-        name = mkInternalName (mkUnique 'x' uid) occ noSrcSpan
-        occ = mkVarOcc (T.unpack (symbolText sym))
-
-stringTyCon :: Char -> Int -> String -> TyCon
-stringTyCon = stringTyConWithKind anyTy
-
--- FIXME: reusing uniques like this is really dangerous
-stringTyConWithKind :: Kind -> Char -> Int -> String -> TyCon
-stringTyConWithKind k c n s = Ghc.mkKindTyCon name [] k [] name
-  where
-    name          = mkInternalName (mkUnique c n) occ noSrcSpan
-    occ           = mkTcOcc s
-
-hasBaseTypeVar :: Var -> Bool
-hasBaseTypeVar = isBaseType . varType
-
--- same as Constraint isBase
-isBaseType :: Type -> Bool
-isBaseType (ForAllTy _ _)  = False
-isBaseType (FunTy { ft_arg = t1, ft_res = t2}) = isBaseType t1 && isBaseType t2
-isBaseType (TyVarTy _)     = True
-isBaseType (TyConApp _ ts) = all isBaseType ts
-isBaseType (AppTy t1 t2)   = isBaseType t1 && isBaseType t2
-isBaseType _               = False
-
-isTmpVar :: Var -> Bool 
-isTmpVar = isTmpSymbol . dropModuleNamesAndUnique . symbol 
-
-isTmpSymbol    :: Symbol -> Bool
-isTmpSymbol x  = any (`isPrefixOfSym` x) [anfPrefix, tempPrefix, "ds_"]
-
-validTyVar :: String -> Bool
-validTyVar s@(c:_) = isLower c && all (not . isSpace) s
-validTyVar _       = False
-
-tvId :: TyVar -> String
-tvId α = {- traceShow ("tvId: α = " ++ show α) $ -} showPpr α ++ show (varUnique α)
-
-tidyCBs :: [CoreBind] -> [CoreBind]
-tidyCBs = map unTick
-
-unTick :: CoreBind -> CoreBind
-unTick (NonRec b e) = NonRec b (unTickExpr e)
-unTick (Rec bs)     = Rec $ map (second unTickExpr) bs
-
-unTickExpr :: CoreExpr -> CoreExpr
-unTickExpr (App e a)          = App (unTickExpr e) (unTickExpr a)
-unTickExpr (Lam b e)          = Lam b (unTickExpr e)
-unTickExpr (Let b e)          = Let (unTick b) (unTickExpr e)
-unTickExpr (Case e b t as)    = Case (unTickExpr e) b t (map unTickAlt as)
-    where unTickAlt (a, b, e) = (a, b, unTickExpr e)
-unTickExpr (Cast e c)         = Cast (unTickExpr e) c
-unTickExpr (Tick _ e)         = unTickExpr e
-unTickExpr x                  = x
-
-isFractionalClass :: Class -> Bool
-isFractionalClass clas = classKey clas `elem` fractionalClassKeys
-
-isOrdClass :: Class -> Bool
-isOrdClass clas = classKey clas == ordClassKey
-
---------------------------------------------------------------------------------
--- | Pretty Printers -----------------------------------------------------------
---------------------------------------------------------------------------------
-notracePpr :: Outputable a => String -> a -> a
-notracePpr _ x = x
-
-tracePpr :: Outputable a => String -> a -> a
-tracePpr s x = trace ("\nTrace: [" ++ s ++ "] : " ++ showPpr x) x
-
-pprShow :: Show a => a -> Ghc.SDoc
-pprShow = text . show
-
-
-toFixSDoc :: Fixpoint a => a -> PJ.Doc
-toFixSDoc = PJ.text . PJ.render . toFix
-
-sDocDoc :: Ghc.SDoc -> PJ.Doc
-sDocDoc   = PJ.text . showSDoc
-
-pprDoc :: Outputable a => a -> PJ.Doc
-pprDoc    = sDocDoc . ppr
-
--- Overriding Outputable functions because they now require DynFlags!
-showPpr :: Outputable a => a -> String
-showPpr       = showSDoc . ppr
-
--- FIXME: somewhere we depend on this printing out all GHC entities with
--- fully-qualified names...
-showSDoc :: Ghc.SDoc -> String
-showSDoc sdoc = Ghc.renderWithStyle unsafeGlobalDynFlags sdoc (Ghc.mkUserStyle unsafeGlobalDynFlags myQualify {- Ghc.alwaysQualify -} Ghc.AllTheWay)
-
-myQualify :: Ghc.PrintUnqualified
-myQualify = Ghc.neverQualify { Ghc.queryQualifyName = Ghc.alwaysQualifyNames }
--- { Ghc.queryQualifyName = \_ _ -> Ghc.NameNotInScope1 }
-
-showSDocDump :: Ghc.SDoc -> String
-showSDocDump  = Ghc.showSDocDump unsafeGlobalDynFlags
-
-instance Outputable a => Outputable (S.HashSet a) where
-  ppr = ppr . S.toList
-
-typeUniqueString :: Outputable a => a -> String
-typeUniqueString = {- ("sort_" ++) . -} showSDocDump . ppr
-
-
---------------------------------------------------------------------------------
--- | Manipulating Source Spans -------------------------------------------------
---------------------------------------------------------------------------------
-
-newtype Loc    = L (Int, Int) deriving (Eq, Ord, Show)
-
-instance Hashable Loc where
-  hashWithSalt i (L z) = hashWithSalt i z
-
---instance (Uniquable a) => Hashable a where
-
-instance Hashable SrcSpan where
-  hashWithSalt i (UnhelpfulSpan reason) = case reason of
-    UnhelpfulNoLocationInfo -> hashWithSalt i (uniq $ fsLit "UnhelpfulNoLocationInfo")
-    UnhelpfulWiredIn        -> hashWithSalt i (uniq $ fsLit "UnhelpfulWiredIn")
-    UnhelpfulInteractive    -> hashWithSalt i (uniq $ fsLit "UnhelpfulInteractive")
-    UnhelpfulGenerated      -> hashWithSalt i (uniq $ fsLit "UnhelpfulGenerated")
-    UnhelpfulOther fs       -> hashWithSalt i (uniq fs)
-  hashWithSalt i (RealSrcSpan s _)      = hashWithSalt i (srcSpanStartLine s, srcSpanStartCol s, srcSpanEndCol s)
-
-fSrcSpan :: (F.Loc a) => a -> SrcSpan
-fSrcSpan = fSrcSpanSrcSpan . F.srcSpan
-
-fSourcePos :: (F.Loc a) => a -> F.SourcePos 
-fSourcePos = F.sp_start . F.srcSpan 
-
-fSrcSpanSrcSpan :: F.SrcSpan -> SrcSpan
-fSrcSpanSrcSpan (F.SS p p') = sourcePos2SrcSpan p p'
-
-srcSpanFSrcSpan :: SrcSpan -> F.SrcSpan
-srcSpanFSrcSpan sp = F.SS p p'
-  where
-    p              = srcSpanSourcePos sp
-    p'             = srcSpanSourcePosE sp
-
-sourcePos2SrcSpan :: SourcePos -> SourcePos -> SrcSpan
-sourcePos2SrcSpan p p' = RealSrcSpan (realSrcSpan f (unPos l) (unPos c) (unPos l') (unPos c')) Nothing
-  where
-    (f, l,  c)         = F.sourcePosElts p
-    (_, l', c')        = F.sourcePosElts p'
-
-sourcePosSrcSpan   :: SourcePos -> SrcSpan
-sourcePosSrcSpan p@(SourcePos file line col) = sourcePos2SrcSpan p (SourcePos file line (succPos col))
-
-sourcePosSrcLoc    :: SourcePos -> SrcLoc
-sourcePosSrcLoc (SourcePos file line col) = mkSrcLoc (fsLit file) (unPos line) (unPos col)
-
-srcSpanSourcePos :: SrcSpan -> SourcePos
-srcSpanSourcePos (UnhelpfulSpan _) = dummyPos "<no source information>"
-srcSpanSourcePos (RealSrcSpan s _) = realSrcSpanSourcePos s
-
-srcSpanSourcePosE :: SrcSpan -> SourcePos
-srcSpanSourcePosE (UnhelpfulSpan _) = dummyPos "<no source information>"
-srcSpanSourcePosE (RealSrcSpan s _) = realSrcSpanSourcePosE s
-
-srcSpanFilename :: SrcSpan -> String
-srcSpanFilename    = maybe "" unpackFS . srcSpanFileName_maybe
-
-srcSpanStartLoc :: RealSrcSpan -> Loc
-srcSpanStartLoc l  = L (srcSpanStartLine l, srcSpanStartCol l)
-
-srcSpanEndLoc :: RealSrcSpan -> Loc
-srcSpanEndLoc l    = L (srcSpanEndLine l, srcSpanEndCol l)
-
-
-oneLine :: RealSrcSpan -> Bool
-oneLine l          = srcSpanStartLine l == srcSpanEndLine l
-
-lineCol :: RealSrcSpan -> (Int, Int)
-lineCol l          = (srcSpanStartLine l, srcSpanStartCol l)
-
-realSrcSpanSourcePos :: RealSrcSpan -> SourcePos
-realSrcSpanSourcePos s = safeSourcePos file line col
-  where
-    file               = unpackFS $ srcSpanFile s
-    line               = srcSpanStartLine       s
-    col                = srcSpanStartCol        s
-
-
-realSrcSpanSourcePosE :: RealSrcSpan -> SourcePos
-realSrcSpanSourcePosE s = safeSourcePos file line col
-  where
-    file                = unpackFS $ srcSpanFile s
-    line                = srcSpanEndLine       s
-    col                 = srcSpanEndCol        s
-
-getSourcePos :: NamedThing a => a -> SourcePos
-getSourcePos = srcSpanSourcePos  . getSrcSpan
-
-getSourcePosE :: NamedThing a => a -> SourcePos
-getSourcePosE = srcSpanSourcePosE . getSrcSpan
-
-locNamedThing :: NamedThing a => a -> F.Located a
-locNamedThing x = F.Loc l lE x
-  where
-    l          = getSourcePos  x
-    lE         = getSourcePosE x
-
-instance F.Loc Var where 
-  srcSpan v = SS (getSourcePos v) (getSourcePosE v) 
-
-namedLocSymbol :: (F.Symbolic a, NamedThing a) => a -> F.Located F.Symbol
-namedLocSymbol d = F.symbol <$> locNamedThing d
-
-varLocInfo :: (Type -> a) -> Var -> F.Located a
-varLocInfo f x = f . varType <$> locNamedThing x
-
-namedPanic :: (NamedThing a) => a -> String -> b
-namedPanic x msg = panic (Just (getSrcSpan x)) msg
-
---------------------------------------------------------------------------------
--- | Manipulating CoreExpr -----------------------------------------------------
---------------------------------------------------------------------------------
-
-collectArguments :: Int -> CoreExpr -> [Var]
-collectArguments n e = if length xs > n then take n xs else xs
-  where
-    (vs', e')        = collectValBinders' $ snd $ collectTyBinders e
-    vs               = fst $ collectBinders $ ignoreLetBinds e'
-    xs               = vs' ++ vs
-
-{-
-collectTyBinders :: CoreExpr -> ([Var], CoreExpr)
-collectTyBinders expr
-  = go [] expr
-  where
-    go tvs (Lam b e) | isTyVar b = go (b:tvs) e
-    go tvs e                     = (reverse tvs, e)
--}
-
-collectValBinders' :: Ghc.Expr Var -> ([Var], Ghc.Expr Var)
-collectValBinders' = go []
-  where
-    go tvs (Lam b e) | isTyVar b = go tvs     e
-    go tvs (Lam b e) | isId    b = go (b:tvs) e
-    go tvs (Tick _ e)            = go tvs e
-    go tvs e                     = (reverse tvs, e)
-
-ignoreLetBinds :: Ghc.Expr t -> Ghc.Expr t
-ignoreLetBinds (Let (NonRec _ _) e')
-  = ignoreLetBinds e'
-ignoreLetBinds e
-  = e
-
---------------------------------------------------------------------------------
--- | Predicates on CoreExpr and DataCons ---------------------------------------
---------------------------------------------------------------------------------
-
-isTupleId :: Id -> Bool
-isTupleId = maybe False Ghc.isTupleDataCon . idDataConM
-
-idDataConM :: Id -> Maybe DataCon
-idDataConM x = case idDetails x of
-  DataConWorkId d -> Just d
-  DataConWrapId d -> Just d
-  _               -> Nothing 
-
-isDataConId :: Id -> Bool
-isDataConId = isJust . idDataConM
-
-getDataConVarUnique :: Var -> Unique
-getDataConVarUnique v
-  | isId v && isDataConId v = getUnique (idDataCon v)
-  | otherwise               = getUnique v
-
-isDictionaryExpression :: Ghc.Expr Id -> Maybe Id
-isDictionaryExpression (Tick _ e) = isDictionaryExpression e
-isDictionaryExpression (Var x)    | isDictionary x = Just x
-isDictionaryExpression _          = Nothing
-
-realTcArity :: TyCon -> Arity
-realTcArity = tyConArity
-
-{-
-  tracePpr ("realTcArity of " ++ showPpr c
-     ++ "\n tyConKind = " ++ showPpr (tyConKind c)
-     ++ "\n kindArity = " ++ show (kindArity (tyConKind c))
-     ++ "\n kindArity' = " ++ show (kindArity' (tyConKind c)) -- this works for TypeAlias
-     ) $ kindArity' (tyConKind c)
--}
-
-kindTCArity :: TyCon -> Arity
-kindTCArity = go . tyConKind
-  where
-    go (FunTy { ft_res = res}) = 1 + go res
-    go _               = 0
-
-
-kindArity :: Kind -> Arity
-kindArity (ForAllTy _ res)
-  = 1 + kindArity res
-kindArity _
-  = 0
-
-uniqueHash :: Uniquable a => Int -> a -> Int
-uniqueHash i = hashWithSalt i . getKey . getUnique
-
--- slightly modified version of DynamicLoading.lookupRdrNameInModule
-lookupRdrName :: HscEnv -> ModuleName -> RdrName -> IO (Maybe Name)
-lookupRdrName hsc_env mod_name rdr_name = do
-    -- First find the package the module resides in by searching exposed packages and home modules
-    found_module <- findImportedModule hsc_env mod_name Nothing
-    case found_module of
-        Found _ mod -> do
-            -- Find the exports of the module
-            (_, mb_iface) <- getModuleInterface hsc_env mod
-            case mb_iface of
-                Just iface -> do
-                    -- Try and find the required name in the exports
-                    let decl_spec = ImpDeclSpec { is_mod = mod_name, is_as = mod_name
-                                                , is_qual = False, is_dloc = noSrcSpan }
-                        provenance = Just $ ImpSpec decl_spec ImpAll
-                        env = case mi_globals iface of
-                                Nothing -> mkGlobalRdrEnv (gresFromAvails provenance (mi_exports iface))
-                                Just e -> e
-                    case lookupGRE_RdrName rdr_name env of
-                        [gre] -> return (Just (gre_name gre))
-                        []    -> return Nothing
-                        _     -> Ghc.panic "lookupRdrNameInModule"
-                Nothing -> throwCmdLineErrorS dflags $ Ghc.hsep [Ghc.ptext (sLit "Could not determine the exports of the module"), ppr mod_name]
-        err -> throwCmdLineErrorS dflags $ cannotFindModule dflags mod_name err
-  where dflags = hsc_dflags hsc_env
-        throwCmdLineErrorS dflags = throwCmdLineError . Ghc.showSDoc dflags
-        throwCmdLineError = throwGhcException . CmdLineError
-
--- qualImportDecl :: ModuleName -> ImportDecl name
--- qualImportDecl mn = (simpleImportDecl mn) { ideclQualified = True }
-
-ignoreInline :: ParsedModule -> ParsedModule
-ignoreInline x = x {pm_parsed_source = go <$> pm_parsed_source x}
-  where 
-    go  x      = x {hsmodDecls = filter go' (hsmodDecls x) }
-    go' :: LHsDecl GhcPs -> Bool
-    go' x 
-      | SigD _ (InlineSig {}) <-  unLoc x = False
-      | otherwise                         = True
-
---------------------------------------------------------------------------------
--- | Symbol Conversions --------------------------------------------------------
---------------------------------------------------------------------------------
-
-symbolTyConWithKind :: Kind -> Char -> Int -> Symbol -> TyCon
-symbolTyConWithKind k x i n = stringTyConWithKind k x i (symbolString n)
-
-symbolTyCon :: Char -> Int -> Symbol -> TyCon
-symbolTyCon x i n = stringTyCon x i (symbolString n)
-
-symbolTyVar :: Symbol -> TyVar
-symbolTyVar = stringTyVar . symbolString
-
-localVarSymbol ::  Var -> Symbol
-localVarSymbol v
-  | us `isSuffixOfSym` vs = vs
-  | otherwise             = suffixSymbol vs us
-  where
-    us                    = symbol $ showPpr $ getDataConVarUnique v
-    vs                    = exportedVarSymbol v 
-
-exportedVarSymbol :: Var -> Symbol
-exportedVarSymbol x = notracepp msg . symbol . getName $ x            
-  where 
-    msg = "exportedVarSymbol: " ++ showPpr x 
-
-qualifiedNameSymbol :: Name -> Symbol
-qualifiedNameSymbol n = symbol $ concatFS [modFS, occFS, uniqFS]
-  where
-  _msg   = showSDoc (ppr n) -- getOccString n
-  modFS = case nameModule_maybe n of
-            Nothing -> fsLit ""
-            Just m  -> concatFS [moduleNameFS (moduleName m), fsLit "."]
-
-  occFS = occNameFS (getOccName n)
-  uniqFS
-    | isSystemName n
-    = concatFS [fsLit "_",  fsLit (showPpr (getUnique n))]
-    | otherwise
-    = fsLit ""
-
-instance Symbolic FastString where
-  symbol = symbol . fastStringText
-
-fastStringText :: FastString -> T.Text
-fastStringText = T.decodeUtf8With TE.lenientDecode . bytesFS
-
-tyConTyVarsDef :: TyCon -> [TyVar]
-tyConTyVarsDef c
-  | noTyVars c = []
-  | otherwise  = Ghc.tyConTyVars c
-  --where
-  --  none         = tracepp ("tyConTyVarsDef: " ++ show c) (noTyVars c)
-
-noTyVars :: TyCon -> Bool
-noTyVars c =  (Ghc.isPrimTyCon c || isFunTyCon c || Ghc.isPromotedDataCon c)
-
---------------------------------------------------------------------------------
--- | Symbol Instances
---------------------------------------------------------------------------------
-
-instance Symbolic TyCon where
-  symbol = symbol . getName
-
-instance Symbolic Class where
-  symbol = symbol . getName
-
-instance Symbolic Name where
-  symbol = symbol . qualifiedNameSymbol
-
--- | [NOTE:REFLECT-IMPORTS] we **eschew** the `unique` suffix for exported vars,
--- to make it possible to lookup names from symbols _across_ modules;
--- anyways exported names are top-level and you shouldn't have local binders
--- that shadow them. However, we **keep** the `unique` suffix for local variables,
--- as otherwise there are spurious, but extremely problematic, name collisions
--- in the fixpoint environment.
-
-instance Symbolic Var where   -- TODO:reflect-datacons varSymbol
-  symbol v
-    | isExportedId v = exportedVarSymbol v
-    | otherwise      = localVarSymbol    v
-
-
-instance Hashable Var where
-  hashWithSalt = uniqueHash
-
-instance Hashable TyCon where
-  hashWithSalt = uniqueHash
-
-instance Hashable Class where
-  hashWithSalt = uniqueHash
-
-instance Hashable DataCon where
-  hashWithSalt = uniqueHash
-
-instance Fixpoint Var where
-  toFix = pprDoc
-
-instance Fixpoint Name where
-  toFix = pprDoc
-
-instance Fixpoint Type where
-  toFix = pprDoc
-
-instance Show Name where
-  show = symbolString . symbol
-
-instance Show Var where
-  show = show . getName
-
-instance Show Class where
-  show = show . getName
-
-instance Show TyCon where
-  show = show . getName
-
-instance NFData Class where
-  rnf t = seq t ()
-
-instance NFData TyCon where
-  rnf t = seq t ()
-
-instance NFData Type where
-  rnf t = seq t ()
-
-instance NFData Var where
-  rnf t = seq t ()
-
---------------------------------------------------------------------------------
--- | Manipulating Symbols ------------------------------------------------------
---------------------------------------------------------------------------------
-
-takeModuleUnique :: Symbol -> Symbol
-takeModuleUnique = mungeNames tailName sepUnique   "takeModuleUnique: "
-  where
-    tailName msg = symbol . safeLast msg
-
-splitModuleUnique :: Symbol -> (Symbol, Int)
-splitModuleUnique x = (dropModuleNamesAndUnique x, base62ToI (takeModuleUnique x))
-
-base62ToI :: Symbol -> Int
-base62ToI s =  fromMaybe (errorstar "base62ToI Out Of Range") $ go (F.symbolText s)
-  where
-    digitToI :: OM.Map Char Int
-    digitToI = OM.fromList $ zip (['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z']) [0..]
-    f acc (flip OM.lookup digitToI -> x) = (acc * 62 +) <$> x
-    go s = foldM f 0 (T.unpack s)
-
-
-splitModuleName :: Symbol -> (Symbol, Symbol)
-splitModuleName x = (takeModuleNames x, dropModuleNamesAndUnique x)
-
-dropModuleNamesAndUnique :: Symbol -> Symbol
-dropModuleNamesAndUnique = dropModuleUnique . dropModuleNames
-
-dropModuleNames  :: Symbol -> Symbol
-dropModuleNames = dropModuleNamesCorrect 
-{- 
-dropModuleNames = mungeNames lastName sepModNames "dropModuleNames: "
- where
-   lastName msg = symbol . safeLast msg
--}
-
-dropModuleNamesCorrect  :: Symbol -> Symbol
-dropModuleNamesCorrect = F.symbol . go . F.symbolText
-  where
-    go s = case T.uncons s of
-             Just (c,tl) -> if isUpper c  && T.any (== '.') tl
-                              then go $ snd $ fromJust $ T.uncons $ T.dropWhile (/= '.') s
-                              else s
-             Nothing -> s
-
-takeModuleNames  :: Symbol -> Symbol
-takeModuleNames  = F.symbol . go [] . F.symbolText
-  where
-    go acc s = case T.uncons s of
-                Just (c,tl) -> if isUpper c && T.any (== '.') tl
-                                 then go (getModule s:acc) $ snd $ fromJust $ T.uncons $ T.dropWhile (/= '.') s
-                                 else T.intercalate "." (reverse acc) 
-                Nothing -> T.intercalate "." (reverse acc) 
-    getModule s = T.takeWhile (/= '.') s
-
-{- 
-takeModuleNamesOld  = mungeNames initName sepModNames "takeModuleNames: "
-  where
-    initName msg = symbol . T.intercalate "." . safeInit msg
--}
-dropModuleUnique :: Symbol -> Symbol
-dropModuleUnique = mungeNames headName sepUnique   "dropModuleUnique: "
-  where
-    headName msg = symbol . safeHead msg
-
-cmpSymbol :: Symbol -> Symbol -> Bool
-cmpSymbol coreSym logicSym
-  =  (dropModuleUnique coreSym == dropModuleNamesAndUnique logicSym)
-  || (dropModuleUnique coreSym == dropModuleUnique         logicSym)
-
-sepModNames :: T.Text
-sepModNames = "."
-
-sepUnique :: T.Text
-sepUnique = "#"
-
-mungeNames :: (String -> [T.Text] -> Symbol) -> T.Text -> String -> Symbol -> Symbol
-mungeNames _ _ _ ""  = ""
-mungeNames f d msg s'@(symbolText -> s)
-  | s' == tupConName = tupConName
-  | otherwise        = f (msg ++ T.unpack s) $ T.splitOn d $ stripParens s
-
-qualifySymbol :: Symbol -> Symbol -> Symbol
-qualifySymbol (symbolText -> m) x'@(symbolText -> x)
-  | isQualified x  = x'
-  | isParened x    = symbol (wrapParens (m `mappend` "." `mappend` stripParens x))
-  | otherwise      = symbol (m `mappend` "." `mappend` x)
-
-isQualifiedSym :: Symbol -> Bool
-isQualifiedSym (symbolText -> x) = isQualified x 
-
-isQualified :: T.Text -> Bool
-isQualified y = "." `T.isInfixOf` y
-
-wrapParens :: (IsString a, Monoid a) => a -> a
-wrapParens x  = "(" `mappend` x `mappend` ")"
-
-isParened :: T.Text -> Bool
-isParened xs  = xs /= stripParens xs
-
-isDictionary :: Symbolic a => a -> Bool
-isDictionary = isPrefixOfSym "$f" . dropModuleNames . symbol
-
-isMethod :: Symbolic a => a -> Bool
-isMethod = isPrefixOfSym "$c" . dropModuleNames . symbol
-
-isInternal :: Symbolic a => a -> Bool
-isInternal   = isPrefixOfSym "$"  . dropModuleNames . symbol
-
-isWorker :: Symbolic a => a -> Bool 
-isWorker s = notracepp ("isWorkerSym: s = " ++ ss) $ "$W" `L.isInfixOf` ss 
-  where 
-    ss     = symbolString (symbol s)
-
-isSCSel :: Symbolic a => a -> Bool
-isSCSel  = isPrefixOfSym "$p" . dropModuleNames . symbol
-
-stripParens :: T.Text -> T.Text
-stripParens t = fromMaybe t (strip t)
-  where
-    strip = T.stripPrefix "(" >=> T.stripSuffix ")"
-
-stripParensSym :: Symbol -> Symbol
-stripParensSym (symbolText -> t) = symbol (stripParens t)
-
-desugarModule :: TypecheckedModule -> Ghc DesugaredModule
-desugarModule tcm = do
-  let ms = pm_mod_summary $ tm_parsed_module tcm
-  -- let ms = modSummary tcm
-  let (tcg, _) = tm_internals_ tcm
-  hsc_env <- getSession
-  let hsc_env_tmp = hsc_env { hsc_dflags = ms_hspp_opts ms }
-  guts <- liftIO $ hscDesugar{- WithLoc -} hsc_env_tmp ms tcg
-  return DesugaredModule { dm_typechecked_module = tcm, dm_core_module = guts }
-
---------------------------------------------------------------------------------
--- | GHC Compatibility Layer ---------------------------------------------------
---------------------------------------------------------------------------------
-
-gHC_VERSION :: String
-gHC_VERSION = show __GLASGOW_HASKELL__
-
-symbolFastString :: Symbol -> FastString
-symbolFastString = mkFastStringByteString . T.encodeUtf8 . symbolText
-
-lintCoreBindings :: [Var] -> CoreProgram -> (Bag MsgDoc, Bag MsgDoc)
-lintCoreBindings = Ghc.lintCoreBindings (defaultDynFlags undefined (undefined "LlvmTargets")) CoreDoNothing
-
-synTyConRhs_maybe :: TyCon -> Maybe Type
-synTyConRhs_maybe = Ghc.synTyConRhs_maybe
-
-tcRnLookupRdrName :: HscEnv -> Ghc.Located RdrName -> IO (Messages, Maybe [Name])
-tcRnLookupRdrName = Ghc.tcRnLookupRdrName
-
-showCBs :: Bool -> [CoreBind] -> String
-showCBs untidy
-  | untidy    = Ghc.showSDocDebug unsafeGlobalDynFlags . ppr . tidyCBs
-  | otherwise = showPpr
-
-
-ignoreCoreBinds :: S.HashSet Var -> [CoreBind] -> [CoreBind]
-ignoreCoreBinds vs cbs 
-  | S.null vs         = cbs 
-  | otherwise         = concatMap go cbs
-  where
-    go :: CoreBind -> [CoreBind]
-    go b@(NonRec x _) 
-      | S.member x vs = [] 
-      | otherwise     = [b] 
-    go (Rec xes)      = [Rec (filter ((`notElem` vs) . fst) xes)]
-
-
-findVarDef :: Symbol -> [CoreBind] -> Maybe (Var, CoreExpr)
-findVarDef x cbs = case xCbs of
-                     (NonRec v def   : _ ) -> Just (v, def)
-                     (Rec [(v, def)] : _ ) -> Just (v, def)
-                     _                     -> Nothing
-  where
-    xCbs            = [ cb | cb <- concatMap unRec cbs, x `elem` coreBindSymbols cb ]
-    unRec (Rec xes) = [NonRec x es | (x,es) <- xes]
-    unRec nonRec    = [nonRec]
-
-
-findVarDefMethod :: Symbol -> [CoreBind] -> Maybe (Var, CoreExpr)
-findVarDefMethod x cbs =
-  case rcbs  of
-                     (NonRec v def   : _ ) -> Just (v, def)
-                     (Rec [(v, def)] : _ ) -> Just (v, def)
-                     _                     -> Nothing
-  where
-    rcbs | isMethod x = mCbs
-         | isDictionary (dropModuleNames x) = dCbs
-         | otherwise  = xCbs
-    xCbs            = [ cb | cb <- concatMap unRec cbs, x `elem` coreBindSymbols cb 
-                           ]
-    mCbs            = [ cb | cb <- concatMap unRec cbs, x `elem` methodSymbols cb]
-    dCbs            = [ cb | cb <- concatMap unRec cbs, x `elem` dictionarySymbols cb]
-    unRec (Rec xes) = [NonRec x es | (x,es) <- xes]
-    unRec nonRec    = [nonRec]
-
-dictionarySymbols :: CoreBind -> [Symbol]
-dictionarySymbols = filter isDictionary . map (dropModuleNames . symbol) . binders
-
-
-methodSymbols :: CoreBind -> [Symbol]
-methodSymbols = filter isMethod . map (dropModuleNames . symbol) . binders
-
-
-
-coreBindSymbols :: CoreBind -> [Symbol]
-coreBindSymbols = map (dropModuleNames . simplesymbol) . binders
-
-simplesymbol :: (NamedThing t) => t -> Symbol
-simplesymbol = symbol . getName
-
-binders :: Bind a -> [a]
-binders (NonRec z _) = [z]
-binders (Rec xes)    = fst <$> xes
-
-expandVarType :: Var -> Type
-expandVarType = expandTypeSynonyms . varType
-
---------------------------------------------------------------------------------
--- | The following functions test if a `CoreExpr` or `CoreVar` can be
---   embedded in logic. With type-class support, we can no longer erase
---   such expressions arbitrarily.
---------------------------------------------------------------------------------
-isEmbeddedDictExpr :: CoreExpr -> Bool
-isEmbeddedDictExpr = isEmbeddedDictType . exprType
-
-isEmbeddedDictVar :: Var -> Bool
-isEmbeddedDictVar v = F.notracepp msg . isEmbeddedDictType . varType $ v
-  where
-    msg     =  "isGoodCaseBind v = " ++ show v
-
-isEmbeddedDictType :: Type -> Bool
-isEmbeddedDictType = anyF [isOrdPred, isNumericPred, isEqPred, isPrelEqPred]
-
--- unlike isNumCls, isFracCls, these two don't check if the argument's
--- superclass is Ord or Num. I believe this is the more predictable behavior
-
-isPrelEqPred :: Type -> Bool
-isPrelEqPred ty = case tyConAppTyCon_maybe ty of
-  Just tyCon -> isPrelEqTyCon tyCon
-  _          -> False
-
-
-isPrelEqTyCon :: TyCon -> Bool
-isPrelEqTyCon tc = tc `hasKey` eqClassKey
-
-isOrdPred :: Type -> Bool
-isOrdPred ty = case tyConAppTyCon_maybe ty of
-  Just tyCon -> tyCon `hasKey` ordClassKey
-  _          -> False
-
--- Not just Num, but Fractional, Integral as well
-isNumericPred :: Type -> Bool
-isNumericPred ty = case tyConAppTyCon_maybe ty of
-  Just tyCon -> getUnique tyCon `elem` numericClassKeys
-  _          -> False
-
-
-
---------------------------------------------------------------------------------
--- | The following functions test if a `CoreExpr` or `CoreVar` are just types
---   in disguise, e.g. have `PredType` (in the GHC sense of the word), and so
---   shouldn't appear in refinements.
---------------------------------------------------------------------------------
-isPredExpr :: CoreExpr -> Bool
-isPredExpr = isPredType . Ghc.exprType
-
-isPredVar :: Var -> Bool
-isPredVar v = F.notracepp msg . isPredType . varType $ v
-  where
-    msg     =  "isGoodCaseBind v = " ++ show v
-
-isPredType :: Type -> Bool
-isPredType = anyF [ isClassPred, isEqPred, isEqPrimPred ]
-
-anyF :: [a -> Bool] -> a -> Bool
-anyF ps x = or [ p x | p <- ps ]
-
-
--- | 'defaultDataCons t ds' returns the list of '(dc, types)' pairs,
---   corresponding to the _missing_ cases, i.e. _other_ than those in 'ds',
---   that are being handled by DEFAULT.
-defaultDataCons :: Type -> [AltCon] -> Maybe [(DataCon, [TyVar], [Type])]
-defaultDataCons (TyConApp tc argτs) ds = do 
-  allDs     <- Ghc.tyConDataCons_maybe tc
-  let seenDs = [d | DataAlt d <- ds ]
-  let defDs  = keyDiff showPpr allDs seenDs 
-  return [ (d, Ghc.dataConExTyVars d, map irrelevantMult $ Ghc.dataConInstArgTys d argτs) | d <- defDs ] 
-
-defaultDataCons _ _ = 
-  Nothing
-
-
-
-isEvVar :: Id -> Bool 
-isEvVar x = isPredVar x || isTyVar x || isCoVar x
-
-
---------------------------------------------------------------------------------
--- | Elaboration
---------------------------------------------------------------------------------
-
--- FIXME: the handling of exceptions seems to be broken
-
--- partially stolen from GHC'sa exprType
-
--- elaborateHsExprInst
---   :: GhcMonad m => LHsExpr GhcPs -> m (Messages, Maybe CoreExpr)
--- elaborateHsExprInst expr = elaborateHsExpr TM_Inst expr
-
-
--- elaborateHsExpr
---   :: GhcMonad m => TcRnExprMode -> LHsExpr GhcPs -> m (Messages, Maybe CoreExpr)
--- elaborateHsExpr mode expr =
---   withSession $ \hsc_env -> liftIO $ hscElabHsExpr hsc_env mode expr
-
--- hscElabHsExpr :: HscEnv -> TcRnExprMode -> LHsExpr GhcPs -> IO (Messages, Maybe CoreExpr)
--- hscElabHsExpr hsc_env0 mode expr = runInteractiveHsc hsc_env0 $ do
---   hsc_env <- Ghc.getHscEnv
---   liftIO $ elabRnExpr hsc_env mode expr
-
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-elabRnExpr
-  :: TcRnExprMode -> LHsExpr GhcPs -> TcRn CoreExpr
-elabRnExpr mode rdr_expr = do
-    (rn_expr, _fvs) <- rnLExpr rdr_expr
-    failIfErrsM
-    uniq <- newUnique
-    let fresh_it = itName uniq (getLoc rdr_expr)
-        orig     = Ghc.lexprCtOrigin rn_expr
-    (tclvl, lie, (tc_expr, res_ty)) <- pushLevelAndCaptureConstraints $ do
-      (_tc_expr, expr_ty) <- tcInferSigma rn_expr
-      expr_ty'            <- if inst
-        then snd <$> deeplyInstantiate orig expr_ty
-        else return expr_ty
-      return (_tc_expr, expr_ty')
-    (_, _, evbs, residual, _) <- simplifyInfer tclvl
-                                            infer_mode
-                                            []    {- No sig vars -}
-                                            [(fresh_it, res_ty)]
-                                            lie
-    evbs' <- perhaps_disable_default_warnings $ simplifyInteractive residual
-    full_expr <- zonkTopLExpr (mkHsDictLet (EvBinds evbs') (mkHsDictLet evbs tc_expr))
-    initDsTc $ dsLExpr full_expr
- where
-  (inst, infer_mode, perhaps_disable_default_warnings) = case mode of
-    TM_Inst    -> (True, NoRestrictions, id)
-    TM_NoInst  -> (False, NoRestrictions, id)
-    TM_Default -> (True, EagerDefaulting, unsetWOptM Opt_WarnTypeDefaults)
-#else
-elabRnExpr
-  :: TcRnExprMode -> LHsExpr GhcPs -> TcRn CoreExpr
-elabRnExpr mode rdr_expr = do
-    (rn_expr, _fvs) <- rnLExpr rdr_expr
-    failIfErrsM
-
-        -- Now typecheck the expression, and generalise its type
-        -- it might have a rank-2 type (e.g. :t runST)
-    uniq <- newUnique ;
-    let fresh_it  = itName uniq (getLoc rdr_expr) 
-    ((tclvl, (tc_expr, res_ty)), lie)
-          <- captureTopConstraints $
-             pushTcLevelM          $
-             tc_infer rn_expr
-
-    -- Generalise
-    (qtvs, dicts, evbs, residual, _)
-         <- simplifyInfer tclvl infer_mode
-                          []    {- No sig vars -}
-                          [(fresh_it, res_ty)]
-                          lie
-
-    -- Ignore the dictionary bindings
-    evbs' <- perhaps_disable_default_warnings $
-         simplifyInteractive residual
-    full_expr <- zonkTopLExpr (mkHsDictLet (EvBinds evbs') (mkHsDictLet evbs tc_expr))
-    initDsTc $ dsLExpr full_expr
-  where
-    tc_infer expr | inst      = tcInferRho expr
-                  | otherwise = tcInferSigma expr
-                  -- tcInferSigma: see Note [Implementing :type]
-
-    -- See Note [TcRnExprMode]
-    (inst, infer_mode, perhaps_disable_default_warnings) = case mode of
-      TM_Inst    -> (True,  NoRestrictions, id)
-      TM_NoInst  -> (False, NoRestrictions, id)
-      TM_Default -> (True,  EagerDefaulting, unsetWOptM Opt_WarnTypeDefaults)
-#endif
-newtype HashableType = HashableType {getHType :: Type}
-
-instance Eq HashableType where
-  x == y = eqType (getHType x) (getHType y)
-
-instance Ord HashableType where
-  compare x y = nonDetCmpType (getHType x) (getHType y)
-
-instance Outputable HashableType where
-  ppr = ppr . getHType
-
-
---------------------------------------------------------------------------------
--- | Superclass coherence
---------------------------------------------------------------------------------
-
-canonSelectorChains :: PredType -> OM.Map HashableType [Id]
-canonSelectorChains t = foldr (OM.unionWith const) mempty (zs : xs)
- where
-  (cls, ts) = Ghc.getClassPredTys t
-  scIdTys   = classSCSelIds cls
-  ys        = fmap (\d -> (d, piResultTys (idType d) (ts ++ [t]))) scIdTys
-  zs        = OM.fromList $ fmap (\(x, y) -> (HashableType y, [x])) ys
-  xs        = fmap (\(d, t') -> fmap (d :) (canonSelectorChains t')) ys
-
-buildCoherenceOblig :: Class -> [[([Id], [Id])]]
-buildCoherenceOblig cls = evalState (mapM f xs) OM.empty
- where
-  (ts, _, selIds, _) = classBigSig cls
-  tts                = mkTyVarTy <$> ts
-  t                  = mkClassPred cls tts
-  ys = fmap (\d -> (d, piResultTys (idType d) (tts ++ [t]))) selIds
-  xs                 = fmap (\(d, t') -> fmap (d:) (canonSelectorChains t')) ys
-  f tid = do
-    ctid' <- get
-    modify (flip (OM.unionWith const) tid)
-    pure . OM.elems $ OM.intersectionWith (,) ctid' (fmap tail tid)
-
-
--- to be zipped onto the super class selectors
-coherenceObligToRef :: (F.Symbolic s) => s -> [Id] -> [Id] -> F.Reft
-coherenceObligToRef d = coherenceObligToRefE (F.eVar $ F.symbol d)
-
-coherenceObligToRefE :: F.Expr -> [Id] -> [Id] -> F.Reft
-coherenceObligToRefE e rps0 rps1 = F.Reft (F.vv_, F.PAtom F.Eq lhs rhs)
-  where lhs = L.foldr EApp e ps0
-        rhs = L.foldr EApp (F.eVar F.vv_) ps1
-        ps0 = F.eVar . F.symbol <$> L.reverse rps0
-        ps1 = F.eVar . F.symbol <$> L.reverse rps1
-
-data TcWiredIn = TcWiredIn {
-    tcWiredInName :: Name
-  , tcWiredInFixity :: Maybe (Int, FixityDirection)
-  , tcWiredInType :: LHsType GhcRn
-  }
-
--- | Run a computation in GHC's typechecking monad with wired in values locally bound in the typechecking environment.
-withWiredIn :: TcM a -> TcM a
-withWiredIn m = discardConstraints $ do
-  -- undef <- lookupUndef
-  wiredIns <- mkWiredIns
-  -- snd <$> tcValBinds Ghc.NotTopLevel (binds undef wiredIns) (sigs wiredIns) m
-  snd <$> tcValBinds Ghc.NotTopLevel [] (sigs wiredIns) m
-
- where
-  -- lookupUndef = do
-  --   lookupOrig gHC_ERR (Ghc.mkVarOcc "undefined")
-  --   -- tcLookupGlobal undefName
-
-  -- binds :: Name -> [TcWiredIn] -> [(Ghc.RecFlag, LHsBinds GhcRn)]
-  -- binds undef wiredIns = map (\w -> 
-  --     let ext = Ghc.unitNameSet undef in -- $ varName $ tyThingId undef in
-  --     let co_fn = idHsWrapper in
-  --     let matches = 
-  --           let ctxt = LambdaExpr in
-  --           let grhss = GRHSs Ghc.noExtField [Ghc.L locSpan (GRHS Ghc.noExtField [] (Ghc.L locSpan (HsVar Ghc.noExtField (Ghc.L locSpan undef))))] (Ghc.L locSpan emptyLocalBinds) in
-  --           MG Ghc.noExtField (Ghc.L locSpan [Ghc.L locSpan (Match Ghc.noExtField ctxt [] grhss)]) Ghc.Generated 
-  --     in
-  --     let b = FunBind ext (Ghc.L locSpan $ tcWiredInName w) matches co_fn [] in
-  --     (Ghc.NonRecursive, unitBag (Ghc.L locSpan b))
-  --   ) wiredIns
-
-  sigs wiredIns = concatMap (\w ->
-      let inf = maybeToList $ fmap (\(fPrec, fDir) -> Ghc.L locSpan $ FixSig Ghc.noExtField $ FixitySig Ghc.noExtField [Ghc.L locSpan (tcWiredInName w)] $ Ghc.Fixity Ghc.NoSourceText fPrec fDir) $ tcWiredInFixity w in
-      let t = 
-            let ext = 
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)
-                      HsIBRn {hsib_vars = [], hsib_closed = True} in -- TODO: What goes here? XXX
-#else
-                      [] in
-#endif
-#endif
-            let ext' = [] in
-            [Ghc.L locSpan $ TypeSig Ghc.noExtField [Ghc.L locSpan (tcWiredInName w)] $ HsWC ext' $ HsIB ext $ tcWiredInType w]
-      in
-      inf <> t
-    ) wiredIns
-
-  locSpan = UnhelpfulSpan (UnhelpfulOther "Language.Haskell.Liquid.GHC.Misc: WiredIn")
-
-  mkHsFunTy :: LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
-  mkHsFunTy a b = nlHsFunTy a b
-
-  mkWiredIns = sequence [impl, dimpl, eq, len]
-
-  toName s = do
-    u <- getUniqueM
-    return $ Ghc.mkInternalName u (Ghc.mkVarOcc s) locSpan
-
-  toLoc = Ghc.L locSpan
-  nameToTy = Ghc.L locSpan . HsTyVar Ghc.noExtField Ghc.NotPromoted
-
-  boolTy :: LHsType GhcRn
-  boolTy = nameToTy $ toLoc boolTyConName
-    -- boolName <- lookupOrig (Module (stringToUnitId "Data.Bool") (mkModuleName "Data.Bool")) (Ghc.mkVarOcc "Bool")
-    -- return $ Ghc.L locSpan $ HsTyVar Ghc.noExtField Ghc.NotPromoted $ Ghc.L locSpan boolName
-  intTy = nameToTy $ toLoc intTyConName
-  listTy lt = toLoc $ HsAppTy Ghc.noExtField (nameToTy $ toLoc listTyConName) lt
- 
-  -- infixr 1 ==> :: Bool -> Bool -> Bool
-  impl = do
-    n <- toName "==>"
-    let ty = mkHsFunTy boolTy (mkHsFunTy boolTy boolTy)
-    return $ TcWiredIn n (Just (1, Ghc.InfixR)) ty
-
-  -- infixr 1 <=> :: Bool -> Bool -> Bool
-  dimpl = do
-    n <- toName "<=>"
-    let ty = mkHsFunTy boolTy (mkHsFunTy boolTy boolTy)
-    return $ TcWiredIn n (Just (1, Ghc.InfixR)) ty
-
-  -- infix 4 == :: forall a . a -> a -> Bool
-  eq = do
-    n <- toName "=="
-    aName <- Ghc.L locSpan <$> toName "a"
-    let aTy = nameToTy aName
-    let ty = noLoc $ HsForAllTy Ghc.noExtField
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
-             ForallInvis
-#endif
-             [Ghc.L locSpan $ UserTyVar Ghc.noExtField aName] $ mkHsFunTy aTy (mkHsFunTy aTy boolTy)
-#else
-             (mkHsForAllInvisTele [Ghc.L locSpan $ UserTyVar Ghc.noExtField SpecifiedSpec aName]) $ mkHsFunTy aTy (mkHsFunTy aTy boolTy)
-#endif
-    return $ TcWiredIn n (Just (4, Ghc.InfixN)) ty
-  
-  -- TODO: This is defined as a measure in liquid-base GHC.Base. We probably want to insert all measures to the environment.
-  -- len :: forall a. [a] -> Int
-  len = do
-    n <- toName "len"
-    aName <- Ghc.L locSpan <$> toName "a"
-    let aTy = nameToTy aName
-    let ty =
-          noLoc $ HsForAllTy Ghc.noExtField
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
-               ForallInvis
-#endif
-               [Ghc.L locSpan $ UserTyVar Ghc.noExtField aName] $ mkHsFunTy (listTy aTy) intTy
-    return $ TcWiredIn n Nothing ty
-#else
-               (mkHsForAllInvisTele [Ghc.L locSpan $ UserTyVar Ghc.noExtField SpecifiedSpec aName]) $ mkHsFunTy (listTy aTy) intTy
-    return $ TcWiredIn n Nothing ty
-#endif
-
-
-
-prependGHCRealQual :: FastString -> RdrName
-prependGHCRealQual = varQual_RDR gHC_REAL
-
-isFromGHCReal :: NamedThing a => a -> Bool
-isFromGHCReal x = Ghc.nameModule (Ghc.getName x) == gHC_REAL
diff --git a/src/Language/Haskell/Liquid/GHC/Play.hs b/src/Language/Haskell/Liquid/GHC/Play.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Play.hs
+++ /dev/null
@@ -1,148 +0,0 @@
-{-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
-{-# LANGUAGE FlexibleInstances         #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE PatternSynonyms           #-}
-
-module Language.Haskell.Liquid.GHC.Play where
-
-import Prelude hiding (error)
-
-import           Control.Arrow       ((***))
-import qualified Data.HashMap.Strict as M
-import qualified Data.List           as L
-
-import Language.Haskell.Liquid.GHC.API as Ghc hiding (substTysWith, panic)
-import Language.Haskell.Liquid.GHC.Misc ()
-import Language.Haskell.Liquid.Types.Errors
-
-
-isRecursivenewTyCon :: TyCon -> Bool 
-isRecursivenewTyCon c 
-  | not (isNewTyCon c)
-  = False 
-isRecursivenewTyCon c 
-  = go t 
-  where 
-    t = snd $ newTyConRhs c
-    go (AppTy t1 t2)      = go t1 || go t2 
-    go (TyConApp c' ts)   = c == c' || any go ts 
-    go (ForAllTy _ t1)    = go t1 
-    go (FunTy _ _ t1 t2)  = go t1 || go t2
-    go (CastTy t1 _)      = go t1 
-    go _                  = False   
-  
-
-isHoleVar :: Var -> Bool 
-isHoleVar x = L.isPrefixOf "_" (show x)
-
-dataConImplicitIds :: DataCon -> [Id]
-dataConImplicitIds dc = [ x | AnId x <- dataConImplicitTyThings dc]
-
-class Subable a where
-  sub   :: M.HashMap CoreBndr CoreExpr -> a -> a
-  subTy :: M.HashMap TyVar Type -> a -> a
-
-instance Subable CoreExpr where
-  sub s (Var v)        = M.lookupDefault (Var v) v s
-  sub _ (Lit l)        = Lit l
-  sub s (App e1 e2)    = App (sub s e1) (sub s e2)
-  sub s (Lam b e)      = Lam b (sub s e)
-  sub s (Let b e)      = Let (sub s b) (sub s e)
-  sub s (Case e b t a) = Case (sub s e) (sub s b) t (map (sub s) a)
-  sub s (Cast e c)     = Cast (sub s e) c
-  sub s (Tick t e)     = Tick t (sub s e)
-  sub _ (Type t)       = Type t
-  sub _ (Coercion c)   = Coercion c
-
-  subTy s (Var v)      = Var (subTy s v)
-  subTy _ (Lit l)      = Lit l
-  subTy s (App e1 e2)  = App (subTy s e1) (subTy s e2)
-  subTy s (Lam b e)    | isTyVar b = Lam v' (subTy s e)
-   where v' = case M.lookup b s of
-               Just (TyVarTy v) -> v
-               _                -> b
-
-  subTy s (Lam b e)      = Lam (subTy s b) (subTy s e)
-  subTy s (Let b e)      = Let (subTy s b) (subTy s e)
-  subTy s (Case e b t a) = Case (subTy s e) (subTy s b) (subTy s t) (map (subTy s) a)
-  subTy s (Cast e c)     = Cast (subTy s e) (subTy s c)
-  subTy s (Tick t e)     = Tick t (subTy s e)
-  subTy s (Type t)       = Type (subTy s t)
-  subTy s (Coercion c)   = Coercion (subTy s c)
-
-instance Subable Coercion where
-  sub _ c                = c
-  subTy _ _              = panic Nothing "subTy Coercion"
-
-instance Subable (Alt Var) where
- sub s (a, b, e)   = (a, map (sub s) b,   sub s e)
- subTy s (a, b, e) = (a, map (subTy s) b, subTy s e)
-
-instance Subable Var where
- sub s v   | M.member v s = subVar $ s M.! v
-           | otherwise    = v
- subTy s v = setVarType v (subTy s (varType v))
-
-subVar :: Expr t -> Id
-subVar (Var x) = x
-subVar  _      = panic Nothing "sub Var"
-
-instance Subable (Bind Var) where
- sub s (NonRec x e)   = NonRec (sub s x) (sub s e)
- sub s (Rec xes)      = Rec ((sub s *** sub s) <$> xes)
-
- subTy s (NonRec x e) = NonRec (subTy s x) (subTy s e)
- subTy s (Rec xes)    = Rec ((subTy s  *** subTy s) <$> xes)
-
-instance Subable Type where
- sub _ e   = e
- subTy     = substTysWith
-
-substTysWith :: M.HashMap Var Type -> Type -> Type
-substTysWith s tv@(TyVarTy v)      = M.lookupDefault tv v s
-substTysWith s (FunTy aaf m t1 t2) = FunTy aaf m (substTysWith s t1) (substTysWith s t2)
-substTysWith s (ForAllTy v t)      = ForAllTy v (substTysWith (M.delete (binderVar v) s) t)
-substTysWith s (TyConApp c ts)     = TyConApp c (map (substTysWith s) ts)
-substTysWith s (AppTy t1 t2)       = AppTy (substTysWith s t1) (substTysWith s t2)
-substTysWith _ (LitTy t)           = LitTy t
-substTysWith s (CastTy t c)        = CastTy (substTysWith s t) c
-substTysWith _ (CoercionTy c)      = CoercionTy c 
-
-substExpr :: M.HashMap Var Var -> CoreExpr -> CoreExpr
-substExpr s = go 
-  where
-    subsVar v                = M.lookupDefault v v s
-    go (Var v)               = Var $ subsVar v
-    go (Lit l)               = Lit l 
-    go (App e1 e2)           = App (go e1) (go e2) 
-    go (Lam x e)             = Lam (subsVar x) (go e)
-    go (Let (NonRec x ex) e) = Let (NonRec (subsVar x) (go ex)) (go e) 
-    go (Let (Rec xes) e)     = Let (Rec [(subsVar x, go e) | (x,e) <- xes]) (go e)
-    go (Case e b t alts)     = Case (go e) (subsVar b) t [(c, subsVar <$> xs, go e) | (c, xs, e) <- alts]
-    go (Cast e c)            = Cast (go e) c 
-    go (Tick t e)            = Tick t (go e)
-    go (Type t)              = Type t 
-    go (Coercion c)          = Coercion c 
-
-mapType :: (Type -> Type) -> Type -> Type
-mapType f = go
-  where
-    go t@(TyVarTy _)        = f t
-    go (AppTy t1 t2)        = f $ AppTy (go t1) (go t2)
-    go (TyConApp c ts)      = f $ TyConApp c (go <$> ts)
-    go (FunTy aaf m t1 t2)  = f $ FunTy aaf m (go t1) (go t2)
-    go (ForAllTy v t)       = f $ ForAllTy v (go t)
-    go t@(LitTy _)          = f t
-    go (CastTy t c)         = CastTy (go t) c
-    go (CoercionTy c)       = f $ CoercionTy c 
-
-
-stringClassArg :: Type -> Maybe Type
-stringClassArg t | isFunTy t 
-  = Nothing
-stringClassArg t
-  = case (tyConAppTyCon_maybe t, tyConAppArgs_maybe t) of
-      (Just c, Just [t]) | isStringClassName == tyConName c
-           -> Just t
-      _    -> Nothing
diff --git a/src/Language/Haskell/Liquid/GHC/Plugin.hs b/src/Language/Haskell/Liquid/GHC/Plugin.hs
--- a/src/Language/Haskell/Liquid/GHC/Plugin.hs
+++ b/src/Language/Haskell/Liquid/GHC/Plugin.hs
@@ -1,17 +1,13 @@
 -- | This module provides a GHC 'Plugin' that allows LiquidHaskell to be hooked directly into GHC's
 -- compilation pipeline, facilitating its usage and adoption.
 
-{-# LANGUAGE MultiWayIf                 #-}
 {-# LANGUAGE TypeFamilies               #-}
 {-# LANGUAGE FlexibleInstances          #-}
 {-# LANGUAGE ScopedTypeVariables        #-}
 {-# LANGUAGE BangPatterns               #-}
-{-# LANGUAGE DeriveDataTypeable         #-}
 {-# LANGUAGE LambdaCase                 #-}
 {-# LANGUAGE OverloadedStrings          #-}
 {-# LANGUAGE RecordWildCards            #-}
-{-# LANGUAGE TupleSections              #-}
-{-# LANGUAGE TypeApplications           #-}
 {-# LANGUAGE ViewPatterns               #-}
 
 module Language.Haskell.Liquid.GHC.Plugin (
@@ -20,35 +16,38 @@
 
   ) where
 
-import qualified Language.Haskell.Liquid.GHC.API         as O
-import           Language.Haskell.Liquid.GHC.API         as GHC hiding (Target)
+import qualified Liquid.GHC.API         as O
+import           Liquid.GHC.API         as GHC hiding (Target, Type)
 import qualified Text.PrettyPrint.HughesPJ               as PJ
 import qualified Language.Fixpoint.Types                 as F
-import qualified Language.Haskell.Liquid.GHC.Misc        as LH
+import qualified Liquid.GHC.Misc        as LH
 import qualified Language.Haskell.Liquid.UX.CmdLine      as LH
-import qualified Language.Haskell.Liquid.GHC.Interface   as LH
+import qualified Liquid.GHC.Interface   as LH
 import qualified Language.Haskell.Liquid.Liquid          as LH
-import qualified Language.Haskell.Liquid.Types.PrettyPrint as LH (reportErrors)
-import qualified Language.Haskell.Liquid.GHC.Logging     as LH   (fromPJDoc)
+import qualified Language.Haskell.Liquid.Types.PrettyPrint as LH ( filterReportErrors
+                                                                 , filterReportErrorsWith
+                                                                 , defaultFilterReporter
+                                                                 , reduceFilters )
+import qualified Liquid.GHC.Logging     as LH   (fromPJDoc)
 
 import           Language.Haskell.Liquid.GHC.Plugin.Types
 import           Language.Haskell.Liquid.GHC.Plugin.Util as Util
 import           Language.Haskell.Liquid.GHC.Plugin.SpecFinder
                                                          as SpecFinder
 
-import           Language.Haskell.Liquid.GHC.Types       (MGIModGuts(..), miModGuts)
-import qualified Language.Haskell.Liquid.GHC.GhcMonadLike
+import           Liquid.GHC.Types       (MGIModGuts(..), miModGuts)
+import qualified Liquid.GHC.GhcMonadLike
                                                          as GhcMonadLike
-import           Language.Haskell.Liquid.GHC.GhcMonadLike ( GhcMonadLike
+import           Liquid.GHC.GhcMonadLike ( GhcMonadLike
                                                           , askHscEnv
                                                           , isBootInterface
                                                           )
 import           GHC.LanguageExtensions
 
 import           Control.Monad
-import           Control.Exception                        (evaluate)
 
 import           Data.Coerce
+import           Data.Kind                                ( Type )
 import           Data.List                               as L
                                                    hiding ( intersperse )
 import           Data.IORef
@@ -60,7 +59,8 @@
 import qualified Data.HashMap.Strict                     as HM
 
 import           System.IO.Unsafe                         ( unsafePerformIO )
-import           Language.Fixpoint.Types           hiding ( panic
+import           Language.Fixpoint.Types           hiding ( errs
+                                                          , panic
                                                           , Error
                                                           , Result
                                                           , Expr
@@ -75,6 +75,12 @@
 
 import           Optics
 
+-- | Represents an abnormal but non-fatal state of the plugin. Because it is not
+-- meant to escape the plugin, it is not thrown in IO but instead carried around
+-- in an `Either`'s `Left` case and handled at the top level of the plugin
+-- function.
+newtype LiquidCheckException = ErrorsOccurred [Filter] -- Unmatched expected errors
+  deriving (Eq, Ord, Show)
 
 ---------------------------------------------------------------------------------
 -- | State and configuration management -----------------------------------------
@@ -121,17 +127,28 @@
     liquidPlugin :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
     liquidPlugin opts summary gblEnv = do
       dynFlags <- getDynFlags
-      if gopt Opt_Haddock dynFlags
-        then do
-          -- Warn the user
-          let msg     = PJ.vcat [ PJ.text "LH can't be run with Haddock."
-                                , PJ.nest 4 $ PJ.text "Documentation will still be created."
-                                ]
-          let srcLoc  = mkSrcLoc (mkFastString $ ms_hspp_file summary) 1 1
-          let warning = mkWarning (mkSrcSpan srcLoc srcLoc) msg
-          liftIO $ printWarning dynFlags warning
-          pure gblEnv
-        else typecheckHook opts summary gblEnv
+      withTiming dynFlags (text "LiquidHaskell" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $ do
+        if gopt Opt_Haddock dynFlags
+          then do
+            -- Warn the user
+            let msg     = PJ.vcat [ PJ.text "LH can't be run with Haddock."
+                                  , PJ.nest 4 $ PJ.text "Documentation will still be created."
+                                  ]
+            let srcLoc  = mkSrcLoc (mkFastString $ ms_hspp_file summary) 1 1
+            let warning = mkWarning (mkSrcSpan srcLoc srcLoc) msg
+            liftIO $ printWarning dynFlags warning
+            pure gblEnv
+          else do
+            newGblEnv <- typecheckHook opts summary gblEnv
+            case newGblEnv of
+              -- Exit with success if all expected errors were found
+              Left (ErrorsOccurred []) -> pure gblEnv
+              -- Exit with error if there were unmatched expected errors
+              Left (ErrorsOccurred errorFilters) -> do
+                defaultFilterReporter (LH.modSummaryHsFile summary) errorFilters
+                failM
+              Right newGblEnv' ->
+                pure newGblEnv'
 
 --------------------------------------------------------------------------------
 -- | GHC Configuration & Setup -------------------------------------------------
@@ -165,7 +182,7 @@
 -- desugaring the module during /parsing/ (before that's already too late) and we cache the core binds for
 -- the rest of the program execution.
 class Unoptimise a where
-  type UnoptimisedTarget a :: *
+  type UnoptimisedTarget a :: Type
   unoptimise :: a -> UnoptimisedTarget a
 
 instance Unoptimise DynFlags where
@@ -201,7 +218,7 @@
 --    grab from parsing (again) the module by using the GHC API, so we are really
 --    independent from the \"normal\" compilation pipeline.
 --
-typecheckHook :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
+typecheckHook :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM (Either LiquidCheckException TcGblEnv)
 typecheckHook _ (unoptimise -> modSummary) tcGblEnv = do
   debugLog $ "We are in module: " <> show (toStableModule thisModule)
 
@@ -231,21 +248,37 @@
                                                               }
                    }
 
--- | Partially calls into LiquidHaskell's GHC API.
-liquidHaskellCheck :: PipelineData -> ModSummary -> TcGblEnv -> TcM TcGblEnv
-liquidHaskellCheck pipelineData modSummary tcGblEnv = do
-  cfg <- liftIO getConfig
+serialiseSpec :: Module -> TcGblEnv -> LiquidLib -> TcM TcGblEnv
+serialiseSpec thisModule tcGblEnv liquidLib = do
+  -- ---
+  -- -- CAN WE 'IGNORE' THE BELOW? TODO:IGNORE -- issue use `emptyLiquidLib` instead of pmrClientLib
+  -- ProcessModuleResult{..} <- processModule lhContext
 
-  -- The 'specQuotes' contain stuff we need from imported modules, extracted
-  -- from the annotations in their interface files.
-  let specQuotes :: [BPspec]
-      specQuotes = LH.extractSpecQuotes' tcg_mod tcg_anns tcGblEnv
+  -- liftIO $ putStrLn "liquidHaskellCheck 7"
 
-  -- Here, we are calling Liquid Haskell's parser, acting on the unparsed
-  -- spec comments stored in the pipeline data, supported by the specQuotes
-  -- obtained from the imported modules.
-  inputSpec :: BareSpec <- getLiquidSpec thisModule (pdSpecComments pipelineData) specQuotes
+  -- -- Call into the existing Liquid interface
+  -- out <- liftIO $ LH.checkTargetInfo pmrTargetInfo
 
+  -- liftIO $ putStrLn "liquidHaskellCheck 8"
+
+  -- -- Report the outcome of the checking
+  -- LH.reportResult errorLogger cfg [giTarget (giSrc pmrTargetInfo)] out
+  -- case o_result out of
+  --   Safe _stats -> pure ()
+  --   _           -> failM
+
+  -- liftIO $ putStrLn "liquidHaskellCheck 9"
+  -- ---
+
+  let serialisedSpec = Util.serialiseLiquidLib liquidLib thisModule
+  debugLog $ "Serialised annotation ==> " ++ (O.showSDocUnsafe . O.ppr $ serialisedSpec)
+
+  -- liftIO $ putStrLn "liquidHaskellCheck 10"
+
+  pure $ tcGblEnv { tcg_anns = serialisedSpec : tcg_anns tcGblEnv }
+
+processInputSpec :: Config -> PipelineData -> ModSummary -> TcGblEnv -> BareSpec -> TcM (Either LiquidCheckException TcGblEnv)
+processInputSpec cfg pipelineData modSummary tcGblEnv inputSpec = do
   debugLog $ " Input spec: \n" ++ show inputSpec
   debugLog $ "Relevant ===> \n" ++ unlines (renderModule <$> S.toList (relevantModules modGuts))
 
@@ -262,67 +295,98 @@
       , lhModuleGuts      = pdUnoptimisedCore pipelineData
       , lhRelevantModules = relevantModules modGuts
       }
-  
+
   -- liftIO $ putStrLn ("liquidHaskellCheck 6: " ++ show isIg)
+  if isIgnore inputSpec
+    then pure $ Left (ErrorsOccurred [])
+    else do
+      liquidLib' <- checkLiquidHaskellContext lhContext
+      traverse (serialiseSpec thisModule tcGblEnv) liquidLib'
 
-  liquidLib <- if isIgnore inputSpec 
-                then pure emptyLiquidLib 
-                else checkLiquidHaskellContext lhContext 
- 
-  -- --- 
-  -- -- CAN WE 'IGNORE' THE BELOW? TODO:IGNORE -- issue use `emptyLiquidLib` instead of pmrClientLib
-  -- ProcessModuleResult{..} <- processModule lhContext
-  
-  -- liftIO $ putStrLn "liquidHaskellCheck 7"
+  where
+    thisModule :: Module
+    thisModule = tcg_mod tcGblEnv
 
-  -- -- Call into the existing Liquid interface
-  -- out <- liftIO $ LH.checkTargetInfo pmrTargetInfo
-  -- liftIO $ putStrLn "liquidHaskellCheck 8"
+    modGuts :: ModGuts
+    modGuts = fromUnoptimised . pdUnoptimisedCore $ pipelineData
 
-  -- -- Report the outcome of the checking
-  -- LH.reportResult errorLogger cfg [giTarget (giSrc pmrTargetInfo)] out
-  -- case o_result out of
-  --   Safe _stats -> pure ()
-  --   _           -> failM
+liquidHaskellCheckWithConfig :: Config -> PipelineData -> ModSummary -> TcGblEnv -> TcM (Either LiquidCheckException TcGblEnv)
+liquidHaskellCheckWithConfig globalCfg pipelineData modSummary tcGblEnv = do
+  -- The 'specQuotes' contain stuff we need from imported modules, extracted
+  -- from the annotations in their interface files.
+  let specQuotes :: [BPspec]
+      specQuotes = LH.extractSpecQuotes' tcg_mod tcg_anns tcGblEnv
 
-  -- liftIO $ putStrLn "liquidHaskellCheck 9"
-  -- ---
+  -- Here, we are calling Liquid Haskell's parser, acting on the unparsed
+  -- spec comments stored in the pipeline data, supported by the specQuotes
+  -- obtained from the imported modules.
+  inputSpec' :: Either LiquidCheckException BareSpec <-
+    getLiquidSpec thisFile thisModule (pdSpecComments pipelineData) specQuotes
 
-  let serialisedSpec = Util.serialiseLiquidLib liquidLib thisModule
-  debugLog $ "Serialised annotation ==> " ++ (O.showSDocUnsafe . O.ppr $ serialisedSpec)
-  
-  -- liftIO $ putStrLn "liquidHaskellCheck 10"
+  case inputSpec' of
+    Left e -> pure $ Left e
+    Right inputSpec ->
+      withPragmas globalCfg thisFile (Ms.pragmas $ review bareSpecIso inputSpec) $ \moduleCfg -> do
+        processInputSpec moduleCfg pipelineData modSummary tcGblEnv inputSpec
+          `gcatch` (\(e :: UserError) -> reportErrs moduleCfg [e])
+          `gcatch` (\(e :: Error) -> reportErrs moduleCfg [e])
+          `gcatch` (\(es :: [Error]) -> reportErrs moduleCfg es)
 
-  pure $ tcGblEnv { tcg_anns = serialisedSpec : tcg_anns tcGblEnv }
   where
+    thisFile :: FilePath
+    thisFile = LH.modSummaryHsFile modSummary
+
+    continue :: TcM (Either LiquidCheckException TcGblEnv)
+    continue = pure $ Left (ErrorsOccurred [])
+
+    reportErrs :: (Show e, F.PPrint e) => Config -> [TError e] -> TcM (Either LiquidCheckException TcGblEnv)
+    reportErrs cfg = LH.filterReportErrors thisFile GHC.failM continue (getFilters cfg) Full
+
     thisModule :: Module
     thisModule = tcg_mod tcGblEnv
 
-    modGuts :: ModGuts
-    modGuts = fromUnoptimised . pdUnoptimisedCore $ pipelineData
+-- | Partially calls into LiquidHaskell's GHC API.
+liquidHaskellCheck :: PipelineData -> ModSummary -> TcGblEnv -> TcM (Either LiquidCheckException TcGblEnv)
+liquidHaskellCheck pipelineData modSummary tcGblEnv = do
+  cfg <- liftIO getConfig
+  liquidHaskellCheckWithConfig cfg pipelineData modSummary tcGblEnv
 
-checkLiquidHaskellContext :: LiquidHaskellContext -> TcM LiquidLib
+checkLiquidHaskellContext :: LiquidHaskellContext -> TcM (Either LiquidCheckException LiquidLib)
 checkLiquidHaskellContext lhContext = do
-  ProcessModuleResult{..} <- processModule lhContext
-
-  -- Call into the existing Liquid interface
-  out <- liftIO $ LH.checkTargetInfo pmrTargetInfo
+  pmr <- processModule lhContext
+  case pmr of
+    Left e -> pure $ Left e
+    Right ProcessModuleResult{..} -> do
+      -- Call into the existing Liquid interface
+      out <- liftIO $ LH.checkTargetInfo pmrTargetInfo
 
-  let cfg = lhGlobalCfg lhContext
-  -- Report the outcome of the checking
-  LH.reportResult errorLogger cfg [giTarget (giSrc pmrTargetInfo)] out
-  case o_result out of
-    Safe _stats -> pure ()
-    _           -> failM
-  return pmrClientLib
+      let bareSpec = lhInputSpec lhContext
+          file = LH.modSummaryHsFile $ lhModuleSummary lhContext
 
-errorLogger :: OutputResult -> TcM ()
-errorLogger outputResult = do
-  errs <- forM (LH.orMessages outputResult) $ \(spn, e) -> mkLongErrAt spn (LH.fromPJDoc e) O.empty
-  GHC.reportErrors errs
+      withPragmas (lhGlobalCfg lhContext) file (Ms.pragmas $ review bareSpecIso bareSpec) $ \moduleCfg ->  do
+        let filters = getFilters moduleCfg
+        -- Report the outcome of the checking
+        LH.reportResult (errorLogger file filters) moduleCfg [giTarget (giSrc pmrTargetInfo)] out
+        -- If there are unmatched filters or errors, and we are not reporting with
+        -- json, we don't make it to this part of the code because errorLogger
+        -- will throw an exception.
+        case o_result out of
+          F.Safe _ -> return $ Right pmrClientLib
+          _ | json moduleCfg -> failM
+            | otherwise -> return $ Left $ ErrorsOccurred []
 
-emptyLiquidLib :: LiquidLib
-emptyLiquidLib = mkLiquidLib emptyLiftedSpec
+errorLogger :: FilePath -> [Filter] -> OutputResult -> TcM ()
+errorLogger file filters outputResult = do
+  LH.filterReportErrorsWith
+    FilterReportErrorsArgs { msgReporter = GHC.reportErrors
+                           , filterReporter = LH.defaultFilterReporter file
+                           , failure = GHC.failM
+                           , continue = pure ()
+                           , pprinter = \(spn, e) -> mkLongErrAt spn (LH.fromPJDoc e) O.empty
+                           , matchingFilters = LH.reduceFilters (\(src, doc) -> PJ.render doc ++ " at " ++ LH.showPpr src) filters
+                           , filters = filters
+                           }
+    (LH.orMessages outputResult)
 
 isIgnore :: BareSpec -> Bool
 isIgnore (MkBareSpec sp) = any ((== "--skip-module") . F.val) (pragmas sp)
@@ -419,24 +483,25 @@
 -- spec quotes from the imported module. Also looks for
 -- "companion specs" for the current module and merges them in
 -- if it finds one.
-getLiquidSpec :: Module -> [SpecComment] -> [BPspec] -> TcM BareSpec
-getLiquidSpec thisModule specComments specQuotes = do
-
+getLiquidSpec :: FilePath -> Module -> [SpecComment] -> [BPspec] -> TcM (Either LiquidCheckException BareSpec)
+getLiquidSpec thisFile thisModule specComments specQuotes = do
+  globalCfg <- liftIO getConfig
   let commSpecE :: Either [Error] (ModName, Spec LocBareType LocSymbol)
       commSpecE = hsSpecificationP (moduleName thisModule) (coerce specComments) specQuotes
   case commSpecE of
-    Left errors -> do
-      LH.reportErrors Full errors
-      failM
+    Left errors ->
+      LH.filterReportErrors thisFile GHC.failM continue (getFilters globalCfg) Full errors
     Right (view bareSpecIso . snd -> commSpec) -> do
       res <- SpecFinder.findCompanionSpec thisModule
       case res of
         SpecFound _ _ companionSpec -> do
           debugLog $ "Companion spec found for " ++ renderModule thisModule
-          pure $ commSpec <> companionSpec
-        _ -> pure commSpec
+          pure $ Right $ commSpec <> companionSpec
+        _ -> pure $ Right commSpec
+  where
+    continue = pure $ Left (ErrorsOccurred [])
 
-processModule :: LiquidHaskellContext -> TcM ProcessModuleResult
+processModule :: LiquidHaskellContext -> TcM (Either LiquidCheckException ProcessModuleResult)
 processModule LiquidHaskellContext{..} = do
   debugLog ("Module ==> " ++ renderModule thisModule)
   hscEnv              <- askHscEnv
@@ -462,8 +527,8 @@
     when debugLogs $
       forM_ (HM.keys . getDependencies $ dependencies) $ debugLog . moduleStableString . unStableModule
 
-    debugLog $ "mg_exports => " ++ (O.showSDocUnsafe $ O.ppr $ mg_exports modGuts)
-    debugLog $ "mg_tcs => " ++ (O.showSDocUnsafe $ O.ppr $ mg_tcs modGuts)
+    debugLog $ "mg_exports => " ++ O.showSDocUnsafe (O.ppr $ mg_exports modGuts)
+    debugLog $ "mg_tcs => " ++ O.showSDocUnsafe (O.ppr $ mg_tcs modGuts)
 
     targetSrc  <- makeTargetSrc moduleCfg file lhModuleTcData modGuts hscEnv
     dynFlags <- getDynFlags
@@ -472,17 +537,19 @@
     -- Due to the fact the internals can throw exceptions from pure code at any point, we need to
     -- call 'evaluate' to force any exception and catch it, if we can.
 
+
     result <-
-      (makeTargetSpec moduleCfg lhModuleLogicMap targetSrc bareSpec dependencies)
-        `gcatch` (\(e :: UserError) -> LH.reportErrors Full [e] >> failM)
-        `gcatch` (\(e :: Error)     -> LH.reportErrors Full [e] >> failM)
+      makeTargetSpec moduleCfg lhModuleLogicMap targetSrc bareSpec dependencies
 
-    case result of
+    let continue = pure $ Left (ErrorsOccurred [])
+        reportErrs :: (Show e, F.PPrint e) => [TError e] -> TcRn (Either LiquidCheckException ProcessModuleResult)
+        reportErrs = LH.filterReportErrors file GHC.failM continue (getFilters moduleCfg) Full
+
+    (case result of
       -- Print warnings and errors, aborting the compilation.
       Left diagnostics -> do
         liftIO $ mapM_ (printWarning dynFlags)    (allWarnings diagnostics)
-        LH.reportErrors Full (allErrors diagnostics)
-        failM
+        reportErrs $ allErrors diagnostics
       Right (warnings, targetSpec, liftedSpec) -> do
         liftIO $ mapM_ (printWarning dynFlags) warnings
         let targetInfo = TargetInfo targetSrc targetSpec
@@ -492,12 +559,15 @@
 
         let clientLib  = mkLiquidLib liftedSpec & addLibDependencies dependencies
 
-        let result = ProcessModuleResult {
+        let result' = ProcessModuleResult {
               pmrClientLib  = clientLib
             , pmrTargetInfo = targetInfo
             }
 
-        pure result
+        pure $ Right result')
+      `gcatch` (\(e :: UserError) -> reportErrs [e])
+      `gcatch` (\(e :: Error) -> reportErrs [e])
+      `gcatch` (\(es :: [Error]) -> reportErrs es)
 
   where
     modGuts    = fromUnoptimised lhModuleGuts
@@ -521,7 +591,7 @@
   -- the ones exported. This covers the case of \"wrapper modules\" that simply re-exports
   -- everything from the imported modules.
   let availTcs    = tcAvailableTyCons tcData
-  let allTcs      = L.nub $ (mgi_tcs mgiModGuts ++ availTcs)
+  let allTcs      = L.nub (mgi_tcs mgiModGuts ++ availTcs)
 
   let dataCons       = concatMap (map dataConWorkId . tyConDataCons) allTcs
   let (fiTcs, fiDcs) = LH.makeFamInstEnv (getFamInstances modGuts)
@@ -544,8 +614,8 @@
   debugLog $ "gsFiDcs   => " ++ show fiDcs
   debugLog $ "gsPrimTcs => " ++ (O.showSDocUnsafe . O.ppr $ GHC.primTyCons)
   debugLog $ "things   => " ++ (O.showSDocUnsafe . O.vcat . map O.ppr $ things)
-  debugLog $ "allImports => " ++ (show $ tcAllImports tcData)
-  debugLog $ "qualImports => " ++ (show $ tcQualifiedImports tcData)
+  debugLog $ "allImports => " ++ show (tcAllImports tcData)
+  debugLog $ "qualImports => " ++ show (tcQualifiedImports tcData)
 
   return $ TargetSrc
     { giIncDir    = mempty
diff --git a/src/Language/Haskell/Liquid/GHC/Plugin/SpecFinder.hs b/src/Language/Haskell/Liquid/GHC/Plugin/SpecFinder.hs
--- a/src/Language/Haskell/Liquid/GHC/Plugin/SpecFinder.hs
+++ b/src/Language/Haskell/Liquid/GHC/Plugin/SpecFinder.hs
@@ -1,5 +1,4 @@
 {-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE MultiWayIf #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE BangPatterns #-}
 {-# LANGUAGE RankNTypes   #-}
@@ -12,7 +11,7 @@
     , configToRedundantDependencies
     ) where
 
-import           Language.Haskell.Liquid.GHC.GhcMonadLike as GhcMonadLike ( GhcMonadLike
+import           Liquid.GHC.GhcMonadLike as GhcMonadLike ( GhcMonadLike
                                                                           , lookupModSummary
                                                                           , askHscEnv
                                                                           )
@@ -25,8 +24,8 @@
 import           Language.Fixpoint.Utils.Files            ( Ext(Spec), withExt )
 
 import           Optics
-import qualified Language.Haskell.Liquid.GHC.API         as O
-import           Language.Haskell.Liquid.GHC.API         as GHC hiding (linear)
+import qualified Liquid.GHC.API         as O
+import           Liquid.GHC.API         as GHC
 
 import           Data.Bifunctor
 import           Data.Maybe
@@ -60,9 +59,7 @@
                   -> [Module]
                   -- ^ Any relevant module fetched during dependency-discovery.
                   -> m [SpecFinderResult]
-findRelevantSpecs eps hpt mods = do
-  res  <- foldlM loadRelevantSpec mempty mods
-  pure res
+findRelevantSpecs eps hpt mods = foldlM loadRelevantSpec mempty mods
   where
 
     loadRelevantSpec :: [SpecFinderResult] -> Module -> m [SpecFinderResult]
@@ -120,10 +117,10 @@
 configToRedundantDependencies :: forall m. GhcMonadLike m => Config -> m [StableModule]
 configToRedundantDependencies cfg = do
   env <- askHscEnv
-  catMaybes <$> mapM (lookupModule env . first ($ cfg)) configSensitiveDependencies
+  catMaybes <$> mapM (lookupModule' env . first ($ cfg)) configSensitiveDependencies
   where
-    lookupModule :: HscEnv -> (Bool, ModuleName) -> m (Maybe StableModule)
-    lookupModule env (fetchModule, modName)
+    lookupModule' :: HscEnv -> (Bool, ModuleName) -> m (Maybe StableModule)
+    lookupModule' env (fetchModule, modName)
       | fetchModule = liftIO $ lookupLiquidBaseModule env modName
       | otherwise   = pure Nothing
 
diff --git a/src/Language/Haskell/Liquid/GHC/Plugin/Types.hs b/src/Language/Haskell/Liquid/GHC/Plugin/Types.hs
--- a/src/Language/Haskell/Liquid/GHC/Plugin/Types.hs
+++ b/src/Language/Haskell/Liquid/GHC/Plugin/Types.hs
@@ -4,8 +4,6 @@
 {-# LANGUAGE LambdaCase #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE NamedFieldPuns #-}
 {-# LANGUAGE RecordWildCards #-}
 {-# LANGUAGE DeriveDataTypeable #-}
 {-# LANGUAGE DeriveGeneric #-}
@@ -64,8 +62,8 @@
 
 import           Language.Fixpoint.Types.Spans
 import           Language.Haskell.Liquid.Types.Specs
-import           Language.Haskell.Liquid.GHC.API         as GHC
-import qualified Language.Haskell.Liquid.GHC.Interface   as LH
+import           Liquid.GHC.API         as GHC
+import qualified Liquid.GHC.Interface   as LH
 import           Language.Fixpoint.Types.Names            ( Symbol )
 
 
@@ -84,7 +82,7 @@
 
 -- | Adds a set of dependencies to the input 'LiquidLib'.
 addLibDependencies :: TargetDependencies -> LiquidLib -> LiquidLib
-addLibDependencies deps lib = lib { llDeps = deps <> (llDeps lib) }
+addLibDependencies deps lib = lib { llDeps = deps <> llDeps lib }
 
 -- | Returns the target 'LiftedSpec' of this 'LiquidLib'.
 libTarget :: LiquidLib -> LiftedSpec
diff --git a/src/Language/Haskell/Liquid/GHC/Plugin/Util.hs b/src/Language/Haskell/Liquid/GHC/Plugin/Util.hs
--- a/src/Language/Haskell/Liquid/GHC/Plugin/Util.hs
+++ b/src/Language/Haskell/Liquid/GHC/Plugin/Util.hs
@@ -1,6 +1,5 @@
 {-# LANGUAGE TypeApplications #-}
 {-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE DeriveDataTypeable #-}
 module Language.Haskell.Liquid.GHC.Plugin.Util (
         partitionMaybe
       , extractSpecComments
@@ -26,7 +25,7 @@
 import           Data.Data
 import           Data.Either                              ( partitionEithers )
 
-import           Language.Haskell.Liquid.GHC.API
+import           Liquid.GHC.API
 import           Language.Haskell.Liquid.GHC.Plugin.Types ( SpecComment
                                                           , LiquidLib
                                                           )
diff --git a/src/Language/Haskell/Liquid/GHC/Resugar.hs b/src/Language/Haskell/Liquid/GHC/Resugar.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Resugar.hs
+++ /dev/null
@@ -1,165 +0,0 @@
-{-# LANGUAGE CPP                       #-}
-{-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE FlexibleInstances         #-}
-{-# LANGUAGE GADTs                     #-}
-{-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE RankNTypes                #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
-{-# LANGUAGE UndecidableInstances      #-}
-
--- | This module contains functions for "resugaring" low-level GHC `CoreExpr`
---   into high-level patterns, that can receive special case handling in
---   different phases (e.g. ANF, Constraint Generation, etc.)
-
-module Language.Haskell.Liquid.GHC.Resugar (
-  -- * High-level Source Patterns
-    Pattern (..)
-
-  -- * Lift a CoreExpr into a Pattern
-  , lift
-
-  -- * Lower a pattern back into a CoreExpr
-  , lower
-  ) where
-
-import qualified Data.List as L
-import           Language.Haskell.Liquid.GHC.API  as Ghc hiding (PatBind)
-import qualified Language.Haskell.Liquid.GHC.Misc as GM
-import qualified Language.Fixpoint.Types          as F 
-import qualified Text.PrettyPrint.HughesPJ        as PJ 
--- import           Debug.Trace
-
---------------------------------------------------------------------------------
--- | Data type for high-level patterns -----------------------------------------
---------------------------------------------------------------------------------
-
-data Pattern
-  = PatBind
-      { patE1  :: !CoreExpr
-      , patX   :: !Var
-      , patE2  :: !CoreExpr
-      , patM   :: !Type
-      , patDct :: !CoreExpr
-      , patTyA :: !Type
-      , patTyB :: !Type
-      , patFF  :: !Var
-      }                      -- ^ e1 >>= \x -> e2
-
-  | PatReturn                -- return @ m @ t @ $dT @ e
-     { patE    :: !CoreExpr  -- ^ e
-     , patM    :: !Type      -- ^ m
-     , patDct  :: !CoreExpr  -- ^ $dT
-     , patTy   :: !Type      -- ^ t
-     , patRet  :: !Var       -- ^ "return"
-     }
-
-  | PatProject               -- (case xe as x of C [x1,...,xn] -> xi) : ty
-    { patXE    :: !Var       -- ^ xe
-    , patX     :: !Var       -- ^ x
-    , patTy    :: !Type      -- ^ ty
-    , patCtor  :: !DataCon   -- ^ C
-    , patBinds :: ![Var]     -- ^ [x1,...,xn]
-    , patIdx   :: !Int       -- ^ i :: NatLT {len patBinds}
-    }
-
-  | PatSelfBind              -- let x = e in x
-    { patX     :: !Var       -- ^ x
-    , patE     :: !CoreExpr  -- ^ e
-    }
-
-  | PatSelfRecBind           -- letrec x = e in x
-    { patX     :: !Var       -- ^ x
-    , patE     :: !CoreExpr  -- ^ e
-    }
-
-instance F.PPrint Pattern where 
-  pprintTidy  = ppPat
-
-ppPat :: F.Tidy -> Pattern -> PJ.Doc 
-ppPat k (PatReturn e m d t rv) = 
-  "PatReturn: " 
-  PJ.$+$ 
-  F.pprintKVs k
-    [ ("rv" :: PJ.Doc, GM.pprDoc rv) 
-    , ("e " :: PJ.Doc, GM.pprDoc e) 
-    , ("m " :: PJ.Doc, GM.pprDoc m) 
-    , ("$d" :: PJ.Doc, GM.pprDoc d) 
-    , ("t " :: PJ.Doc, GM.pprDoc t) 
-    ] 
-ppPat _ _  = "TODO: PATTERN" 
-    
-
-_mbId :: CoreExpr -> Maybe Var
-_mbId (Var x)    = Just x
-_mbId (Tick _ e) = _mbId e
-_mbId _          = Nothing
-
---------------------------------------------------------------------------------
--- | Lift expressions into High-level patterns ---------------------------------
---------------------------------------------------------------------------------
-lift :: CoreExpr -> Maybe Pattern
---------------------------------------------------------------------------------
-lift e = exprArgs e (collectArgs e)
-
-exprArgs :: CoreExpr -> (CoreExpr, [CoreExpr]) -> Maybe Pattern
-exprArgs _e (Var op, [Type m, d, Type a, Type b, e1, Lam x e2])
-  | op `is` Ghc.bindMName
-  = Just (PatBind e1 x e2 m d a b op)
-
-exprArgs (Case (Var xe) x t [(DataAlt c, ys, Var y)]) _
-  | Just i <- y `L.elemIndex` ys
-  = Just (PatProject xe x t c ys i)
-
-
-{- TEMPORARILY DISABLED: TODO-REBARE; in reality it hasn't been working AT ALL 
-   since at least the GHC 8.2.1 port (?) because the TICKs get in the way 
-   of recognizing the pattern? Anyways, messes up 
-
-     tests/pattern/pos/Return00.hs  
-
-   because we treat _all_ types of the form `m a` as "invariant" in the parameter `a`.
-   Looks like the above tests only pass in earlier LH versions because this pattern 
-   was NOT getting tickled!
-
-exprArgs _e (Var op, [Type m, d, Type t, e])
-  | op `is` PN.returnMName
-  = Just (PatReturn e m d t op)
--}
-
-{- TEMPORARILY DISBLED
-
-exprArgs (Let (NonRec x e) e') _
-  | Just y <- _mbId e', x == y
-  = Just (PatSelfBind x e)
-
-exprArgs (Let (Rec [(x, e)]) e') _
-  | Just y <- _mbId e', x == y
-  = Just (PatSelfRecBind x e)
-
--}
-exprArgs _ _
-  = Nothing
-
-is :: Var -> Name -> Bool
-is v n = n == getName v
-
---------------------------------------------------------------------------------
--- | Lower patterns back into expressions --------------------------------------
---------------------------------------------------------------------------------
-lower :: Pattern -> CoreExpr
---------------------------------------------------------------------------------
-lower (PatBind e1 x e2 m d a b op)
-  = Ghc.mkCoreApps (Var op) [Type m, d, Type a, Type b, e1, Lam x e2]
-
-lower (PatReturn e m d t op)
-  = Ghc.mkCoreApps (Var op) [Type m, d, Type t, e]
-
-lower (PatProject xe x t c ys i)
-  = Case (Var xe) x t [(DataAlt c, ys, Var yi)] where yi = ys !! i
-
-lower (PatSelfBind x e)
-  = Let (NonRec x e) (Var x)
-
-lower (PatSelfRecBind x e)
-  = Let (Rec [(x, e)]) (Var x)
diff --git a/src/Language/Haskell/Liquid/GHC/SpanStack.hs b/src/Language/Haskell/Liquid/GHC/SpanStack.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/SpanStack.hs
+++ /dev/null
@@ -1,80 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-
-module Language.Haskell.Liquid.GHC.SpanStack
-   ( -- * Stack of positions
-     Span (..)
-   , SpanStack
-
-     -- * Creating Stacks
-   , empty, push
-
-     -- * Using Stacks
-   , srcSpan
-
-     -- * Creating general spans
-   , showSpan
-   ) where
-
-import           Prelude                   hiding (error)
-import           Data.Maybe                       (listToMaybe, fromMaybe)
-import           Language.Haskell.Liquid.GHC.Misc (tickSrcSpan, showPpr)
-import qualified Language.Haskell.Liquid.GHC.API  as Ghc
-import           Language.Haskell.Liquid.GHC.API  ( SrcSpan
-                                                  , fsLit
-                                                  , getSrcSpan
-                                                  , isGoodSrcSpan
-                                                  , mkGeneralSrcSpan
-                                                  )
-
--- | Opaque type for a stack of spans
-newtype SpanStack = SpanStack { unStack :: [(Span, SrcSpan)] }
-
---------------------------------------------------------------------------------
-empty :: SpanStack
---------------------------------------------------------------------------------
-empty = SpanStack []
-
---------------------------------------------------------------------------------
-push :: Span -> SpanStack -> SpanStack
---------------------------------------------------------------------------------
-push !s stk -- @(SpanStack stk)
-  | Just sp <- spanSrcSpan s = SpanStack ((s, sp) : unStack stk)
-  | otherwise                = stk
-
--- | A single span
-data Span
-  = Var  !Ghc.Var               -- ^ binder for whom we are generating constraint
-  | Tick !(Ghc.Tickish Ghc.Var) -- ^ nearest known Source Span
-  | Span SrcSpan
-
-instance Show Span where
-  show (Var x)   = show x
-  show (Tick tt) = showPpr tt
-  show (Span s)  = show s 
-
---------------------------------------------------------------------------------
-srcSpan :: SpanStack -> SrcSpan
---------------------------------------------------------------------------------
-srcSpan s  = fromMaybe noSpan (mbSrcSpan s)
-  where
-    noSpan = showSpan "Yikes! No source information"
-
-mbSrcSpan :: SpanStack -> Maybe SrcSpan
-mbSrcSpan = fmap snd . listToMaybe  . unStack
-
-spanSrcSpan :: Span -> Maybe SrcSpan
-spanSrcSpan      = maybeSpan Nothing . go
-  where
-    go (Var x)   = getSrcSpan x
-    go (Tick tt) = tickSrcSpan tt
-    go (Span s)  = s 
-
-maybeSpan :: Maybe SrcSpan -> SrcSpan -> Maybe SrcSpan
-maybeSpan d sp
-  | isGoodSrcSpan sp = Just sp
-  | otherwise        = d
-
---------------------------------------------------------------------------------
-showSpan :: (Show a) => a -> SrcSpan
---------------------------------------------------------------------------------
-showSpan = mkGeneralSrcSpan . fsLit . show
diff --git a/src/Language/Haskell/Liquid/GHC/TypeRep.hs b/src/Language/Haskell/Liquid/GHC/TypeRep.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/TypeRep.hs
+++ /dev/null
@@ -1,191 +0,0 @@
-{-# LANGUAGE CPP                       #-}
-{-# LANGUAGE OverloadedStrings         #-}
-{-# LANGUAGE FlexibleInstances         #-}
-{-# LANGUAGE GADTs                     #-}
-{-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE RankNTypes                #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
-{-# LANGUAGE UndecidableInstances      #-}
-{-# LANGUAGE ViewPatterns              #-}
-{-# LANGUAGE PatternSynonyms           #-}
-{-# LANGUAGE StandaloneDeriving        #-}
-
--- | This module contains a wrappers and utility functions for
--- accessing GHC module information. It should NEVER depend on
-module Language.Haskell.Liquid.GHC.TypeRep (
-  mkTyArg, 
-
-  showTy
-  ) where
-
-import           Language.Haskell.Liquid.GHC.Misc (showPpr)
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding (mkTyArg, showPpr, panic)
-import           Language.Fixpoint.Types (symbol)
-
--- e368f3265b80aeb337fbac3f6a70ee54ab14edfd
-
-mkTyArg :: TyVar -> TyVarBinder
-mkTyArg v = Bndr v Required
-
-instance Eq Type where
-  t1 == t2 = eqType' t1 t2
-
-eqType' :: Type -> Type -> Bool 
-eqType' (LitTy l1) (LitTy l2) 
-  = l1 == l2  
-eqType' (CoercionTy c1) (CoercionTy c2) 
-  = c1 == c2  
-eqType'(CastTy t1 c1) (CastTy t2 c2) 
-  = eqType' t1 t2 && c1 == c2 
-eqType' (FunTy a1 m1 t11 t12) (FunTy a2 m2 t21 t22)
-  = a1 == a2 && m1 == m2 && eqType' t11 t21 && eqType' t12 t22  
-eqType' (ForAllTy (Bndr v1 _) t1) (ForAllTy (Bndr v2 _) t2) 
-  = eqType' t1 (subst v2 (TyVarTy v1) t2) 
-eqType' (TyVarTy v1) (TyVarTy v2) 
-  = v1 == v2 
-eqType' (AppTy t11 t12) (AppTy t21 t22) 
-  = eqType' t11 t21 && eqType' t12 t22  
-eqType' (TyConApp c1 ts1) (TyConApp c2 ts2) 
-  = c1 == c2 && and (zipWith eqType' ts1 ts2) 
-eqType' _ _ 
-  = False 
-
-
-deriving instance (Eq tyvar, Eq argf) => Eq (VarBndr tyvar argf)
-
-instance Eq Coercion where
-  _ == _ = True 
-
-
-showTy :: Type -> String 
-showTy (TyConApp c ts) = "(RApp   " ++ showPpr c ++ " " ++ sep' ", " (showTy <$> ts) ++ ")"
-showTy (AppTy t1 t2)   = "(TAppTy " ++ (showTy t1 ++ " " ++ showTy t2) ++ ")" 
-showTy (TyVarTy v)   = "(RVar " ++ show (symbol v)  ++ ")" 
-showTy (ForAllTy (Bndr v _) t)  = "ForAllTy " ++ show (symbol v) ++ ". (" ++  showTy t ++ ")"
-showTy (FunTy af _m1 t1 t2) = "FunTy " ++ showPpr af ++ " " ++ showTy t1 ++ ". (" ++  showTy t2 ++ ")"
-showTy (CastTy _ _)    = "CastTy"
-showTy (CoercionTy _)  = "CoercionTy"
-showTy (LitTy _)       = "LitTy"
-
-sep' :: String -> [String] -> String
-sep' _ [x] = x
-sep' _ []  = []
-sep' s (x:xs) = x ++ s ++ sep' s xs 
-
-
-
--------------------------------------------------------------------------------
--- | GHC Type Substitutions ---------------------------------------------------
--------------------------------------------------------------------------------
-
-class SubstTy a where
-  subst :: TyVar -> Type -> a -> a
-  subst _ _ = id  
-
-instance SubstTy Type where
-  subst = substType
-
-substType :: TyVar -> Type -> Type -> Type
-substType x tx (TyConApp c ts) 
-  = TyConApp c (subst x tx <$> ts)
-substType x tx (AppTy t1 t2)   
-  = AppTy (subst x tx t1) (subst x tx t2) 
-substType x tx (TyVarTy y)   
-  | symbol x == symbol y
-  = tx 
-  | otherwise
-  = TyVarTy y 
-substType x tx (FunTy aaf m t1 t2)
-  = FunTy aaf m (subst x tx t1) (subst x tx t2)
-substType x tx f@(ForAllTy b@(Bndr y _) t)  
-  | symbol x == symbol y 
-  = f
-  | otherwise 
-  = ForAllTy b (subst x tx t)
-substType x tx (CastTy t c)    
-  = CastTy (subst x tx t) (subst x tx c)
-substType x tx (CoercionTy c)  
-  = CoercionTy $ subst x tx c 
-substType _ _  (LitTy l)
-  = LitTy l  
-
-
-instance SubstTy Coercion where
-  subst = substCoercion
-
-substCoercion :: TyVar -> Type -> Coercion -> Coercion
-substCoercion x tx (TyConAppCo r c cs)
-  = TyConAppCo (subst x tx r) c (subst x tx <$> cs)
-substCoercion x tx (AppCo c1 c2)
-  = AppCo (subst x tx c1) (subst x tx c2)
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-substCoercion x tx (FunCo r c1 c2)
-  = FunCo r (subst x tx c1) (subst x tx c2)
-#else
-substCoercion x tx (FunCo r cN c1 c2)
-  = FunCo r cN (subst x tx c1) (subst x tx c2) -- TODO(adinapoli) Is this the correct substitution?
-#endif
-#endif
-substCoercion x tx (ForAllCo y c1 c2)
-  | symbol x == symbol y 
-  = (ForAllCo y c1 c2)
-  | otherwise 
-  = ForAllCo y (subst x tx c1) (subst x tx c2)
-substCoercion _ _ (CoVarCo y)
-  = CoVarCo y 
-substCoercion x tx (AxiomInstCo co bi cs)
-  = AxiomInstCo (subst x tx co) bi (subst x tx <$> cs)  
-substCoercion x tx (UnivCo y r t1 t2)
-  = UnivCo (subst x tx y) (subst x tx r) (subst x tx t1) (subst x tx t2)
-substCoercion x tx (SymCo c)
-  = SymCo (subst x tx c)
-substCoercion x tx (TransCo c1 c2)
-  = TransCo (subst x tx c1) (subst x tx c2)
-substCoercion x tx (AxiomRuleCo ca cs)
-  = AxiomRuleCo (subst x tx ca)  (subst x tx <$> cs)  
-substCoercion x tx (NthCo r i c)
-  = NthCo r i (subst x tx c)
-substCoercion x tx (LRCo i c)
-  = LRCo i (subst x tx c)
-substCoercion x tx (InstCo c1 c2)
-  = InstCo (subst x tx c1) (subst x tx c2)
-substCoercion x tx (KindCo c)
-  = KindCo (subst x tx c)
-substCoercion x tx (SubCo c)
-  = SubCo (subst x tx c)
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,6,5,0) && !MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)
-substCoercion x tx (Refl r t)
-  = Refl (subst x tx r) (subst x tx t)
-substCoercion x tx (CoherenceCo c1 c2)
-  = CoherenceCo (subst x tx c1) (subst x tx c2)
-#endif
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
-substCoercion x tx (Refl t)
-  = Refl (subst x tx t)
-substCoercion x tx (GRefl r t co) -- FIXME(adn) Is this a correct substitution?
-  = GRefl r (subst x tx t) co     -- FIXME(adn) Is this a correct substitution?
-substCoercion _x _tx (HoleCo cH)
-  = HoleCo cH                     -- FIXME(adn) Is this a correct substitution?
-#endif
-#endif
-
-instance SubstTy Role where
-instance SubstTy (CoAxiom Branched) where
-
-instance SubstTy UnivCoProvenance where
-  subst x tx (PhantomProv c)
-    = PhantomProv $ subst x tx c 
-  subst x tx (ProofIrrelProv c)
-    = ProofIrrelProv $ subst x tx c 
-  subst _ _ ch 
-    = ch 
-
-instance SubstTy CoAxiomRule where
-  subst x tx (CoAxiomRule n rs r ps) 
-    = CoAxiomRule n (subst x tx <$> rs) (subst x tx r) (\eq -> subst x tx (ps (subst x tx eq)))
-
-instance (SubstTy a, Functor m) => SubstTy (m a) where
-  subst x tx xs = subst x tx <$> xs
diff --git a/src/Language/Haskell/Liquid/GHC/Types.hs b/src/Language/Haskell/Liquid/GHC/Types.hs
deleted file mode 100644
--- a/src/Language/Haskell/Liquid/GHC/Types.hs
+++ /dev/null
@@ -1,79 +0,0 @@
-{-# LANGUAGE DeriveGeneric #-}
-module Language.Haskell.Liquid.GHC.Types where
-
-import           Data.HashSet (HashSet, fromList)
-import           Data.Hashable
-import           GHC.Generics hiding (moduleName)
-import           Language.Haskell.Liquid.GHC.API
-
--- | A 'StableName' is virtually isomorphic to a GHC's 'Name' but crucially we don't use
--- the 'Eq' instance defined on a 'Name' because it's 'Unique'-based. In particular, GHC
--- doesn't guarantee that if we load an interface multiple times we would get the same 'Unique' for the
--- same 'Name', and this is a problem when we rely on 'Name's to be the same when we call 'isExportedVar',
--- which used to use a 'NameSet' derived from the '[AvailInfo]'. As the name implies, a 'NameSet' uses a
--- 'Name's 'Unique' for duplicate detection and indexing, and this would lead to 'Var's being resolved to
--- a 'Name' which is basically the same, but it has a /different/ 'Unique', and that would cause the lookup
--- inside the 'NameSet' to fail.
-newtype StableName =
-  MkStableName { unStableName :: Name }
-  deriving Generic
-
-instance Show StableName where
-  show (MkStableName n) = nameStableString n
-
-instance Hashable StableName where
-  hashWithSalt s (MkStableName n) = hashWithSalt s (nameStableString n)
-
-instance Eq StableName where
-  (MkStableName n1) == (MkStableName n2) = -- n1 `stableNameCmp` n2 == EQ
-    let sameOccName = (occNameString $ nameOccName n1) == (occNameString $ nameOccName n2)
-        sameModule  = nameModule  n1 == nameModule  n2
-        sameSrcLoc  = nameSrcLoc  n1 == nameSrcLoc  n2
-        sameSrcSpan = nameSrcSpan n1 == nameSrcSpan n2
-    in sameOccName && sameModule && sameSrcLoc  && sameSrcSpan
-
--- | Creates a new 'StableName' out of a 'Name'.
-mkStableName :: Name -> StableName
-mkStableName = MkStableName
-
--- | Converts a list of 'AvailInfo' into a \"StableNameSet\", similarly to what 'availsToNameSet' would do.
-availsToStableNameSet :: [AvailInfo] -> HashSet StableName
-availsToStableNameSet avails = foldr add mempty avails
-      where add av acc = acc <> fromList (map mkStableName (availNames av))
-
---------------------------------------------------------------------------------
--- | Datatype For Holding GHC ModGuts ------------------------------------------
---------------------------------------------------------------------------------
-data MGIModGuts = MI 
-  { mgi_binds     :: !CoreProgram
-  , mgi_module    :: !Module
-  , mgi_deps      :: !Dependencies
-  , mgi_dir_imps  :: ![ModuleName]
-  , mgi_rdr_env   :: !GlobalRdrEnv
-  , mgi_tcs       :: ![TyCon]
-  , mgi_fam_insts :: ![FamInst]
-  , mgi_exports   :: !(HashSet StableName)
-  , mgi_cls_inst  :: !(Maybe [ClsInst])
-  }
-
-miModGuts :: Maybe [ClsInst] -> ModGuts -> MGIModGuts
-miModGuts cls mg  = MI 
-  { mgi_binds     = mg_binds mg
-  , mgi_module    = mg_module mg
-  , mgi_deps      = mg_deps mg
-  , mgi_dir_imps  = mg_dir_imps mg
-  , mgi_rdr_env   = mg_rdr_env mg
-  , mgi_tcs       = mg_tcs mg
-  , mgi_fam_insts = mg_fam_insts mg
-  , mgi_exports   = availsToStableNameSet $ mg_exports mg
-  , mgi_cls_inst  = cls
-  }
-
-nameSetToStableNameSet :: NameSet -> HashSet StableName
-nameSetToStableNameSet = fromList . map mkStableName . nameSetElemsStable
-
-mg_dir_imps :: ModGuts -> [ModuleName]
-mg_dir_imps = map gwib_mod . getDependenciesModuleNames . mg_deps
-
-mgi_namestring :: MGIModGuts -> String
-mgi_namestring = moduleNameString . moduleName . mgi_module
diff --git a/src/Language/Haskell/Liquid/LawInstances.hs b/src/Language/Haskell/Liquid/LawInstances.hs
--- a/src/Language/Haskell/Liquid/LawInstances.hs
+++ b/src/Language/Haskell/Liquid/LawInstances.hs
@@ -7,7 +7,7 @@
 
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.Types.Equality
-import           Language.Haskell.Liquid.GHC.API            hiding ((<+>), text)
+import           Liquid.GHC.API            hiding ((<+>), text)
 import qualified Language.Fixpoint.Types                    as F
 
 checkLawInstances :: GhcSpecLaws -> Diagnostics
@@ -63,7 +63,7 @@
     t22 = fromRTypeRep (trep2 {ty_vars = [], ty_binds = fst <$> args2, ty_args = snd <$> args2, ty_refts = drop (length tc2) (ty_refts trep2)})
     t11 = fromRTypeRep (trep1 { ty_vars = []
                               , ty_binds = fst <$> args2
-                              , ty_args = (tx . snd) <$> args1
+                              , ty_args = tx . snd <$> args1
                               , ty_refts = F.subst esubst <$> drop (length tc1) (ty_refts trep1)
                               , ty_res = tx $ ty_res trep1})
     tx = subtsSpec tsubst . F.subst esubst
@@ -76,10 +76,10 @@
     esubst = F.mkSubst (esubst1
                  ++  [(F.symbol x, F.EVar (F.symbol y)) | (Left x, (Left y, _)) <- lilEqus li]
                      )
-    esubst1 = zip  (fst <$> args1) ((F.EVar . fst) <$> args2)
+    esubst1 = zip  (fst <$> args1) (F.EVar . fst <$> args2)
 
     tsubst = reverse $ zip ((\(RTV v) -> v) <$> (findTyVars tc1 ++ (ty_var_value <$> concat argVars)))
-                 (toType False <$> (argBds ++ (((`RVar` mempty) . ty_var_value) <$> (fst <$> ty_vars trep2))))
+                 (toType False <$> (argBds ++ ((`RVar` mempty) . ty_var_value <$> (fst <$> ty_vars trep2))))
 
     (argVars, argBds) = unzip (splitForall [] . val <$> lilTyArgs li)
 
diff --git a/src/Language/Haskell/Liquid/Liquid.hs b/src/Language/Haskell/Liquid/Liquid.hs
--- a/src/Language/Haskell/Liquid/Liquid.hs
+++ b/src/Language/Haskell/Liquid/Liquid.hs
@@ -1,7 +1,4 @@
-{-# LANGUAGE NamedFieldPuns      #-}
-{-# LANGUAGE TupleSections       #-}
 {-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE RecordWildCards     #-}
 
 {-@ LIQUID "--diff"     @-}
 
@@ -42,18 +39,19 @@
 import           Language.Haskell.Liquid.UX.Errors
 import           Language.Haskell.Liquid.UX.CmdLine
 import           Language.Haskell.Liquid.UX.Tidy
-import           Language.Haskell.Liquid.GHC.Misc (showCBs, ignoreCoreBinds) -- howPpr)
-import           Language.Haskell.Liquid.GHC.Interface
+import           Liquid.GHC.Misc (showCBs, ignoreCoreBinds) -- howPpr)
+import           Liquid.GHC.Interface
 import           Language.Haskell.Liquid.Constraint.Generate
 import           Language.Haskell.Liquid.Constraint.ToFixpoint
 import           Language.Haskell.Liquid.Constraint.Types
 import           Language.Haskell.Liquid.UX.Annotate (mkOutput)
 import qualified Language.Haskell.Liquid.Termination.Structural as ST
-import qualified Language.Haskell.Liquid.GHC.Misc          as GM 
-import           Language.Haskell.Liquid.GHC.API as GHC hiding (text, vcat, ($+$), getOpts, (<+>))
+import qualified Liquid.GHC.Misc          as GM 
+import           Liquid.GHC.API as GHC hiding (text, vcat, ($+$), getOpts, (<+>))
 
 type MbEnv = Maybe HscEnv
 
+
 --------------------------------------------------------------------------------
 liquid :: [String] -> IO b
 --------------------------------------------------------------------------------
@@ -87,7 +85,7 @@
 checkTargets cfg  = go 
   where
     go env []     = return (ExitSuccess, env)
-    go env (f:fs) = do whenLoud $ colorPhaseLn Loud ("[Checking: " ++ f ++ "]") ""
+    go env (f:fs) = do -- whenLoud $ colorPhaseLn Loud ("[Checking: " ++ f ++ "]") ""
                        (ec, env') <- runLiquidTargets env cfg [f] 
                        case ec of 
                          ExitSuccess -> go env' fs
@@ -170,7 +168,7 @@
     check :: IO (Output Doc)
     check
       | compileSpec cfg = do
-        donePhase Loud "Only compiling specifications [skipping verification]"
+        -- donePhase Loud "Only compiling specifications [skipping verification]"
         pure mempty { o_result = F.Safe mempty }
       | otherwise = do
         whenNormal $ donePhase Loud "Extracted Core using GHC"
@@ -268,7 +266,7 @@
                                  `addErrors` makeFailErrors (S.toList failBs) rf 
                                  `addErrors` makeFailUseErrors (S.toList failBs) (giCbs $ giSrc info)
   let lErrors       = applySolution sol <$> logErrors cgi
-  hErrors          <- if (typedHoles cfg) 
+  hErrors          <- if typedHoles cfg 
                         then synthesize tgt fcfg (cgi{holesMap = applySolution sol <$> holesMap  cgi}) 
                         else return [] 
   let resModel      = resModel' `addErrors` (e2u cfg sol <$> (lErrors ++ hErrors)) 
@@ -285,8 +283,8 @@
   let e' = attachSubcId e
    in fmap F.pprint (tidyError cfg s e')
   where
-    attachSubcId es@(ErrSubType{}) = es { cid = Just subcId }
-    attachSubcId es@(ErrSubTypeModel{}) = es { cid = Just subcId }
+    attachSubcId es@ErrSubType{}      = es { cid = Just subcId }
+    attachSubcId es@ErrSubTypeModel{} = es { cid = Just subcId }
     attachSubcId es = es
 
 -- writeCGI tgt cgi = {-# SCC "ConsWrite" #-} writeFile (extFileName Cgi tgt) str
@@ -312,7 +310,7 @@
 makeFailErrors bs cis = [ mkError x | x <- bs, notElem (val x) vs ]  
   where 
     mkError  x = ErrFail (GM.sourcePosSrcSpan $ loc x) (pprint $ val x)
-    vs         = [v | Just v <- (ci_var <$> cis) ]
+    vs         = Mb.mapMaybe ci_var cis
 
 splitFails :: S.HashSet Var -> F.FixResult (a, Cinfo) -> (F.FixResult (a, Cinfo),  [Cinfo])
 splitFails _ r@(F.Crash _ _) = (r,mempty)
diff --git a/src/Language/Haskell/Liquid/Measure.hs b/src/Language/Haskell/Liquid/Measure.hs
--- a/src/Language/Haskell/Liquid/Measure.hs
+++ b/src/Language/Haskell/Liquid/Measure.hs
@@ -3,7 +3,6 @@
 {-# LANGUAGE UndecidableInstances   #-}
 {-# LANGUAGE OverloadedStrings      #-}
 {-# LANGUAGE ConstraintKinds        #-}
-{-# LANGUAGE DeriveGeneric          #-}
 
 module Language.Haskell.Liquid.Measure (
   -- * Specifications
@@ -33,8 +32,8 @@
 
 import           Language.Fixpoint.Misc
 import           Language.Fixpoint.Types                hiding (panic, R, DataDecl, SrcSpan, LocSymbol)
-import           Language.Haskell.Liquid.GHC.API        as Ghc hiding (Expr, showPpr, panic, (<+>))
-import           Language.Haskell.Liquid.GHC.Misc
+import           Liquid.GHC.API        as Ghc hiding (Expr, showPpr, panic, (<+>))
+import           Liquid.GHC.Misc
 -- import qualified Language.Haskell.Liquid.Misc as Misc
 import           Language.Haskell.Liquid.Types.Types    -- hiding (GhcInfo(..), GhcSpec (..))
 import           Language.Haskell.Liquid.Types.RefType
@@ -69,14 +68,14 @@
 
 
 checkDuplicateMeasure :: [Measure ty ctor] -> [Measure ty ctor]
-checkDuplicateMeasure ms
+checkDuplicateMeasure measures
   = case M.toList dups of
-      []         -> ms
-      (m,ms):_   -> uError $ err m (msName <$> ms)
+      []         -> measures
+      (m,ms):_   -> uError $ mkErr m (msName <$> ms)
     where
-      gms        = group [(msName m , m) | m <- ms]
+      gms        = group [(msName m , m) | m <- measures]
       dups       = M.filter ((1 <) . length) gms
-      err m ms   = ErrDupMeas (fSrcSpan m) (pprint (val m)) (fSrcSpan <$> ms)
+      mkErr m ms = ErrDupMeas (fSrcSpan m) (pprint (val m)) (fSrcSpan <$> ms)
 
 
 dataConTypes :: Bool -> MSpec (RRType Reft) DataCon -> ([(Var, RRType Reft)], [(LocSymbol, RRType Reft)])
@@ -154,7 +153,7 @@
   = t
   where
     rep = toRTypeRep t
-    xs' = zipWith (\_ i -> symbol ("x" ++ show i)) (ty_binds rep) [1..]
+    xs' = zipWith (\_ i -> symbol ("x" ++ show i)) (ty_binds rep) [(1::Int)..]
     su  = mkSubst $ zip (ty_binds rep) (EVar <$> xs')
 
 combineDCTypes :: String -> Type -> [RRType Reft] -> RRType Reft
diff --git a/src/Language/Haskell/Liquid/Misc.hs b/src/Language/Haskell/Liquid/Misc.hs
--- a/src/Language/Haskell/Liquid/Misc.hs
+++ b/src/Language/Haskell/Liquid/Misc.hs
@@ -56,9 +56,9 @@
 safeFromJust _  (Just x) = x
 safeFromJust err _       = errorstar err
 
-safeFromLeft :: String -> Either a b -> a 
-safeFromLeft _   (Left l) = l 
-safeFromLeft err _        = errorstar err 
+safeFromLeft :: String -> Either a b -> a
+safeFromLeft _   (Left l) = l
+safeFromLeft err _        = errorstar err
 
 
 takeLast :: Int -> [a] -> [a]
@@ -153,17 +153,17 @@
 
 
 
-unzip4 :: [(t, t1, t2, t3)] -> ([t],[t1],[t2],[t3]) 
+unzip4 :: [(t, t1, t2, t3)] -> ([t],[t1],[t2],[t3])
 unzip4 = go [] [] [] []
-  where go a1 a2 a3 a4 ((x1,x2,x3,x4):xs) = go (x1:a1) (x2:a2) (x3:a3) (x4:a4) xs 
+  where go a1 a2 a3 a4 ((x1,x2,x3,x4):xs) = go (x1:a1) (x2:a2) (x3:a3) (x4:a4) xs
         go a1 a2 a3 a4 [] = (reverse  a1, reverse a2, reverse a3, reverse a4)
-  
 
-isIncludeFile :: FilePath -> FilePath -> Bool 
+
+isIncludeFile :: FilePath -> FilePath -> Bool
 isIncludeFile incDir src = -- do 
   -- incDir <- getIncludeDir 
   -- return 
-  (incDir `L.isPrefixOf` src)
+  incDir `L.isPrefixOf` src
 
 getIncludeDir :: IO FilePath
 getIncludeDir = dropFileName <$> getDataFileName ("include" </> "Prelude.spec")
@@ -180,10 +180,10 @@
     exePath <- dropFileName <$> getExecutablePath
     let atExe = exePath </> fileName
     exists <- doesFileExist atExe
-    
-    if exists then 
+
+    if exists then
       return atExe
-    else 
+    else
       fmap (</> fileName) getIncludeDir
 
 
@@ -213,7 +213,7 @@
 
 
 mapNs :: (Eq a, Num a, Foldable t) => t a -> (a1 -> a1) -> [a1] -> [a1]
-mapNs ns f xs = foldl (\xs n -> mapN n f xs) xs ns
+mapNs ns f xs = foldl (\ys n -> mapN n f ys) xs ns
 
 mapN :: (Eq a, Num a) => a -> (a1 -> a1) -> [a1] -> [a1]
 mapN 0 f (x:xs) = f x : xs
@@ -253,7 +253,7 @@
 firstMaybes = listToMaybe . catMaybes
 
 fromFirstMaybes :: a -> [Maybe a] -> a
-fromFirstMaybes x = fromMaybe x . firstMaybes 
+fromFirstMaybes x = fromMaybe x . firstMaybes
 -- fromFirstMaybes x = fromMaybe x . listToMaybe . catMaybes
 
 hashMapMapWithKey   :: (k -> v1 -> v2) -> M.HashMap k v1 -> M.HashMap k v2
@@ -267,17 +267,17 @@
 
 replaceSubset :: (Eq k, Hashable k) => [(k, a)] -> [(k, a)] -> [(k, a)]
 replaceSubset kvs kvs' = M.toList (L.foldl' upd m0 kvs')
-  where 
-    m0                = M.fromList kvs 
-    upd m (k, v') 
-      | M.member k m  = M.insert k v' m 
-      | otherwise     = m 
+  where
+    m0                = M.fromList kvs
+    upd m (k, v')
+      | M.member k m  = M.insert k v' m
+      | otherwise     = m
 
 replaceWith :: (Eq a, Hashable a) => (b -> a) -> [b] -> [b] -> [b]
-replaceWith f xs ys = snd <$> replaceSubset xs' ys' 
-  where 
-    xs'             = [ (f x, x) | x <- xs ] 
-    ys'             = [ (f y, y) | y <- ys ] 
+replaceWith f xs ys = snd <$> replaceSubset xs' ys'
+  where
+    xs'             = [ (f x, x) | x <- xs ]
+    ys'             = [ (f y, y) | y <- ys ]
 
 
 
@@ -328,7 +328,7 @@
 mkGraph = fmap S.fromList . group
 
 tryIgnore :: String -> IO () -> IO ()
-tryIgnore s a = 
+tryIgnore s a =
   Ex.catch a $ \e -> do
     let err = show (e :: Ex.IOException)
     writeLoud ("Warning: Couldn't do " ++ s ++ ": " ++ err)
@@ -370,7 +370,7 @@
     tx (k, vs)  = Left  (k, vs)
 
 uniqueByKey' :: (Eq k, Hashable k) => ((k, [v]) -> Either e v) -> [(k, v)] -> Either e [v]
-uniqueByKey' tx = sequence . map tx . groupList
+uniqueByKey' tx = mapM tx . groupList
 
 
 join :: (Eq b, Hashable b) => [(a, b)] -> [(b, c)] -> [(a, c)]
@@ -389,10 +389,10 @@
 sortOn :: (Ord b) => (a -> b) -> [a] -> [a]
 sortOn f = L.sortBy (compare `on` f)
 
-firstGroup :: (Eq k, Ord k, Hashable k) => [(k, a)] -> [a] 
-firstGroup kvs = case groupList kvs of 
-  []   -> [] 
-  kvss -> snd . head . sortOn fst $ kvss 
+firstGroup :: (Eq k, Ord k, Hashable k) => [(k, a)] -> [a]
+firstGroup kvs = case groupList kvs of
+  []   -> []
+  kvss -> snd . head . sortOn fst $ kvss
 
 {- mapEither :: (a -> Either b c) -> [a] -> ([b], [c])
 mapEither f []     = ([], [])
@@ -409,28 +409,28 @@
 catEithers zs = case ls of
   [] -> Right rs
   _  -> Left ls
-  where 
+  where
     ls = [ l | Left  l <- zs ]
     rs = [ r | Right r <- zs ]
 
 
 keyDiff :: (Eq k, Hashable k) => (a -> k) -> [a] -> [a] -> [a]
 keyDiff f x1s x2s = M.elems (M.difference (m x1s) (m x2s))
-  where 
-    m xs          = M.fromList [(f x, x) | x <- xs] 
+  where
+    m xs          = M.fromList [(f x, x) | x <- xs]
 
 concatUnzip :: [([a], [b])] -> ([a], [b])
 concatUnzip xsyss = (concatMap fst xsyss, concatMap snd xsyss)
 
 
-sayReadFile :: FilePath -> IO String 
-sayReadFile f = do 
+sayReadFile :: FilePath -> IO String
+sayReadFile f = do
   -- print ("SAY-READ-FILE: " ++ f)
-  res <- readFile f 
+  res <- readFile f
   Ex.evaluate res
 
-lastModified :: FilePath -> IO (Maybe UTCTime) 
-lastModified f = do 
+lastModified :: FilePath -> IO (Maybe UTCTime)
+lastModified f = do
   ex  <- doesFileExist f
   if ex then Just <$> getModificationTime f
         else return   Nothing
diff --git a/src/Language/Haskell/Liquid/Parse.hs b/src/Language/Haskell/Liquid/Parse.hs
--- a/src/Language/Haskell/Liquid/Parse.hs
+++ b/src/Language/Haskell/Liquid/Parse.hs
@@ -2,7 +2,6 @@
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE UndecidableInstances      #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE TupleSections             #-}
 {-# LANGUAGE OverloadedStrings         #-}
 {-# LANGUAGE DeriveDataTypeable        #-}
@@ -35,13 +34,13 @@
 import           Data.Char                              (isSpace, isAlphaNum)
 import           Data.List                              (foldl', partition)
 import           GHC                                    (ModuleName, mkModuleName)
-import qualified Text.PrettyPrint.HughesPJ              as PJ 
-import           Text.PrettyPrint.HughesPJ.Compat       ((<+>)) 
+import qualified Text.PrettyPrint.HughesPJ              as PJ
+import           Text.PrettyPrint.HughesPJ.Compat       ((<+>))
 import           Language.Fixpoint.Types                hiding (panic, SVar, DDecl, DataDecl, DataCtor (..), Error, R, Predicate)
-import           Language.Haskell.Liquid.GHC.Misc       hiding (getSourcePos)
+import           Liquid.GHC.Misc       hiding (getSourcePos)
 import           Language.Haskell.Liquid.Types
 -- import           Language.Haskell.Liquid.Types.Errors
-import qualified Language.Fixpoint.Misc                 as Misc      
+import qualified Language.Fixpoint.Misc                 as Misc
 import qualified Language.Haskell.Liquid.Misc           as Misc
 import qualified Language.Haskell.Liquid.Measure        as Measure
 import           Language.Fixpoint.Parse                hiding (defineP, dataDeclP, refBindP, refP, refDefP, parseTest')
@@ -61,21 +60,21 @@
   case go ([], []) initPStateWithList $ reverse specComments of
     ([], specs) ->
       Right $ mkSpec (ModName SrcImport modName) (specs ++ specQuotes)
-    (errs, _) ->
-      Left errs
+    (errors, _) ->
+      Left errors
   where
     go :: ([Error], [BPspec])   -- accumulated errors and parsed specs (in reverse order)
        -> PState                -- parser state (primarily infix operator priorities)
        -> [(SourcePos, String)] -- remaining unparsed spec comments
        -> ([Error], [BPspec])   -- final errors and parsed specs
-    go (errs, specs) _ []
-      = (reverse errs, reverse specs)
-    go (errs, specs) pstate ((pos, specComment):xs)
+    go (errors, specs) _ []
+      = (reverse errors, reverse specs)
+    go (errors, specs) pstate ((pos, specComment):xs)
       = -- 'specP' parses a single spec comment, i.e., a single LH directive
         -- we allow a "block" of specs now
         case parseWithError pstate (block specP) pos specComment of
-          Left err        -> go (parseErrorBundleToErrors err ++ errs, specs) pstate xs
-          Right (st,spec) -> go (errs,spec ++ specs) st xs
+          Left err'       -> go (parseErrorBundleToErrors err' ++ errors, specs) pstate xs
+          Right (st,spec) -> go (errors,spec ++ specs) st xs
 
 initPStateWithList :: PState
 initPStateWithList
@@ -197,9 +196,9 @@
 toLogicOneP :: Parser  (LocSymbol, [Symbol], Expr)
 toLogicOneP
   = do reserved "define"
-       (x:xs) <- some (locSymbolP)
+       (x:xs) <- some locSymbolP
        reservedOp "="
-       e      <- exprP
+       e      <- exprP <|> predP
        return (x, val <$> xs, e)
 
 
@@ -253,16 +252,16 @@
     PcExplicit b -> parseFun c b
   <?> "btP"
   where
-    parseFun c@(PC sb t1) b  =
-      ((do
+    parseFun c@(PC sb t1) sym  =
+      (do
             reservedOp "->"
             PC _ t2 <- btP
-            return (PC sb (rFun b t1 t2)))
+            return (PC sb (rFun sym t1 t2)))
         <|>
          (do
             reservedOp "~>"
             PC _ t2 <- btP
-            return (PC sb (rImpF b t1 t2)))
+            return (PC sb (rImpF sym t1 t2)))
         <|>
          (do
             reservedOp "=>"
@@ -273,8 +272,8 @@
           (do
              b <- locInfixSymbolP
              PC _ t2 <- btP
-             return $ PC sb $ (RApp (mkBTyCon b) [t1,t2] [] mempty))
-         <|> return c)
+             return $ PC sb $ RApp (mkBTyCon b) [t1,t2] [] mempty)
+         <|> return c
 
 
 compP :: Parser ParamComp
@@ -288,7 +287,7 @@
  <|> bareTypeBracesP                        -- starts with '{'
  <|> unnamedCircleP
  <|> anglesCircleP                          -- starts with '<'
- <|> nullPC <$> (dummyP bbaseP)             -- starts with '_' or '[' or '(' or lower or "'" or upper
+ <|> nullPC <$> dummyP bbaseP               -- starts with '_' or '[' or '(' or lower or "'" or upper
  <?> "circleP"
 
 anglesCircleP :: Parser ParamComp
@@ -307,13 +306,12 @@
 namedCircleP :: Parser ParamComp
 namedCircleP = do
   lb <- locLowerIdP
-  (do _ <- reservedOp ":"
-      let b = val lb
-      PC (PcExplicit b) <$> bareArgP b
+  do _ <- reservedOp ":"
+     let b = val lb
+     PC (PcExplicit b) <$> bareArgP b
     <|> do
       b <- dummyBindP
       PC (PcImplicit b) <$> dummyP (lowerIdTail (val lb))
-    )
 
 unnamedCircleP :: Parser ParamComp
 unnamedCircleP = do
@@ -335,10 +333,7 @@
 bareTypeBracesP :: Parser ParamComp
 bareTypeBracesP = do
   t <-  try (braces (
-            (try (do
-               ct <- constraintP
-               return $ Right ct
-                     ))
+            try (Right <$> constraintP)
            <|>
             (do
                     x  <- symbolP
@@ -363,7 +358,7 @@
       = (reserved "_" >> return hole)
      <|> try (pAnd <$> brackets (sepBy predP semi))
     helper p = braces $ do
-      t <- (RHole . uTop . Reft . ("VV",)) <$> p
+      t <- RHole . uTop . Reft . ("VV",) <$> p
       return (Left $ nullPC t)
 
 
@@ -371,7 +366,7 @@
 bareArgP vvv
   =  refDefP vvv refasHoleP bbaseP    -- starts with '{'
  <|> holeP                            -- starts with '_'
- <|> (dummyP bbaseP)
+ <|> dummyP bbaseP
  <|> parens bareTypeP                 -- starts with '('
                                       -- starts with '_', '[', '(', lower, upper
  <?> "bareArgP"
@@ -381,7 +376,7 @@
 bareAtomP ref
   =  ref refasHoleP bbaseP
  <|> holeP
- <|> (dummyP bbaseP)
+ <|> dummyP bbaseP
  <?> "bareAtomP"
 
 bareAtomBindP :: Parser BareType
@@ -397,7 +392,7 @@
              -> Parser BareType
 refBindBindP rp kindP'
   = braces (
-      ((do
+      (do
               x  <- symbolP
               _ <- reservedOp ":"
               -- NOSUBST i  <- freshIntP
@@ -408,8 +403,8 @@
               -- su replaces any use of x in the balance of the expression with the unique val
               -- NOSUBST let xi = intSymbol x i
               -- NOSUBST let su v = if v == x then xi else v
-              return $ {- substa su $ NOSUBST -} t (Reft (x, ra)) ))
-     <|> ((RHole . uTop . Reft . ("VV",)) <$> rp)
+              return $ {- substa su $ NOSUBST -} t (Reft (x, ra)) )
+     <|> (RHole . uTop . Reft . ("VV",) <$> rp)
      <?> "refBindBindP"
    )
 
@@ -418,8 +413,8 @@
         -> Parser Expr
         -> Parser (Reft -> BareType)
         -> Parser BareType
-refDefP vv rp kindP' = braces $ do
-  x       <- optBindP vv
+refDefP sym rp kindP' = braces $ do
+  x       <- optBindP sym
   -- NOSUBST i       <- freshIntP
   t       <- try (kindP' <* reservedOp "|") <|> return (RHole . uTop) <?> "refDefP"
   ra      <- rp
@@ -434,6 +429,12 @@
 refP :: Parser (Reft -> BareType) -> Parser BareType
 refP = refBindBindP refaP
 
+relrefaP :: Parser RelExpr 
+relrefaP =
+  try (ERUnChecked <$> refaP <* reserved ":=>" <*> relrefaP)
+    <|> try (ERChecked <$> refaP <* reserved "!=>" <*> relrefaP)
+    <|> ERBasic <$> refaP
+
 -- "sym :" or return the devault sym
 optBindP :: Symbol -> Parser Symbol
 optBindP x = try bindP <|> return x
@@ -469,21 +470,21 @@
      lowerIdTail l
 
 maybeBind :: Parser a -> Parser (Maybe Symbol, a)
-maybeBind p = do {bd <- maybeP' bbindP; ty <- p ; return (bd, ty)}
+maybeBind parser = do {bd <- maybeP' bbindP; ty <- parser ; return (bd, ty)}
   where
     maybeP' p = try (Just <$> p)
              <|> return Nothing
 
 lowerIdTail :: Symbol -> Parser (Reft -> BareType)
 lowerIdTail l =
-     (    (liftM2 bAppTy (return $ bTyVar l) (some bareTyArgP))
-      <|> (liftM2 bRVar  (return $ bTyVar l) monoPredicateP))
+          fmap (bAppTy (bTyVar l)) (some bareTyArgP)
+      <|> fmap (bRVar (bTyVar l)) monoPredicateP
 
 bTyConP :: Parser BTyCon
 bTyConP
   =  (reservedOp "'" >> (mkPromotedBTyCon <$> locUpperIdP))
  <|> mkBTyCon <$> locUpperIdP
- <|> (reserved "*" >> (return $ mkBTyCon (dummyLoc $ symbol ("*" :: String))))
+ <|> (reserved "*" >> return (mkBTyCon (dummyLoc $ symbol ("*" :: String))))
  <?> "bTyConP"
 
 mkPromotedBTyCon :: LocSymbol -> BTyCon
@@ -515,7 +516,7 @@
 bareAtomNoAppP :: Parser BareType
 bareAtomNoAppP
   =  refP bbaseNoAppP
- <|> (dummyP bbaseNoAppP)
+ <|> dummyP bbaseNoAppP
  <?> "bareAtomNoAppP"
 
 
@@ -524,13 +525,12 @@
   = do xts <- constraintEnvP
        t1  <- bareTypeP
        reservedOp "<:"
-       t2  <- bareTypeP
-       return $ fromRTypeRep $ RTypeRep [] [] []
+       fromRTypeRep . RTypeRep [] [] []
                                         [] [] []
                                         ((val . fst <$> xts) ++ [dummySymbol])
                                         (replicate (length xts + 1) defRFInfo)
                                         (replicate (length xts + 1) mempty)
-                                        ((snd <$> xts) ++ [t1]) t2
+                                        ((snd <$> xts) ++ [t1]) <$> bareTypeP
 
 constraintEnvP :: Parser [(LocSymbol, BareType)]
 constraintEnvP
@@ -552,37 +552,43 @@
 --  "forall x y <z :: Nat, w :: Int> . TYPE"
 bareAllP :: Parser BareType
 bareAllP = do
-  as <- tyVarDefsP
-  ps <- angles inAngles
-        <|> (return [])
-  dot
+  sp <- getSourcePos
+  as  <- tyVarDefsP
+  ps  <- angles inAngles
+        <|> return []
+  _ <- dot
   t <- bareTypeP
-  return $ foldr rAllT (foldr RAllP t ps) (makeRTVar <$> as)
+  return $ foldr rAllT (foldr (rAllP sp) t ps) (makeRTVar <$> as)
   where
     rAllT a t = RAllT a t mempty
-    inAngles =
-      (
-       (try  (sepBy  predVarDefP comma))
-       )
+    inAngles  = try  (sepBy  predVarDefP comma)
 
+-- See #1907 for why we have to alpha-rename pvar binders
+rAllP :: SourcePos -> PVar BSort -> BareType -> BareType
+rAllP sp p t = RAllP p' ({- F.tracepp "rAllP" $ -} substPVar p p' t)
+  where
+    p'  = p { pname = pn' }
+    pn' = pname p `intSymbol` lin `intSymbol` col
+    lin = unPos (sourceLine sp)
+    col = unPos (sourceColumn  sp)
+
 tyVarDefsP :: Parser [BTyVar]
 tyVarDefsP
-  = (parens $ many (bTyVar <$> tyKindVarIdP))
+  = parens (many (bTyVar <$> tyKindVarIdP))
  <|> many (bTyVar <$> tyVarIdP)
  <?> "tyVarDefsP"
 
 tyKindVarIdP :: Parser Symbol
 tyKindVarIdP = do
    tv <- tyVarIdP
-   (  (do reservedOp "::"; _ <- kindP; return tv)
-    <|> return tv)
+   do reservedOp "::"; _ <- kindP; return tv <|> return tv
 
 kindP :: Parser BareType
 kindP = bareAtomBindP
 
 predVarDefsP :: Parser [PVar BSort]
 predVarDefsP
-  =  (angles $ sepBy1 predVarDefP comma)
+  =  angles (sepBy1 predVarDefP comma)
  <|> return []
  <?> "predVarDefP"
 
@@ -598,7 +604,7 @@
 bPVar p _ xts  = PV p (PVProp τ) dummySymbol τxs
   where
     (_, τ) = safeLast "bPVar last" xts
-    τxs    = [ (τ, x, EVar x) | (x, τ) <- init xts ]
+    τxs    = [ (τ', x, EVar x) | (x, τ') <- init xts ]
     safeLast _ xs@(_:_) = last xs
     safeLast msg _      = panic Nothing $ "safeLast with empty list " ++ msg
 
@@ -606,16 +612,16 @@
 propositionSortP = map (Misc.mapSnd toRSort) <$> propositionTypeP
 
 propositionTypeP :: Parser [(Symbol, BareType)]
-propositionTypeP = either fail return =<< (mkPropositionType <$> bareTypeP)
+propositionTypeP = either fail return . mkPropositionType =<< bareTypeP
 
 mkPropositionType :: BareType -> Either String [(Symbol, BareType)]
 mkPropositionType t
   | isOk      = Right $ zip (ty_binds tRep) (ty_args tRep)
-  | otherwise = Left err
+  | otherwise = Left mkErr
   where
     isOk      = isPropBareType (ty_res tRep)
     tRep      = toRTypeRep t
-    err       = "Proposition type with non-Bool output: " ++ showpp t
+    mkErr     = "Proposition type with non-Bool output: " ++ showpp t
 
 xyP :: Parser x -> Parser a -> Parser y -> Parser (x, y)
 xyP lP sepP rP =
@@ -661,7 +667,7 @@
 predicatesP :: (IsString tv, Monoid r)
             => Parser [Ref (RType c tv r) BareType]
 predicatesP
-   =  (angles $ sepBy1 predicate1P comma)
+   =  angles (sepBy1 predicate1P comma)
   <|> return []
   <?> "predicatesP"
 
@@ -670,7 +676,7 @@
 predicate1P
    =  try (RProp <$> symsP <*> refP bbaseP)
   <|> (rPropP [] . predUReft <$> monoPredicate1P)
-  <|> (braces $ bRProp <$> symsP' <*> refaP)
+  <|> braces (bRProp <$> symsP' <*> refaP)
   <?> "predicate1P"
    where
     symsP'       = do ss    <- symsP
@@ -697,8 +703,7 @@
   <|> (pdVar <$>        predVarUseP)
   <?> "monoPredicate1P"
 
-predVarUseP :: IsString t
-            => Parser (PVar t)
+predVarUseP :: Parser (PVar String)
 predVarUseP
   = do (p, xs) <- funArgsP
        return   $ PV p (PVProp dummyTyId) dummySymbol [ (dummyTyId, dummySymbol, x) | x <- xs ]
@@ -714,11 +719,10 @@
 boundP = do
   name   <- locUpperIdP
   reservedOp "="
-  vs     <- bvsP
-  params <- many (parens tyBindP)
-  args   <- bargsP
-  body   <- predP
-  return $ Bound name vs params args body
+  vs      <- bvsP
+  params' <- many (parens tyBindP)
+  args    <- bargsP
+  Bound name vs params' args <$> predP
  where
     bargsP =     ( do reservedOp "\\"
                       xs <- many (parens tyBindP)
@@ -762,12 +766,12 @@
 bRProp :: [((Symbol, τ), Symbol)]
        -> Expr -> Ref τ (RType c BTyVar (UReft Reft))
 bRProp []    _    = panic Nothing "Parse.bRProp empty list"
-bRProp syms' expr = RProp ss $ bRVar (BTV dummyName) mempty r
+bRProp syms' epr  = RProp ss $ bRVar (BTV dummyName) mempty r
   where
-    (ss, (v, _))  = (init syms, last syms)
-    syms          = [(y, s) | ((_, s), y) <- syms']
+    (ss, (v, _))  = (init symsf, last symsf)
+    symsf         = [(y, s) | ((_, s), y) <- syms']
     su            = mkSubst [(x, EVar y) | ((x, _), y) <- syms']
-    r             = su `subst` Reft (v, expr)
+    r             = su `subst` Reft (v, epr)
 
 bRVar :: tv -> Predicate -> r -> RType c tv (UReft r)
 bRVar α p r = RVar α (MkUReft r p)
@@ -776,8 +780,8 @@
      -> [RTProp BTyCon tv (UReft r)]
      -> r
      -> RType BTyCon tv (UReft r)
-bLst (Just t) rs r        = RApp (mkBTyCon $ dummyLoc listConName) [t] rs (reftUReft r)
-bLst (Nothing) rs r       = RApp (mkBTyCon $ dummyLoc listConName) []  rs (reftUReft r)
+bLst (Just t) rs r = RApp (mkBTyCon $ dummyLoc listConName) [t] rs (reftUReft r)
+bLst Nothing  rs r = RApp (mkBTyCon $ dummyLoc listConName) []  rs (reftUReft r)
 
 bTup :: (PPrint r, Reftable r, Reftable (RType BTyCon BTyVar (UReft r)), Reftable (RTProp BTyCon BTyVar (UReft r)))
      => [(Maybe Symbol, RType BTyCon BTyVar (UReft r))]
@@ -786,12 +790,12 @@
      -> RType BTyCon BTyVar (UReft r)
 bTup [(_,t)] _ r
   | isTauto r  = t
-  | otherwise  = t `strengthen` (reftUReft r)
+  | otherwise  = t `strengthen` reftUReft r
 bTup ts rs r
   | all Mb.isNothing (fst <$> ts) || length ts < 2
   = RApp (mkBTyCon $ dummyLoc tupConName) (snd <$> ts) rs (reftUReft r)
   | otherwise
-  = RApp (mkBTyCon $ dummyLoc tupConName) ((top . snd) <$> ts) rs' (reftUReft r)
+  = RApp (mkBTyCon $ dummyLoc tupConName) (top . snd <$> ts) rs' (reftUReft r)
   where
     args       = [(Mb.fromMaybe dummySymbol x, mapReft mempty t) | (x,t) <- ts]
     makeProp i = RProp (take i args) ((snd <$> ts)!!i)
@@ -844,6 +848,8 @@
   | Impt    Symbol                                        -- ^ 'import' a specification module
   | DDecl   DataDecl                                      -- ^ refined 'data'    declaration 
   | NTDecl  DataDecl                                      -- ^ refined 'newtype' declaration
+  | Relational (LocSymbol, LocSymbol, ty, ty, RelExpr, RelExpr) -- ^ relational signature
+  | AssmRel (LocSymbol, LocSymbol, ty, ty, RelExpr, RelExpr) -- ^ 'assume' relational signature
   | Class   (RClass ty)                                   -- ^ refined 'class' definition
   | CLaws   (RClass ty)                                   -- ^ 'class laws' definition
   | ILaws   (RILaws ty)
@@ -873,95 +879,96 @@
   | CMeas   (Measure ty ())                               -- ^ 'class measure' definition
   | IMeas   (Measure ty ctor)                             -- ^ 'instance measure' definition
   | Varia   (LocSymbol, [Variance])                       -- ^ 'variance' annotations, marking type constructor params as co-, contra-, or in-variant
+  | DSize   ([ty], LocSymbol)                             -- ^ 'data size' annotations, generating fancy termination metric 
   | BFix    ()                                            -- ^ fixity annotation
   | Define  (LocSymbol, Symbol)                           -- ^ 'define' annotation for specifying aliases c.f. `include-CoreToLogic.lg`
   deriving (Data, Show, Typeable)
 
-instance (PPrint ty, PPrint ctor) => PPrint (Pspec ty ctor) where 
-  pprintTidy = ppPspec 
+instance (PPrint ty, PPrint ctor) => PPrint (Pspec ty ctor) where
+  pprintTidy = ppPspec
 
 splice :: PJ.Doc -> [PJ.Doc] -> PJ.Doc
 splice sep = PJ.hcat . PJ.punctuate sep
 
 ppAsserts :: (PPrint t) => Tidy -> [LocSymbol] -> t -> Maybe [Located Expr] -> PJ.Doc
-ppAsserts k lxs t les 
+ppAsserts k lxs t mles
   = PJ.hcat [ splice ", " (pprintTidy k <$> (val <$> lxs))
-            , " :: " 
-            , pprintTidy k t   
-            , ppLes les 
+            , " :: "
+            , pprintTidy k t
+            , ppLes mles
             ]
-  where 
+  where
     ppLes Nothing    = ""
     ppLes (Just les) = "/" <+> pprintTidy k (val <$> les)
 
 ppPspec :: (PPrint t, PPrint c) => Tidy -> Pspec t c -> PJ.Doc
-ppPspec k (Meas m)        
-  = "measure" <+> pprintTidy k m 
-ppPspec k (Assm (lx, t))  
-  = "assume"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t 
-ppPspec k (Asrt (lx, t))  
-  = "assert"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t 
-ppPspec k (LAsrt (lx, t)) 
-  = "local assert"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t 
-ppPspec k (Asrts (lxs, (t, les))) 
+ppPspec k (Meas m)
+  = "measure" <+> pprintTidy k m
+ppPspec k (Assm (lx, t))
+  = "assume"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t
+ppPspec k (Asrt (lx, t))
+  = "assert"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t
+ppPspec k (LAsrt (lx, t))
+  = "local assert"  <+> pprintTidy k (val lx) <+> "::" <+> pprintTidy k t
+ppPspec k (Asrts (lxs, (t, les)))
   = ppAsserts k lxs t les
-ppPspec k (Impt  x) 
-  = "import" <+> pprintTidy k x 
-ppPspec k (DDecl d) 
-  = pprintTidy k d 
-ppPspec k (NTDecl d) 
-  = "newtype" <+> pprintTidy k d 
-ppPspec _ (Incl f) 
+ppPspec k (Impt  x)
+  = "import" <+> pprintTidy k x
+ppPspec k (DDecl d)
+  = pprintTidy k d
+ppPspec k (NTDecl d)
+  = "newtype" <+> pprintTidy k d
+ppPspec _ (Incl f)
   = "include" <+> "<" PJ.<> PJ.text f PJ.<> ">"
 ppPspec k (Invt t)
-  = "invariant" <+> pprintTidy k t 
-ppPspec k (Using (t1, t2)) 
+  = "invariant" <+> pprintTidy k t
+ppPspec k (Using (t1, t2))
   = "using" <+> pprintTidy k t1 <+> "as" <+> pprintTidy k t2
-ppPspec k (Alias   (Loc _ _ rta)) 
-  = "type" <+> pprintTidy k rta 
-ppPspec k (EAlias  (Loc _ _ rte)) 
-  = "predicate" <+> pprintTidy k rte 
-ppPspec k (Embed   (lx, tc, NoArgs)) 
-  = "embed" <+> pprintTidy k (val lx)         <+> "as" <+> pprintTidy k tc 
-ppPspec k (Embed   (lx, tc, WithArgs)) 
-  = "embed" <+> pprintTidy k (val lx) <+> "*" <+> "as" <+> pprintTidy k tc 
-ppPspec k (Qualif  q)              
-  = pprintTidy k q 
-ppPspec k (Decr (lx, ns))        
+ppPspec k (Alias   (Loc _ _ rta))
+  = "type" <+> pprintTidy k rta
+ppPspec k (EAlias  (Loc _ _ rte))
+  = "predicate" <+> pprintTidy k rte
+ppPspec k (Embed   (lx, tc, NoArgs))
+  = "embed" <+> pprintTidy k (val lx)         <+> "as" <+> pprintTidy k tc
+ppPspec k (Embed   (lx, tc, WithArgs))
+  = "embed" <+> pprintTidy k (val lx) <+> "*" <+> "as" <+> pprintTidy k tc
+ppPspec k (Qualif  q)
+  = pprintTidy k q
+ppPspec k (Decr (lx, ns))
   = "decreasing" <+> pprintTidy k (val lx) <+> pprintTidy k ns
-ppPspec k (LVars   lx) 
-  = "lazyvar" <+> pprintTidy k (val lx) 
-ppPspec k (Lazy   lx) 
-  = "lazy" <+> pprintTidy k (val lx) 
-ppPspec k (Rewrite   lx) 
-  = "rewrite" <+> pprintTidy k (val lx) 
-ppPspec k (Rewritewith (lx, lxs)) 
-  = "rewriteWith" <+> pprintTidy k (val lx) <+> (PJ.hsep $ map go lxs)
+ppPspec k (LVars   lx)
+  = "lazyvar" <+> pprintTidy k (val lx)
+ppPspec k (Lazy   lx)
+  = "lazy" <+> pprintTidy k (val lx)
+ppPspec k (Rewrite   lx)
+  = "rewrite" <+> pprintTidy k (val lx)
+ppPspec k (Rewritewith (lx, lxs))
+  = "rewriteWith" <+> pprintTidy k (val lx) <+> PJ.hsep (map go lxs)
   where
     go s = pprintTidy k $ val s
-ppPspec k (Fail   lx) 
-  = "fail" <+> pprintTidy k (val lx) 
-ppPspec k (Insts   (lx, mbN)) 
-  = "automatic-instances" <+> pprintTidy k (val lx) <+> maybe "" (("with" <+>) . pprintTidy k) mbN 
-ppPspec k (HMeas   lx) 
-  = "measure" <+> pprintTidy k (val lx) 
-ppPspec k (Reflect lx) 
-  = "reflect" <+> pprintTidy k (val lx) 
-ppPspec k (Inline  lx) 
-  = "inline" <+> pprintTidy k (val lx) 
-ppPspec k (Ignore  lx) 
-  = "ignore" <+> pprintTidy k (val lx) 
-ppPspec k (HBound  lx) 
-  = "bound" <+> pprintTidy k (val lx) 
-ppPspec k (ASize   lx) 
-  = "autosize" <+> pprintTidy k (val lx) 
-ppPspec k (PBound  bnd) 
-  = pprintTidy k bnd 
-ppPspec _ (Pragma  (Loc _ _ s)) 
-  = "LIQUID" <+> PJ.text s 
-ppPspec k (CMeas   m) 
+ppPspec k (Fail   lx)
+  = "fail" <+> pprintTidy k (val lx)
+ppPspec k (Insts   (lx, mbN))
+  = "automatic-instances" <+> pprintTidy k (val lx) <+> maybe "" (("with" <+>) . pprintTidy k) mbN
+ppPspec k (HMeas   lx)
+  = "measure" <+> pprintTidy k (val lx)
+ppPspec k (Reflect lx)
+  = "reflect" <+> pprintTidy k (val lx)
+ppPspec k (Inline  lx)
+  = "inline" <+> pprintTidy k (val lx)
+ppPspec k (Ignore  lx)
+  = "ignore" <+> pprintTidy k (val lx)
+ppPspec k (HBound  lx)
+  = "bound" <+> pprintTidy k (val lx)
+ppPspec k (ASize   lx)
+  = "autosize" <+> pprintTidy k (val lx)
+ppPspec k (PBound  bnd)
+  = pprintTidy k bnd
+ppPspec _ (Pragma  (Loc _ _ s))
+  = "LIQUID" <+> PJ.text s
+ppPspec k (CMeas   m)
   = "class measure" <+> pprintTidy k m
-ppPspec k (IMeas   m) 
+ppPspec k (IMeas   m)
   = "instance  measure" <+> pprintTidy k m
 ppPspec k (Class   cls) 
   = pprintTidy k cls 
@@ -971,12 +978,24 @@
   = pprintTidy k inst 
 ppPspec k (Varia   (lx, vs))  
   = "data variance" <+> pprintTidy k (val lx) <+> splice " " (pprintTidy k <$> vs) 
+ppPspec k (DSize   (ds, ss))  
+  = "data size" <+> splice " " (pprintTidy k <$> ds) <+> pprintTidy k (val ss) 
 ppPspec _ (BFix    _)           -- 
   = "fixity"
-ppPspec k (Define  (lx, y))     
-  = "define" <+> pprintTidy k (val lx) <+> "=" <+> pprintTidy k y 
-ppPspec _ (ILaws {}) 
+ppPspec k (Define  (lx, y))
+  = "define" <+> pprintTidy k (val lx) <+> "=" <+> pprintTidy k y
+ppPspec _ ILaws{}
   = "TBD-INSTANCE-LAWS"
+ppPspec k (Relational (lxl, lxr, tl, tr, q, p))
+  = "relational" 
+        <+> pprintTidy k (val lxl) <+> "::" <+> pprintTidy k tl <+> "~" 
+        <+> pprintTidy k (val lxr) <+> "::" <+> pprintTidy k tr <+> "|" 
+        <+> pprintTidy k q <+> "=>" <+> pprintTidy k p
+ppPspec k (AssmRel (lxl, lxr, tl, tr, q, p))
+  = "assume relational" 
+        <+> pprintTidy k (val lxl) <+> "::" <+> pprintTidy k tl <+> "~" 
+        <+> pprintTidy k (val lxr) <+> "::" <+> pprintTidy k tr <+> "|" 
+        <+> pprintTidy k q <+> "=>" <+> pprintTidy k p
 
 
 -- | For debugging
@@ -1048,7 +1067,7 @@
   , Measure.localSigs  = []
   , Measure.reflSigs   = []
   , Measure.impSigs    = []
-  , Measure.expSigs    = [] 
+  , Measure.expSigs    = []
   , Measure.invariants = [(Nothing, t) | Invt   t <- xs]
   , Measure.ialiases   = [t | Using t <- xs]
   , Measure.imports    = [i | Impt   i <- xs]
@@ -1066,8 +1085,11 @@
   , Measure.cmeasures  = [m | CMeas  m <- xs]
   , Measure.imeasures  = [m | IMeas  m <- xs]
   , Measure.classes    = [c | Class  c <- xs]
+  , Measure.relational = [r | Relational r <- xs]
+  , Measure.asmRel     = [r | AssmRel r <- xs]
   , Measure.claws      = [c | CLaws  c <- xs]
   , Measure.dvariance  = [v | Varia  v <- xs]
+  , Measure.dsize      = [v | DSize  v <- xs]
   , Measure.rinstance  = [i | RInst  i <- xs]
   , Measure.ilaws      = [i | ILaws  i <- xs]
   , Measure.termexprs  = [(y, es) | Asrts (ys, (_, Just es)) <- xs, y <- ys]
@@ -1089,65 +1111,68 @@
 -- | Parse a single top level liquid specification
 specP :: Parser BPspec
 specP
-  =     (fallbackSpecP "assume"     (liftM Assm    tyBindP  ))
-    <|> (fallbackSpecP "assert"     (liftM Asrt    tyBindP  ))
-    <|> (fallbackSpecP "autosize"   (liftM ASize   asizeP   ))
-    <|> (reserved "local"         >> liftM LAsrt   tyBindP  )
+  =     fallbackSpecP "assume"      
+    ((reserved "relational" >>  fmap AssmRel relationalP)
+        <|>                           fmap Assm   tyBindP  )
+    <|> fallbackSpecP "assert"      (fmap Asrt    tyBindP  )
+    <|> fallbackSpecP "autosize"    (fmap ASize   asizeP   )
+    <|> (reserved "local"         >> fmap LAsrt   tyBindP  )
 
     -- TODO: These next two are synonyms, kill one
-    <|> (fallbackSpecP "axiomatize" (liftM Reflect axiomP   ))
-    <|> (fallbackSpecP "reflect"    (liftM Reflect axiomP   ))
+    <|> fallbackSpecP "axiomatize"  (fmap Reflect axiomP   )
+    <|> fallbackSpecP "reflect"     (fmap Reflect axiomP   )
 
-    <|> (fallbackSpecP "measure"    hmeasureP)
+    <|> fallbackSpecP "measure"    hmeasureP
 
-    <|> (fallbackSpecP "define"     (liftM Define  defineP  ))
-    <|> (reserved "infixl"        >> liftM BFix    infixlP  )
-    <|> (reserved "infixr"        >> liftM BFix    infixrP  )
-    <|> (reserved "infix"         >> liftM BFix    infixP   )
-    <|> (fallbackSpecP "inline"     (liftM Inline  inlineP  ))
-    <|> (fallbackSpecP "ignore"     (liftM Ignore  inlineP  ))
+    <|> fallbackSpecP "define"      (fmap Define  defineP  )
+    <|> (reserved "infixl"        >> fmap BFix    infixlP  )
+    <|> (reserved "infixr"        >> fmap BFix    infixrP  )
+    <|> (reserved "infix"         >> fmap BFix    infixP   )
+    <|> fallbackSpecP "inline"      (fmap Inline  inlineP  )
+    <|> fallbackSpecP "ignore"      (fmap Ignore  inlineP  )
 
-    <|> (fallbackSpecP "bound"    (((liftM PBound  boundP   )
-                                <|> (liftM HBound  hboundP  ))))
+    <|> fallbackSpecP "bound"       (fmap PBound  boundP
+                                 <|> fmap HBound  hboundP  )
     <|> (reserved "class"
-         >> ((reserved "measure"  >> liftM CMeas  cMeasureP )
-         <|> (reserved "laws"     >> liftM CLaws  classP)
-         <|> liftM Class  classP                            ))
+         >> ((reserved "measure"  >> fmap CMeas  cMeasureP )
+         <|> (reserved "laws"     >> fmap CLaws  classP)
+         <|> fmap Class  classP                            ))
     <|> (reserved "instance"
-         >> ((reserved "measure"  >> liftM IMeas  iMeasureP )
-         <|> (reserved "laws"     >> liftM ILaws instanceLawP)
-         <|> liftM RInst  instanceP ))
+         >> ((reserved "measure"  >> fmap IMeas  iMeasureP )
+         <|> (reserved "laws"     >> fmap ILaws instanceLawP)
+         <|> fmap RInst  instanceP ))
 
-    <|> (reserved "import"        >> liftM Impt   symbolP   )
+    <|> (reserved "import"        >> fmap Impt   symbolP   )
 
     <|> (reserved "data"
-        >> ((reserved "variance"  >> liftM Varia  datavarianceP)
-                                 <|> liftM DDecl  dataDeclP ))
-
-    <|> (reserved "newtype"       >> liftM NTDecl dataDeclP )
-    <|> (reserved "include"       >> liftM Incl   filePathP )
-    <|> (fallbackSpecP "invariant"  (liftM Invt   invariantP))
-    <|> (reserved "using"         >> liftM Using invaliasP )
-    <|> (reserved "type"          >> liftM Alias  aliasP    )
+        >> ((reserved "variance"  >> fmap Varia  datavarianceP)
+        <|> (reserved "size"      >> fmap DSize  dsizeP)
+        <|> fmap DDecl  dataDeclP ))
+    <|> (reserved "newtype"       >> fmap NTDecl dataDeclP )
+    <|> (reserved "relational"    >> fmap Relational relationalP )
+    <|> (reserved "include"       >> fmap Incl   filePathP )
+    <|> fallbackSpecP "invariant"   (fmap Invt   invariantP)
+    <|> (reserved "using"          >> fmap Using invaliasP )
+    <|> (reserved "type"          >> fmap Alias  aliasP    )
 
     -- TODO: Next two are basically synonyms
-    <|> (fallbackSpecP "predicate"  (liftM EAlias ealiasP   ))
-    <|> (fallbackSpecP "expression" (liftM EAlias ealiasP   ))
+    <|> fallbackSpecP "predicate"   (fmap EAlias ealiasP   )
+    <|> fallbackSpecP "expression"  (fmap EAlias ealiasP   )
 
-    <|> (fallbackSpecP "embed"      (liftM Embed  embedP    ))
-    <|> (fallbackSpecP "qualif"     (liftM Qualif (qualifierP sortP)))
-    <|> (reserved "decrease"      >> liftM Decr   decreaseP )
-    <|> (reserved "lazyvar"       >> liftM LVars  lazyVarP  )
+    <|> fallbackSpecP "embed"       (fmap Embed  embedP    )
+    <|> fallbackSpecP "qualif"      (fmap Qualif (qualifierP sortP))
+    <|> (reserved "decrease"      >> fmap Decr   decreaseP )
+    <|> (reserved "lazyvar"       >> fmap LVars  lazyVarP  )
 
-    <|> (reserved "lazy"          >> liftM Lazy   lazyVarP  )
-    <|> (reserved "rewrite"       >> liftM Rewrite   rewriteVarP )
-    <|> (reserved "rewriteWith"   >> liftM Rewritewith   rewriteWithP )
-    <|> (reserved "fail"          >> liftM Fail   failVarP  )
-    <|> (reserved "ple"           >> liftM Insts autoinstP  )
-    <|> (reserved "automatic-instances" >> liftM Insts autoinstP  )
-    <|> (reserved "LIQUID"        >> liftM Pragma pragmaP   )
-    <|> (reserved "liquid"        >> liftM Pragma pragmaP   )
-    <|> {- DEFAULT -}                liftM Asrts  tyBindsP
+    <|> (reserved "lazy"          >> fmap Lazy   lazyVarP  )
+    <|> (reserved "rewrite"       >> fmap Rewrite   rewriteVarP )
+    <|> (reserved "rewriteWith"   >> fmap Rewritewith   rewriteWithP )
+    <|> (reserved "fail"          >> fmap Fail   failVarP  )
+    <|> (reserved "ple"           >> fmap Insts autoinstP  )
+    <|> (reserved "automatic-instances" >> fmap Insts autoinstP  )
+    <|> (reserved "LIQUID"        >> fmap Pragma pragmaP   )
+    <|> (reserved "liquid"        >> fmap Pragma pragmaP   )
+    <|> {- DEFAULT -}                fmap Asrts  tyBindsP
     <?> "specP"
 
 -- | Try the given parser on the tail after matching the reserved word, and if
@@ -1156,7 +1181,7 @@
 fallbackSpecP :: String -> Parser BPspec -> Parser BPspec
 fallbackSpecP kw p = do
   (Loc l1 l2 _) <- locReserved kw
-  (p <|> liftM Asrts (tyBindsRemP (Loc l1 l2 (symbol kw)) ))
+  p <|> fmap Asrts (tyBindsRemP (Loc l1 l2 (symbol kw)) )
 
 -- | Same as tyBindsP, except the single initial symbol has already been matched
 tyBindsRemP :: LocSymbol -> Parser ([LocSymbol], (Located BareType, Maybe [Located Expr]))
@@ -1215,6 +1240,10 @@
 datavarianceP :: Parser (Located Symbol, [Variance])
 datavarianceP = liftM2 (,) locUpperIdP (many varianceP)
 
+dsizeP :: Parser ([Located BareType], Located Symbol)
+dsizeP = liftM2 (,) (parens $ sepBy (located genBareTypeP) comma) locBinderP
+
+
 varianceP :: Parser Variance
 varianceP = (reserved "bivariant"     >> return Bivariant)
         <|> (reserved "invariant"     >> return Invariant)
@@ -1237,8 +1266,7 @@
 termBareTypeP :: Parser (Located BareType, Maybe [Located Expr])
 termBareTypeP = do
   t <- located genBareTypeP
-  (termTypeP t
-    <|> return (t, Nothing))
+  termTypeP t <|> return (t, Nothing)
 
 termTypeP :: Located BareType ->Parser (Located BareType, Maybe [Located Expr])
 termTypeP t
@@ -1296,18 +1324,17 @@
 hmeasureP = do
   setLayout
   b <- locBinderP
-  ((do reservedOp "::"
-       ty <- located genBareTypeP
-       popLayout >> popLayout
-       eqns <- block $ try $ measureDefP (rawBodyP <|> tyBodyP ty)
-       return (Meas $ Measure.mkM b ty eqns MsMeasure mempty))
+  (do reservedOp "::"
+      ty <- located genBareTypeP
+      popLayout >> popLayout
+      eqns <- block $ try $ measureDefP (rawBodyP <|> tyBodyP ty)
+      return (Meas $ Measure.mkM b ty eqns MsMeasure mempty))
     <|> (popLayout >> popLayout >> return (HMeas b))
-    )
 
 measureP :: Parser (Measure (Located BareType) LocSymbol)
 measureP = do
   (x, ty) <- indentedLine tyBindP
-  optional semi
+  _ <- optional semi
   eqns    <- block $ measureDefP (rawBodyP <|> tyBodyP ty)
   return   $ Measure.mkM x ty eqns MsMeasure mempty
 
@@ -1330,6 +1357,11 @@
                <|> ((:) <$> (fmap bTyVar <$> locLowerIdP) <*> classParams)
     sing x      = [x]
 
+
+superP :: Parser (Located BareType)
+superP = located (toRCls <$> bareAtomBindP)
+  where toRCls x = x
+
 instanceLawP :: Parser (RILaws (Located BareType))
 instanceLawP
   = do l1   <- getSourcePos
@@ -1340,11 +1372,9 @@
        l2   <- getSourcePos
        return $ RIL c sups tvs ms (Loc l1 l2 ())
   where
-    superP   = located (toRCls <$> bareAtomBindP)
-    supersP  = try (((parens (superP `sepBy1` comma)) <|> fmap pure superP)
+    supersP  = try ((parens (superP `sepBy1` comma) <|> fmap pure superP)
                        <* reservedOp "=>")
                <|> return []
-    toRCls x = x
 
     eqBinderP = xyP xP (reservedOp "=") xP
 
@@ -1354,18 +1384,16 @@
 instanceP
   = do _    <- supersP
        c    <- classBTyConP
-       tvs  <- (try oneClassArg) <|> (manyTill iargsP (try $ reserved "where"))
+       tvs  <- try oneClassArg <|> manyTill iargsP (try $ reserved "where")
        ms   <- block riMethodSigP
        return $ RI c tvs ms
   where
-    superP   = located (toRCls <$> bareAtomBindP)
-    supersP  = try (((parens (superP `sepBy1` comma)) <|> fmap pure superP)
+    supersP  = try ((parens (superP `sepBy1` comma) <|> fmap pure superP)
                        <* reservedOp "=>")
                <|> return []
-    toRCls x = x
 
     iargsP   =   (mkVar . bTyVar <$> tyVarIdP)
-            <|> (parens $ located $ bareTypeP)
+            <|> parens (located bareTypeP)
 
 
     mkVar v  = dummyLoc $ RVar v mempty
@@ -1388,19 +1416,16 @@
        ms   <- block tyBindP -- <|> sepBy tyBindP semi
        return $ RClass c sups tvs ms
   where
-    superP   = located (toRCls <$> bareAtomBindP)
-    supersP  = try (((parens (superP `sepBy1` comma)) <|> fmap pure superP)
+    supersP  = try ((parens (superP `sepBy1` comma) <|> fmap pure superP)
                        <* reservedOp "=>")
                <|> return []
-    toRCls x = x
 
 rawBodyP :: Parser Body
 rawBodyP
   = braces $ do
       v <- symbolP
       reservedOp "|"
-      p <- predP
-      return $ R v p
+      R v <$> predP
 
 tyBodyP :: Located BareType -> Parser Body
 tyBodyP ty
@@ -1437,7 +1462,7 @@
 -}
 binderP :: Parser Symbol
 binderP =
-      (symbol . (\ x -> "(" <> x <> ")") . symbolText) <$> parens (infixBinderIdP)
+      symbol . (\ x -> "(" <> x <> ")") . symbolText <$> parens infixBinderIdP
   <|> binderIdP
   -- Note: It is important that we do *not* use the LH/fixpoint reserved words here,
   -- because, for example, we must be able to use "assert" as an identifier.
@@ -1451,7 +1476,7 @@
        (c, xs) <- measurePatP
        reservedOp "="
        body    <- bodyP
-       let xs'  = (symbol . val) <$> xs
+       let xs'  = symbol . val <$> xs
        return   $ Def mname (symbol <$> c) Nothing ((, Nothing) <$> xs') body
 
 measurePatP :: Parser (LocSymbol, [LocSymbol])
@@ -1530,9 +1555,9 @@
   return $ DataCtor x (tRepVars as tr) [] (tRepFields tr) (Just $ ty_res tr)
 
 tRepVars :: Symbolic a => [Symbol] -> RTypeRep c a r -> [Symbol]
-tRepVars as tr = case fst <$> ty_vars tr of 
-  [] -> as 
-  vs -> symbol . ty_var_value <$> vs 
+tRepVars as tr = case fst <$> ty_vars tr of
+  [] -> as
+  vs -> symbol . ty_var_value <$> vs
 
 tRepFields :: RTypeRep c tv r -> [(Symbol, RType c tv r)]
 tRepFields tr = zip (ty_binds tr) (ty_args tr)
@@ -1555,12 +1580,27 @@
   = brackets (Just . SymSizeFun <$> locLowerIdP)
   <|> return Nothing
 
+relationalP :: Parser (LocSymbol, LocSymbol, LocBareType, LocBareType, RelExpr, RelExpr)
+relationalP = do 
+   x <- locBinderP
+   reserved "~"
+   y <- locBinderP
+   reserved "::"
+   braces $ do 
+    tx <- located genBareTypeP
+    reserved "~"
+    ty <- located genBareTypeP
+    reserved "|"
+    assm <- try (relrefaP <* reserved "|-") <|> return (ERBasic PTrue)
+    ex <- relrefaP
+    return (x,y,tx,ty,assm,ex)
+
 dataDeclP :: Parser DataDecl
 dataDeclP = do
   pos <- getSourcePos
   x   <- locUpperOrInfixIdP
   fsize <- dataSizeP
-  (dataDeclBodyP pos x fsize <|> return (emptyDecl x pos fsize))
+  dataDeclBodyP pos x fsize <|> return (emptyDecl x pos fsize)
 
 emptyDecl :: LocSymbol -> SourcePos -> Maybe SizeFun -> DataDecl
 emptyDecl x pos fsize@(Just _)
@@ -1596,7 +1636,7 @@
 dataCtorsP as = do
   (pTy, dcs) <-     (reservedOp "="     >> ((Nothing, ) <$>                 sepBy (dataConP    as) (reservedOp "|")))
                 <|> (reserved   "where" >> ((Nothing, ) <$>                 block (adtDataConP as)                 ))
-                <|> (                      ((,)         <$> dataPropTyP <*> block (adtDataConP as)                 ))
+                <|>                        ((,)         <$> dataPropTyP <*> block (adtDataConP as)                  )
   return (pTy, Misc.sortOn (val . dcName) dcs)
 
 noWhere :: Parser Symbol
diff --git a/src/Language/Haskell/Liquid/Synthesize.hs b/src/Language/Haskell/Liquid/Synthesize.hs
--- a/src/Language/Haskell/Liquid/Synthesize.hs
+++ b/src/Language/Haskell/Liquid/Synthesize.hs
@@ -8,7 +8,7 @@
 
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.Constraint.Types
-import           Language.Haskell.Liquid.Constraint.Generate 
+import           Language.Haskell.Liquid.Constraint.Generate
 import qualified Language.Haskell.Liquid.Types.RefType as R
 import           Language.Haskell.Liquid.Synthesize.Termination
 import           Language.Haskell.Liquid.Synthesize.Generate
@@ -18,22 +18,22 @@
 import           Language.Haskell.Liquid.Constraint.Fresh (trueTy)
 import qualified Language.Fixpoint.Smt.Interface as SMT
 import           Language.Fixpoint.Types hiding (SEnv, SVar, Error)
-import qualified Language.Fixpoint.Types        as F 
+import qualified Language.Fixpoint.Types        as F
 import qualified Language.Fixpoint.Types.Config as F
 import           Language.Haskell.Liquid.Synthesize.Env
-import           Language.Haskell.Liquid.GHC.API as GHC hiding (text, ($+$))
+import           Liquid.GHC.API as GHC hiding (text, ($+$))
 
 import           Text.PrettyPrint.HughesPJ (text, ($+$))
 import           Control.Monad.State.Lazy
-import qualified Data.HashMap.Strict as M 
+import qualified Data.HashMap.Strict as M
 import           Data.Maybe
 
 synthesize :: FilePath -> F.Config -> CGInfo -> IO [Error]
-synthesize tgt fcfg cginfo = 
+synthesize tgt fcfg cginfo =
   mapM go (M.toList $ holesMap cginfo)
-  where 
+  where
     measures = map (val . msName) ((gsMeasures . gsData . giSpec . ghcI) cginfo)
-    go (x, HoleInfo _ loc env (cgi,cge)) = do 
+    go (x, HoleInfo _ loc env (cgi,cge)) = do
       let topLvlBndr = fromMaybe (error "Top-level binder not found") (cgVar cge)
           typeOfTopLvlBnd = fromMaybe (error "Type: Top-level symbol not found") (M.lookup (symbol topLvlBndr) (reGlobal env))
           coreProgram = giCbs $ giSrc $ ghcI cgi
@@ -48,7 +48,7 @@
 
           ssenv0 = symbolToVar coreProgram topLvlBndr fromREnv
           (senv1, foralls') = initSSEnv typeOfTopLvlBnd cginfo ssenv0
-      
+
       ctx <- SMT.makeContext fcfg tgt
       state0 <- initState ctx fcfg cgi cge env topLvlBndr (reverse uniVars) M.empty
       let foralls = foralls' ++ fs
@@ -57,20 +57,20 @@
       return $ ErrHole loc (
         if not (null fills)
           then text "\n Hole Fills:" $+$ pprintMany (map (coreToHs typeOfTopLvlBnd topLvlBndr . fromAnf) fills)
-          else mempty) mempty (symbol x) typeOfTopLvlBnd 
+          else mempty) mempty (symbol x) typeOfTopLvlBnd
 
 
 synthesize' :: SMT.Context -> CGInfo -> SSEnv -> SpecType ->  Var -> SpecType -> [Var] -> SState -> IO [CoreExpr]
-synthesize' ctx cgi senv tx xtop ttop foralls st2
- = evalSM (go tx) ctx senv st2
-  where 
+synthesize' ctx cgi ssenv tx xtop ttop foralls st2
+ = evalSM (go tx) ctx ssenv st2
+  where
 
     go :: SpecType -> SM [CoreExpr]
 
     -- Type Abstraction 
     go (RAllT a t _x)      = GHC.Lam (tyVarVar a) <$$> go t
-          
-    go t@(RApp c _ts _ _r) = do  
+
+    go t@(RApp c _ts _ _r) = do
       let coreProgram = giCbs $ giSrc $ ghcI cgi
           args  = drop 1 (argsP coreProgram xtop)
           (_, (xs, _, txs, _), _) = bkArrow ttop
@@ -82,7 +82,7 @@
                   if null ts  then modify (\s -> s { sUGoalTy = Nothing } )
                               else modify (\s -> s { sUGoalTy = Just ts } )
                   modify (\s -> s {sForalls = (foralls, [])})
-                  emem0 <- insEMem0 senv
+                  emem0 <- insEMem0 ssenv
                   modify (\s -> s { sExprMem = emem0 })
                   synthesizeBasic t
 
@@ -90,28 +90,28 @@
 
     go (RRTy _env _ref _obl t) = go t
 
-    go t@RFun{} 
+    go t@RFun{}
          = do ys <- mapM freshVar txs
-              let su = F.mkSubst $ zip xs (EVar . symbol <$> ys) 
-              mapM_ (uncurry addEnv) (zip ys ((subst su)<$> txs)) 
+              let su = F.mkSubst $ zip xs (EVar . symbol <$> ys)
+              mapM_ (uncurry addEnv) (zip ys (subst su<$> txs))
               let dt = decrType xtop ttop ys (zip xs txs)
-              addEnv xtop dt 
-              mapM_ (uncurry addEmem) (zip ys (subst su <$> txs)) 
+              addEnv xtop dt
+              mapM_ (uncurry addEmem) (zip ys (subst su <$> txs))
               addEmem xtop dt
               senv1 <- getSEnv
-              let goalType = subst su to
-                  hsGoalTy = toType False goalType 
+              let goalType' = subst su to
+                  hsGoalTy = toType False goalType'
                   ts = unifyWith hsGoalTy
               if null ts  then modify (\s -> s { sUGoalTy = Nothing } )
                           else modify (\s -> s { sUGoalTy = Just ts } )
               modify (\s -> s { sForalls = (foralls, []) } )
               emem0 <- insEMem0 senv1
               modify (\s -> s { sExprMem = emem0 })
-              mapM_ (\y -> addDecrTerm y []) ys
+              mapM_ (`addDecrTerm` []) ys
               scruts <- synthesizeScrut ys
               modify (\s -> s { scrutinees = scruts })
-              GHC.mkLams ys <$$> synthesizeBasic goalType
-      where (_, (xs, _,txs, _), to) = bkArrow t 
+              GHC.mkLams ys <$$> synthesizeBasic goalType'
+      where (_, (xs, _,txs, _), to) = bkArrow t
 
     go t = error (" Unmatched t = " ++ show t)
 
@@ -129,12 +129,12 @@
 synthesizeMatch :: SpecType -> SM [CoreExpr]
 synthesizeMatch t = do
   scruts <- scrutinees <$> get
-  i <- incrCase 
+  i <- incrCase
   case safeIxScruts i scruts of
-    Nothing ->  return []
-    Just id ->  if null scruts
+    Nothing  ->  return []
+    Just id' ->  if null scruts
                   then return []
-                  else withIncrDepth (matchOnExpr t (scruts !! id))
+                  else withIncrDepth (matchOnExpr t (scruts !! id'))
 
 synthesizeScrut :: [Var] -> SM [(CoreExpr, Type, TyCon)]
 synthesizeScrut vs = do
@@ -142,17 +142,17 @@
   let exprs' = map (\e -> (exprType e, e)) exprs
       isDataCon v = case varType v of { TyConApp c _ -> not . isClassTyCon $ c; _ -> False }
       vs0 = filter isDataCon vs
-      es0 = map GHC.Var vs0 
+      es0 = map GHC.Var vs0
       es1 = map (\e -> (exprType e, e)) es0
       es2 = [(e, t, c) | (t@(TyConApp c _), e) <- es1]
   return (es2 ++ [(e, t, c) | (t@(TyConApp c _), e) <- exprs'])
 
 matchOnExpr :: SpecType -> (CoreExpr, Type, TyCon) -> SM [CoreExpr]
-matchOnExpr t (GHC.Var v, tx, c) 
+matchOnExpr t (GHC.Var v, tx, c)
   = matchOn t (v, tx, c)
 matchOnExpr t (e, tx, c)
   = do  freshV <- freshVarType tx
-        freshSpecTy <- liftCG $ (trueTy False) tx
+        freshSpecTy <- liftCG $ trueTy False tx
         -- use consE
         addEnv freshV freshSpecTy
         es <- matchOn t (freshV, tx, c)
@@ -164,17 +164,17 @@
 
 
 makeAlt :: SpecType -> (Var, Type) -> DataCon -> SM [GHC.CoreAlt]
-makeAlt t (x, TyConApp _ ts) c = locally $ do
+makeAlt t (x, TyConApp _ kts) c = locally $ do
   ts <- liftCG $ mapM (trueTy False) τs
-  xs <- mapM freshVar ts    
+  xs <- mapM freshVar ts
   newScruts <- synthesizeScrut xs
   modify (\s -> s { scrutinees = scrutinees s ++ newScruts } )
-  addsEnv $ zip xs ts 
-  addsEmem $ zip xs ts 
+  addsEnv $ zip xs ts
+  addsEmem $ zip xs ts
   addDecrTerm x xs
   liftCG0 (\γ -> caseEnv γ x mempty (GHC.DataAlt c) xs Nothing)
   es <- synthesizeBasic t
   return $ (GHC.DataAlt c, xs, ) <$> es
-  where 
-    (_, _, τs) = dataConInstSig c ts
+  where
+    (_, _, τs) = dataConInstSig c kts
 makeAlt _ _ _ = error "makeAlt.bad argument "
diff --git a/src/Language/Haskell/Liquid/Synthesize/Check.hs b/src/Language/Haskell/Liquid/Synthesize/Check.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Check.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Check.hs
@@ -1,6 +1,8 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 {-# LANGUAGE BangPatterns #-}
+
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.Check (check, hasType, isWellTyped, checkError) where
 
 
@@ -19,11 +21,11 @@
 import           Language.Haskell.Liquid.Constraint.ToFixpoint
 import           Language.Haskell.Liquid.Synthesize.Monad
 import           Language.Haskell.Liquid.Synthesize.GHC
-import           Language.Haskell.Liquid.GHC.API as Ghc
+import           Liquid.GHC.API as Ghc
 import           Language.Haskell.Liquid.Misc   ( mapThd3 )
 import           Control.Monad.State.Lazy
 import           System.Console.CmdArgs.Verbosity
-import           Language.Haskell.Liquid.GHC.TypeRep
+import           Liquid.GHC.TypeRep
 import           Language.Haskell.Liquid.Types
 
 hasType :: SpecType -> CoreExpr -> SM Bool
diff --git a/src/Language/Haskell/Liquid/Synthesize/Env.hs b/src/Language/Haskell/Liquid/Synthesize/Env.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Env.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Env.hs
@@ -1,7 +1,9 @@
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.Env where 
 
 import           Language.Fixpoint.Types
-import           Language.Haskell.Liquid.GHC.API as GHC
+import           Liquid.GHC.API as GHC
 import           Language.Haskell.Liquid.Constraint.Types
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.Synthesize.Monad
diff --git a/src/Language/Haskell/Liquid/Synthesize/GHC.hs b/src/Language/Haskell/Liquid/Synthesize/GHC.hs
--- a/src/Language/Haskell/Liquid/Synthesize/GHC.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/GHC.hs
@@ -1,15 +1,17 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 {-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE CPP #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.GHC where
 
 import qualified Language.Fixpoint.Types       as F
 import           Language.Haskell.Liquid.Types
 import           Data.Default
 import           Data.Maybe                     ( fromMaybe )
-import           Language.Haskell.Liquid.GHC.TypeRep
-import           Language.Haskell.Liquid.GHC.API as GHC
+import           Liquid.GHC.TypeRep
+import           Liquid.GHC.API as GHC
 import           Language.Fixpoint.Types
 import qualified Data.HashMap.Strict           as M
 
@@ -17,16 +19,16 @@
 import           Data.List.Split
 
 instance Default Type where
-    def = TyVarTy alphaTyVar 
+    def = TyVarTy alphaTyVar
 
 mkVar :: Maybe String -> Int -> Type -> Var
-mkVar x i t = mkGlobalVar VanillaId name t vanillaIdInfo 
-  where 
+mkVar x i t = mkGlobalVar VanillaId name t vanillaIdInfo
+  where
     name = mkSystemName (mkUnique 'S' i) (mkVarOcc x')
-    x'   = fromMaybe (freshName i) x 
+    x'   = fromMaybe (freshName i) x
 
-freshName :: Int -> String 
-freshName i = "lSyn$" ++ show i 
+freshName :: Int -> String
+freshName i = "lSyn$" ++ show i
 
 -- | Assuming that the functions are instantiated when this function is called.
 goalType ::  Type ->   --  This is the goal type. It is used for basic types.
@@ -48,8 +50,8 @@
 
 subgoals :: Type ->               -- Given a function type,
             Maybe (Type, [Type])  -- separate the result type from the input types.
-subgoals t = if null gTys then Nothing else Just (resTy, inpTys) 
-  where gTys            = createSubgoals t 
+subgoals t = if null gTys then Nothing else Just (resTy, inpTys)
+  where gTys            = createSubgoals t
         (resTy, inpTys) = (last gTys, take (length gTys - 1) gTys)
 
 
@@ -57,18 +59,18 @@
 -- returns all expressions in @ExprMemory@ that have the same type.
 withSubgoal :: [(Type, CoreExpr, Int)] -> Type -> [(CoreExpr, Int)]
 withSubgoal []                  _ = []
-withSubgoal ((t, e, i) : exprs) τ = 
-  if τ == t 
+withSubgoal ((t, e, i) : exprs) τ =
+  if τ == t
     then (e, i) : withSubgoal exprs τ
     else withSubgoal exprs τ
 
 -- | Assuming that goals are type variables or constructors.
 --    Note: We maintain ordering from the goal type.
 --    Not handled (compared to @varsInType): function types, type applications
-unifyWith :: Type -> [Type] 
-unifyWith v@(TyVarTy _)   = [v] 
-unifyWith (TyConApp _ ts) = ts 
-unifyWith t               = error $ " [ unifyWith ] " ++ showTy t 
+unifyWith :: Type -> [Type]
+unifyWith v@(TyVarTy _)   = [v]
+unifyWith (TyConApp _ ts) = ts
+unifyWith t               = error $ " [ unifyWith ] " ++ showTy t
 
 fromAnf :: CoreExpr -> CoreExpr
 fromAnf e = fst $ fromAnf' e []
@@ -84,17 +86,17 @@
   = case bnd of Rec {}       -> error " By construction, no recursive bindings in let expression. "
                 NonRec rb lb -> let (lb', bnds') = fromAnf' lb bnds
                                 in  fromAnf' e ((rb, lb') : bnds')
-fromAnf' (Var var) bnds 
+fromAnf' (Var var) bnds
   = (fromMaybe (Var var) (lookup var bnds), bnds)
 fromAnf' (Case scr bnd tp alts) bnds
   = (Case scr bnd tp (map (\(altc, xs, e) -> (altc, xs, fst $ fromAnf' e bnds)) alts), bnds)
 fromAnf' (App e1 e2) bnds
-  = let (e1', bnds')  = fromAnf' e1 bnds 
+  = let (e1', bnds')  = fromAnf' e1 bnds
         (e2', bnds'') = fromAnf' e2 bnds'
     in  (App e1' e2', bnds'')
-fromAnf' t@Type{} bnds 
+fromAnf' t@Type{} bnds
   = (t, bnds)
-fromAnf' l@Lit{} bnds 
+fromAnf' l@Lit{} bnds
   = (l, bnds)
 fromAnf' _ _
   = error " Should not reach this point. "
@@ -112,8 +114,8 @@
 pprintSymbols txt = foldr (\x xs -> pprintSym symbols x ++ xs) [] txt
 
 pprintSym :: String -> Char -> String
-pprintSym symbols s 
-  = case find (== s) symbols of 
+pprintSym symbols s
+  = case find (== s) symbols of
       Nothing -> [s]
       Just s' -> ['(', s', ')']
 
@@ -121,33 +123,31 @@
 discardModName v = last (splitOn "." (show v))
 
 rmModName :: String -> String
-rmModName s = 
+rmModName s =
   let ts = splitOn "." s
   in  maintainLParen ts ++ last ts ++ maintainRParen ts
 
 maintainLParen :: [String] -> String
-maintainLParen ts 
+maintainLParen ts
   = if length ts > 1 && head (head ts) == '('
       then  "("
       else  ""
 
 maintainRParen :: [String] -> String
-maintainRParen ts 
+maintainRParen ts
   = if last (last ts) == '('
       then  ")"
       else  ""
 
 pprintFormals :: Int -> Var -> CoreExpr -> Int -> [Var] -> String
 pprintFormals i v (Lam b e) cnt vs
-  = if isTyVar b
-      then pprintFormals i v e cnt vs
-      else  if cnt > 0 
-              then  pprintFormals i v e (cnt - 1) (b:vs)
-              else  " " ++ show b ++ pprintFormals i v e cnt vs
+  | isTyVar b = pprintFormals i v e cnt vs
+  | cnt > 0 = pprintFormals i v e (cnt - 1) (b:vs)
+  | otherwise = " " ++ show b ++ pprintFormals i v e cnt vs
 pprintFormals i _ e _ vs
   = " =" ++ pprintBody vs i e
 
-caseIndent :: Int 
+caseIndent :: Int
 caseIndent = 4
 
 indent :: Int -> String
@@ -156,22 +156,22 @@
 errorExprPp :: CoreExpr -> Bool
 errorExprPp (GHC.App (GHC.App err@(GHC.Var _) (GHC.Type _)) _)
   = show err == "Language.Haskell.Liquid.Synthesize.Error.err"
-errorExprPp _ 
+errorExprPp _
   = False
 
-pprintVar :: Var -> String 
+pprintVar :: Var -> String
 pprintVar v = if isTyVar v then "" else " " ++ discardModName v
 
 pprintBody :: [Var] -> Int -> CoreExpr -> String
-pprintBody vs i (Lam b e) 
+pprintBody vs i (Lam b e)
   = pprintFormals i b e 0 vs
 pprintBody vs _ (Var v)
-  = case find (== v) vs of 
+  = case find (== v) vs of
       Nothing -> pprintVar v
       Just _  -> ""
 pprintBody vs _ e@App{}
   = let pprintApp = fixApplication (show e)
-        noTcVars  = filter (\x -> case find (== x) (map show vs) of 
+        noTcVars  = filter (\x -> case find (== x) (map show vs) of
                                     Nothing -> True
                                     Just _  -> False) (words pprintApp)
     in  if errorExprPp e
@@ -180,16 +180,16 @@
 pprintBody _ _ l@Lit{}
   = " " ++ show l
 pprintBody vs i (Case scr _ _ alts)
-  = "\n" ++ indent i ++ 
-    "case" ++ pprintBody vs i scr ++ " of\n" ++ 
-    concatMap (pprintAlts vs (i + caseIndent)) alts 
-pprintBody _ _ Type{} 
+  = "\n" ++ indent i ++
+    "case" ++ pprintBody vs i scr ++ " of\n" ++
+    concatMap (pprintAlts vs (i + caseIndent)) alts
+pprintBody _ _ Type{}
   = ""
 pprintBody _ _ e
   = error (" Not yet implemented for e = " ++ show e)
 
 fixApplication :: String -> String
-fixApplication e = 
+fixApplication e =
   let ws' = words (replaceNewLine e)
       ws = handleCommas ws'
       cleanWs = rmTypeAppl ws
@@ -213,56 +213,56 @@
 fixParen :: [String] -> [String]
 fixParen [] = []
 fixParen [x] = [x]
-fixParen (x:y:xs) 
+fixParen (x:y:xs)
   = if replicate (length y) ')' == y
-      then  let w0 = x ++ y 
-                w = if head w0 == '(' && last w0 == ')' 
-                      then tail (init w0) 
+      then  let w0 = x ++ y
+                w = if head w0 == '(' && last w0 == ')'
+                      then tail (init w0)
                       else w0
             in  w : fixParen xs
       else x : fixParen (y:xs)
 
 rmTypeAppl :: [String] -> [String]
-rmTypeAppl [] 
+rmTypeAppl []
   = []
-rmTypeAppl (c:cs) 
+rmTypeAppl (c:cs)
   = if c == "@"
-      then  case cs of 
+      then  case cs of
               [] -> error " Type application: Badly formatted string. "
-              (c': cs') -> 
+              (c': cs') ->
                 let p = paren c'
                 in  if null p then rmTypeAppl cs' else p : rmTypeAppl cs'
       else c:rmTypeAppl cs
 
-paren :: String -> String 
-paren [] 
+paren :: String -> String
+paren []
   = []
-paren (c:cs) 
+paren (c:cs)
   = if c == ')' then c : paren cs else paren cs
 
 replaceNewLine :: String -> String
-replaceNewLine [] 
+replaceNewLine []
   = []
-replaceNewLine (c:cs) 
-  = if c == '\n' 
-      then ' ' : replaceNewLine cs 
+replaceNewLine (c:cs)
+  = if c == '\n'
+      then ' ' : replaceNewLine cs
       else c : replaceNewLine cs
 
 pprintAlts :: [Var] -> Int -> Alt Var -> String
 pprintAlts vars i (DataAlt dataCon, vs, e)
-  = indent i ++ show dataCon ++ concatMap (\v -> " " ++ show v) vs ++ " ->" ++ 
+  = indent i ++ show dataCon ++ concatMap (\v -> " " ++ show v) vs ++ " ->" ++
     pprintBody vars (i+caseIndent) e ++ "\n"
 pprintAlts _ _ _
   = error " Pretty printing for pattern match on datatypes. "
 
 -- TODO Remove variables generated for type class constraints
 countTcConstraints :: SpecType -> Int
-countTcConstraints t = 
+countTcConstraints t =
   let ws = words (show t)
 
       countCommas :: [String] -> Int
       countCommas []     = 0
-      countCommas (x:xs) = 
+      countCommas (x:xs) =
         case find (== ',') x of
           Nothing -> countCommas xs
           Just _  -> 1 + countCommas xs
@@ -270,9 +270,9 @@
   in  case find (== "=>") ws of
         Nothing -> 0
         Just _  -> 1 + countCommas (takeWhile (/= "=>") ws)
-  
 
 
+
 -----------------------------------------------------------------------------------
 --  |                          Prune trivial expressions                       | --
 -----------------------------------------------------------------------------------
@@ -281,7 +281,7 @@
 nonTrivial _                        = True
 
 nonTrivials :: [GHC.CoreExpr] -> Bool
-nonTrivials = foldr (\x b -> nonTrivial x || b) False 
+nonTrivials = foldr (\x b -> nonTrivial x || b) False
 
 trivial :: GHC.CoreExpr -> Bool
 trivial (GHC.App (GHC.Var _) (GHC.Type _)) = True -- Is this a nullary constructor?
@@ -291,7 +291,7 @@
 hasTrivial es = foldr (\x b -> trivial x || b) False es
 
 allTrivial :: [[GHC.CoreExpr]] -> Bool
-allTrivial es = foldr (\x b -> hasTrivial x && b) True es 
+allTrivial es = foldr (\x b -> hasTrivial x && b) True es
 
 rmTrivials :: [(GHC.CoreExpr, Int)] -> [(GHC.CoreExpr, Int)]
 rmTrivials = filter (not . trivial . fst)
@@ -305,10 +305,10 @@
 isVar _           = False
 
 returnsTuple :: Var -> Bool
-returnsTuple v = 
+returnsTuple v =
   case subgoals (varType v) of
     Nothing      -> False
-    Just (t, _) -> 
+    Just (t, _) ->
       case t of
         TyConApp c _ts -> c == pairTyCon
         _              -> False
@@ -320,7 +320,7 @@
 type SSEnv = M.HashMap Symbol (SpecType, Var)
 
 filterREnv :: M.HashMap Symbol SpecType -> M.HashMap Symbol SpecType
-filterREnv renv = 
+filterREnv renv =
   let renv_lst  = M.toList renv
       renv_lst' = filter (\(_, specT) ->  let ht = toType False specT
                                           in  showTy ht /= "(RApp   GHC.Prim.Addr# )") renv_lst
@@ -332,19 +332,19 @@
 
 -- | That' s a hack to get the type variables we need for instantiation.
 getUniVars :: GHC.CoreProgram -> Var -> ([Var], [Var])
-getUniVars cp tlVar = 
-  case filter (`isInCB` tlVar) cp of 
+getUniVars cp tlVar =
+  case filter (`isInCB` tlVar) cp of
     [cb] -> getUniVars0 (getBody cb tlVar) ([], [])
     _    -> error " Every top-level corebind must be unique! "
 
 getUniVars0 :: GHC.CoreExpr -> ([Var], [Var]) -> ([Var], [Var])
 getUniVars0 (Lam b e) (uvs, tcDicts)
-  = case varType b of 
-      TyConApp c _ -> 
-        if isClassTyCon c 
+  = case varType b of
+      TyConApp c _ ->
+        if isClassTyCon c
           then getUniVars0 e (uvs, b : tcDicts)
           else getUniVars0 e (b:uvs, tcDicts)
-      _ -> getUniVars0 e (b:uvs, tcDicts) 
+      _ -> getUniVars0 e (b:uvs, tcDicts)
 getUniVars0 _ vs
   = vs
 
@@ -354,13 +354,13 @@
 
 --                       | Current top-level binder |
 varsP :: GHC.CoreProgram -> Var -> (GHC.CoreExpr -> [Var]) -> [Var]
-varsP cp tlVar f = 
-  case filter (\cb -> isInCB cb tlVar) cp of
+varsP cp tlVar f =
+  case filter (`isInCB` tlVar) cp of
     [cb] -> varsCB cb f
     _    -> error " Every top-level corebind must be unique! "
 
 isInCB :: GHC.CoreBind -> Var -> Bool
-isInCB (GHC.NonRec b _) tlVar = b == tlVar 
+isInCB (GHC.NonRec b _) tlVar = b == tlVar
 isInCB (GHC.Rec recs) tlVar   = foldr ((\v b -> v == tlVar && b) . fst) True recs
 
 varsCB :: GHC.CoreBind -> (GHC.CoreExpr -> [Var]) -> [Var]
@@ -374,18 +374,18 @@
 varsE (GHC.Tick _ e) = varsE e
 varsE _ = []
 
-caseVarsE :: GHC.CoreExpr -> [Var] 
-caseVarsE (GHC.Lam _ e) = caseVarsE e 
+caseVarsE :: GHC.CoreExpr -> [Var]
+caseVarsE (GHC.Lam _ e) = caseVarsE e
 caseVarsE (GHC.Let (GHC.NonRec _ _) e) = caseVarsE e
-caseVarsE (GHC.Case _ b _ alts) = foldr (\(_, _, e) res -> caseVarsE e ++ res) [b] alts 
-caseVarsE (GHC.Tick _ e) = caseVarsE e 
-caseVarsE _ = [] 
+caseVarsE (GHC.Case _ b _ alts) = foldr (\(_, _, e) res -> caseVarsE e ++ res) [b] alts
+caseVarsE (GHC.Tick _ e) = caseVarsE e
+caseVarsE _ = []
 
 instance Default Var where
   def = alphaTyVar
 
 symbolToVar :: GHC.CoreProgram -> Var -> M.HashMap Symbol SpecType -> SSEnv
-symbolToVar cp tlBndr renv = 
+symbolToVar cp tlBndr renv =
   let vars = [(F.symbol x, x) | x <- varsP cp tlBndr varsE]
       casevars = [F.symbol x | x <- varsP cp tlBndr caseVarsE]
       tlVars = [(F.symbol x, x) | x <- getTopLvlBndrs cp]
@@ -394,9 +394,9 @@
       renv' = foldr M.delete renv casevars
   in  M.fromList [ (s, (t, symbolVar s)) | (s, t) <- M.toList renv']
 
-argsP :: GHC.CoreProgram -> Var -> [Var] 
+argsP :: GHC.CoreProgram -> Var -> [Var]
 argsP []         tlVar = error $ " [ argsP ] " ++ show tlVar
-argsP (cb : cbs) tlVar 
+argsP (cb : cbs) tlVar
   | isInCB cb tlVar = argsCB cb
   | otherwise = argsP cbs tlVar
 
@@ -405,9 +405,10 @@
 argsCB _                = error " [ argsCB ] "
 
 argsE :: GHC.CoreExpr -> [Var]
-argsE (GHC.Lam a e) = a : argsE e 
+argsE (GHC.Lam a e) = a : argsE e
 argsE (GHC.Let (GHC.NonRec _ _) e) = argsE e
-argsE _ = [] 
+argsE _ = []
 
-notrace :: String -> a -> a 
+notrace :: String -> a -> a
 notrace _ a = a
+
diff --git a/src/Language/Haskell/Liquid/Synthesize/Generate.hs b/src/Language/Haskell/Liquid/Synthesize/Generate.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Generate.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Generate.hs
@@ -1,11 +1,12 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 {-# LANGUAGE TupleSections #-}
 {-# LANGUAGE BangPatterns #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.Generate where
 
-import           Language.Haskell.Liquid.GHC.API as GHC hiding (Depth)
+import           Liquid.GHC.API as GHC hiding (Depth)
 import           Language.Haskell.Liquid.Types
 import           Language.Haskell.Liquid.Synthesize.GHC
                                          hiding ( SSEnv )
@@ -37,7 +38,7 @@
 genTerms' i specTy = 
   do  goalTys <- sGoalTys <$> get
       case find (== toType False specTy) goalTys of 
-        Nothing -> modify (\s -> s { sGoalTys = (toType False specTy) : sGoalTys s })
+        Nothing -> modify (\s -> s { sGoalTys = toType False specTy : sGoalTys s })
         Just _  -> return ()
       fixEMem specTy 
       fnTys <- functionCands (toType False specTy)
diff --git a/src/Language/Haskell/Liquid/Synthesize/Misc.hs b/src/Language/Haskell/Liquid/Synthesize/Misc.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Misc.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Misc.hs
@@ -1,16 +1,16 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
-{-# LANGUAGE TupleSections #-}
-{-# LANGUAGE BangPatterns #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.Misc where
 
 import qualified Language.Fixpoint.Types        as F
 import           Control.Monad.State.Lazy
 import           Text.PrettyPrint.HughesPJ (text, Doc, vcat, ($+$))
 import           Language.Haskell.Liquid.Synthesize.GHC
-import           Language.Haskell.Liquid.GHC.TypeRep
-import           Language.Haskell.Liquid.GHC.API hiding (text, ($+$), vcat)
+import           Liquid.GHC.TypeRep
+import           Liquid.GHC.API hiding (text, ($+$), vcat)
 import           Language.Fixpoint.Types
 
 
diff --git a/src/Language/Haskell/Liquid/Synthesize/Monad.hs b/src/Language/Haskell/Liquid/Synthesize/Monad.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Monad.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Monad.hs
@@ -1,13 +1,12 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
-{-# LANGUAGE TupleSections #-}
-{-# LANGUAGE BangPatterns #-}
 {-# LANGUAGE FlexibleContexts #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Synthesize.Monad where
 
 
-import           Language.Haskell.Liquid.GHC.API as GHC
+import           Liquid.GHC.API as GHC
 import           Language.Haskell.Liquid.Bare.Resolve
                                                as B
 import           Language.Haskell.Liquid.Types
@@ -32,7 +31,7 @@
 import           Data.List
 import           Data.Tuple.Extra
 
-localMaxMatchDepth :: SM Int 
+localMaxMatchDepth :: SM Int
 localMaxMatchDepth = maxMatchDepth . getConfig . sCGEnv <$> get
 
 -------------------------------------------------------------------------------
@@ -46,17 +45,17 @@
 
 type ExprMemory = [(Type, CoreExpr, Int)]
 type T = M.HashMap Type (CoreExpr, Int)
-data SState 
-  = SState { rEnv       :: !REnv 
+data SState
+  = SState { rEnv       :: !REnv
            , ssEnv      :: !SSEnv -- Local Binders Generated during Synthesis 
            , ssIdx      :: !Int
-           , ssDecrTerm :: !SSDecrTerm 
+           , ssDecrTerm :: !SSDecrTerm
            , sContext   :: !SMT.Context
            , sCGI       :: !CGInfo
            , sCGEnv     :: !CGEnv
            , sFCfg      :: !F.Config
            , sDepth     :: !Int
-           , sExprMem   :: !ExprMemory 
+           , sExprMem   :: !ExprMemory
            , sExprId    :: !Int
            , sArgsId    :: !Int
            , sArgsDepth :: !Int
@@ -75,67 +74,67 @@
 
 type SM = StateT SState IO
 
-localMaxAppDepth :: SM Int 
+localMaxAppDepth :: SM Int
 localMaxAppDepth = maxAppDepth . getConfig . sCGEnv <$> get
 
 localMaxArgsDepth :: SM Int
 localMaxArgsDepth = maxArgsDepth . getConfig . sCGEnv <$> get
 
-locally :: SM a -> SM a 
-locally act = do 
-  st <- get 
-  r <- act 
+locally :: SM a -> SM a
+locally act = do
+  st <- get
+  r <- act
   modify $ \s -> s{sCGEnv = sCGEnv st, sCGI = sCGI st, sExprMem = sExprMem st, scrutinees = scrutinees st}
-  return r 
+  return r
 
 
-evalSM :: SM a -> SMT.Context -> SSEnv -> SState -> IO a 
-evalSM act ctx env st = do 
+evalSM :: SM a -> SMT.Context -> SSEnv -> SState -> IO a
+evalSM act ctx env st = do
   let st' = st {ssEnv = env}
   r <- evalStateT act st'
-  SMT.cleanupContext ctx 
-  return r 
+  _ <- SMT.cleanupContext ctx
+  return r
 
-initState :: SMT.Context -> F.Config -> CGInfo -> CGEnv -> REnv -> Var -> [Var] -> SSEnv -> IO SState 
-initState ctx fcfg cgi cgenv renv xtop uniVars env = 
+initState :: SMT.Context -> F.Config -> CGInfo -> CGEnv -> REnv -> Var -> [Var] -> SSEnv -> IO SState
+initState ctx fcfg cgi cgenv renv xtop uniVars env =
   return $ SState renv env 0 [] ctx cgi cgenv fcfg 0 exprMem0 0 0 0 uniVars xtop [] Nothing Nothing ([], []) 0 []
   where exprMem0 = initExprMem env
 
 getSEnv :: SM SSEnv
-getSEnv = ssEnv <$> get 
+getSEnv = ssEnv <$> get
 
 getSEMem :: SM ExprMemory
 getSEMem = sExprMem <$> get
 
-getSFix :: SM Var 
+getSFix :: SM Var
 getSFix = sFix <$> get
 
 getSUniVars :: SM [Var]
 getSUniVars = sUniVars <$> get
 
-getSDecrTerms :: SM SSDecrTerm 
+getSDecrTerms :: SM SSDecrTerm
 getSDecrTerms = ssDecrTerm <$> get
 
-addsEnv :: [(Var, SpecType)] -> SM () 
-addsEnv xts = 
-  mapM_ (\(x,t) -> modify (\s -> s {ssEnv = M.insert (symbol x) (t,x) (ssEnv s)})) xts  
+addsEnv :: [(Var, SpecType)] -> SM ()
+addsEnv xts =
+  mapM_ (\(x,t) -> modify (\s -> s {ssEnv = M.insert (symbol x) (t,x) (ssEnv s)})) xts
 
-addsEmem :: [(Var, SpecType)] -> SM () 
-addsEmem xts = do 
+addsEmem :: [(Var, SpecType)] -> SM ()
+addsEmem xts = do
   curAppDepth <- sExprId <$> get
-  mapM_ (\(x,t) -> modify (\s -> s {sExprMem = (toType False t, GHC.Var x, curAppDepth+1) : (sExprMem s)})) xts  
-  
+  mapM_ (\(x,t) -> modify (\s -> s {sExprMem = (toType False t, GHC.Var x, curAppDepth+1) : sExprMem s})) xts
 
+
 addEnv :: Var -> SpecType -> SM ()
-addEnv x t = do 
+addEnv x t = do
   liftCG0 (\γ -> γ += ("arg", symbol x, t))
-  modify (\s -> s {ssEnv = M.insert (symbol x) (t,x) (ssEnv s)}) 
+  modify (\s -> s {ssEnv = M.insert (symbol x) (t,x) (ssEnv s)})
 
 addEmem :: Var -> SpecType -> SM ()
-addEmem x t = do 
+addEmem x t = do
   let ht0 = toType False t
   curAppDepth <- sExprId <$> get
-  xtop <- getSFix 
+  xtop <- getSFix
   (ht1, _) <- instantiateTL
   let ht = if x == xtop then ht1 else ht0
   modify (\s -> s {sExprMem = (ht, GHC.Var x, curAppDepth) : sExprMem s})
@@ -145,8 +144,8 @@
 ---------------------------------------------------------------------------------------------
 addDecrTerm :: Var -> [Var] -> SM ()
 addDecrTerm x vars = do
-  decrTerms <- getSDecrTerms 
-  case lookup x decrTerms of 
+  decrTerms <- getSDecrTerms
+  case lookup x decrTerms of
     Nothing    -> lookupAll x vars decrTerms
     Just vars' -> do
       let ix = elemIndex (x, vars') decrTerms
@@ -174,14 +173,14 @@
 
 -- | Entry point.
 structuralCheck :: [CoreExpr] -> SM [CoreExpr]
-structuralCheck es 
+structuralCheck es
   = do  decr <- ssDecrTerm <$> get
         fix <- sFix <$> get
         return (filter (notStructural decr fix) es)
 
 structCheck :: Var -> CoreExpr -> (Maybe Var, [CoreExpr])
 structCheck xtop var@(GHC.Var v)
-  = if v == xtop 
+  = if v == xtop
       then (Just xtop, [])
       else (Nothing, [var])
 structCheck xtop (GHC.App e1 (GHC.Type _))
@@ -189,9 +188,9 @@
 structCheck xtop (GHC.App e1 e2)
   =  (mbVar, e2:es)
     where (mbVar, es) = structCheck xtop e1
-structCheck xtop (GHC.Let _ e) 
+structCheck xtop (GHC.Let _ e)
   = structCheck xtop e
-structCheck _ e 
+structCheck _ e
   = error (" StructCheck " ++ show e)
 
 notStructural :: SSDecrTerm -> Var -> CoreExpr -> Bool
@@ -210,19 +209,19 @@
 --                               END OF STRUCTURAL CHECK                                   --
 ---------------------------------------------------------------------------------------------
 
-liftCG0 :: (CGEnv -> CG CGEnv) -> SM () 
-liftCG0 act = do 
-  st <- get 
-  let (cgenv, cgi) = runState (act (sCGEnv st)) (sCGI st) 
-  modify (\s -> s {sCGI = cgi, sCGEnv = cgenv}) 
+liftCG0 :: (CGEnv -> CG CGEnv) -> SM ()
+liftCG0 act = do
+  st <- get
+  let (cgenv, cgi) = runState (act (sCGEnv st)) (sCGI st)
+  modify (\s -> s {sCGI = cgi, sCGEnv = cgenv})
 
 
-liftCG :: CG a -> SM a 
-liftCG act = do 
-  st <- get 
-  let (x, cgi) = runState act (sCGI st) 
+liftCG :: CG a -> SM a
+liftCG act = do
+  st <- get
+  let (x, cgi) = runState act (sCGI st)
   modify (\s -> s {sCGI = cgi})
-  return x 
+  return x
 
 
 freshVarType :: Type -> SM Var
@@ -233,9 +232,9 @@
 freshVar = freshVarType . toType False
 
 withIncrDepth :: Monoid a => SM a -> SM a
-withIncrDepth m = do 
+withIncrDepth m = do
     s <- get
-    matchBound <- localMaxMatchDepth 
+    matchBound <- localMaxMatchDepth
     let d = sDepth s
     if d + 1 > matchBound
       then return mempty
@@ -243,25 +242,25 @@
               r <- m
               modify $ \s -> s{sDepth = d}
               return r
-        
-  
-incrSM :: SM Int 
-incrSM = do s <- get 
+
+
+incrSM :: SM Int
+incrSM = do s <- get
             put s{ssIdx = ssIdx s + 1}
             return (ssIdx s)
 
-incrCase :: SM Int 
+incrCase :: SM Int
 incrCase
-  = do  s <- get 
+  = do  s <- get
         put s { caseIdx = caseIdx s + 1 }
         return (caseIdx s)
-  
+
 safeIxScruts :: Int -> [a] -> Maybe Int
-safeIxScruts i l 
+safeIxScruts i l
   | i >= length l = Nothing
   | otherwise     = Just i
 
-symbolExpr :: Type -> F.Symbol -> SM CoreExpr 
+symbolExpr :: Type -> F.Symbol -> SM CoreExpr
 symbolExpr τ x = incrSM >>= (\i -> return $ F.notracepp ("symExpr for " ++ F.showpp x) $  GHC.Var $ mkVar (Just $ F.symbolString x) i τ)
 
 
@@ -281,7 +280,7 @@
 insEMem0 senv = do
   xtop      <- getSFix
   (ttop, _) <- instantiateTL
-  mbUTy     <- sUGoalTy <$> get 
+  mbUTy     <- sUGoalTy <$> get
   uniVs <- sUniVars <$> get
 
   let ts = fromMaybe [] mbUTy
@@ -289,11 +288,11 @@
   fs0 <- fst . sForalls <$> get
   modify ( \s -> s { sForalls = (fs0, ts : ts0) } )
 
-  let handleIt e = case e of  GHC.Var v -> if xtop == v 
-                                              then (instantiate e (Just uniVs), ttop) 
+  let handleIt e = case e of  GHC.Var v -> if xtop == v
+                                              then (instantiate e (Just uniVs), ttop)
                                               else change e
                               _         -> change e
-      change e =  let { e' = instantiateTy e mbUTy; t' = exprType e' } 
+      change e =  let { e' = instantiateTy e mbUTy; t' = exprType e' }
                   in  (e', t')
 
       em0 = initExprMem senv
@@ -301,18 +300,16 @@
                               in  (t', e', i)) em0
 
 instantiateTy :: CoreExpr -> Maybe [Type] -> CoreExpr
-instantiateTy e mbTy = 
-  case mbTy of 
+instantiateTy e mbTy =
+  case mbTy of
     Nothing  -> e
-    Just tys -> case applyTy tys e of 
-                  Nothing -> e
-                  Just e0 -> e0
+    Just tys -> fromMaybe e (applyTy tys e)
 
 -- | Used for instantiation: Applies types to an expression.
 --   > The result does not have @forall@.
 --   Nothing as a result suggests that there are more types than foralls in the expression.
 applyTy :: [Type] -> GHC.CoreExpr -> Maybe GHC.CoreExpr
-applyTy []     e =  case exprType e of 
+applyTy []     e =  case exprType e of
                       ForAllTy{} -> Nothing
                       _          -> Just e
 applyTy (t:ts) e =  case exprType e of
@@ -324,7 +321,7 @@
 fixEMem t
   = do  (fs, ts) <- sForalls <$> get
         let uTys = unifyWith (toType False t)
-        needsFix <- case find (== uTys) ts of 
+        needsFix <- case find (== uTys) ts of
                       Nothing -> return True   -- not yet instantiated
                       Just _  -> return False  -- already instantiated
 
@@ -344,7 +341,7 @@
 -- | Instantiate the top-level variable.
 instantiateTL :: SM (Type, GHC.CoreExpr)
 instantiateTL = do
-  uniVars <- getSUniVars 
+  uniVars <- getSUniVars
   xtop <- getSFix
   let e = fromJust $ apply uniVars (GHC.Var xtop)
   return (exprType e, e)
@@ -354,40 +351,38 @@
 --   parametricity (same number of @forall@) as the length of the 1st argument.
 --   > The result has zero @forall@.
 apply :: [Var] -> GHC.CoreExpr -> Maybe GHC.CoreExpr
-apply []     e = 
-  case exprType e of 
+apply []     e =
+  case exprType e of
     ForAllTy {} -> Nothing
     _           -> Just e
-apply (v:vs) e 
-  = case exprType e of 
+apply (v:vs) e
+  = case exprType e of
       ForAllTy{} -> apply vs (GHC.App e (GHC.Type (TyVarTy v)))
       _          -> Nothing
 
 instantiate :: CoreExpr -> Maybe [Var] -> CoreExpr
-instantiate e mbt = 
+instantiate e mbt =
   case mbt of
     Nothing     -> e
-    Just tyVars -> case apply tyVars e of 
-                      Nothing -> e
-                      Just e' -> e'
+    Just tyVars -> fromMaybe e (apply tyVars e)
 
 -----------------------------------------------------------------------------------------------------
 
-withTypeEs :: SpecType -> SM [CoreExpr] 
-withTypeEs t = do 
-    em <- sExprMem <$> get 
-    return (map snd3 (filter (\x -> fst3 x == toType False t) em)) 
+withTypeEs :: SpecType -> SM [CoreExpr]
+withTypeEs t = do
+    em <- sExprMem <$> get
+    return (map snd3 (filter (\x -> fst3 x == toType False t) em))
 
 findCandidates :: Type ->         -- Goal type: Find all candidate expressions of this type,
                                   --   or that produce this type (i.e. functions).
                   SM ExprMemory
 findCandidates goalTy = do
   sEMem <- sExprMem <$> get
-  return (filter ((goalType goalTy) . fst3) sEMem)
+  return (filter (goalType goalTy . fst3) sEMem)
 
 functionCands :: Type -> SM [(Type, GHC.CoreExpr, Int)]
-functionCands goalTy = do 
-  all <- findCandidates goalTy 
+functionCands goalTy = do
+  all <- findCandidates goalTy
   return (filter (isFunction . fst3) all)
 
 
@@ -396,17 +391,17 @@
 ---------------------------------------------------------------------------------
 
 varError :: SM Var
-varError = do 
+varError = do
   info      <- ghcI . sCGI <$> get
-  let env    = B.makeEnv (gsConfig $ giSpec info) (toGhcSrc $ giSrc info) mempty mempty 
+  let env    = B.makeEnv (gsConfig $ giSpec info) (toGhcSrc $ giSrc info) mempty mempty
   let name   = giTargetMod $ giSrc info
   let errSym = dummyLoc $ symbol "Language.Haskell.Liquid.Synthesize.Error.err"
-  case B.lookupGhcVar env name "Var" errSym of 
+  case B.lookupGhcVar env name "Var" errSym of
     Right v -> return v
     Left e  -> error (show e)
-  
 
-toGhcSrc :: TargetSrc -> GhcSrc 
+
+toGhcSrc :: TargetSrc -> GhcSrc
 toGhcSrc a = Src
       { _giIncDir    = giIncDir a
       , _giTarget    = giTarget a
diff --git a/src/Language/Haskell/Liquid/Synthesize/Termination.hs b/src/Language/Haskell/Liquid/Synthesize/Termination.hs
--- a/src/Language/Haskell/Liquid/Synthesize/Termination.hs
+++ b/src/Language/Haskell/Liquid/Synthesize/Termination.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 
 module Language.Haskell.Liquid.Synthesize.Termination (
@@ -9,7 +8,7 @@
 import qualified Language.Haskell.Liquid.Types.RefType
                                                as R
 import qualified Language.Fixpoint.Types       as F
-import           Language.Haskell.Liquid.GHC.API
+import           Liquid.GHC.API
 
 decrType :: Var -> SpecType -> [Var] -> [(F.Symbol, SpecType)] -> SpecType
 decrType _x ti xs _xts =
diff --git a/src/Language/Haskell/Liquid/Termination/Structural.hs b/src/Language/Haskell/Liquid/Termination/Structural.hs
--- a/src/Language/Haskell/Liquid/Termination/Structural.hs
+++ b/src/Language/Haskell/Liquid/Termination/Structural.hs
@@ -2,11 +2,13 @@
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE LambdaCase #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Termination.Structural (terminationVars) where
 
 import Language.Haskell.Liquid.Types hiding (isDecreasing)
-import Language.Haskell.Liquid.GHC.Misc (showPpr)
-import Language.Haskell.Liquid.GHC.API  as GHC hiding ( showPpr
+import Liquid.GHC.Misc (showPpr)
+import Liquid.GHC.API  as GHC hiding ( showPpr
                                                       , Env
                                                       , text
                                                       )
@@ -27,7 +29,7 @@
 
 failingBinds :: TargetInfo -> [CoreBind]
 failingBinds info = filter (hasErrors . checkBind) structBinds
-  where 
+  where
     structCheckWholeProgram = structuralTerm info
     program = giCbs . giSrc $ info
     structFuns = gsStTerm . gsTerm . giSpec $ info
@@ -59,7 +61,7 @@
 nextBinds = \case
   App e a -> nextBinds e ++ nextBinds a
   Lam _ e -> nextBinds e
-  Let b e -> [b] ++ nextBinds e
+  Let b e -> b : nextBinds e
   Case scrut _ _ alts -> nextBinds scrut ++ ([body | (_, _, body) <- alts] >>= nextBinds)
   Cast e _ -> nextBinds e
   Tick _ e -> nextBinds e
@@ -77,7 +79,7 @@
   , resultErrors :: [TermError]
   } deriving (Show)
 
-data TermError = TE 
+data TermError = TE
   { teVar   :: Var
   , teError :: UserError
   } deriving (Show)
diff --git a/src/Language/Haskell/Liquid/Transforms/ANF.hs b/src/Language/Haskell/Liquid/Transforms/ANF.hs
--- a/src/Language/Haskell/Liquid/Transforms/ANF.hs
+++ b/src/Language/Haskell/Liquid/Transforms/ANF.hs
@@ -5,7 +5,6 @@
 {-# LANGUAGE FlexibleInstances          #-}
 {-# LANGUAGE NoMonomorphismRestriction  #-}
 {-# LANGUAGE TupleSections              #-}
-{-# LANGUAGE TypeSynonymInstances       #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE OverloadedStrings          #-}
 {-# LANGUAGE ViewPatterns               #-}
@@ -14,31 +13,31 @@
 module Language.Haskell.Liquid.Transforms.ANF (anormalize) where
 
 import           Prelude                          hiding (error)
-import           Language.Haskell.Liquid.GHC.TypeRep
-import           Language.Haskell.Liquid.GHC.API  as Ghc hiding ( mkTyArg
+import           Liquid.GHC.TypeRep
+import           Liquid.GHC.API  as Ghc hiding ( mkTyArg
                                                                 , showPpr
                                                                 , DsM
                                                                 , panic)
-import qualified Language.Haskell.Liquid.GHC.API  as Ghc
+import qualified Liquid.GHC.API  as Ghc
 import           Control.Monad.State.Lazy
 import           System.Console.CmdArgs.Verbosity (whenLoud)
 import qualified Language.Fixpoint.Misc     as F
 import qualified Language.Fixpoint.Types    as F
 
 import           Language.Haskell.Liquid.UX.Config  as UX
-import qualified Language.Haskell.Liquid.Misc       as Misc 
-import           Language.Haskell.Liquid.GHC.Misc   as GM
+import qualified Language.Haskell.Liquid.Misc       as Misc
+import           Liquid.GHC.Misc   as GM
 import           Language.Haskell.Liquid.Transforms.Rec
 import           Language.Haskell.Liquid.Transforms.InlineAux
 import           Language.Haskell.Liquid.Transforms.Rewrite
 import           Language.Haskell.Liquid.Types.Errors
 
-import qualified Language.Haskell.Liquid.GHC.SpanStack as Sp
-import qualified Language.Haskell.Liquid.GHC.Resugar   as Rs
+import qualified Liquid.GHC.SpanStack as Sp
+import qualified Liquid.GHC.Resugar   as Rs
 import           Data.Maybe                       (fromMaybe)
 import           Data.List                        (sortBy, (\\))
 import           Data.Function                    (on)
-import qualified Text.Printf as Printf 
+import qualified Text.Printf as Printf
 import           Data.Hashable
 import Data.HashMap.Strict (HashMap)
 import qualified Data.HashMap.Strict as HM
@@ -56,7 +55,7 @@
     putStrLn $ GM.showCBs untidy orig_cbs
     putStrLn "***************************** RWR CoreBinds ***************************"
     putStrLn $ GM.showCBs untidy rwr_cbs
-  (fromMaybe err . snd) <$> initDsWithModGuts hscEnv modGuts act -- hscEnv m grEnv tEnv emptyFamInstEnv act
+  fromMaybe err . snd <$> initDsWithModGuts hscEnv modGuts act -- hscEnv m grEnv tEnv emptyFamInstEnv act
     where
       err      = panic Nothing "Oops, cannot A-Normalize GHC Core!"
       act      = Misc.concatMapM (normalizeTopBind γ0) rwr_cbs
@@ -97,14 +96,14 @@
 
 normalizeTyVars :: Bind Id -> Bind Id
 normalizeTyVars (NonRec x e) = NonRec (setVarType x t') $ normalizeForAllTys e
-  where 
+  where
     t'       = subst msg as as' bt
     msg      = "WARNING: unable to renameVars on " ++ GM.showPpr x
     as'      = fst $ splitForAllTys $ exprType e
     (as, bt) = splitForAllTys (varType x)
 normalizeTyVars (Rec xes)    = Rec xes'
-  where 
-    nrec     = normalizeTyVars <$> ((\(x, e) -> NonRec x e) <$> xes)
+  where
+    nrec     = normalizeTyVars <$> (uncurry NonRec <$> xes)
     xes'     = (\(NonRec x e) -> (x, e)) <$> nrec
 
 subst :: String -> [TyVar] -> [TyVar] -> Type -> Type
@@ -128,7 +127,7 @@
 newtype DsM a = DsM {runDsM :: Ghc.DsM a}
    deriving (Functor, Monad, MonadUnique, Applicative)
 
-data DsST = DsST { st_binds :: [CoreBind] }
+newtype DsST = DsST { st_binds :: [CoreBind] }
 
 type DsMW = StateT DsST DsM
 
@@ -180,8 +179,8 @@
        return $ Var x
 
 shouldNormalize :: Literal -> Bool
-shouldNormalize (LitNumber {})  = True 
-shouldNormalize (LitString {})    = True 
+shouldNormalize (LitNumber {})  = True
+shouldNormalize (LitString {})    = True
 shouldNormalize _               = False
 
 add :: [CoreBind] -> DsMW ()
@@ -203,7 +202,7 @@
   , Just p <- Rs.lift e
   = normalizePattern γ p
 
-normalize γ (Lam x e) | isTyVar x 
+normalize γ (Lam x e) | isTyVar x
   = do e' <- normalize γ e
        return $ Lam x e'
 
@@ -221,7 +220,7 @@
   = do n     <- normalizeName γ e
        x'    <- lift $ freshNormalVar γ τx -- rename "wild" to avoid shadowing
        let γ' = extendAnfEnv γ x x'
-       as'   <- forM as $ \(c, xs, e') -> liftM (c, xs,) (stitch (incrCaseDepth c γ') e')
+       as'   <- forM as $ \(c, xs, e') -> fmap (c, xs,) (stitch (incrCaseDepth c γ') e')
        as''  <- lift $ expandDefaultCase γ τx as'
        return $ Case n x' t as''
     where τx = GM.expandVarType x
@@ -297,9 +296,9 @@
 
 
 --------------------------------------------------------------------------------
-expandDefault :: AnfEnv -> Bool 
+expandDefault :: AnfEnv -> Bool
 --------------------------------------------------------------------------------
-expandDefault γ = aeCaseDepth γ <= maxCaseExpand γ 
+expandDefault γ = aeCaseDepth γ <= maxCaseExpand γ
 
 --------------------------------------------------------------------------------
 expandDefaultCase :: AnfEnv
@@ -316,46 +315,46 @@
                      let n   = length ds'
                      if n == 1
                        then expandDefaultCase' γ tyapp z
-                       else if maxCaseExpand γ /= 2 
-                            then return z 
-                            else return (trace (expandMessage False γ n) z) 
+                       else if maxCaseExpand γ /= 2
+                            then return z
+                            else return (trace (expandMessage False γ n) z)
        Nothing -> return z --
 
 expandDefaultCase _ _ z
    = return z
 
-expandDefaultCase' 
+expandDefaultCase'
   :: AnfEnv -> Type -> [(AltCon, [Id], c)] -> DsM [(AltCon, [Id], c)]
 expandDefaultCase' γ t ((DEFAULT, _, e) : dcs)
-  | Just dtss <- GM.defaultDataCons t (F.fst3 <$> dcs) = do 
+  | Just dtss <- GM.defaultDataCons t (F.fst3 <$> dcs) = do
       dcs'    <- warnCaseExpand γ <$> forM dtss (cloneCase γ e)
       return   $ sortCases (dcs' ++ dcs)
 expandDefaultCase' _ _ z
-   = return z 
+   = return z
 
 cloneCase :: AnfEnv -> e -> (DataCon, [TyVar], [Type]) -> DsM (AltCon, [Id], e)
-cloneCase γ e (d, as, ts) = do 
-  xs  <- mapM (freshNormalVar γ) ts 
+cloneCase γ e (d, as, ts) = do
+  xs  <- mapM (freshNormalVar γ) ts
   return (DataAlt d, as ++ xs, e)
 
 sortCases :: [(AltCon, b, c)] -> [(AltCon, b, c)]
-sortCases = sortBy (cmpAltCon `on` F.fst3) 
+sortCases = sortBy (cmpAltCon `on` F.fst3)
 
-warnCaseExpand :: AnfEnv -> [a] -> [a] 
-warnCaseExpand γ xs  
-  | 10 < n          = trace (expandMessage True γ n) xs 
+warnCaseExpand :: AnfEnv -> [a] -> [a]
+warnCaseExpand γ xs
+  | 10 < n          = trace (expandMessage True γ n) xs
   | otherwise       = xs
-  where 
-   n                = length xs 
+  where
+   n                = length xs
 
-expandMessage :: Bool -> AnfEnv -> Int -> String 
-expandMessage expand γ n = unlines [msg1, msg2]   
-  where 
-    msg1            = Printf.printf "WARNING: (%s) %s DEFAULT with %d cases at depth %d" (showPpr sp) v1 n d 
-    msg2            = Printf.printf "%s expansion with --max-case-expand=%d" v2 d' 
-    (v1, v2, d') 
+expandMessage :: Bool -> AnfEnv -> Int -> String
+expandMessage expand γ n = unlines [msg1, msg2]
+  where
+    msg1            = Printf.printf "WARNING: (%s) %s DEFAULT with %d cases at depth %d" (showPpr sp) v1 n d
+    msg2            = Printf.printf "%s expansion with --max-case-expand=%d" v2 d'
+    (v1, v2, d')
       | expand      = ("Expanding"    , "Disable", d-1) :: (String, String, Int)
-      | otherwise   = ("Not expanding", "Enable" , d+1) 
+      | otherwise   = ("Not expanding", "Enable" , d+1)
     d               = aeCaseDepth γ
     sp              = Sp.srcSpan (aeSrcSpan γ)
 
@@ -398,9 +397,8 @@
     -- We first use the default 'Eq' instance, which works on uniques (basically, integers) and is
     -- efficient. If we get 'False' it means those 'Unique' are really different, but if we get 'True',
     -- we need to be /really/ sure that's the case by using the 'stableNameCmp' function on the 'Name's.
-    case id1 == id2 of
-      False -> False -- Nothing to do, as the uniques are /really/ different
-      True  -> stableNameCmp (getName id1) (getName id2) == EQ -- Avoid unique clashing.
+    -- Nothing to do when id1 == id2 as the uniques are /really/ different.
+    (id1 == id2) && (stableNameCmp (getName id1) (getName id2) == EQ) -- Avoid unique clashing.
 
 -- For the 'Hashable' instance, we rely on the 'Unique'. This means in pratice there is a tiny chance
 -- of collision, but this should only marginally affects the efficiency of the data structure.
@@ -428,9 +426,9 @@
 extendAnfEnv :: AnfEnv -> Id -> Id -> AnfEnv
 extendAnfEnv γ (StableId -> x) y = γ { aeVarEnv = HM.insert x y (aeVarEnv γ) }
 
-incrCaseDepth :: AltCon -> AnfEnv -> AnfEnv 
+incrCaseDepth :: AltCon -> AnfEnv -> AnfEnv
 incrCaseDepth DEFAULT γ = γ { aeCaseDepth = 1 + aeCaseDepth γ }
-incrCaseDepth _       γ = γ 
+incrCaseDepth _       γ = γ
 
 at :: AnfEnv -> Tickish Id -> AnfEnv
 at γ tt = γ { aeSrcSpan = Sp.push (Sp.Tick tt) (aeSrcSpan γ)}
diff --git a/src/Language/Haskell/Liquid/Transforms/CoreToLogic.hs b/src/Language/Haskell/Liquid/Transforms/CoreToLogic.hs
--- a/src/Language/Haskell/Liquid/Transforms/CoreToLogic.hs
+++ b/src/Language/Haskell/Liquid/Transforms/CoreToLogic.hs
@@ -1,9 +1,12 @@
 {-# LANGUAGE FlexibleInstances      #-}
-{-# LANGUAGE CPP                    #-}
 {-# LANGUAGE FlexibleContexts       #-}
 {-# LANGUAGE UndecidableInstances   #-}
 {-# LANGUAGE OverloadedStrings      #-}
 {-# LANGUAGE TupleSections          #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Transforms.CoreToLogic
   ( coreToDef
   , coreToFun
@@ -12,7 +15,7 @@
   , runToLogic
   , runToLogicWithBoolBinds
   , logicType
-  , inlineSpecType  
+  , inlineSpecType
   , measureSpecType
   , weakenResult
   , normalize
@@ -20,31 +23,31 @@
 
 import           Data.ByteString                       (ByteString)
 import           Prelude                               hiding (error)
-import           Language.Haskell.Liquid.GHC.TypeRep   () -- needed for Eq 'Type'
-import           Language.Haskell.Liquid.GHC.API       hiding (Expr, Located, panic)
-import qualified Language.Haskell.Liquid.GHC.API       as Ghc
-import qualified Language.Haskell.Liquid.GHC.API       as C
+import           Liquid.GHC.TypeRep   () -- needed for Eq 'Type'
+import           Liquid.GHC.API       hiding (Expr, Located, panic)
+import qualified Liquid.GHC.API       as Ghc
+import qualified Liquid.GHC.API       as C
 import qualified Data.List                             as L
-import           Data.Maybe                            (listToMaybe) 
+import           Data.Maybe                            (listToMaybe)
 import qualified Data.Text                             as T
-import qualified Data.Char 
-import qualified Text.Printf as Printf 
+import qualified Data.Char
+import qualified Text.Printf as Printf
 import           Data.Text.Encoding
 import           Data.Text.Encoding.Error
 import           Control.Monad.State
 import           Control.Monad.Except
 import           Control.Monad.Identity
-import qualified Language.Fixpoint.Misc                as Misc 
-import qualified Language.Haskell.Liquid.Misc          as Misc 
+import qualified Language.Fixpoint.Misc                as Misc
+import qualified Language.Haskell.Liquid.Misc          as Misc
 import           Language.Fixpoint.Types               hiding (panic, Error, R, simplify)
 import qualified Language.Fixpoint.Types               as F
-import qualified Language.Haskell.Liquid.GHC.Misc      as GM
+import qualified Liquid.GHC.Misc      as GM
 
 
-import           Language.Haskell.Liquid.Bare.Types 
-import           Language.Haskell.Liquid.Bare.DataType 
+import           Language.Haskell.Liquid.Bare.Types
+import           Language.Haskell.Liquid.Bare.DataType
 import           Language.Haskell.Liquid.Bare.Misc     (simpleSymbolVar)
-import           Language.Haskell.Liquid.GHC.Play
+import           Liquid.GHC.Play
 import           Language.Haskell.Liquid.Types.Types   --     hiding (GhcInfo(..), GhcSpec (..), LM)
 import           Language.Haskell.Liquid.Types.RefType
 
@@ -73,8 +76,8 @@
     isErasable     = if allowTC then isEmbeddedClass else isClassType
     f              = dummyLoc (symbol v)
     t              = ofType (GM.expandVarType v) :: SpecType
-    mkA            = EVar . fst 
-    mkR            = if isBool res then propReft else exprReft 
+    mkA            = EVar . fst
+    mkR            = if isBool res then propReft else exprReft
 
 -- | Refine types of measures: keep going until you find the last data con!
 --   this code is a hack! we refine the last data constructor,
@@ -85,16 +88,16 @@
 
 -- formerly: strengthenResult'
 measureSpecType :: Bool -> Var -> SpecType
-measureSpecType allowTC v = go mkT [] [1..] t
-  where 
-    mkR | boolRes   = propReft 
-        | otherwise = exprReft  
+measureSpecType allowTC v = go mkT [] [(1::Int)..] t
+  where
+    mkR | boolRes   = propReft
+        | otherwise = exprReft
     mkT xs          = MkUReft (mkR $ mkEApp f (EVar <$> reverse xs)) mempty
-    f               = dummyLoc (symbol v) 
+    f               = dummyLoc (symbol v)
     t               = ofType (GM.expandVarType v) :: SpecType
-    boolRes         =  isBool $ ty_res $ toRTypeRep t 
+    boolRes         =  isBool $ ty_res $ toRTypeRep t
 
-    go f args i (RAllT a t r)    = RAllT a (go f args i t) r 
+    go f args i (RAllT a t r)    = RAllT a (go f args i t) r
     go f args i (RAllP p t)      = RAllP p $ go f args i t
     go f args i (RFun x ii t1 t2 r)
      | (if allowTC then isEmbeddedClass else isClassType) t1           = RFun x ii t1 (go f args i t2) r
@@ -106,21 +109,21 @@
     hasRApps (RFun _ _ t1 t2 _) = hasRApps t1 || hasRApps t2
     hasRApps RApp {}          = True
     hasRApps _                = False
-    
-   
+
+
 -- | 'weakenResult foo t' drops the singleton constraint `v = foo x y` 
 --   that is added, e.g. for measures in /strengthenResult'. 
 --   This should only be used _when_ checking the body of 'foo' 
 --   where the output, is, by definition, equal to the singleton.
-weakenResult :: Bool -> Var -> SpecType -> SpecType 
+weakenResult :: Bool -> Var -> SpecType -> SpecType
 weakenResult allowTC v t = F.notracepp msg t'
-  where 
+  where
     msg          = "weakenResult v =" ++ GM.showPpr v ++ " t = " ++ showpp t
-    t'           = fromRTypeRep $ rep { ty_res = mapExprReft weaken (ty_res rep) } 
+    t'           = fromRTypeRep $ rep { ty_res = mapExprReft weaken (ty_res rep) }
     rep          = toRTypeRep t
-    weaken x     = pAnd . filter ((Just vE /=) . isSingletonExpr x) . conjuncts 
+    weaken x     = pAnd . filter ((Just vE /=) . isSingletonExpr x) . conjuncts
     vE           = mkEApp vF xs
-    xs           = EVar . fst <$> dropWhile ((if allowTC then isEmbeddedClass else isClassType) . snd) xts 
+    xs           = EVar . fst <$> dropWhile ((if allowTC then isEmbeddedClass else isClassType) . snd) xts
     xts          = zip (ty_binds rep) (ty_args rep)
     vF           = dummyLoc (symbol v)
 
@@ -136,7 +139,7 @@
 
 throw :: String -> LogicM a
 throw str = do
-  fmkError  <- lsError <$> get
+  fmkError  <- gets lsError
   throwError $ fmkError str
 
 getState :: LogicM LState
@@ -159,17 +162,17 @@
       , lsDCMap  = dm
       }
 
-coreAltToDef :: (Reftable r) => Bool -> LocSymbol -> Var -> [Var] -> Var -> Type -> [C.CoreAlt] 
+coreAltToDef :: (Reftable r) => Bool -> LocSymbol -> Var -> [Var] -> Var -> Type -> [C.CoreAlt]
              -> LogicM [Def (Located (RRType r)) DataCon]
-coreAltToDef allowTC x z zs y t alts  
-  | not (null litAlts) = measureFail x "Cannot lift definition with literal alternatives" 
-  | otherwise          = do 
-      d1s <- F.notracepp "coreAltDefs-1" <$> mapM (mkAlt x cc myArgs z) dataAlts 
-      d2s <- F.notracepp "coreAltDefs-2" <$>       mkDef x cc myArgs z  defAlts defExpr 
+coreAltToDef allowTC x z zs y t alts
+  | not (null litAlts) = measureFail x "Cannot lift definition with literal alternatives"
+  | otherwise          = do
+      d1s <- F.notracepp "coreAltDefs-1" <$> mapM (mkAlt x cc myArgs z) dataAlts
+      d2s <- F.notracepp "coreAltDefs-2" <$>       mkDef x cc myArgs z  defAlts defExpr
       return (d1s ++ d2s)
-  where 
+  where
     myArgs   = reverse zs
-    cc       = if eqType t boolTy then P else E 
+    cc       = if eqType t boolTy then P else E
     defAlts  = GM.defaultDataCons (GM.expandVarType y) (Misc.fst3 <$> alts)
     defExpr  = listToMaybe [ e |   (C.DEFAULT  , _, e) <- alts ]
     dataAlts =             [ a | a@(C.DataAlt _, _, _) <- alts ]
@@ -177,29 +180,29 @@
 
     -- mkAlt :: LocSymbol -> (Expr -> Body) -> [Var] -> Var -> (C.AltCon, [Var], C.CoreExpr)
     mkAlt x ctor _args dx (C.DataAlt d, xs, e)
-      = Def x {- (toArgs id args) -} d (Just $ varRType dx) (toArgs Just xs') 
-      . ctor 
-      . (`subst1` (F.symbol dx, F.mkEApp (GM.namedLocSymbol d) (F.eVar <$> xs'))) 
+      = Def x {- (toArgs id args) -} d (Just $ varRType dx) (toArgs Just xs')
+      . ctor
+      . (`subst1` (F.symbol dx, F.mkEApp (GM.namedLocSymbol d) (F.eVar <$> xs')))
      <$> coreToLg allowTC e
       where xs' = filter (not . if allowTC then GM.isEmbeddedDictVar else GM.isEvVar) xs
-    mkAlt _ _ _ _ alt 
+    mkAlt _ _ _ _ alt
       = throw $ "Bad alternative" ++ GM.showPpr alt
 
-    mkDef x ctor _args dx (Just dtss) (Just e) = do  
+    mkDef x ctor _args dx (Just dtss) (Just e) = do
       eDef   <- ctor <$> coreToLg allowTC e
       -- let ys  = toArgs id args
       let dxt = Just (varRType dx)
       return  [ Def x {- ys -} d dxt (defArgs x ts) eDef | (d, _, ts) <- dtss ]
-    
-    mkDef _ _ _ _ _ _ = 
-      return [] 
 
+    mkDef _ _ _ _ _ _ =
+      return []
+
 toArgs :: Reftable r => (Located (RRType r) -> b) -> [Var] -> [(Symbol, b)]
 toArgs f args = [(symbol x, f $ varRType x) | x <- args]
 
 defArgs :: Monoid r => LocSymbol -> [Type] -> [(Symbol, Maybe (Located (RRType r)))]
-defArgs x     = zipWith (\i t -> (defArg i, defRTyp t)) [0..] 
-  where 
+defArgs x     = zipWith (\i t -> (defArg i, defRTyp t)) [0..]
+  where
     defArg    = tempSymbol (val x)
     defRTyp   = Just . F.atLoc x . ofType
 
@@ -209,28 +212,28 @@
   where
     go args   (C.Lam  x e)        = go (x:args) e
     go args   (C.Tick _ e)        = go args e
-    go (z:zs) (C.Case _ y t alts) = coreAltToDef allowTC x z zs y t alts 
-    go (z:zs) e                   
+    go (z:zs) (C.Case _ y t alts) = coreAltToDef allowTC x z zs y t alts
+    go (z:zs) e
       | Just t <- isMeasureArg z  = coreAltToDef allowTC x z zs z t [(C.DEFAULT, [], e)]
-    go _ _                        = measureFail x "Does not have a case-of at the top-level" 
+    go _ _                        = measureFail x "Does not have a case-of at the top-level"
 
     inlinePreds   = inline (eqType boolTy . GM.expandVarType)
 
 measureFail       :: LocSymbol -> String -> a
-measureFail x msg = panic sp e 
-  where 
+measureFail x msg = panic sp e
+  where
     sp            = Just (GM.fSrcSpan x)
     e             = Printf.printf "Cannot create measure '%s': %s" (F.showpp x) msg
-    
 
+
 -- | 'isMeasureArg x' returns 'Just t' if 'x' is a valid argument for a measure.
-isMeasureArg :: Var -> Maybe Type 
-isMeasureArg x 
-  | Just tc <- tcMb 
-  , Ghc.isAlgTyCon tc = F.notracepp "isMeasureArg" $ Just t 
-  | otherwise           = Nothing 
-  where 
-    t                   = GM.expandVarType x  
+isMeasureArg :: Var -> Maybe Type
+isMeasureArg x
+  | Just tc <- tcMb
+  , Ghc.isAlgTyCon tc = F.notracepp "isMeasureArg" $ Just t
+  | otherwise           = Nothing
+  where
+    t                   = GM.expandVarType x
     tcMb                = tyConAppTyCon_maybe t
 
 
@@ -246,8 +249,8 @@
     go acc (C.Lam x e)  = go (x:acc) e
     go acc (C.Tick _ e) = go acc e
     go acc e            = (reverse acc,) . Right <$> coreToLg allowTC e
-    
 
+
 instance Show C.CoreExpr where
   show = GM.showPpr
 
@@ -257,20 +260,16 @@
 
 coreToLg :: Bool -> C.CoreExpr -> LogicM Expr
 coreToLg allowTC  (C.Let (C.NonRec x (C.Coercion c)) e)
-  = coreToLg allowTC (C.substExpr
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
-                      C.empty
-#endif
-                      (C.extendCvSubst C.emptySubst x c) e)
+  = coreToLg allowTC (C.substExpr (C.extendCvSubst C.emptySubst x c) e)
 coreToLg allowTC  (C.Let b e)
   = subst1 <$> coreToLg allowTC e <*>  makesub allowTC b
 coreToLg allowTC (C.Tick _ e)          = coreToLg allowTC e
 coreToLg allowTC (C.App (C.Var v) e)
   | ignoreVar v                = coreToLg allowTC e
-coreToLg allowTC (C.Var x)
+coreToLg _allowTC (C.Var x)
   | x == falseDataConId        = return PFalse
   | x == trueDataConId         = return PTrue
-  | otherwise                  = (lsSymMap <$> getState) >>= eVarWithMap x
+  | otherwise                  = getState >>= eVarWithMap x . lsSymMap
 coreToLg allowTC e@(C.App _ _)         = toPredApp allowTC e
 coreToLg allowTC (C.Case e b _ alts)
   | eqType (GM.expandVarType b) boolTy  = checkBoolAlts alts >>= coreToIte allowTC e
@@ -290,7 +289,7 @@
 coreToLg True (C.Lam x e) = do p     <- coreToLg True e
                                tce   <- lsEmb <$> getState
                                return $ ELam (symbol x, typeSort tce (GM.expandVarType x)) p
-coreToLg _ e@(C.Lam _ _)        = throw ("Cannot transform lambda abstraction to Logic:\t" ++ GM.showPpr e ++ 
+coreToLg _ e@(C.Lam _ _)        = throw ("Cannot transform lambda abstraction to Logic:\t" ++ GM.showPpr e ++
                                             "\n\n Try using a helper function to remove the lambda.")
 coreToLg _ e                     = throw ("Cannot transform to Logic:\t" ++ GM.showPpr e)
 
@@ -338,19 +337,19 @@
 checkDataAlt :: C.AltCon -> Expr -> LogicM Expr
 checkDataAlt (C.DataAlt d) e = return $ EApp (EVar (makeDataConChecker d)) e
 checkDataAlt C.DEFAULT     _ = return PTrue
-checkDataAlt (C.LitAlt l)  e 
-  | Just le <- mkLit l       = return (EEq le e)  
+checkDataAlt (C.LitAlt l)  e
+  | Just le <- mkLit l       = return (EEq le e)
   | otherwise                = throw $ "Oops, not yet handled: checkDataAlt on Lit: " ++ GM.showPpr l
 
 -- | 'altsDefault' reorders the CoreAlt to ensure that 'DEFAULT' is at the end.
 normalizeAlts :: [C.CoreAlt] -> [C.CoreAlt]
-normalizeAlts alts      = ctorAlts ++ defAlts 
-  where 
-    (defAlts, ctorAlts) = L.partition isDefault alts 
-    isDefault (c,_,_)   = c == C.DEFAULT 
+normalizeAlts alts      = ctorAlts ++ defAlts
+  where
+    (defAlts, ctorAlts) = L.partition isDefault alts
+    isDefault (c,_,_)   = c == C.DEFAULT
 
 altToLg :: Bool -> Expr -> C.CoreAlt -> LogicM (C.AltCon, Expr)
-altToLg allowTC de (a@(C.DataAlt d), xs, e) = do 
+altToLg allowTC de (a@(C.DataAlt d), xs, e) = do
   p  <- coreToLg allowTC e
   dm <- gets lsDCMap
   let su = mkSubst $ concat [ dataConProj dm de d x i | (x, i) <- zip (filter (not . if allowTC then GM.isEmbeddedDictVar else GM.isEvVar) xs) [1..]]
@@ -362,10 +361,10 @@
 dataConProj :: DataConMap -> Expr -> DataCon -> Var -> Int -> [(Symbol, Expr)]
 dataConProj dm de d x i = [(symbol x, t), (GM.simplesymbol x, t)]
   where
-    t | primDataCon  d  = de 
+    t | primDataCon  d  = de
       | otherwise       = EApp (EVar $ makeDataConSelector (Just dm) d i) de
 
-primDataCon :: DataCon -> Bool 
+primDataCon :: DataCon -> Bool
 primDataCon d = d == intDataCon
 
 coreToIte :: Bool -> C.CoreExpr -> (C.CoreExpr, C.CoreExpr) -> LogicM Expr
@@ -403,15 +402,15 @@
       = PAnd . deList <$> coreToLg allowTC es
     go (_, _)
       = toLogicApp allowTC p
-    
+
     deList :: Expr -> [Expr]
     deList (EApp (EApp (EVar cons) e) es)
       | cons == symbol ("GHC.Types.:" :: String)
-      = e:deList es 
+      = e:deList es
     deList (EVar nil)
       | nil == symbol ("GHC.Types.[]" :: String)
-      = [] 
-    deList e 
+      = []
+    deList e
       = [e]
 
 toLogicApp :: Bool -> C.CoreExpr -> LogicM Expr
@@ -421,7 +420,7 @@
     C.Var _ -> do args <- mapM (coreToLg allowTC) es
                   lmap <- lsSymMap <$> getState
                   def  <- (`mkEApp` args) <$> tosymbol f
-                  ((\x -> makeApp def lmap x args) <$> (tosymbol' f))
+                  (\x -> makeApp def lmap x args) <$> tosymbol' f
     _       -> do fe   <- coreToLg allowTC f
                   args <- mapM (coreToLg allowTC) es
                   return $ foldl EApp fe args
@@ -519,7 +518,7 @@
     _      -> throw ("Bad Measure Definition:\n" ++ GM.showPpr e ++ "\t cannot be applied")
 
 tosymbol' :: C.CoreExpr -> LogicM (Located Symbol)
-tosymbol' (C.Var x) = return $ dummyLoc $ symbol x 
+tosymbol' (C.Var x) = return $ dummyLoc $ symbol x
 tosymbol' e        = throw ("Bad Measure Definition:\n" ++ GM.showPpr e ++ "\t cannot be applied")
 
 makesub :: Bool -> C.CoreBind -> LogicM (Symbol, Expr)
@@ -535,7 +534,7 @@
 mkLit (LitFloat  n)    = mkR n
 mkLit (LitDouble n)    = mkR n
 mkLit (LitString    s)    = mkS s
-mkLit (LitChar   c)    = mkC c 
+mkLit (LitChar   c)    = mkC c
 mkLit _                 = Nothing -- ELit sym sort
 
 mkI :: Integer -> Maybe Expr
@@ -548,9 +547,9 @@
 mkS                    = Just . ESym . SL  . decodeUtf8With lenientDecode
 
 mkC :: Char -> Maybe Expr
-mkC                    = Just . ECon . (`F.L` F.charSort)  . repr 
-  where 
-    repr               = T.pack . show . Data.Char.ord 
+mkC                    = Just . ECon . (`F.L` F.charSort)  . repr
+  where
+    repr               = T.pack . show . Data.Char.ord
 
 ignoreVar :: Id -> Bool
 ignoreVar i = simpleSymbolVar i `elem` ["I#", "D#"]
@@ -566,18 +565,18 @@
 isBangInteger _ = False
 
 isErasable :: Id -> Bool
-isErasable v = F.notracepp msg $ isGhcSplId v && not (isDCId v) 
-  where 
+isErasable v = F.notracepp msg $ isGhcSplId v && not (isDCId v)
+  where
     msg      = "isErasable: " ++ GM.showPpr (v, Ghc.idDetails v)
 
 isGhcSplId :: Id -> Bool
 isGhcSplId v = isPrefixOfSym (symbol ("$" :: String)) (simpleSymbolVar v)
 
 isDCId :: Id -> Bool
-isDCId v = case Ghc.idDetails v of 
-  DataConWorkId _ -> True 
-  DataConWrapId _ -> True 
-  _               -> False 
+isDCId v = case Ghc.idDetails v of
+  DataConWorkId _ -> True
+  DataConWrapId _ -> True
+  _               -> False
 
 isANF :: Id -> Bool
 isANF      v = isPrefixOfSym (symbol ("lq_anf" :: String)) (simpleSymbolVar v)
@@ -621,7 +620,8 @@
   simplify allowTC (C.Let xes e)
     = C.Let (simplify allowTC xes) (simplify allowTC e)
   simplify allowTC (C.Case e x _t alts@[(_,_,ee),_,_]) | isBangInteger alts
-    = Misc.traceShow ("To simplify allowTC case") $ 
+  -- XXX(matt): seems to be for debugging?
+    = -- Misc.traceShow ("To simplify allowTC case") $ 
        sub (M.singleton x (simplify allowTC e)) (simplify allowTC ee)
   simplify allowTC (C.Case e x t alts)
     = C.Case (simplify allowTC e) x t (filter (not . isUndefined) (simplify allowTC <$> alts))
@@ -651,7 +651,7 @@
 isUndefined (_, _, e) = isUndefinedExpr e
   where
    -- auto generated undefined case: (\_ -> (patError @type "error message")) void
-   isUndefinedExpr (C.App (C.Var x) _) | (show x) `elem` perrors = True
+   isUndefinedExpr (C.App (C.Var x) _) | show x `elem` perrors = True
    isUndefinedExpr (C.Let _ e) = isUndefinedExpr e
    -- otherwise
    isUndefinedExpr _ = False
diff --git a/src/Language/Haskell/Liquid/Transforms/InlineAux.hs b/src/Language/Haskell/Liquid/Transforms/InlineAux.hs
--- a/src/Language/Haskell/Liquid/Transforms/InlineAux.hs
+++ b/src/Language/Haskell/Liquid/Transforms/InlineAux.hs
@@ -1,26 +1,18 @@
-{-# LANGUAGE CPP              #-}
 {-# LANGUAGE FlexibleContexts #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Transforms.InlineAux
   ( inlineAux
   )
 where
 import qualified Language.Haskell.Liquid.UX.Config  as UX
-import           Language.Haskell.Liquid.GHC.API
+import           Liquid.GHC.API
 import           Control.Arrow                  (second)
-import qualified Language.Haskell.Liquid.GHC.Misc
+import qualified Liquid.GHC.Misc
                                                as GM
 import qualified Data.HashMap.Strict           as M
-import           Data.Functor.Foldable
 
-buildDictSubst :: CoreProgram -> M.HashMap Id CoreExpr
-buildDictSubst = cata f
- where
-  f Nil = M.empty
-  f (Cons b s) | NonRec x e <- b, isDFunId x || isDictonaryId x = M.insert x e s
-               | otherwise = s
-
-
 inlineAux :: UX.Config -> Module -> CoreProgram -> CoreProgram
 inlineAux cfg m cbs =  if UX.auxInline cfg then occurAnalysePgm m (const False) (const False) [] (map f cbs) else cbs
  where
@@ -56,44 +48,6 @@
 --   go recs = pure recs
 --   subst = buildDictSubst cbs
 
-
-
-lookupIdSubstAll :: SDoc -> M.HashMap Id CoreExpr -> Id -> CoreExpr
-lookupIdSubstAll doc env v | Just e <- M.lookup v env = e
-                           | otherwise                = Var v
-
-
-substExprAll :: SDoc -> M.HashMap Id CoreExpr -> CoreExpr -> CoreExpr
-substExprAll doc subst orig_expr = subst_expr_all doc subst orig_expr
-
-
-subst_expr_all :: SDoc -> M.HashMap Id CoreExpr -> CoreExpr -> CoreExpr
-subst_expr_all doc subst expr = go expr
- where
-  go (Var v) = lookupIdSubstAll (doc $$ text "subst_expr_all") subst v
-  go (Type     ty      ) = Type ty
-  go (Coercion co      ) = Coercion co
-  go (Lit      lit     ) = Lit lit
-  go (App  fun     arg ) = App (go fun) (go arg)
-  go (Tick tickish e   ) = Tick tickish (go e)
-  go (Cast e       co  ) = Cast (go e) co
-     -- Do not optimise even identity coercions
-     -- Reason: substitution applies to the LHS of RULES, and
-     --         if you "optimise" an identity coercion, you may
-     --         lose a binder. We optimise the LHS of rules at
-     --         construction time
-
-  go (Lam  bndr    body) = Lam bndr (subst_expr_all doc subst body)
-
-  go (Let  bind    body) = Let (mapBnd go bind) (subst_expr_all doc subst body)
-
-  go (Case scrut bndr ty alts) =
-    Case (go scrut) bndr ty (map (go_alt subst) alts)
-
-  go_alt subst (con, bndrs, rhs) = (con, bndrs, subst_expr_all doc subst rhs)
-
-
-
 -- grab the dictionaries
 grepDFunIds :: CoreProgram -> [(DFunId, CoreExpr)]
 grepDFunIds = filter (isDFunId . fst) . flattenBinds
@@ -123,12 +77,8 @@
   go :: CoreExpr -> CoreExpr
   go (Lam b body) = Lam b (go body)
   go (Let b body)
-    | NonRec x e <- b, isDictId x = go
-     $ substExpr
-#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)     
-        empty
-#endif
-        (extendIdSubst emptySubst x e) body
+    | NonRec x e <- b, isDictId x =
+        go $ substExpr (extendIdSubst emptySubst x e) body
     | otherwise = Let (mapBnd go b) (go body)
   go (Case e x t alts) = Case (go e) x t (fmap (mapAlt go) alts)
   go (Cast e c       ) = Cast (go e) c
diff --git a/src/Language/Haskell/Liquid/Transforms/Rec.hs b/src/Language/Haskell/Liquid/Transforms/Rec.hs
--- a/src/Language/Haskell/Liquid/Transforms/Rec.hs
+++ b/src/Language/Haskell/Liquid/Transforms/Rec.hs
@@ -1,11 +1,10 @@
-{-# LANGUAGE DeriveDataTypeable        #-}
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE ScopedTypeVariables       #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Transforms.Rec (
      transformRecExpr, transformScope
      , outerScTr , innerScTr
@@ -16,9 +15,9 @@
 import           Control.Monad.State
 import qualified Data.HashMap.Strict                  as M
 import           Data.Hashable
-import           Language.Haskell.Liquid.GHC.API      as Ghc hiding (panic, mapSndM)
-import           Language.Haskell.Liquid.GHC.Misc
-import           Language.Haskell.Liquid.GHC.Play
+import           Liquid.GHC.API      as Ghc hiding (panic, mapSndM)
+import           Liquid.GHC.Misc
+import           Liquid.GHC.Play
 import           Language.Haskell.Liquid.Misc         (mapSndM)
 import           Language.Fixpoint.Misc               (mapSnd) -- , traceShow)
 import           Language.Haskell.Liquid.Types.Errors
@@ -33,7 +32,7 @@
   -- TODO-REBARE weird GHC crash on Data/Text/Array.hs = pg
   -- TODO-REBARE weird GHC crash on Data/Text/Array.hs | otherwise
   -- TODO-REBARE weird GHC crash on Data/Text/Array.hs = panic Nothing ("Type-check" ++ showSDoc (pprMessageBag e))
-  where 
+  where
     pg     = inlineFailCases pg0
     pg0    = evalState (transPg (inlineLoopBreaker <$> cbs)) initEnv
     -- (_, e) = lintCoreBindings [] pg
@@ -47,7 +46,7 @@
   where
     (αs, as, be) = collectTyAndValBinders e
 
-    e' = L.foldl' App (L.foldl' App (Var x) ((Type . TyVarTy) <$> αs)) (Var <$> as)
+    e' = L.foldl' App (L.foldl' App (Var x) (Type . TyVarTy <$> αs)) (Var <$> as)
 
     hasLoopBreaker (Let (Rec [(x1, e1)]) (Var x2)) | isLoopBreaker x1 && x1 == x2 = Just (x1, e1)
     hasLoopBreaker _                               = Nothing
@@ -76,7 +75,7 @@
 
     goalt su (c, xs, e)     = (c, xs, go' su e)
 
-    isFailId x  = isLocalId x && (isSystemName $ varName x) && L.isPrefixOf "fail" (show x)
+    isFailId x  = isLocalId x && isSystemName (varName x) && L.isPrefixOf "fail" (show x)
     getFailExpr = L.lookup
 
     addFailExpr x (Lam _ e) su = (x, e):su
@@ -88,7 +87,7 @@
 
 -- No need for this transformation after ghc-8!!!
 transformScope :: [Bind Id] -> [Bind Id]
-transformScope = outerScTr . innerScTr 
+transformScope = outerScTr . innerScTr
 
 outerScTr :: [Bind Id] -> [Bind Id]
 outerScTr = mapNonRec (go [])
@@ -126,12 +125,12 @@
 
 transBd :: Bind CoreBndr
         -> State TrEnv (Bind CoreBndr)
-transBd (NonRec x e) = liftM (NonRec x) (transExpr =<< mapBdM transBd e)
-transBd (Rec xes)    = liftM Rec $ mapM (mapSndM (mapBdM transBd)) xes
+transBd (NonRec x e) = fmap (NonRec x) (transExpr =<< mapBdM transBd e)
+transBd (Rec xes)    = Rec <$> mapM (mapSndM (mapBdM transBd)) xes
 
 transExpr :: CoreExpr -> TE CoreExpr
 transExpr e
-  | (isNonPolyRec e') && (not (null tvs))
+  | isNonPolyRec e' && not (null tvs)
   = trans tvs ids bs e'
   | otherwise
   = return e
@@ -160,12 +159,12 @@
       -> Expr Var
       -> State TrEnv (Expr Id)
 trans vs ids bs (Let (Rec xes) e)
-  = liftM (mkLam . mkLet) (makeTrans vs liveIds e')
+  = fmap (mkLam . mkLet) (makeTrans vs liveIds e')
   where liveIds = mkAlive <$> ids
         mkLet e = foldr Let e bs
         mkLam e = foldr Lam e $ vs ++ liveIds
         e'      = Let (Rec xes') e
-        xes'    = (second mkLet) <$> xes
+        xes'    = second mkLet <$> xes
 
 trans _ _ _ _ = panic Nothing "TransformRec.trans called with invalid input"
 
@@ -197,7 +196,7 @@
 mkSubs :: (Eq k, Hashable k)
        => [k] -> [Var] -> [Id] -> [(k, Id)] -> M.HashMap k (Expr b)
 mkSubs ids tvs xs ys = M.fromList $ s1 ++ s2
-  where s1 = (second (appTysAndIds tvs xs)) <$> ys
+  where s1 = second (appTysAndIds tvs xs) <$> ys
         s2 = zip ids (Var <$> xs)
 
 mkFreshIds :: [TyVar]
@@ -245,7 +244,7 @@
   fresh _ = freshUnique
 
 instance Freshable Var where
-  fresh v = liftM (setVarUnique v) freshUnique
+  fresh v = fmap (setVarUnique v) freshUnique
 
 freshInt :: MonadState TrEnv m => m Int
 freshInt
@@ -255,7 +254,7 @@
        return n
 
 freshUnique :: MonadState TrEnv m => m Unique
-freshUnique = liftM (mkUnique 'X') freshInt
+freshUnique = fmap (mkUnique 'X') freshInt
 
 
 mapNonRec :: (b -> [Bind b] -> [Bind b]) -> [Bind b] -> [Bind b]
diff --git a/src/Language/Haskell/Liquid/Transforms/RefSplit.hs b/src/Language/Haskell/Liquid/Transforms/RefSplit.hs
--- a/src/Language/Haskell/Liquid/Transforms/RefSplit.hs
+++ b/src/Language/Haskell/Liquid/Transforms/RefSplit.hs
@@ -1,6 +1,9 @@
 {-# LANGUAGE FlexibleInstances    #-}
 {-# LANGUAGE UndecidableInstances #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Transforms.RefSplit (
 
         splitXRelatedRefs
diff --git a/src/Language/Haskell/Liquid/Transforms/Rewrite.hs b/src/Language/Haskell/Liquid/Transforms/Rewrite.hs
--- a/src/Language/Haskell/Liquid/Transforms/Rewrite.hs
+++ b/src/Language/Haskell/Liquid/Transforms/Rewrite.hs
@@ -1,14 +1,14 @@
-{-# LANGUAGE CPP                       #-}
 {-# LANGUAGE OverloadedStrings         #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE GADTs                     #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE RankNTypes                #-}
 {-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE UndecidableInstances      #-}
 {-# LANGUAGE FlexibleContexts          #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- | This module contains functions for recursively "rewriting"
 --   GHC core using "rules".
 
@@ -24,16 +24,16 @@
 
   ) where
 
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding (showPpr, substExpr)
-import           Language.Haskell.Liquid.GHC.TypeRep ()
+import           Liquid.GHC.API as Ghc hiding (showPpr, substExpr)
+import           Liquid.GHC.TypeRep ()
 import           Data.Maybe     (fromMaybe)
 import           Control.Monad.State hiding (lift)
 import           Language.Fixpoint.Misc       ({- mapFst, -}  mapSnd)
 import qualified          Language.Fixpoint.Types as F
 import           Language.Haskell.Liquid.Misc (safeZipWithError, mapThd3, Nat)
-import           Language.Haskell.Liquid.GHC.Play (substExpr)
-import           Language.Haskell.Liquid.GHC.Resugar
-import           Language.Haskell.Liquid.GHC.Misc (unTickExpr, isTupleId, showPpr, mkAlive) -- , showPpr, tracePpr)
+import           Liquid.GHC.Play (substExpr)
+import           Liquid.GHC.Resugar
+import           Liquid.GHC.Misc (unTickExpr, isTupleId, showPpr, mkAlive) -- , showPpr, tracePpr)
 import           Language.Haskell.Liquid.UX.Config  (Config, noSimplifyCore)
 import qualified Data.List as L
 import qualified Data.HashMap.Strict as M
@@ -43,14 +43,65 @@
 --------------------------------------------------------------------------------
 rewriteBinds :: Config -> [CoreBind] -> [CoreBind]
 rewriteBinds cfg
-  | simplifyCore cfg 
-  = fmap (normalizeTuples . rewriteBindWith tidyTuples . rewriteBindWith simplifyPatTuple)
-  | otherwise        
+  | simplifyCore cfg
+  = fmap (normalizeTuples 
+       . rewriteBindWith undollar 
+       . rewriteBindWith tidyTuples 
+       . rewriteBindWith simplifyPatTuple)
+  | otherwise
   = id
 
 simplifyCore :: Config -> Bool
 simplifyCore = not . noSimplifyCore
 
+undollar :: RewriteRule
+undollar = go 
+  where 
+    go e 
+     -- matches `$ t1 t2 t3 f a`  
+     | App e1 a  <- untick e
+     , App e2 f  <- untick e1
+     , App e3 t3 <- untick e2 
+     , App e4 t2 <- untick e3 
+     , App d t1  <- untick e4 
+     , Var v     <- untick d 
+     , v `hasKey` dollarIdKey
+     , Type _    <- untick t1
+     , Type _    <- untick t2
+     , Type _    <- untick t3
+     = Just $ App f a 
+    go (Tick t e)
+      = Tick t <$> go e
+    go (Let (NonRec x ex) e)
+      = do ex' <- go ex
+           e'  <- go e
+           return $ Let (NonRec x ex') e'
+    go (Let (Rec bes) e)
+      = Let <$> (Rec <$> mapM goRec bes) <*> go e
+    go (Case e x t alts)
+      = Case e x t <$> mapM goAlt alts
+    go (App e1 e2)
+      = App <$> go e1 <*> go e2
+    go (Lam x e)
+      = Lam x <$> go e
+    go (Cast e c)
+      = (`Cast` c) <$> go e
+    go e
+      = return e
+
+    goRec (x, e)
+      = (x,) <$> go e
+
+    goAlt (c, bs, e)
+      = (c, bs,) <$> go e
+
+  
+ 
+
+untick :: CoreExpr -> CoreExpr 
+untick (Tick _ e) = untick e 
+untick e          = e 
+
 tidyTuples :: RewriteRule
 tidyTuples e = Just $ evalState (go e) []
   where
@@ -87,23 +138,23 @@
             Just bs' -> return (c, bs', substTuple bs' bs e)
             Nothing  -> do let bs' = mkAlive <$> bs
                            modify (((c,v),bs'):)
-                           return $ (c, bs', e)
+                           return (c, bs', e)
 
 
 
 normalizeTuples :: CoreBind -> CoreBind
-normalizeTuples b 
-  | NonRec x e <- b 
-  = NonRec x $ go e 
-  | Rec xes <- b 
-  = let (xs,es) = unzip xes in 
-    Rec $ zip xs (go <$> es) 
-  where 
+normalizeTuples b
+  | NonRec x e <- b
+  = NonRec x $ go e
+  | Rec xes <- b
+  = let (xs,es) = unzip xes in
+    Rec $ zip xs (go <$> es)
+  where
     go (Let (NonRec x ex) e)
-      | Case _ _ _ alts  <- unTickExpr ex 
-      , [(_, vs, Var z)] <- alts 
+      | Case _ _ _ alts  <- unTickExpr ex
+      , [(_, vs, Var z)] <- alts
       , z `elem` vs
-      = Let (NonRec z (go ex)) (substTuple [z] [x] (go e)) 
+      = Let (NonRec z (go ex)) (substTuple [z] [x] (go e))
     go (Let (NonRec x ex) e)
       = Let (NonRec x (go ex)) (go e)
     go (Let (Rec xes) e)
@@ -115,17 +166,17 @@
     go (Case e b t alt)
       = Case (go e) b t (mapThd3 go <$> alt)
     go (Cast e c)
-      = Cast (go e) c 
+      = Cast (go e) c
     go (Tick t e)
       = Tick t (go e)
     go (Type t)
-      = Type t 
+      = Type t
     go (Coercion c)
       = Coercion c
     go (Lit l)
-      = Lit l 
+      = Lit l
     go (Var x)
-      = Var x 
+      = Var x
 
 
 --------------------------------------------------------------------------------
@@ -250,7 +301,7 @@
 
 _tidyAlt n (Just (Let (NonRec x e) rest))
   | Just (yes, e') <- takeBinds n rest
-  = Just $ Let (NonRec x e) $ foldl (\e (x, ex) -> Let (NonRec x ex) e) e' ((reverse $ go $ reverse yes))
+  = Just $ Let (NonRec x e) $ foldl (\e (x, ex) -> Let (NonRec x ex) e) e' (reverse $ go $ reverse yes)
 
   where
     go xes@((_, e):_) = let bs = grapBinds e in mapSnd (replaceBinds bs) <$> xes
@@ -312,8 +363,8 @@
 
 isProjection :: CoreExpr -> Bool
 isProjection e = case lift e of
-                   Just (PatProject {}) -> True
-                   _                    -> False
+                   Just PatProject{} -> True
+                   _                 -> False
 
 --------------------------------------------------------------------------------
 -- | `hasTuple ys e` CHECKS if `e` contains a tuple that "looks like" (y1...yn)
@@ -411,7 +462,7 @@
 isIrrefutErrorVar :: Var -> Bool
 -- isIrrefutErrorVar _x = False -- Ghc.iRREFUT_PAT_ERROR_ID == x -- TODO:GHC-863
 isIrrefutErrorVar x = x == Ghc.pAT_ERROR_ID
- 
+
 --------------------------------------------------------------------------------
 -- | `substTuple xs ys e'` returns e' [y1 := x1,...,yn := xn]
 --------------------------------------------------------------------------------
diff --git a/src/Language/Haskell/Liquid/Types/Bounds.hs b/src/Language/Haskell/Liquid/Types/Bounds.hs
--- a/src/Language/Haskell/Liquid/Types/Bounds.hs
+++ b/src/Language/Haskell/Liquid/Types/Bounds.hs
@@ -4,6 +4,8 @@
 {-# LANGUAGE DeriveDataTypeable #-}
 {-# LANGUAGE DeriveGeneric      #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Types.Bounds (
 
     Bound(..),
@@ -77,7 +79,7 @@
 makeBound (Bound _  vs ps xs p) ts qs
          = RRTy cts mempty OCons
   where
-    cts  = (\(x, t) -> (x, foldr subsTyVar_meet t su)) <$> cts'
+    cts  = (\(x, t) -> (x, foldr subsTyVarMeet t su)) <$> cts'
 
     cts' = makeBoundType penv rs xs
 
diff --git a/src/Language/Haskell/Liquid/Types/Dictionaries.hs b/src/Language/Haskell/Liquid/Types/Dictionaries.hs
--- a/src/Language/Haskell/Liquid/Types/Dictionaries.hs
+++ b/src/Language/Haskell/Liquid/Types/Dictionaries.hs
@@ -1,6 +1,5 @@
 {-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleContexts     #-}
-{-# LANGUAGE TupleSections        #-}
 module Language.Haskell.Liquid.Types.Dictionaries (
     makeDictionaries
   , makeDictionary
@@ -19,8 +18,8 @@
 import           Prelude                                   hiding (error)
 import qualified Language.Fixpoint.Types as F
 import           Language.Haskell.Liquid.Types.PrettyPrint ()
-import qualified Language.Haskell.Liquid.GHC.Misc       as GM 
-import qualified Language.Haskell.Liquid.GHC.API        as Ghc
+import qualified Liquid.GHC.Misc       as GM
+import qualified Liquid.GHC.API        as Ghc
 import           Language.Haskell.Liquid.Types.Types
 -- import           Language.Haskell.Liquid.Types.Visitors (freeVars)
 import           Language.Haskell.Liquid.Types.RefType ()
@@ -42,7 +41,7 @@
 makeDictionaryName t ts
   = F.notracepp _msg $ F.symbol ("$f" ++ F.symbolString (val t) ++ concatMap mkName ts)
   where
-    mkName = makeDicTypeName sp . dropUniv . val 
+    mkName = makeDicTypeName sp . dropUniv . val
     sp     = GM.fSrcSpan t
     _msg   = "MAKE-DICTIONARY " ++ F.showpp (val t, ts)
 
@@ -51,13 +50,13 @@
 --   class resolution.
 
 makeDicTypeName :: Ghc.SrcSpan -> SpecType -> String
-makeDicTypeName _ (RFun _ _ _ _ _) = "(->)"
+makeDicTypeName _ RFun{}           = "(->)"
 makeDicTypeName _ (RApp c _ _ _)   = F.symbolString . GM.dropModuleNamesCorrect . F.symbol . rtc_tc $ c
-makeDicTypeName _ (RVar (RTV a) _) = show (Ghc.getName a)      
+makeDicTypeName _ (RVar (RTV a) _) = show (Ghc.getName a)
 makeDicTypeName sp t               = panic (Just sp) ("makeDicTypeName: called with invalid type " ++ show t)
 
-dropUniv :: SpecType -> SpecType 
-dropUniv t = t' where (_,_,t') = bkUniv t 
+dropUniv :: SpecType -> SpecType
+dropUniv t = t' where (_,_,t') = bkUniv t
 
 --------------------------------------------------------------------------------
 -- | Dictionary Environment ----------------------------------------------------
diff --git a/src/Language/Haskell/Liquid/Types/Equality.hs b/src/Language/Haskell/Liquid/Types/Equality.hs
--- a/src/Language/Haskell/Liquid/Types/Equality.hs
+++ b/src/Language/Haskell/Liquid/Types/Equality.hs
@@ -1,13 +1,14 @@
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- Syntactic Equality of Types up tp forall type renaming
 
 module Language.Haskell.Liquid.Types.Equality where 
 
 import qualified Language.Fixpoint.Types as F
 import           Language.Haskell.Liquid.Types
-import qualified Language.Haskell.Liquid.GHC.API as Ghc
+import qualified Liquid.GHC.API as Ghc
 
 import Control.Monad.Writer.Lazy
 -- import Control.Monad
@@ -19,7 +20,7 @@
 compareRType :: SpecType -> SpecType -> Bool 
 compareRType i1 i2 = res && unify vs   
   where 
-    unify vs = and (sndEq <$> (L.groupBy (\(x1,_) (x2,_) -> x1 == x2) vs)) 
+    unify vs = and (sndEq <$> L.groupBy (\(x1,_) (x2,_) -> x1 == x2) vs) 
     sndEq [] = True 
     sndEq [_] = True 
     sndEq ((_,y):xs) = all (==y) (snd <$> xs)
@@ -48,7 +49,7 @@
     go (RApp x1 ts1 ps1 r1) (RApp x2 ts2 ps2 r2)
       | x1 == x2 &&  
         r1 =*= r2 && and (zipWith (=*=) ps1 ps2) 
-      = and <$> (zipWithM go ts1 ts2)
+      = and <$> zipWithM go ts1 ts2
     go (RAllE x1 t11 t12) (RAllE x2 t21 t22) | x1 == x2 
       = liftM2 (&&) (go t11 t21) (go t12 t22) 
     go (REx x1 t11 t12) (REx x2 t21 t22) | x1 == x2
diff --git a/src/Language/Haskell/Liquid/Types/Errors.hs b/src/Language/Haskell/Liquid/Types/Errors.hs
--- a/src/Language/Haskell/Liquid/Types/Errors.hs
+++ b/src/Language/Haskell/Liquid/Types/Errors.hs
@@ -1,14 +1,13 @@
-{-# LANGUAGE ImplicitParams      #-}
-{-# LANGUAGE TupleSections       #-}
 {-# LANGUAGE FlexibleInstances   #-}
 {-# LANGUAGE OverloadedStrings   #-}
 {-# LANGUAGE DeriveGeneric       #-}
 {-# LANGUAGE DeriveDataTypeable  #-}
 {-# LANGUAGE DeriveFunctor       #-}
-{-# LANGUAGE OverloadedStrings   #-}
-{-# LANGUAGE DerivingStrategies  #-}
 {-# LANGUAGE DerivingVia         #-}
 
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+{-# OPTIONS_GHC -Wno-orphans #-} -- PPrint and aeson instances.
+
 -- | This module contains the *types* related creating Errors.
 --   It depends only on Fixpoint and basic haskell libraries,
 --   and hence, should be importable everywhere.
@@ -50,7 +49,7 @@
   , srcSpanFileMb
   ) where
 
-import           Prelude                      hiding (error)
+import           Prelude                      hiding (error, span)
 
 import           GHC.Generics
 import           Control.DeepSeq
@@ -69,7 +68,7 @@
 import           Text.PrettyPrint.HughesPJ
 import qualified Text.Megaparsec              as P
 
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding ( Expr
+import           Liquid.GHC.API as Ghc hiding ( Expr
                                                                , panicDoc
                                                                , ($+$)
                                                                , nest
@@ -86,6 +85,7 @@
                                                                , panic
                                                                , int
                                                                , hcat
+                                                               , spans
                                                                )
 import           Language.Fixpoint.Types      (pprint, showpp, Tidy (..), PPrint (..), Symbol, Expr, SubcId)
 import qualified Language.Fixpoint.Misc       as Misc
@@ -163,7 +163,7 @@
 makeContext _ _ _  []  = empty
 makeContext l c c' [s] = makeContext1 l c c' s
 makeContext l _ _  ss  = vcat $ text " "
-                              : (zipWith makeContextLine [l..] ss)
+                              : zipWith makeContextLine [l..] ss
                               ++ [ text " "
                                  , text " " ]
 
@@ -475,6 +475,12 @@
                 , msg :: !Doc
                 }
 
+  | ErrPosTyCon { pos  :: SrcSpan
+                , tc   :: !Doc
+                , dc   :: !Doc
+                }
+
+
   | ErrOther    { pos   :: SrcSpan
                 , msg   :: !Doc
                 } -- ^ Sigh. Other.
@@ -537,7 +543,7 @@
     hcat $ [ pathDoc <-> colon
            , int sline <-> colon
            , int scol
-           ] ++ if ecol - scol <= 1 then [] else [char '-' <-> int (ecol - 1)]
+           ] ++ [char '-' <-> int (ecol - 1) | (ecol - scol) > 1]
   | otherwise =
     hcat [ pathDoc <-> colon
          , parens (int sline <-> comma <-> int scol)
@@ -629,7 +635,7 @@
 
 ppContext :: PPrint t => Tidy -> M.HashMap Symbol t -> Doc
 ppContext td c
-  | 0 < length xts = nests 2 [ text "in the context"
+  | not (null xts) = nests 2 [ text "in the context"
                              , vsep (map (uncurry (pprintBind td)) xts)
                              ]
   | otherwise      = empty
@@ -640,7 +646,7 @@
 pprintBind td v t = pprintTidy td v <+> char ':' <+> pprintTidy td t
 
 ppReqModelInContext
-  :: (PPrint t) => Tidy -> WithModel t -> t -> (M.HashMap Symbol (WithModel t)) -> Doc
+  :: (PPrint t) => Tidy -> WithModel t -> t -> M.HashMap Symbol (WithModel t) -> Doc
 ppReqModelInContext td tA tE c
   = sepVcat blankLine
       [ nests 2 [ text "The inferred type"
@@ -718,9 +724,9 @@
 
 instance FromJSON SrcSpan where
   parseJSON (Object v) = do tag <- v .: "realSpan"
-                            case tag of
-                              False -> return noSrcSpan
-                              True  -> RealSrcSpan <$> v .: "spanInfo" <*> pure Nothing
+                            if tag
+                              then RealSrcSpan <$> v .: "spanInfo" <*> pure Nothing
+                              else return noSrcSpan
   parseJSON _          = mempty
 
 -- Default definition use ToJSON and FromJSON
@@ -728,8 +734,8 @@
 instance FromJSONKey SrcSpan
 
 instance (PPrint a, Show a) => ToJSON (TError a) where
-  toJSON e = object [ "pos" .= (pos e)
-                    , "msg" .= (render $ ppError' Full empty e)
+  toJSON e = object [ "pos" .= pos e
+                    , "msg" .= render (ppError' Full empty e)
                     ]
 
 instance FromJSON (TError a) where
@@ -759,7 +765,7 @@
 ppError' td dCtx (ErrAssType _ o _ c p)
   = pprintTidy td o
         $+$ dCtx
-        $+$ (ppFull td $ ppPropInContext td p c)
+        $+$ ppFull td (ppPropInContext td p c)
 
 ppError' td dCtx err@(ErrSubType _ _ _ _ _ tE)
   | totalityType td tE
@@ -779,28 +785,28 @@
 
 ppError' td dCtx (ErrSubType _ _ cid c tA tE)
   = text "Liquid Type Mismatch"
-    $+$ nest 4 
-          (blankLine 
+    $+$ nest 4
+          (blankLine
            $+$ dCtx
-           $+$ (ppFull td $ ppReqInContext td tA tE c)
+           $+$ ppFull td (ppReqInContext td tA tE c)
            $+$ maybe mempty (\i -> text "Constraint id" <+> text (show i)) cid)
 
 ppError' td dCtx (ErrSubTypeModel _ _ cid c tA tE)
   = text "Liquid Type Mismatch"
-    $+$ nest 4 
+    $+$ nest 4
           (dCtx
-          $+$ (ppFull td $ ppReqModelInContext td tA tE c)
+          $+$ ppFull td (ppReqModelInContext td tA tE c)
           $+$ maybe mempty (\i -> text "Constraint id" <+> text (show i)) cid)
 
 ppError' td  dCtx (ErrFCrash _ _ c tA tE)
   = text "Fixpoint Crash on Constraint"
         $+$ dCtx
-        $+$ (ppFull td $ ppReqInContext td tA tE c)
+        $+$ ppFull td (ppReqInContext td tA tE c)
 
 ppError' _ dCtx (ErrParse _ _ e)
   = text "Cannot parse specification:"
         $+$ dCtx
-        $+$ (nest 4 $ pprint e)
+        $+$ nest 4 (pprint e)
 
 ppError' _ dCtx (ErrTySpec _ _k v t s)
   = ("Illegal type specification for" <+> ppTicks v) --  <-> ppKind k <-> ppTicks v)
@@ -843,9 +849,9 @@
 ppError' _ dCtx (ErrTermSpec _ v msg e t s)
   = text "Illegal termination specification for" <+> ppTicks v
         $+$ dCtx
-        $+$ (nest 4 $ ((text "Termination metric" <+> ppTicks e <+> text "is" <+> msg <+> "in type signature")
-                        $+$ nest 4 (pprint t)
-                        $+$ pprint s))
+        $+$ nest 4 ((text "Termination metric" <+> ppTicks e <+> text "is" <+> msg <+> "in type signature")
+                     $+$ nest 4 (pprint t)
+                     $+$ pprint s)
 
 ppError' _ _ (ErrInvt _ t s)
   = text "Bad Invariant Specification"
@@ -886,7 +892,7 @@
 ppError' _ dCtx (ErrDupField _ dc x)
   = text "Malformed refined data constructor" <+> dc
         $+$ dCtx
-        $+$ (nest 4 $ text "Duplicated definitions for field" <+> ppTicks x)
+        $+$ nest 4 (text "Duplicated definitions for field" <+> ppTicks x)
 
 ppError' _ dCtx (ErrDupNames _ x ns)
   = text "Ambiguous specification symbol" <+> ppTicks x
@@ -909,7 +915,7 @@
 ppError' _ dCtx (ErrGhc _ s)
   = text "GHC Error"
         $+$ dCtx
-        $+$ (nest 4 $ pprint s)
+        $+$ nest 4 (pprint s)
 
 ppError' _ _ (ErrFail _ s)
   = text "Failure Error:"
@@ -918,17 +924,17 @@
 ppError' _ _ (ErrFailUsed _ s xs)
   = text "Failure Error:"
         $+$ text "Binder" <+> pprint s <+> text "declared to fail is used by"
-        <+> (hsep $ L.intersperse comma xs)
+        <+> hsep (L.intersperse comma xs)
 
 ppError' _ dCtx (ErrResolve _ kind v msg)
   = (text "Unknown" <+> kind <+> ppTicks v)
         $+$ dCtx
-        $+$ (nest 4 msg)
+        $+$ nest 4 msg
 
 ppError' _ dCtx (ErrPartPred _ c p i eN aN)
   = text "Malformed predicate application"
         $+$ dCtx
-        $+$ (nest 4 $ vcat
+        $+$ nest 4 (vcat
                         [ "The" <+> text (Misc.intToString i) <+> "argument of" <+> c <+> "is predicate" <+> ppTicks p
                         , "which expects" <+> pprint eN <+> "arguments" <+> "but is given only" <+> pprint aN
                         , " "
@@ -940,14 +946,14 @@
 ppError' _ dCtx e@(ErrMismatch _ x msg τ t cause hsSp)
   = "Specified type does not refine Haskell type for" <+> ppTicks x <+> parens msg
         $+$ dCtx
-        $+$ (sepVcat blankLine
+        $+$ sepVcat blankLine
               [ "The Liquid type"
               , nest 4 t
               , "is inconsistent with the Haskell type"
               , nest 4 τ
               , "defined at" <+> pprint hsSp
               , maybe empty ppCause cause
-              ])
+              ]
     where
       ppCause (hsD, lqD) = sepVcat blankLine
               [ "Specifically, the Liquid component"
@@ -960,7 +966,7 @@
 ppError' _ dCtx (ErrAliasCycle _ acycle)
   = text "Cyclic type alias definition for" <+> ppTicks n0
         $+$ dCtx
-        $+$ (nest 4 $ sepVcat blankLine (hdr : map describe acycle))
+        $+$ nest 4 (sepVcat blankLine (hdr : map describe acycle))
   where
     hdr             = text "The following alias definitions form a cycle:"
     describe (p, n) = text "*" <+> ppTicks n <+> parens (text "defined at:" <+> pprint p)
@@ -975,8 +981,8 @@
 ppError' _ dCtx (ErrAliasApp _ name dl s)
   = text "Malformed application of type alias" <+> ppTicks name
         $+$ dCtx
-        $+$ (nest 4 $ vcat [ text "The alias" <+> ppTicks name <+> "defined at:" <+> pprint dl
-                           , s ] )
+        $+$ nest 4 (vcat [ text "The alias" <+> ppTicks name <+> "defined at:" <+> pprint dl
+                           , s ])
 
 ppError' _ dCtx (ErrSaved _ name s)
   = name -- <+> "(saved)"
@@ -1004,7 +1010,7 @@
 ppError' _ dCtx (ErrTermin _ xs s)
   = text "Termination Error"
         $+$ dCtx
-        <+> (hsep $ L.intersperse comma xs) $+$ s
+        <+> hsep (L.intersperse comma xs) $+$ s
 
 ppError' _ dCtx (ErrStTerm _ x s)
   = text "Structural Termination Error"
@@ -1019,11 +1025,11 @@
   = text "Standalone class method refinement"
     $+$ dCtx
     $+$ (text "Invalid type specification for" <+> v)
-    $+$ (text "Use class or instance refinements instead.")
+    $+$ text "Use class or instance refinements instead."
 
 ppError' _ _ (ErrRClass p0 c is)
   = text "Refined classes cannot have refined instances"
-    $+$ (nest 4 $ sepVcat blankLine $ describeCls : map describeInst is)
+    $+$ nest 4 (sepVcat blankLine $ describeCls : map describeInst is)
   where
     describeCls
       =   text "Refined class definition for:" <+> c
@@ -1041,6 +1047,16 @@
   = text "Rewrite error"
         $+$ dCtx
         $+$ nest 4 msg
+
+ppError' _ dCtx (ErrPosTyCon _ tc dc)
+  = text "Negative occurence of" <+> tc <+> "in" <+> dc
+        $+$ dCtx
+        $+$ vcat
+            ["\n"
+             , "To deactivate or understand the need of positivity check, see:"
+             , " "
+             , nest 2 "https://ucsd-progsys.github.io/liquidhaskell/options/#positivity-check"
+            ]
 
 ppError' _ dCtx (ErrParseAnn _ msg)
   = text "Malformed annotation"
diff --git a/src/Language/Haskell/Liquid/Types/Fresh.hs b/src/Language/Haskell/Liquid/Types/Fresh.hs
--- a/src/Language/Haskell/Liquid/Types/Fresh.hs
+++ b/src/Language/Haskell/Liquid/Types/Fresh.hs
@@ -4,11 +4,11 @@
 {-# LANGUAGE OverloadedStrings     #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
 {-# LANGUAGE TupleSections         #-}
-{-# LANGUAGE TypeSynonymInstances  #-}
 {-# LANGUAGE UndecidableInstances  #-}
-{-# LANGUAGE BangPatterns          #-}
 {-# LANGUAGE ConstraintKinds       #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Types.Fresh
   ( Freshable(..)
   , refreshTy
@@ -231,7 +231,7 @@
 refreshVVRef (RProp ss t)
   = do xs    <- mapM (const fresh) (fst <$> ss)
        let su = F.mkSubst $ zip (fst <$> ss) (F.EVar <$> xs)
-       (RProp (zip xs (snd <$> ss)) . F.subst su) <$> refreshVV t
+       RProp (zip xs (snd <$> ss)) . F.subst su <$> refreshVV t
 
 --------------------------------------------------------------------------------
 refreshArgs :: (FreshM m) => SpecType -> m SpecType
diff --git a/src/Language/Haskell/Liquid/Types/Literals.hs b/src/Language/Haskell/Liquid/Types/Literals.hs
--- a/src/Language/Haskell/Liquid/Types/Literals.hs
+++ b/src/Language/Haskell/Liquid/Types/Literals.hs
@@ -8,8 +8,8 @@
   ) where
 
 import Prelude hiding (error)
-import Language.Haskell.Liquid.GHC.TypeRep ()
-import Language.Haskell.Liquid.GHC.API hiding (panic)
+import Liquid.GHC.TypeRep ()
+import Liquid.GHC.API hiding (panic)
 
 import Language.Haskell.Liquid.Types.Types
 import Language.Haskell.Liquid.Types.RefType
diff --git a/src/Language/Haskell/Liquid/Types/Meet.hs b/src/Language/Haskell/Liquid/Types/Meet.hs
--- a/src/Language/Haskell/Liquid/Types/Meet.hs
+++ b/src/Language/Haskell/Liquid/Types/Meet.hs
@@ -8,7 +8,7 @@
 import qualified Language.Fixpoint.Types as F
 import           Language.Haskell.Liquid.Types.Types
 import           Language.Haskell.Liquid.Types.RefType ()
-import           Language.Haskell.Liquid.GHC.API as Ghc
+import           Liquid.GHC.API as Ghc
 
 meetVarTypes :: F.TCEmb TyCon -> Doc -> (SrcSpan, SpecType) -> (SrcSpan, SpecType) -> SpecType
 meetVarTypes _emb _v hs lq = {- meetError emb err -} F.meet hsT lqT
diff --git a/src/Language/Haskell/Liquid/Types/Names.hs b/src/Language/Haskell/Liquid/Types/Names.hs
--- a/src/Language/Haskell/Liquid/Types/Names.hs
+++ b/src/Language/Haskell/Liquid/Types/Names.hs
@@ -1,5 +1,5 @@
 module Language.Haskell.Liquid.Types.Names
-  (lenLocSymbol, anyTypeSymbol, functionComposisionSymbol) where
+  (lenLocSymbol, anyTypeSymbol, functionComposisionSymbol, selfSymbol) where
 
 import Language.Fixpoint.Types
 
@@ -14,3 +14,7 @@
 --  defined in include/GHC/Base.hs
 functionComposisionSymbol :: Symbol
 functionComposisionSymbol = symbol ("GHC.Base.." :: String)
+
+
+selfSymbol :: Symbol
+selfSymbol = symbol ("liquid_internal_this" :: String)
diff --git a/src/Language/Haskell/Liquid/Types/PredType.hs b/src/Language/Haskell/Liquid/Types/PredType.hs
--- a/src/Language/Haskell/Liquid/Types/PredType.hs
+++ b/src/Language/Haskell/Liquid/Types/PredType.hs
@@ -1,10 +1,12 @@
-{-# LANGUAGE DeriveDataTypeable   #-}
 {-# LANGUAGE FlexibleContexts     #-}
 {-# LANGUAGE FlexibleInstances    #-}
 {-# LANGUAGE OverloadedStrings    #-}
 {-# LANGUAGE TupleSections        #-}
 {-# LANGUAGE UndecidableInstances #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Types.PredType (
     PrType
   , TyConP (..), DataConP (..)
@@ -27,11 +29,12 @@
 
   -- * should be elsewhere
   , dataConWorkRep
+  , substPVar
   ) where
 
 import           Prelude                         hiding (error)
 import           Text.PrettyPrint.HughesPJ
-import           Language.Haskell.Liquid.GHC.API hiding ( panic
+import           Liquid.GHC.API hiding ( panic
                                                         , (<+>)
                                                         , hsep
                                                         , punctuate
@@ -39,10 +42,10 @@
                                                         , parens
                                                         , showPpr
                                                         )
-import           Language.Haskell.Liquid.GHC.TypeRep ()
+import           Liquid.GHC.TypeRep ()
 import           Data.Hashable
 import qualified Data.HashMap.Strict             as M
-import qualified Data.Maybe                                 as Mb 
+import qualified Data.Maybe                                 as Mb
 import qualified Data.List         as L -- (foldl', partition)
 -- import           Data.List                       (nub)
 
@@ -50,31 +53,31 @@
 
 -- import           Language.Fixpoint.Types         hiding (Expr, Predicate)
 import qualified Language.Fixpoint.Types                    as F
-import qualified Language.Haskell.Liquid.GHC.API            as Ghc 
-import           Language.Haskell.Liquid.GHC.Misc
+import qualified Liquid.GHC.API            as Ghc
+import           Liquid.GHC.Misc
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Types.RefType hiding (generalize)
 import           Language.Haskell.Liquid.Types.Types
 import           Data.Default
 
 makeTyConInfo :: F.TCEmb Ghc.TyCon -> [Ghc.TyCon] -> [TyConP] -> TyConMap
-makeTyConInfo tce fiTcs tcps = TyConMap 
+makeTyConInfo tce fiTcs tcps = TyConMap
   { tcmTyRTy    = tcM
-  , tcmFIRTy    = tcInstM 
+  , tcmFIRTy    = tcInstM
   , tcmFtcArity = arities
   }
-  where 
+  where
     tcM         = M.fromList [(tcpCon tcp, mkRTyCon tcp) | tcp <- tcps ]
-    tcInstM     = mkFInstRTyCon tce fiTcs tcM 
+    tcInstM     = mkFInstRTyCon tce fiTcs tcM
     arities     = safeFromList "makeTyConInfo" [ (c, length ts) | (c, ts) <- M.keys tcInstM ]
 
 mkFInstRTyCon :: F.TCEmb Ghc.TyCon -> [Ghc.TyCon] -> M.HashMap Ghc.TyCon RTyCon -> M.HashMap (Ghc.TyCon, [F.Sort]) RTyCon
-mkFInstRTyCon tce fiTcs tcm = M.fromList 
-  [ ((c, typeSort tce <$> ts), rtc) 
+mkFInstRTyCon tce fiTcs tcm = M.fromList
+  [ ((c, typeSort tce <$> ts), rtc)
     | fiTc    <- fiTcs
     , rtc     <- Mb.maybeToList (M.lookup fiTc tcm)
     , (c, ts) <- Mb.maybeToList (famInstArgs fiTc)
-  ] 
+  ]
 
 mkRTyCon ::  TyConP -> RTyCon
 mkRTyCon (TyConP _ tc αs' ps tyvariance predvariance size)
@@ -152,8 +155,8 @@
 meetWorkWrapRep :: DataCon -> SpecRep -> SpecRep -> SpecRep
 meetWorkWrapRep c workR wrapR
   | 0 <= pad
-  = workR { ty_binds = xs ++ (ty_binds wrapR)
-          , ty_args  = ts ++ zipWith F.meet ts' (ty_args wrapR) 
+  = workR { ty_binds = xs ++ ty_binds wrapR
+          , ty_args  = ts ++ zipWith F.meet ts' (ty_args wrapR)
           , ty_res   = strengthenRType (ty_res workR)    (ty_res  wrapR)
           , ty_preds = ty_preds wrapR
           }
@@ -180,7 +183,7 @@
   where
     isCls    = Ghc.isClassTyCon $ Ghc.dataConTyCon dc
     (xs, ts) = unzip (reverse yts)
-    mkDSym z = (F.symbol z) `F.suffixSymbol` (F.symbol dc)
+    mkDSym z = F.symbol z `F.suffixSymbol` F.symbol dc
     ys       = mkDSym <$> xs
     tx _  []     []     []     = []
     tx su (x:xs) (y:ys) (t:ts) = (y, classRFInfo allowTC , if allowTC && isCls then t else F.subst (F.mkSubst su) t, mempty)
@@ -194,31 +197,31 @@
     makeVars' = zip makeVars (repeat mempty)
 
 instance PPrint TyConP where
-  pprintTidy k tc = "data" <+> pprintTidy k (tcpCon tc) 
-                           <+> ppComm     k (tcpFreeTyVarsTy tc) 
-                           <+> ppComm     k (tcpFreePredTy   tc) 
+  pprintTidy k tc = "data" <+> pprintTidy k (tcpCon tc)
+                           <+> ppComm     k (tcpFreeTyVarsTy tc)
+                           <+> ppComm     k (tcpFreePredTy   tc)
       --  (parens $ hsep (punctuate comma (pprintTidy k <$> vs))) <+>
       -- (parens $ hsep (punctuate comma (pprintTidy k <$> ps))) <+>
       -- (parens $ hsep (punctuate comma (pprintTidy k <$> ls)))
 
-ppComm :: PPrint a => F.Tidy -> [a] -> Doc 
+ppComm :: PPrint a => F.Tidy -> [a] -> Doc
 ppComm k = parens . hsep . punctuate comma . fmap (pprintTidy k)
 
 
-    
 
+
 instance Show TyConP where
  show = showpp -- showSDoc . ppr
 
 instance PPrint DataConP where
   pprintTidy k (DataConP _ dc vs ps cs yts t isGadt mname _)
      =  pprintTidy k dc
-    <+> (parens $ hsep (punctuate comma (pprintTidy k <$> vs)))
-    <+> (parens $ hsep (punctuate comma (pprintTidy k <$> ps)))
-    <+> (parens $ hsep (punctuate comma (pprintTidy k <$> cs)))
-    <+> (parens $ hsep (punctuate comma (pprintTidy k <$> yts)))
-    <+> (pprintTidy k isGadt)
-    <+> (pprintTidy k mname)
+    <+> parens (hsep (punctuate comma (pprintTidy k <$> vs)))
+    <+> parens (hsep (punctuate comma (pprintTidy k <$> ps)))
+    <+> parens (hsep (punctuate comma (pprintTidy k <$> cs)))
+    <+> parens (hsep (punctuate comma (pprintTidy k <$> yts)))
+    <+> pprintTidy k isGadt
+    <+> pprintTidy k mname
     <+>  pprintTidy k t
 
 instance Show DataConP where
@@ -257,7 +260,7 @@
 pVartoRConc p (v, args)
   = pApp (pname p) $ F.EVar v : args'
   where
-    args' = (thd3 <$> args) ++ (drop (length args) (thd3 <$> pargs p))
+    args' = (thd3 <$> args) ++ drop (length args) (thd3 <$> pargs p)
 
 -----------------------------------------------------------------------
 -- | @pvarRType π@ returns a trivial @RType@ corresponding to the
@@ -317,6 +320,37 @@
 --   where go z (π, RProp t) = substPred msg   (π, t)     z
 --         go z (π, RPropP r) = replacePVarReft (π, r) <$> z
 
+-------------------------------------------------------------------------------------
+substPVar :: PVar BSort -> PVar BSort -> BareType -> BareType
+-------------------------------------------------------------------------------------
+substPVar src dst = go
+  where
+    go :: BareType -> BareType
+    go (RVar a r)         = RVar a (goRR r)
+    go (RApp c ts rs r)   = RApp c (go <$> ts) (goR <$> rs) (goRR r)
+    go (RAllP q t)
+     | pname q == pname src = RAllP q t
+     | otherwise            = RAllP q (go t)
+    go (RAllT a t r)      = RAllT a   (go t)  (goRR r)
+    go (RFun x i t t' r)  = RFun x i  (go t)  (go t') (goRR r)
+    go (RImpF x i t t' r) = RImpF x i (go t)  (go t') (goRR r)
+    go (RAllE x t t')     = RAllE x   (go t)  (go t')
+    go (REx x t t')       = REx x     (go t)  (go t')
+    go (RRTy e r o t)     = RRTy e'   (goRR r) o (go t) where e' = [(x, go t) | (x, t) <- e]
+    go (RAppTy t1 t2 r)   = RAppTy    (go t1) (go t2) (goRR r)
+    go (RHole r)          = RHole     (goRR r)
+    go t@(RExprArg  _)    = t
+    goR :: BRProp RReft -> BRProp RReft
+    goR rp = rp {rf_body = go (rf_body rp) }
+    goRR :: RReft -> RReft
+    goRR rr = rr { ur_pred = goP (ur_pred rr) }
+    goP :: Predicate -> Predicate
+    goP (Pr ps) = Pr (goPV <$> ps)
+    goPV :: UsedPVar -> UsedPVar
+    goPV pv
+      | pname pv == pname src = pv { pname = pname dst }
+      | otherwise             = pv
+
 -------------------------------------------------------------------------------
 substPred :: String -> (RPVar, SpecProp) -> SpecType -> SpecType
 -------------------------------------------------------------------------------
@@ -336,7 +370,7 @@
     t'                          = RApp c (substPred msg su <$> ts) (substPredP msg su <$> rs) r
     (r2', πs)                   = splitRPvar π r
 
-substPred msg (p, tp) (RAllP (q@(PV _ _ _ _)) t)
+substPred msg (p, tp) (RAllP q@PV{} t)
   | p /= q                      = RAllP q $ substPred msg (p, tp) t
   | otherwise                   = RAllP q t
 
@@ -397,7 +431,7 @@
 
     su = F.mkSubst $ zipWith (\s1 s2 -> (s1, F.EVar s2)) (rvs t1) (rvs t2)
 
-    rvs      = foldReft False (\_ r acc -> rvReft r : acc) [] 
+    rvs      = foldReft False (\_ r acc -> rvReft r : acc) []
     rvReft r = let F.Reft(s,_) = F.toReft r in s
 
 substRCon msg su t _ _        = {- panic Nothing -} errorP "substRCon: " $ msg ++ " " ++ showpp (su, t)
@@ -460,7 +494,7 @@
   = L.nub $ concatMap (freeArgsPs p) (snd <$> env) ++ freeArgsPsRef p r ++ freeArgsPs p t
 
 freeArgsPsRef :: PVar t1 -> UReft t -> [F.Symbol]
-freeArgsPsRef p (MkUReft _ (Pr ps)) = [x | (_, x, w) <- (concatMap pargs ps'),  (F.EVar x) == w]
+freeArgsPsRef p (MkUReft _ (Pr ps)) = [x | (_, x, w) <- concatMap pargs ps', F.EVar x == w]
   where
    ps' = f <$> filter (uPVar p ==) ps
    f q = q {pargs = pargs q ++ drop (length (pargs q)) (pargs $ uPVar p)}
@@ -475,14 +509,14 @@
                      -> Ref τ (RType t1 t2 t3)
                      -> Ref τ (RType t1 t2 t3)
                      -> Ref τ (RType t1 t2 t3)
-meetListWithPSubsRef πs ss r1 r2 = L.foldl' ((meetListWithPSubRef ss) r1) r2 πs
+meetListWithPSubsRef πs ss r1 r2 = L.foldl' (meetListWithPSubRef ss r1) r2 πs
 
 meetListWithPSub ::  (F.Reftable r, PPrint t) => [(F.Symbol, RSort)]-> r -> r -> PVar t -> r
 meetListWithPSub ss r1 r2 π
   | all (\(_, x, F.EVar y) -> x == y) (pargs π)
   = r2 `F.meet` r1
   | all (\(_, x, F.EVar y) -> x /= y) (pargs π)
-  = r2 `F.meet` (F.subst su r1)
+  = r2 `F.meet` F.subst su r1
   | otherwise
   = panic Nothing $ "PredType.meetListWithPSub partial application to " ++ showpp π
   where
@@ -500,9 +534,9 @@
   = panic Nothing "PredType.meetListWithPSubRef called with invalid input"
 meetListWithPSubRef ss (RProp s1 r1) (RProp s2 r2) π
   | all (\(_, x, F.EVar y) -> x == y) (pargs π)
-  = RProp s1 $ (F.subst su' r2) `F.meet` r1
+  = RProp s1 $ F.subst su' r2 `F.meet` r1
   | all (\(_, x, F.EVar y) -> x /= y) (pargs π)
-  = RProp s2 $ r2 `F.meet` (F.subst su r1)
+  = RProp s2 $ r2 `F.meet` F.subst su r1
   | otherwise
   = panic Nothing $ "PredType.meetListWithPSubRef partial application to " ++ showpp π
   where
@@ -527,7 +561,7 @@
 substParg :: Functor f => (F.Symbol, F.Expr) -> f Predicate -> f Predicate
 substParg (x, y) = fmap fp
   where
-    fxy s        = if (s == F.EVar x) then y else s
+    fxy s        = if s == F.EVar x then y else s
     fp           = subvPredicate (\pv -> pv { pargs = mapThd3 fxy <$> pargs pv })
 
 -------------------------------------------------------------------------------
diff --git a/src/Language/Haskell/Liquid/Types/PrettyPrint.hs b/src/Language/Haskell/Liquid/Types/PrettyPrint.hs
--- a/src/Language/Haskell/Liquid/Types/PrettyPrint.hs
+++ b/src/Language/Haskell/Liquid/Types/PrettyPrint.hs
@@ -7,9 +7,13 @@
 {-# LANGUAGE TupleSections        #-}
 {-# LANGUAGE UndecidableInstances #-}
 {-# LANGUAGE MonoLocalBinds       #-}
-{-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE FlexibleInstances    #-}
+{-# LANGUAGE RecordWildCards      #-}
+{-# LANGUAGE ScopedTypeVariables  #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 module Language.Haskell.Liquid.Types.PrettyPrint
   ( -- * Printable RTypes
     OkRT
@@ -26,20 +30,28 @@
   , printWarning
   , printError
 
+  -- * Filtering errors
+  , Filter(..)
+  , getFilters
+  , reduceFilters
+  , defaultFilterReporter
+
   -- * Reporting errors in the typechecking phase
-  , reportErrors
+  , FilterReportErrorsArgs(..)
+  , filterReportErrorsWith
+  , filterReportErrors
 
   ) where
 
-import           Control.Monad
-
+import           Control.Monad                           (void)
 import qualified Data.HashMap.Strict              as M
 import qualified Data.List                        as L                               -- (sort)
+import qualified Data.Set                         as Set
 import           Data.String
 import           Language.Fixpoint.Misc
 import qualified Language.Fixpoint.Types          as F
-import qualified Language.Haskell.Liquid.GHC.API  as Ghc
-import           Language.Haskell.Liquid.GHC.API  as Ghc ( Class
+import qualified Liquid.GHC.API  as Ghc
+import           Liquid.GHC.API  as Ghc ( Class
                                                          , SrcSpan
                                                          , PprPrec
                                                          , DynFlags
@@ -54,13 +66,21 @@
                                                          , srcSpanStartLine
                                                          , srcSpanStartCol
                                                          )
-import           Language.Haskell.Liquid.GHC.Logging (putErrMsg, mkLongErrAt)
-import           Language.Haskell.Liquid.GHC.Misc
+import           Liquid.GHC.Logging (putErrMsg, mkLongErrAt)
+import           Liquid.GHC.Misc
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Types.Types
 import           Prelude                          hiding (error)
 import           Text.PrettyPrint.HughesPJ        hiding ((<>))
 
+-- | `Filter`s match errors. They are used to ignore classes of errors they
+-- match. `AnyFilter` matches all errors. `StringFilter` matches any error whose
+-- \"representation\" contains the given `String`. A \"representation\" is
+-- pretty-printed String of the error.
+data Filter = StringFilter String
+            | AnyFilter
+  deriving (Eq, Ord, Show)
+
 --------------------------------------------------------------------------------
 pprManyOrdered :: (PPrint a, Ord a) => F.Tidy -> String -> [a] -> [Doc]
 --------------------------------------------------------------------------------
@@ -127,7 +147,7 @@
 
 pprAnnInfoBinds :: (PPrint a, PPrint b) => F.Tidy -> (SrcSpan, [(Maybe a, b)]) -> Doc
 pprAnnInfoBinds k (l, xvs)
-  = vcat $ (pprAnnInfoBind k . (l,)) <$> xvs
+  = vcat $ pprAnnInfoBind k . (l,) <$> xvs
 
 pprAnnInfoBind :: (PPrint a, PPrint b) => F.Tidy -> (SrcSpan, (Maybe a, b)) -> Doc
 pprAnnInfoBind k (Ghc.RealSrcSpan sp _, xv)
@@ -156,7 +176,7 @@
                                  , nest 2 $ text "axiom-map"
                                  , nest 4 $ pprint am
                                  ]
-                    
+
 --------------------------------------------------------------------------------
 -- | Pretty Printing RefType ---------------------------------------------------
 --------------------------------------------------------------------------------
@@ -175,11 +195,11 @@
             <+> text " = "
             <+> pprint (rtBody a)
 
-instance (F.PPrint tv, F.PPrint t) => F.PPrint (RTEnv tv t) where 
-  pprintTidy k rte 
-    =   text "** Type Aliaes *********************" 
-    $+$ nest 4 (F.pprintTidy k (typeAliases rte)) 
-    $+$ text "** Expr Aliases ********************" 
+instance (F.PPrint tv, F.PPrint t) => F.PPrint (RTEnv tv t) where
+  pprintTidy k rte
+    =   text "** Type Aliaes *********************"
+    $+$ nest 4 (F.pprintTidy k (typeAliases rte))
+    $+$ text "** Expr Aliases ********************"
     $+$ nest 4 (F.pprintTidy k (exprAliases rte))
 
 pprints :: (PPrint a) => F.Tidy -> Doc -> [a] -> Doc
@@ -188,7 +208,7 @@
 --------------------------------------------------------------------------------
 rtypeDoc :: (OkRT c tv r) => F.Tidy -> RType c tv r -> Doc
 --------------------------------------------------------------------------------
-rtypeDoc k      = ppr_rtype (ppE k) topPrec
+rtypeDoc k      = pprRtype (ppE k) topPrec
   where
     ppE F.Lossy = ppEnvShort ppEnv
     ppE F.Full  = ppEnv
@@ -197,54 +217,54 @@
   pprintTidy _ F.Full  = "Full"
   pprintTidy _ F.Lossy = "Lossy"
 
-type Prec = PprPrec 
+type Prec = PprPrec
 
 --------------------------------------------------------------------------------
-ppr_rtype :: (OkRT c tv r) => PPEnv -> Prec -> RType c tv r -> Doc
+pprRtype :: (OkRT c tv r) => PPEnv -> Prec -> RType c tv r -> Doc
 --------------------------------------------------------------------------------
-ppr_rtype bb p t@(RAllT _ _ r)
-  = F.ppTy r $ ppr_forall bb p t
-ppr_rtype bb p t@(RAllP _ _)
-  = ppr_forall bb p t
-ppr_rtype _ _ (RVar a r)
+pprRtype bb p t@(RAllT _ _ r)
+  = F.ppTy r $ pprForall bb p t
+pprRtype bb p t@(RAllP _ _)
+  = pprForall bb p t
+pprRtype _ _ (RVar a r)
   = F.ppTy r $ pprint a
-ppr_rtype bb p t@(RImpF _ _ _ _ _)
-  = maybeParen p funPrec (ppr_rty_fun bb empty t)
-ppr_rtype bb p t@(RFun _ _ _ _ _)
-  = maybeParen p funPrec (ppr_rty_fun bb empty t)
-ppr_rtype bb p (RApp c [t] rs r)
+pprRtype bb p t@RImpF{}
+  = maybeParen p funPrec (pprRtyFun bb empty t)
+pprRtype bb p t@RFun{}
+  = maybeParen p funPrec (pprRtyFun bb empty t)
+pprRtype bb p (RApp c [t] rs r)
   | isList c
-  = F.ppTy r $ brackets (ppr_rtype bb p t) <-> ppReftPs bb p rs
-ppr_rtype bb p (RApp c ts rs r)
+  = F.ppTy r $ brackets (pprRtype bb p t) <-> ppReftPs bb p rs
+pprRtype bb p (RApp c ts rs r)
   | isTuple c
-  = F.ppTy r $ parens (intersperse comma (ppr_rtype bb p <$> ts)) <-> ppReftPs bb p rs
-ppr_rtype bb p (RApp c ts rs r)
+  = F.ppTy r $ parens (intersperse comma (pprRtype bb p <$> ts)) <-> ppReftPs bb p rs
+pprRtype bb p (RApp c ts rs r)
   | isEmpty rsDoc && isEmpty tsDoc
   = F.ppTy r $ ppT c
   | otherwise
   = F.ppTy r $ parens $ ppT c <+> rsDoc <+> tsDoc
   where
     rsDoc            = ppReftPs bb p rs
-    tsDoc            = hsep (ppr_rtype bb p <$> ts)
+    tsDoc            = hsep (pprRtype bb p <$> ts)
     ppT              = ppTyConB bb
 
-ppr_rtype bb p t@(REx _ _ _)
+pprRtype bb p t@REx{}
   = ppExists bb p t
-ppr_rtype bb p t@(RAllE _ _ _)
+pprRtype bb p t@RAllE{}
   = ppAllExpr bb p t
-ppr_rtype _ _ (RExprArg e)
+pprRtype _ _ (RExprArg e)
   = braces $ pprint e
-ppr_rtype bb p (RAppTy t t' r)
-  = F.ppTy r $ ppr_rtype bb p t <+> ppr_rtype bb p t'
-ppr_rtype bb p (RRTy e _ OCons t)
-  = sep [braces (ppr_rsubtype bb p e) <+> "=>", ppr_rtype bb p t]
-ppr_rtype bb p (RRTy e r o t)
-  = sep [ppp (pprint o <+> ppe <+> pprint r), ppr_rtype bb p t]
+pprRtype bb p (RAppTy t t' r)
+  = F.ppTy r $ pprRtype bb p t <+> pprRtype bb p t'
+pprRtype bb p (RRTy e _ OCons t)
+  = sep [braces (pprRsubtype bb p e) <+> "=>", pprRtype bb p t]
+pprRtype bb p (RRTy e r o t)
+  = sep [ppp (pprint o <+> ppe <+> pprint r), pprRtype bb p t]
   where
-    ppe  = (hsep $ punctuate comma (ppxt <$> e)) <+> dcolon
-    ppp  = \doc -> text "<<" <+> doc <+> text ">>"
-    ppxt = \(x, t) -> pprint x <+> ":" <+> ppr_rtype bb p t
-ppr_rtype _ _ (RHole r)
+    ppe         = hsep (punctuate comma (ppxt <$> e)) <+> dcolon
+    ppp  doc    = text "<<" <+> doc <+> text ">>"
+    ppxt (x, t) = pprint x <+> ":" <+> pprRtype bb p t
+pprRtype _ _ (RHole r)
   = F.ppTy r $ text "_"
 
 ppTyConB :: TyConable c => PPEnv -> c -> Doc
@@ -255,17 +275,17 @@
 shortModules :: Doc -> Doc
 shortModules = text . F.symbolString . dropModuleNames . F.symbol . render
 
-ppr_rsubtype
+pprRsubtype
   :: (OkRT c tv r, PPrint a, PPrint (RType c tv r), PPrint (RType c tv ()))
   => PPEnv -> Prec -> [(a, RType c tv r)] -> Doc
-ppr_rsubtype bb p e
-  = pprint_env <+> text "|-" <+> ppr_rtype bb p tl <+> "<:" <+> ppr_rtype bb p tr
+pprRsubtype bb p e
+  = pprint_env <+> text "|-" <+> pprRtype bb p tl <+> "<:" <+> pprRtype bb p tr
   where
     (el, r)  = (init e,  last e)
     (env, l) = (init el, last el)
-    tr   = snd $ r
-    tl   = snd $ l
-    pprint_bind (x, t) = pprint x <+> colon <-> colon <+> ppr_rtype bb p t
+    tr   = snd r
+    tl   = snd l
+    pprint_bind (x, t) = pprint x <+> colon <-> colon <+> pprRtype bb p t
     pprint_env         = hsep $ punctuate comma (pprint_bind <$> env)
 
 -- | From GHC: TypeRep
@@ -280,7 +300,7 @@
       F.Reftable (RTProp c tv ()))
   => PPEnv -> Prec -> RType c tv r -> Doc
 ppExists bb p t
-  = text "exists" <+> brackets (intersperse comma [ppr_dbind bb topPrec x t | (x, t) <- zs]) <-> dot <-> ppr_rtype bb p t'
+  = text "exists" <+> brackets (intersperse comma [pprDbind bb topPrec x t | (x, t) <- zs]) <-> dot <-> pprRtype bb p t'
     where (zs,  t')               = split [] t
           split zs (REx x t t')   = split ((x,t):zs) t'
           split zs t                = (reverse zs, t)
@@ -289,8 +309,8 @@
   :: (OkRT c tv r, PPrint (RType c tv r), PPrint (RType c tv ()))
   => PPEnv -> Prec -> RType c tv r -> Doc
 ppAllExpr bb p t
-  = text "forall" <+> brackets (intersperse comma [ppr_dbind bb topPrec x t | (x, t) <- zs]) <-> dot <-> ppr_rtype bb p t'
-    where 
+  = text "forall" <+> brackets (intersperse comma [pprDbind bb topPrec x t | (x, t) <- zs]) <-> dot <-> pprRtype bb p t'
+    where
       (zs,  t')               = split [] t
       split zs (RAllE x t t') = split ((x,t):zs) t'
       split zs t              = (reverse zs, t)
@@ -302,57 +322,57 @@
 ppReftPs _ _ rs
   | all F.isTauto rs   = empty
   | not (ppPs ppEnv) = empty
-  | otherwise        = angleBrackets $ hsep $ punctuate comma $ ppr_ref <$> rs
+  | otherwise        = angleBrackets $ hsep $ punctuate comma $ pprRef <$> rs
 
-ppr_dbind
+pprDbind
   :: (OkRT c tv r, PPrint (RType c tv r), PPrint (RType c tv ()))
   => PPEnv -> Prec -> F.Symbol -> RType c tv r -> Doc
-ppr_dbind bb p x t
+pprDbind bb p x t
   | F.isNonSymbol x || (x == F.dummySymbol)
-  = ppr_rtype bb p t
+  = pprRtype bb p t
   | otherwise
-  = pprint x <-> colon <-> ppr_rtype bb p t
+  = pprint x <-> colon <-> pprRtype bb p t
 
 
 
-ppr_rty_fun
+pprRtyFun
   :: ( OkRT c tv r, PPrint (RType c tv r), PPrint (RType c tv ()))
   => PPEnv -> Doc -> RType c tv r -> Doc
-ppr_rty_fun bb prefix t = hsep (prefix : dArgs ++ [dOut])
+pprRtyFun bb prefix t = hsep (prefix : dArgs ++ [dOut])
   where
     dArgs               = concatMap ppArg args
-    dOut                = ppr_rtype bb topPrec out
-    ppArg (b, t, a)     = [ppr_dbind bb funPrec b t, a]
+    dOut                = pprRtype bb topPrec out
+    ppArg (b, t, a)     = [pprDbind bb funPrec b t, a]
     (args, out)         = brkFun t
 
-{- 
-ppr_rty_fun bb prefix t
-  = prefix <+> ppr_rty_fun' bb t
+{-
+pprRtyFun bb prefix t
+  = prefix <+> pprRtyFun' bb t
 
-ppr_rty_fun'
+pprRtyFun'
   :: ( OkRT c tv r, PPrint (RType c tv r), PPrint (RType c tv ()))
   => PPEnv -> RType c tv r -> Doc
-ppr_rty_fun' bb (RImpF b t t' r)
-  = F.ppTy r $ ppr_dbind bb funPrec b t $+$ ppr_rty_fun bb (text "~>") t'
-ppr_rty_fun' bb (RFun b t t' r)
-  = F.ppTy r $ ppr_dbind bb funPrec b t $+$ ppr_rty_fun bb arrow t'
-ppr_rty_fun' bb t
-  = ppr_rtype bb topPrec t
+pprRtyFun' bb (RImpF b t t' r)
+  = F.ppTy r $ pprDbind bb funPrec b t $+$ pprRtyFun bb (text "~>") t'
+pprRtyFun' bb (RFun b t t' r)
+  = F.ppTy r $ pprDbind bb funPrec b t $+$ pprRtyFun bb arrow t'
+pprRtyFun' bb t
+  = pprRtype bb topPrec t
 -}
 
-brkFun :: RType c tv r -> ([(F.Symbol, RType c tv r, Doc)], RType c tv r) 
-brkFun (RImpF b _ t t' _) = ((b, t, (text "~>")) : args, out)   where (args, out)     = brkFun t'  
-brkFun (RFun b _ t t' _)  = ((b, t, (text "->")) : args, out)   where (args, out)     = brkFun t'  
-brkFun out                = ([], out) 
+brkFun :: RType c tv r -> ([(F.Symbol, RType c tv r, Doc)], RType c tv r)
+brkFun (RImpF b _ t t' _) = ((b, t, text "~>") : args, out)   where (args, out)     = brkFun t'
+brkFun (RFun b _ t t' _)  = ((b, t, text "->") : args, out)   where (args, out)     = brkFun t'
+brkFun out                = ([], out)
 
 
 
 
-ppr_forall :: (OkRT c tv r) => PPEnv -> Prec -> RType c tv r -> Doc
-ppr_forall bb p t = maybeParen p funPrec $ sep [
-                      ppr_foralls (ppPs bb) (fst <$> ty_vars trep) (ty_preds trep)
-                    , ppr_clss cls
-                    , ppr_rtype bb topPrec t'
+pprForall :: (OkRT c tv r) => PPEnv -> Prec -> RType c tv r -> Doc
+pprForall bb p t = maybeParen p funPrec $ sep [
+                      pprForalls (ppPs bb) (fst <$> ty_vars trep) (ty_preds trep)
+                    , pprClss cls
+                    , pprRtype bb topPrec t'
                     ]
   where
     trep          = toRTypeRep t
@@ -360,58 +380,58 @@
     (cls, t')     = bkClass $ fromRTypeRep $ trep {ty_vars = [], ty_preds = []}
     -- t' = fromRTypeRep $ trep {ty_vars = [], ty_preds = []}
 
-    ppr_foralls False _ _  = empty
-    ppr_foralls _    [] [] = empty
-    ppr_foralls True αs πs = text "forall" <+> dαs αs <+> dπs (ppPs bb) πs <-> dot
+    pprForalls False _ _  = empty
+    pprForalls _    [] [] = empty
+    pprForalls True αs πs = text "forall" <+> dαs αs <+> dπs (ppPs bb) πs <-> dot
 
-    ppr_clss []               = empty
-    ppr_clss cs               = (parens $ hsep $ punctuate comma (uncurry (ppr_cls bb p) <$> cs)) <+> text "=>"
+    pprClss []               = empty
+    pprClss cs               = parens (hsep $ punctuate comma (uncurry (pprCls bb p) <$> cs)) <+> text "=>"
 
-    dαs αs                    = ppr_rtvar_def αs
+    dαs αs                    = pprRtvarDef αs
 
     -- dπs :: Bool -> [PVar a] -> Doc
     dπs _ []                  = empty
     dπs False _               = empty
-    dπs True πs               = angleBrackets $ intersperse comma $ ppr_pvar_def bb p <$> πs
+    dπs True πs               = angleBrackets $ intersperse comma $ pprPvarDef bb p <$> πs
 
-ppr_rtvar_def :: (PPrint tv) => [RTVar tv (RType c tv ())] -> Doc
-ppr_rtvar_def = sep . map (pprint . ty_var_value)
+pprRtvarDef :: (PPrint tv) => [RTVar tv (RType c tv ())] -> Doc
+pprRtvarDef = sep . map (pprint . ty_var_value)
 
-ppr_cls
+pprCls
   :: (OkRT c tv r, PPrint a, PPrint (RType c tv r),
       PPrint (RType c tv ()))
   => PPEnv -> Prec -> a -> [RType c tv r] -> Doc
-ppr_cls bb p c ts
-  = pp c <+> hsep (map (ppr_rtype bb p) ts)
+pprCls bb p c ts
+  = pp c <+> hsep (map (pprRtype bb p) ts)
   where
     pp | ppShort bb = text . F.symbolString . dropModuleNames . F.symbol . render . pprint
        | otherwise  = pprint
 
 
-ppr_pvar_def :: (OkRT c tv ()) => PPEnv -> Prec -> PVar (RType c tv ()) -> Doc
-ppr_pvar_def bb p (PV s t _ xts)
-  = pprint s <+> dcolon <+> intersperse arrow dargs <+> ppr_pvar_kind bb p t
+pprPvarDef :: (OkRT c tv ()) => PPEnv -> Prec -> PVar (RType c tv ()) -> Doc
+pprPvarDef bb p (PV s t _ xts)
+  = pprint s <+> dcolon <+> intersperse arrow dargs <+> pprPvarKind bb p t
   where
-    dargs = [ppr_pvar_sort bb p xt | (xt,_,_) <- xts]
+    dargs = [pprPvarSort bb p xt | (xt,_,_) <- xts]
 
 
-ppr_pvar_kind :: (OkRT c tv ()) => PPEnv -> Prec -> PVKind (RType c tv ()) -> Doc
-ppr_pvar_kind bb p (PVProp t) = ppr_pvar_sort bb p t <+> arrow <+> ppr_name F.boolConName -- propConName
-ppr_pvar_kind _ _ (PVHProp)   = panic Nothing "TODO: ppr_pvar_kind:hprop" -- ppr_name hpropConName
+pprPvarKind :: (OkRT c tv ()) => PPEnv -> Prec -> PVKind (RType c tv ()) -> Doc
+pprPvarKind bb p (PVProp t) = pprPvarSort bb p t <+> arrow <+> pprName F.boolConName -- propConName
+pprPvarKind _ _ PVHProp     = panic Nothing "TODO: pprPvarKind:hprop" -- pprName hpropConName
 
-ppr_name :: F.Symbol -> Doc
-ppr_name                      = text . F.symbolString
+pprName :: F.Symbol -> Doc
+pprName                      = text . F.symbolString
 
-ppr_pvar_sort :: (OkRT c tv ()) => PPEnv -> Prec -> RType c tv () -> Doc
-ppr_pvar_sort bb p t = ppr_rtype bb p t
+pprPvarSort :: (OkRT c tv ()) => PPEnv -> Prec -> RType c tv () -> Doc
+pprPvarSort bb p t = pprRtype bb p t
 
-ppr_ref :: (OkRT c tv r) => Ref (RType c tv ()) (RType c tv r) -> Doc
-ppr_ref  (RProp ss s) = ppRefArgs (fst <$> ss) <+> pprint s
--- ppr_ref (RProp ss s) = ppRefArgs (fst <$> ss) <+> pprint (fromMaybe mempty (stripRTypeBase s))
+pprRef :: (OkRT c tv r) => Ref (RType c tv ()) (RType c tv r) -> Doc
+pprRef  (RProp ss s) = ppRefArgs (fst <$> ss) <+> pprint s
+-- pprRef (RProp ss s) = ppRefArgs (fst <$> ss) <+> pprint (fromMaybe mempty (stripRTypeBase s))
 
 ppRefArgs :: [F.Symbol] -> Doc
 ppRefArgs [] = empty
-ppRefArgs ss = text "\\" <-> hsep (ppRefSym <$> ss ++ [F.vv Nothing]) <+> arrow 
+ppRefArgs ss = text "\\" <-> hsep (ppRefSym <$> ss ++ [F.vv Nothing]) <+> arrow
 
 ppRefSym :: (Eq a, IsString a, PPrint a) => a -> Doc
 ppRefSym "" = text "_"
@@ -435,8 +455,114 @@
 printError :: (Show e, F.PPrint e) => F.Tidy -> DynFlags -> TError e -> IO ()
 printError k dyn err = putErrMsg dyn (pos err) (ppError k empty err)
 
--- | Similar in spirit to 'reportErrors' from the GHC API, but it uses our pretty-printer
--- and shim functions under the hood.
-reportErrors :: (Show e, F.PPrint e) => F.Tidy -> [TError e] -> Ghc.TcRn ()
-reportErrors k errs =
-  forM errs (\err -> mkLongErrAt (pos err) (ppError k empty err) mempty) >>= Ghc.reportErrors
+-- | Similar in spirit to 'reportErrors' from the GHC API, but it uses our
+-- pretty-printer and shim functions under the hood. Also filters the errors
+-- according to the given `Filter` list.
+--
+-- @filterReportErrors failure continue filters k@ will call @failure@ if there
+-- are unexpected errors, or will call @continue@ otherwise.
+--
+-- An error is expected if there is any filter that matches it.
+filterReportErrors :: forall e' a. (Show e', F.PPrint e') => FilePath -> Ghc.TcRn a -> Ghc.TcRn a -> [Filter] -> F.Tidy -> [TError e'] -> Ghc.TcRn a
+filterReportErrors path failure continue filters k =
+  filterReportErrorsWith
+    FilterReportErrorsArgs { msgReporter = Ghc.reportErrors
+                           , filterReporter = defaultFilterReporter path
+                           , failure = failure
+                           , continue = continue
+                           , pprinter = \err -> mkLongErrAt (pos err) (ppError k empty err) mempty
+                           , matchingFilters = reduceFilters renderer filters
+                           , filters = filters
+                           }
+  where
+    renderer e = render (ppError k empty e $+$ pprint (pos e))
+
+
+-- | Retrieve the `Filter`s from the Config.
+getFilters :: Config -> [Filter]
+getFilters cfg = anyFilter <> stringFilters
+  where
+    anyFilter = [AnyFilter | expectAnyError cfg]
+    stringFilters = StringFilter <$> expectErrorContaining cfg
+
+-- | Return the list of @filters@ that matched the @err@ , given a @renderer@
+-- for the @err@ and some @filters@
+reduceFilters :: (e -> String) -> [Filter] -> e -> [Filter]
+reduceFilters renderer fs err = filter (filterDoesMatchErr renderer err) fs
+
+filterDoesMatchErr :: (e -> String) -> e -> Filter -> Bool
+filterDoesMatchErr _        _ AnyFilter = True
+filterDoesMatchErr renderer e (StringFilter filter) = stringMatch filter (renderer e)
+
+stringMatch :: String -> String -> Bool
+stringMatch filter str = filter `L.isInfixOf` str
+
+-- | Used in `filterReportErrorsWith'`
+data FilterReportErrorsArgs m filter msg e a =
+  FilterReportErrorsArgs
+  {
+    -- | Report the @msgs@ to the monad (usually IO)
+    msgReporter :: [msg] -> m ()
+  ,
+    -- | Report unmatched @filters@ to the monad
+    filterReporter :: [filter] -> m ()
+  ,
+    -- | Continuation for when there are unmatched filters or unmatched errors
+    failure :: m a
+  ,
+    -- | Continuation for when there are no unmatched errors or filters
+    continue :: m a
+  ,
+    -- | Compute a representation of the given error; does not report the error
+    pprinter :: e -> m msg
+  ,
+    -- | Yields the filters that map a given error. Must only yield
+    -- filters in the @filters@ field.
+    matchingFilters :: e -> [filter]
+  ,
+    -- | List of filters which could have been matched
+    filters :: [filter]
+  }
+
+-- | Calls the continuations in FilterReportErrorsArgs depending on whethere there
+-- are unmatched errors, unmatched filters or none.
+filterReportErrorsWith :: (Monad m, Ord filter) => FilterReportErrorsArgs m filter msg e a -> [e] -> m a
+filterReportErrorsWith FilterReportErrorsArgs {..} errs =
+  let
+    (unmatchedErrors, matchedFilters) =
+      L.partition (null . snd) [ (e, fs) | e <- errs, let fs = matchingFilters e ]
+    unmatchedFilters = Set.toList $
+      Set.fromList filters `Set.difference` Set.fromList (concatMap snd matchedFilters)
+  in
+    if null unmatchedErrors then
+      if null unmatchedFilters then
+        continue
+      else do
+        filterReporter unmatchedFilters
+        failure
+    else do
+      msgs <- traverse (pprinter . fst) unmatchedErrors
+      void $ msgReporter msgs
+      failure
+
+-- | Report errors via GHC's API stating the given `Filter`s did not get
+-- matched. Does nothing if the list of filters is empty.
+defaultFilterReporter :: FilePath -> [Filter] -> Ghc.TcRn ()
+defaultFilterReporter _ [] = pure ()
+defaultFilterReporter path fs = Ghc.reportError =<< mkLongErrAt srcSpan (vcat $ leaderMsg : (nest 4 <$> filterMsgs)) empty
+  where
+    leaderMsg :: Doc
+    leaderMsg = text "Could not match the following expected errors with actual thrown errors:"
+
+    filterToMsg :: Filter -> Doc
+    filterToMsg AnyFilter = text "<Any Liquid error>"
+    filterToMsg (StringFilter s) = text "String filter: " <-> quotes (text s)
+
+    filterMsgs :: [Doc]
+    filterMsgs = filterToMsg <$> fs
+
+    beginningOfFile :: Ghc.SrcLoc
+    beginningOfFile = Ghc.mkSrcLoc (fromString path) 1 1
+
+    srcSpan :: SrcSpan
+    srcSpan = Ghc.mkSrcSpan beginningOfFile beginningOfFile
diff --git a/src/Language/Haskell/Liquid/Types/RefType.hs b/src/Language/Haskell/Liquid/Types/RefType.hs
--- a/src/Language/Haskell/Liquid/Types/RefType.hs
+++ b/src/Language/Haskell/Liquid/Types/RefType.hs
@@ -6,15 +6,17 @@
 {-# LANGUAGE FlexibleContexts          #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE UndecidableInstances      #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE TupleSections             #-}
 {-# LANGUAGE RankNTypes                #-}
 {-# LANGUAGE GADTs                     #-}
 {-# LANGUAGE PatternGuards             #-}
-{-# LANGUAGE ImplicitParams            #-}
 {-# LANGUAGE ConstraintKinds           #-}
 {-# LANGUAGE ViewPatterns              #-}
 
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- | Refinement Types. Mostly mirroring the GHC Type definition, but with
 --   room for refinements of various sorts.
 -- TODO: Desperately needs re-organization.
@@ -51,8 +53,8 @@
 
   -- * Substitutions
   , subts, subvPredicate, subvUReft
-  , subsTyVar_meet, subsTyVar_meet', subsTyVar_nomeet
-  , subsTyVars_nomeet, subsTyVars_meet
+  , subsTyVarMeet, subsTyVarMeet', subsTyVarNoMeet
+  , subsTyVarsNoMeet, subsTyVarsMeet
 
   -- * Destructors
   , addTyConInfo
@@ -83,7 +85,7 @@
   , isBaseTy
   , updateRTVar, isValKind, kindToRType
   , rTVarInfo
-  
+
   , tyVarsPosition, Positions(..)
 
   , isNumeric
@@ -93,7 +95,8 @@
 -- import           GHC.Stack
 import Prelude hiding (error)
 -- import qualified Prelude
-import           Data.Maybe               (fromMaybe, isJust, fromJust)
+import           Data.Maybe               (fromMaybe, isJust)
+import           Data.Bifunctor           (first)
 import           Data.Monoid              (First(..))
 import           Data.Hashable
 import qualified Data.HashMap.Strict  as M
@@ -101,7 +104,7 @@
 import qualified Data.List as L
 import           Control.Monad  (void)
 import           Text.Printf
-import           Text.PrettyPrint.HughesPJ hiding ((<>)) 
+import           Text.PrettyPrint.HughesPJ hiding ((<>), first)
 import           Language.Fixpoint.Misc
 import           Language.Fixpoint.Types hiding (DataDecl (..), DataCtor (..), panic, shiftVV, Predicate, isNumeric)
 import           Language.Fixpoint.Types.Visitor (mapKVars, Visitable)
@@ -113,11 +116,10 @@
 import           Language.Haskell.Liquid.Types.Variance
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Types.Names
-import qualified Language.Haskell.Liquid.GHC.Misc as GM
-import           Language.Haskell.Liquid.GHC.Play (mapType, stringClassArg, isRecursivenewTyCon)
-import           Language.Haskell.Liquid.GHC.API        as Ghc hiding ( Expr
+import qualified Liquid.GHC.Misc as GM
+import           Liquid.GHC.Play (mapType, stringClassArg, isRecursivenewTyCon)
+import           Liquid.GHC.API        as Ghc hiding ( Expr
                                                                       , Located
-                                                                      , mapType
                                                                       , tyConName
                                                                       , punctuate
                                                                       , hcat
@@ -131,21 +133,21 @@
                                                                       , panic
                                                                       , text
                                                                       )
-import           Language.Haskell.Liquid.GHC.TypeRep () -- Eq Type instance
+import           Liquid.GHC.TypeRep () -- Eq Type instance
 import Data.List (foldl')
 
 
 
- 
 
 
 
+
 strengthenDataConType :: (Var, SpecType) -> (Var, SpecType)
 strengthenDataConType (x, t) = (x, fromRTypeRep trep {ty_res = tres})
   where
     tres     = F.notracepp _msg $ ty_res trep `strengthen` MkUReft (exprReft expr) mempty
     trep     = toRTypeRep t
-    _msg     = "STRENGTHEN-DATACONTYPE x = " ++ F.showpp (x, (zip xs ts))
+    _msg     = "STRENGTHEN-DATACONTYPE x = " ++ F.showpp (x, zip xs ts)
     (xs, ts) = dataConArgs trep
     as       = ty_vars  trep
     x'       = symbol x
@@ -235,13 +237,13 @@
     | isTauto r1 = RProp s2 (RHole r2)
     | isTauto r2 = RProp s1 (RHole r1)
     | otherwise  = RProp s1 $ RHole $ r1 `meet`
-                               (subst (mkSubst $ zip (fst <$> s2) (EVar . fst <$> s1)) r2)
+                               subst (mkSubst $ zip (fst <$> s2) (EVar . fst <$> s1)) r2
 
   (<>) (RProp s1 t1) (RProp s2 t2)
     | isTrivial t1 = RProp s2 t2
     | isTrivial t2 = RProp s1 t1
     | otherwise    = RProp s1 $ t1  `strengthenRefType`
-                                (subst (mkSubst $ zip (fst <$> s2) (EVar . fst <$> s1)) t2)
+                                subst (mkSubst $ zip (fst <$> s2) (EVar . fst <$> s1)) t2
 
 -- TODO: remove and use only Semigroup?
 instance ( SubsTy tv (RType c tv ()) c
@@ -406,7 +408,7 @@
 -- Eq Instances ------------------------------------------------------
 
 -- MOVE TO TYPES
-instance (Eq c, Eq tv, Hashable tv, PPrint tv, TyConable c, PPrint c, Reftable (RTProp c tv ())) 
+instance (Eq c, Eq tv, Hashable tv, PPrint tv, TyConable c, PPrint c, Reftable (RTProp c tv ()))
       => Eq (RType c tv ()) where
   (==) = eqRSort M.empty
 
@@ -494,7 +496,7 @@
   { rtv_name   = symbol    $ varName a
   , rtv_kind   = k2t       $ tyVarKind a
   , rtv_is_val = isValKind $ tyVarKind a
-  , rtv_is_pol = True 
+  , rtv_is_pol = True
   }
 
 kindToRType :: Monoid r => Type -> RRType r
@@ -518,7 +520,7 @@
 bTyVar      = BTV
 
 symbolRTyVar :: Symbol -> RTyVar
-symbolRTyVar = rTyVar . GM.symbolTyVar 
+symbolRTyVar = rTyVar . GM.symbolTyVar
 
 bareRTyVar :: BTyVar -> RTyVar
 bareRTyVar (BTV tv) = symbolRTyVar tv
@@ -566,7 +568,7 @@
 
 addPds :: Foldable t
        => t (PVar (RType c tv ())) -> RType c tv r -> RType c tv r
-addPds ps (RAllT v t r) = RAllT v (addPds ps t) r 
+addPds ps (RAllT v t r) = RAllT v (addPds ps t) r
 addPds ps t             = foldl' (flip rPred) t ps
 
 nlzP :: (OkRT c tv r) => [PVar (RType c tv ())] -> RType c tv r -> (RType c tv r, [PVar (RType c tv ())])
@@ -587,17 +589,17 @@
 nlzP ps (RAllT v t r)
  = (RAllT v t' r, ps ++ ps')
   where (t', ps') = nlzP [] t
-nlzP ps t@(RApp _ _ _ _)
+nlzP ps t@RApp{}
  = (t, ps)
 nlzP ps (RAllP p t)
  = (t', [p] ++ ps ++ ps')
   where (t', ps') = nlzP [] t
-nlzP ps t@(REx _ _ _)
+nlzP ps t@REx{}
  = (t, ps)
 nlzP ps t@(RRTy _ _ _ t')
  = (t, ps ++ ps')
  where ps' = snd $ nlzP [] t'
-nlzP ps t@(RAllE _ _ _)
+nlzP ps t@RAllE{}
  = (t, ps)
 nlzP _ t
  = panic Nothing $ "RefType.nlzP: cannot handle " ++ show t
@@ -628,10 +630,10 @@
     f (RVar v1 r1) t  = RVar v1 (r1 `meet` fromMaybe mempty (stripRTypeBase t))
     f t (RVar _ r1)  = t `strengthen` r1
     f t1 t2           = panic Nothing $ printf "strengthenRefTypeGen on differently shaped types \nt1 = %s [shape = %s]\nt2 = %s [shape = %s]"
-                         (pprt_raw t1) (showpp (toRSort t1)) (pprt_raw t2) (showpp (toRSort t2))
+                         (pprRaw t1) (showpp (toRSort t1)) (pprRaw t2) (showpp (toRSort t2))
 
-pprt_raw :: (OkRT c tv r) => RType c tv r -> String
-pprt_raw = render . rtypeDoc Full
+pprRaw :: (OkRT c tv r) => RType c tv r -> String
+pprRaw = render . rtypeDoc Full
 
 {- [NOTE:StrengthenRefType] disabling the `meetable` check because
 
@@ -648,19 +650,19 @@
  -}
 
 strengthenRefType t1 t2
-  | True -- _meetable t1 t2
-  = strengthenRefType_ (\x _ -> x) t1 t2
-  | otherwise
-  = panic Nothing msg
-  where
-    msg = printf "strengthen on differently shaped reftypes \nt1 = %s [shape = %s]\nt2 = %s [shape = %s]"
-            (showpp t1) (showpp (toRSort t1)) (showpp t2) (showpp (toRSort t2))
+  -- | _meetable t1 t2
+  = strengthenRefType_ const t1 t2
+  -- | otherwise
+  -- = panic Nothing msg
+  -- where
+  --   msg = printf "strengthen on differently shaped reftypes \nt1 = %s [shape = %s]\nt2 = %s [shape = %s]"
+  --           (showpp t1) (showpp (toRSort t1)) (showpp t2) (showpp (toRSort t2))
 
 _meetable :: (OkRT c tv r) => RType c tv r -> RType c tv r -> Bool
 _meetable t1 t2 = toRSort t1 == toRSort t2
 
 strengthenRefType_ f (RAllT a1 t1 r1) (RAllT a2 t2 r2)
-  = RAllT a1 (strengthenRefType_ f t1 (subsTyVar_meet (ty_var_value a2, toRSort t, t) t2)) (r1 `meet` r2)
+  = RAllT a1 (strengthenRefType_ f t1 (subsTyVarMeet (ty_var_value a2, toRSort t, t) t2)) (r1 `meet` r2)
   where t = RVar (ty_var_value a1) mempty
 
 strengthenRefType_ f (RAllT a t1 r1) t2
@@ -699,11 +701,18 @@
 
 -- YL: Evidence that we need a Monoid instance for RFInfo?
 strengthenRefType_ f (RFun x1 i1 t1 t1' r1) (RFun x2 i2 t2 t2' r2)
+  | x2 /= F.dummySymbol
   = RFun x2 i1{permitTC = getFirst b} t t' (r1 `meet` r2)
     where t  = strengthenRefType_ f t1 t2
           t' = strengthenRefType_ f (subst1 t1' (x1, EVar x2)) t2'
           b  = First (permitTC i1) <> First (permitTC i2)
 
+strengthenRefType_ f (RFun x1 i1 t1 t1' r1) (RFun x2 i2 t2 t2' r2)
+  = RFun x1 i1{permitTC = getFirst b} t t' (r1 `meet` r2)
+    where t  = strengthenRefType_ f t1 t2
+          t' = strengthenRefType_ f t1' (subst1 t2' (x2, EVar x1))
+          b  = First (permitTC i1) <> First (permitTC i2)
+
 strengthenRefType_ f (RApp tid t1s rs1 r1) (RApp _ t2s rs2 r2)
   = RApp tid ts rs (r1 `meet` r2)
     where ts  = zipWith (strengthenRefType_ f) t1s t2s
@@ -753,7 +762,7 @@
 expandRApp :: (PPrint r, Reftable r, SubsTy RTyVar RSort r, Reftable (RRProp r))
            => TCEmb TyCon -> TyConMap -> RRType r -> RRType r
 -------------------------------------------------------------------------
-expandRApp tce tyi t@(RApp {}) = RApp rc' ts rs' r
+expandRApp tce tyi t@RApp{} = RApp rc' ts rs' r
   where
     RApp rc ts rs r            = t
     (rc', _)                   = appRTyCon tce tyi rc as
@@ -781,7 +790,7 @@
    => PVar (RType c tv ()) -> Ref (RType c tv ()) (RType c tv r)
 rtPropTop pv = case ptype pv of
                  PVProp t -> RProp xts $ ofRSort t
-                 PVHProp  -> RProp xts $ mempty
+                 PVHProp  -> RProp xts mempty
                where
                  xts      =  pvArgs pv
 
@@ -797,7 +806,7 @@
          -> Ref (RType c tv ()) (RType c tv r)
          -> Ref (RType c tv ()) (RType c tv r)
 mkRTProp pv (RProp ss (RHole r))
-  = RProp ss $ (ofRSort $ pvType pv) `strengthen` r
+  = RProp ss $ ofRSort (pvType pv) `strengthen` r
 
 mkRTProp pv (RProp ss t)
   | length (pargs pv) == length ss
@@ -837,55 +846,55 @@
  -}
 
 appRTyCon :: (ToTypeable r) => TCEmb TyCon -> TyConMap -> RTyCon -> [RRType r] -> (RTyCon, [RPVar])
-appRTyCon tce tyi rc ts = F.notracepp _msg (resTc, ps'') 
+appRTyCon tce tyi rc ts = F.notracepp _msg (resTc, ps'')
   where
     _msg  = "appRTyCon-family: " ++ showpp (Ghc.isFamilyTyCon c, Ghc.tyConRealArity c, toType False <$> ts)
     resTc = RTyCon c ps'' (rtc_info rc'')
     c     = rtc_tc rc
-   
+
     (rc', ps') = rTyConWithPVars tyi rc (rTypeSort tce <$> ts)
     -- TODO:faminst-preds rc'   = M.lookupDefault rc c (tcmTyRTy tyi)
     -- TODO:faminst-preds ps'   = rTyConPVs rc' 
 
     -- TODO:faminst-preds: these substitutions may be WRONG if we are using FAMINST.
-    ps''  = subts (zip (RTV <$> αs) ts') <$> ps' 
-      where 
+    ps''  = subts (zip (RTV <$> αs) ts') <$> ps'
+      where
         ts' = if null ts then rVar <$> βs else toRSort <$> ts
         αs  = GM.tyConTyVarsDef (rtc_tc rc')
         βs  = GM.tyConTyVarsDef c
-    
+
     rc''  = if isNumeric tce rc' then addNumSizeFun rc' else rc'
 
 rTyConWithPVars :: TyConMap -> RTyCon -> [F.Sort] -> (RTyCon, [RPVar])
-rTyConWithPVars tyi rc ts = case famInstTyConMb tyi rc ts of 
+rTyConWithPVars tyi rc ts = case famInstTyConMb tyi rc ts of
   Just fiRc    -> (rc', rTyConPVs fiRc)       -- use the PVars from the family-instance TyCon
   Nothing      -> (rc', ps')                  -- use the PVars from the origin          TyCon
-  where 
+  where
     (rc', ps') = plainRTyConPVars tyi rc
 
 -- | @famInstTyConMb rc args@ uses the @RTyCon@ AND @args@ to see if 
 --   this is a family instance @RTyCon@, and if so, returns it.
 --   see [NOTE:FamInstPredVars]
 --   eg: 'famInstTyConMb tyi Field [Blob, a]' should give 'Just R:FieldBlob' 
-    
+
 famInstTyConMb :: TyConMap -> RTyCon -> [F.Sort] -> Maybe RTyCon
-famInstTyConMb tyi rc ts = do 
+famInstTyConMb tyi rc ts = do
   let c = rtc_tc rc
   n    <- M.lookup c      (tcmFtcArity tyi)
   M.lookup (c, take n ts) (tcmFIRTy    tyi)
 
 famInstTyConType :: Ghc.TyCon -> Maybe Ghc.Type
-famInstTyConType c = uncurry Ghc.mkTyConApp <$> famInstArgs c 
+famInstTyConType c = uncurry Ghc.mkTyConApp <$> famInstArgs c
 
 -- | @famInstArgs c@ destructs a family-instance @TyCon@ into its components, e.g. 
 --   e.g. 'famInstArgs R:FieldBlob' is @(Field, [Blob])@ 
 
 famInstArgs :: Ghc.TyCon -> Maybe (Ghc.TyCon, [Ghc.Type])
 famInstArgs c = case Ghc.tyConFamInst_maybe c of
-    Just (c', ts) -> F.notracepp ("famInstArgs: " ++ F.showpp (c, cArity, ts)) 
-                     $ Just (c', take (length ts - cArity) ts) 
+    Just (c', ts) -> F.notracepp ("famInstArgs: " ++ F.showpp (c, cArity, ts))
+                     $ Just (c', take (length ts - cArity) ts)
     Nothing       -> Nothing
-    where 
+    where
       cArity      = Ghc.tyConRealArity c
 
 -- TODO:faminst-preds: case Ghc.tyConFamInst_maybe c of
@@ -904,8 +913,8 @@
 --   'data' definition for the @TyCon@, e.g. will use 
 --   'List Int' to return 'List<p> Int' (if List has an abs-ref).
 plainRTyConPVars :: TyConMap -> RTyCon -> (RTyCon, [RPVar])
-plainRTyConPVars tyi rc = (rc', rTyConPVs rc') 
-  where 
+plainRTyConPVars tyi rc = (rc', rTyConPVs rc')
+  where
     rc'                   = M.lookupDefault rc (rtc_tc rc) (tcmTyRTy tyi)
 
 
@@ -913,7 +922,7 @@
 -- RJ: The code of `isNumeric` is incomprehensible.
 -- Please fix it to use intSort instead of intFTyCon
 isNumeric :: TCEmb TyCon -> RTyCon -> Bool
-isNumeric tce c = F.isNumeric mySort 
+isNumeric tce c = F.isNumeric mySort
   where
     -- mySort      = M.lookupDefault def rc tce
     mySort      = maybe def fst (F.tceLookup rc tce)
@@ -935,7 +944,7 @@
 allTyVars' t = fmap ty_var_value $ vs ++ vs'
   where
     vs      = map fst . fst3 . bkUniv $ t
-    vs'     = freeTyVars    $ t
+    vs'     = freeTyVars t
 
 
 freeTyVars :: Eq tv => RType c tv r -> [RTVar tv (RType c tv ())]
@@ -976,50 +985,50 @@
 -- TODO: Rewrite subsTyvars with Traversable
 --------------------------------------------------------------------------------
 
-subsTyVars_meet
+subsTyVarsMeet
   :: (Eq tv, Foldable t, Hashable tv, Reftable r, TyConable c,
       SubsTy tv (RType c tv ()) c, SubsTy tv (RType c tv ()) r,
       SubsTy tv (RType c tv ()) (RType c tv ()), FreeVar c tv,
       SubsTy tv (RType c tv ()) tv,
       SubsTy tv (RType c tv ()) (RTVar tv (RType c tv ())))
   => t (tv, RType c tv (), RType c tv r) -> RType c tv r -> RType c tv r
-subsTyVars_meet        = subsTyVars True
+subsTyVarsMeet        = subsTyVars True
 
-subsTyVars_nomeet
+subsTyVarsNoMeet
   :: (Eq tv, Foldable t, Hashable tv, Reftable r, TyConable c,
       SubsTy tv (RType c tv ()) c, SubsTy tv (RType c tv ()) r,
       SubsTy tv (RType c tv ()) (RType c tv ()), FreeVar c tv,
       SubsTy tv (RType c tv ()) tv,
       SubsTy tv (RType c tv ()) (RTVar tv (RType c tv ())))
   => t (tv, RType c tv (), RType c tv r) -> RType c tv r -> RType c tv r
-subsTyVars_nomeet      = subsTyVars False
+subsTyVarsNoMeet      = subsTyVars False
 
-subsTyVar_nomeet
+subsTyVarNoMeet
   :: (Eq tv, Hashable tv, Reftable r, TyConable c,
       SubsTy tv (RType c tv ()) c, SubsTy tv (RType c tv ()) r,
       SubsTy tv (RType c tv ()) (RType c tv ()), FreeVar c tv,
       SubsTy tv (RType c tv ()) tv,
       SubsTy tv (RType c tv ()) (RTVar tv (RType c tv ())))
   => (tv, RType c tv (), RType c tv r) -> RType c tv r -> RType c tv r
-subsTyVar_nomeet       = subsTyVar False
+subsTyVarNoMeet       = subsTyVar False
 
-subsTyVar_meet
+subsTyVarMeet
   :: (Eq tv, Hashable tv, Reftable r, TyConable c,
       SubsTy tv (RType c tv ()) c, SubsTy tv (RType c tv ()) r,
       SubsTy tv (RType c tv ()) (RType c tv ()), FreeVar c tv,
       SubsTy tv (RType c tv ()) tv,
       SubsTy tv (RType c tv ()) (RTVar tv (RType c tv ())))
   => (tv, RType c tv (), RType c tv r) -> RType c tv r -> RType c tv r
-subsTyVar_meet         = subsTyVar True
+subsTyVarMeet         = subsTyVar True
 
-subsTyVar_meet'
+subsTyVarMeet'
   :: (Eq tv, Hashable tv, Reftable r, TyConable c,
       SubsTy tv (RType c tv ()) c, SubsTy tv (RType c tv ()) r,
       SubsTy tv (RType c tv ()) (RType c tv ()), FreeVar c tv,
       SubsTy tv (RType c tv ()) tv,
       SubsTy tv (RType c tv ()) (RTVar tv (RType c tv ())))
   => (tv, RType c tv r) -> RType c tv r -> RType c tv r
-subsTyVar_meet' (α, t) = subsTyVar_meet (α, toRSort t, t)
+subsTyVarMeet' (α, t) = subsTyVarMeet (α, toRSort t, t)
 
 subsTyVars
   :: (Eq tv, Foldable t, Hashable tv, Reftable r, TyConable c,
@@ -1071,7 +1080,7 @@
           c' = if α `S.member` s then c else subt z' c
 subsFree meet s (α', τ, t') (RVar α r)
   | α == α' && not (α `S.member` s)
-  = if meet then t' `strengthen` (subt (α, τ) r) else t'
+  = if meet then t' `strengthen` subt (α, τ) r else t'
   | otherwise
   = RVar (subt (α', τ) α) r
 subsFree m s z (RAllE x t t')
@@ -1248,22 +1257,22 @@
 
 instance SubsTy Symbol Symbol (BRType r) where
   subt (x,y) (RVar v r)
-    | BTV x == v = RVar (BTV y) r 
-    | otherwise  = RVar v r 
+    | BTV x == v = RVar (BTV y) r
+    | otherwise  = RVar v r
   subt (x, y) (RAllT (RTVar v i) t r)
     | BTV x == v = RAllT (RTVar v i) t r
     | otherwise  = RAllT (RTVar v i) (subt (x,y) t) r
-  subt su (RFun x i t1 t2 r)  = RFun x i (subt su t1) (subt su t2) r 
+  subt su (RFun x i t1 t2 r)  = RFun x i (subt su t1) (subt su t2) r
   subt su (RImpF x i t1 t2 r) = RImpF x i (subt su t1) (subt su t2) r
   subt su (RAllP p t)       = RAllP p (subt su t)
-  subt su (RApp c ts ps r)  = RApp c (subt su <$> ts) (subt su <$> ps) r 
+  subt su (RApp c ts ps r)  = RApp c (subt su <$> ts) (subt su <$> ps) r
   subt su (RAllE x t1 t2)   = RAllE x (subt su t1) (subt su t2)
   subt su (REx x t1 t2)     = REx x (subt su t1) (subt su t2)
-  subt _  (RExprArg e)      = RExprArg e 
-  subt su (RAppTy t1 t2 r)  = RAppTy (subt su t1) (subt su t2) r 
+  subt _  (RExprArg e)      = RExprArg e
+  subt su (RAppTy t1 t2 r)  = RAppTy (subt su t1) (subt su t2) r
   subt su (RRTy e r o t)    = RRTy [(x, subt su p) | (x,p) <- e] r o (subt su t)
-  subt _ (RHole r)          = RHole r 
-  
+  subt _ (RHole r)          = RHole r
+
 instance SubsTy Symbol Symbol (RTProp BTyCon BTyVar r) where
   subt su (RProp e t) =  RProp [(x, subt su xt) | (x,xt) <- e] (subt su t)
 
@@ -1327,20 +1336,20 @@
 
 -- NOTE: This DOES NOT substitute at the binders
 instance SubsTy RTyVar RSort PrType where
-  subt (α, τ) = subsTyVar_meet (α, τ, ofRSort τ)
+  subt (α, τ) = subsTyVarMeet (α, τ, ofRSort τ)
 
 instance SubsTy RTyVar RSort SpecType where
-  subt (α, τ) = subsTyVar_meet (α, τ, ofRSort τ)
+  subt (α, τ) = subsTyVarMeet (α, τ, ofRSort τ)
 
 instance SubsTy TyVar Type SpecType where
-  subt (α, τ) = subsTyVar_meet (RTV α, ofType τ, ofType τ)
+  subt (α, τ) = subsTyVarMeet (RTV α, ofType τ, ofType τ)
 
 instance SubsTy RTyVar RTyVar SpecType where
   subt (α, a) = subt (α, RVar a () :: RSort)
 
 
 instance SubsTy RTyVar RSort RSort where
-  subt (α, τ) = subsTyVar_meet (α, τ, ofRSort τ)
+  subt (α, τ) = subsTyVarMeet (α, τ, ofRSort τ)
 
 instance SubsTy tv RSort Predicate where
   subt _ = id -- NV TODO
@@ -1353,11 +1362,11 @@
   subt _ t = t
 
 instance SubsTy BTyVar BSort BSort where
-  subt (α, τ) = subsTyVar_meet (α, τ, ofRSort τ)
+  subt (α, τ) = subsTyVarMeet (α, τ, ofRSort τ)
 
 instance (SubsTy tv ty (UReft r), SubsTy tv ty (RType c tv ())) => SubsTy tv ty (RTProp c tv (UReft r))  where
-  subt m (RProp ss (RHole p)) = RProp ((mapSnd (subt m)) <$> ss) $ RHole $ subt m p
-  subt m (RProp ss t) = RProp ((mapSnd (subt m)) <$> ss) $ fmap (subt m) t
+  subt m (RProp ss (RHole p)) = RProp (mapSnd (subt m) <$> ss) $ RHole $ subt m p
+  subt m (RProp ss t) = RProp (mapSnd (subt m) <$> ss) $ fmap (subt m) t
 
 subvUReft     :: (UsedPVar -> UsedPVar) -> UReft Reft -> UReft Reft
 subvUReft f (MkUReft r p) = MkUReft r (subvPredicate f p)
@@ -1413,7 +1422,7 @@
 ofLitType :: (Monoid r) => (TyCon -> [RType c tv r] -> [p] -> r -> RType c tv r) -> TyLit -> RType c tv r
 ofLitType rF (NumTyLit _)  = rF intTyCon [] [] mempty
 ofLitType rF t@(StrTyLit _)
-  | t == holeLit           = RHole mempty 
+  | t == holeLit           = RHole mempty
   | otherwise              = rF listTyCon [rF charTyCon [] [] mempty] [] mempty
 
 holeLit :: TyLit
@@ -1464,7 +1473,7 @@
 isBaseTy (TyVarTy _)      = True
 isBaseTy (AppTy _ _)      = False
 isBaseTy (TyConApp _ ts)  = and $ isBaseTy <$> ts
-isBaseTy (FunTy _ _ _ _)  = False
+isBaseTy FunTy{}          = False
 isBaseTy (ForAllTy _ _)   = False
 isBaseTy (LitTy _)        = True
 isBaseTy (CastTy _ _)     = False
@@ -1503,7 +1512,7 @@
   = toType useRFInfo t
 toType _ (RVar (RTV α) _)
   = TyVarTy α
-toType useRFInfo (RApp (RTyCon {rtc_tc = c}) ts _ _)
+toType useRFInfo (RApp RTyCon{rtc_tc = c} ts _ _)
   = TyConApp c (toType useRFInfo <$> filter notExprArg ts)
   where
     notExprArg (RExprArg _) = False
@@ -1521,7 +1530,7 @@
 toType useRFInfo (RRTy _ _ _ t)
   = toType useRFInfo t
 toType _ (RHole _)
-  = LitTy holeLit  
+  = LitTy holeLit
 -- toType t
 --  = {- impossible Nothing -} Prelude.error $ "RefType.toType cannot handle: " ++ show t
 
@@ -1584,8 +1593,8 @@
 
 --------------------------------------------------------------------------------
 -- shiftVV :: Int -- SpecType -> Symbol -> SpecType
-shiftVV :: (TyConable c, F.Reftable (f Reft), Functor f) 
-        => RType c tv (f Reft) -> Symbol -> RType c tv (f Reft) 
+shiftVV :: (TyConable c, F.Reftable (f Reft), Functor f)
+        => RType c tv (f Reft) -> Symbol -> RType c tv (f Reft)
 --------------------------------------------------------------------------------
 shiftVV t@(RApp _ ts rs r) vv'
   = t { rt_args  = subst1 ts (rTypeValueVar t, EVar vv') }
@@ -1630,11 +1639,11 @@
     go t@FunTy{}        = typeSortFun tce t
     go τ@(ForAllTy _ _) = typeSortForAll tce τ
     -- go (TyConApp c τs)  = fApp (tyConFTyCon tce c) (go <$> τs)
-    go (TyConApp c τs)  
+    go (TyConApp c τs)
       | isNewTyCon c
-      , not (isRecursivenewTyCon c) 
+      , not (isRecursivenewTyCon c)
       = go (Ghc.newTyConInstRhs c τs)
-      | otherwise  
+      | otherwise
       = tyConFTyCon tce c (go <$> τs)
     go (AppTy t1 t2)    = fApp (go t1) [go t2]
     go (TyVarTy tv)     = tyVarSort tv
@@ -1642,17 +1651,17 @@
     go τ                = FObj (typeUniqueSymbol τ)
 
 tyConFTyCon :: TCEmb TyCon -> TyCon -> [Sort] -> Sort
-tyConFTyCon tce c ts = case tceLookup c tce of 
-                         Just (t, WithArgs) -> t 
-                         Just (t, NoArgs)   -> fApp t ts  
-                         Nothing            -> fApp (fTyconSort niTc) ts 
+tyConFTyCon tce c ts = case tceLookup c tce of
+                         Just (t, WithArgs) -> t
+                         Just (t, NoArgs)   -> fApp t ts
+                         Nothing            -> fApp (fTyconSort niTc) ts
   where
     niTc             = symbolNumInfoFTyCon (dummyLoc $ tyConName c) (isNumCls c) (isFracCls c)
     -- oldRes           = F.notracepp _msg $ M.lookupDefault def c tce
     -- _msg             = "tyConFTyCon c = " ++ show c ++ "default " ++ show (def, Ghc.isFamInstTyCon c)
 
 tyVarSort :: TyVar -> Sort
-tyVarSort = FObj . symbol 
+tyVarSort = FObj . symbol
 
 typeUniqueSymbol :: Type -> Symbol
 typeUniqueSymbol = symbol . GM.typeUniqueString
@@ -1677,7 +1686,7 @@
 
 typeSortFun :: TCEmb TyCon -> Type -> Sort
 typeSortFun tce t = mkFFunc 0 sos
-  where 
+  where
     sos           = typeSort tce <$> τs
     τs            = grabArgs [] t
 
@@ -1695,10 +1704,7 @@
 grabArgs τs τ
   = reverse (τ:τs)
 
-isNonValueTy :: Type -> Bool
-isNonValueTy = GM.isPredType-- GM.isEmbeddedDictType 
 
-
 expandProductType :: (PPrint r, Reftable r, SubsTy RTyVar (RType RTyCon RTyVar ()) r, Reftable (RTProp RTyCon RTyVar r))
                   => Var -> RType RTyCon RTyVar r -> RType RTyCon RTyVar r
 expandProductType x t
@@ -1718,7 +1724,7 @@
             -> [(Symbol, RFInfo, RType RTyCon RTyVar r, t)]
 mkProductTy (τ, x, i, t, r) = maybe [(x, i, t, r)] f $ do
   DataConAppContext{..} <- deepSplitProductType_maybe menv τ
-  pure $ (dcac_dc, dcac_tys, map (\(t,s) -> (irrelevantMult t, s)) dcac_arg_tys, dcac_co)
+  pure (dcac_dc, dcac_tys, map (first irrelevantMult) dcac_arg_tys, dcac_co)
   where
     f    :: (DataCon, [Type], [(Type, StrictnessMark)], Coercion) -> [(Symbol, RFInfo, RType RTyCon RTyVar r, t)]
     f    = map ((dummySymbol, defRFInfo, , mempty) . ofType . fst) . third4
@@ -1733,14 +1739,14 @@
   = [(symbol a, trueSortedReft FFrac) | (RVar a _) <- ts]
   | isNumCls c
   = [(symbol a, trueSortedReft FNum) | (RVar a _) <- ts]
-classBinds emb (RApp c [_, _, (RVar a _), t] _ _)
+classBinds emb (RApp c [_, _, RVar a _, t] _ _)
   | isEqual c
   = [(symbol a, rTypeSortedReft emb t)]
-classBinds  emb ty@(RApp c [_, (RVar a _), t] _ _)
-  | isEqualityConstr ty 
+classBinds  emb ty@(RApp c [_, RVar a _, t] _ _)
+  | isEqualityConstr ty
   = [(symbol a, rTypeSortedReft emb t)]
-  | otherwise 
-  = notracepp ("CLASSBINDS-0: " ++ showpp c) [] 
+  | otherwise
+  = notracepp ("CLASSBINDS-0: " ++ showpp c) []
 classBinds _ t
   = notracepp ("CLASSBINDS-1: " ++ showpp (toType False t, isEqualityConstr t)) []
 
@@ -1770,7 +1776,7 @@
 makeDecrType :: Symbolic a
              => S.HashSet TyCon
              -> [(a, (Symbol, RType RTyCon t (UReft Reft)))]
-             -> Either (Symbol, RType RTyCon t (UReft Reft)) String 
+             -> Either (Symbol, RType RTyCon t (UReft Reft)) String
 makeDecrType autoenv = mkDType autoenv [] []
 
 mkDType :: Symbolic a
@@ -1778,7 +1784,7 @@
         -> [(Symbol, Symbol, Symbol -> Expr)]
         -> [Expr]
         -> [(a, (Symbol, RType RTyCon t (UReft Reft)))]
-        -> Either (Symbol, RType RTyCon t (UReft Reft)) String 
+        -> Either (Symbol, RType RTyCon t (UReft Reft)) String
 mkDType autoenv xvs acc [(v, (x, t))]
   = Left ((x, ) $ t `strengthen` tr)
   where
@@ -1816,7 +1822,8 @@
 -- | [NOTE]: THIS IS WHERE THE TERMINATION METRIC REFINEMENTS ARE CREATED.
 cmpLexRef :: [(t1, t1, t1 -> Expr)] -> (t, t, t -> Expr) -> Expr
 cmpLexRef vxs (v, x, g)
-  = pAnd $  (PAtom Lt (g x) (g v)) : (PAtom Ge (g x) zero)
+  = pAnd $   PAtom Lt (g x) (g v)
+         :   PAtom Ge (g x) zero
          :  [PAtom Eq (f y) (f z) | (y, z, f) <- vxs]
          ++ [PAtom Ge (f y) zero  | (y, _, f) <- vxs]
   where zero = ECon $ I 0
@@ -1833,8 +1840,8 @@
 makeLexReft old acc (e:es) (e':es')
   = makeLexReft ((e,e'):old) (r:acc) es es'
   where
-    r    = pAnd $  (PAtom Lt e' e)
-                :  (PAtom Ge e' zero)
+    r    = pAnd $   PAtom Lt e' e
+                :   PAtom Ge e' zero
                 :  [PAtom Eq o' o    | (o,o') <- old]
                 ++ [PAtom Ge o' zero | (_,o') <- old]
     zero = ECon $ I 0
@@ -1849,68 +1856,6 @@
     defTv                     = makeTyConVariance c
 
 
-makeTyConVariance :: TyCon -> VarianceInfo
-makeTyConVariance c = varSignToVariance <$> tvs
-  where
-    tvs = GM.tyConTyVarsDef c
-
-    varsigns = if Ghc.isTypeSynonymTyCon c
-                  then go True (fromJust $ Ghc.synTyConRhs_maybe c)
-                  else L.nub $ concatMap goDCon $ Ghc.tyConDataCons c
-
-    varSignToVariance v = case filter (\p -> GM.showPpr (fst p) == GM.showPpr v) varsigns of
-                            []       -> Invariant
-                            [(_, b)] -> if b then Covariant else Contravariant
-                            _        -> Bivariant
-
-
-    goDCon dc = concatMap (go True) (map irrelevantMult $ Ghc.dataConOrigArgTys dc)
-
-    go pos (FunTy _ _ t1 t2) = go (not pos) t1 ++ go pos t2
-    go pos (ForAllTy _ t)    = go pos t
-    go pos (TyVarTy v)       = [(v, pos)]
-    go pos (AppTy t1 t2)     = go pos t1 ++ go pos t2
-    go pos (TyConApp c' ts)
-       | c == c'
-       = []
-
--- NV fix that: what happens if we have mutually recursive data types?
--- now just provide "default" Bivariant for mutually rec types.
--- but there should be a finer solution
-       | mutuallyRecursive c c'
-       = concatMap (goTyConApp pos Bivariant) ts
-       | otherwise
-       = concat $ zipWith (goTyConApp pos) (makeTyConVariance c') ts
-
-    go _   (LitTy _)       = []
-    go _   (CoercionTy _)  = []
-    go pos (CastTy t _)    = go pos t
-
-    goTyConApp _   Invariant     _ = []
-    goTyConApp pos Bivariant     t = goTyConApp pos Contravariant t ++ goTyConApp pos Covariant t
-    goTyConApp pos Covariant     t = go pos       t
-    goTyConApp pos Contravariant t = go (not pos) t
-
-    mutuallyRecursive c c' = c `S.member` (dataConsOfTyCon c')
-
-
-dataConsOfTyCon :: TyCon -> S.HashSet TyCon
-dataConsOfTyCon = dcs S.empty
-  where
-    dcs vis c                 = mconcat $ go vis <$> [irrelevantMult t | dc <- Ghc.tyConDataCons c, t <- Ghc.dataConOrigArgTys dc]
-    go  vis (FunTy _ _ t1 t2) = go vis t1 `S.union` go vis t2
-    go  vis (ForAllTy _ t)    = go vis t
-    go  _   (TyVarTy _)       = S.empty
-    go  vis (AppTy t1 t2)     = go vis t1 `S.union` go vis t2
-    go  vis (TyConApp c ts)
-      | c `S.member` vis
-      = S.empty
-      | otherwise
-      = (S.insert c $ mconcat $ go vis <$> ts) `S.union` dcs (S.insert c vis) c
-    go  _   (LitTy _)       = S.empty
-    go  _   (CoercionTy _)  = S.empty
-    go  vis (CastTy t _)    = go vis t
-
 --------------------------------------------------------------------------------
 -- | Printing Refinement Types -------------------------------------------------
 --------------------------------------------------------------------------------
@@ -1933,15 +1878,15 @@
 instance PPrint DataCtor where
   -- pprintTidy k (DataCtor c as _   xts Nothing)  = pprintTidy k c <+> dcolon ppVars as <+> braces (ppFields k ", " xts)
   -- pprintTidy k (DataCtor c as ths xts (Just t)) = pprintTidy k c <+> dcolon <+> ppVars as <+> ppThetas ths <+> (ppFields k " ->" xts) <+> "->" <+> pprintTidy k t
-  pprintTidy k (DataCtor c as ths xts t) = pprintTidy k c <+> dcolon <+> ppVars k as <+> ppThetas ths <+> (ppFields k " ->" xts) <+> "->" <+> res 
+  pprintTidy k (DataCtor c as ths xts t) = pprintTidy k c <+> dcolon <+> ppVars k as <+> ppThetas ths <+> ppFields k " ->" xts <+> "->" <+> res
     where
-      res         = maybe "*" (pprintTidy k) t 
+      res         = maybe "*" (pprintTidy k) t
       ppThetas [] = empty
       ppThetas ts = parens (hcat $ punctuate ", " (pprintTidy k <$> ts)) <+> "=>"
 
 
 ppVars :: (PPrint a) => Tidy -> [a] -> Doc
-ppVars k as = "forall" <+> hcat (punctuate " " (F.pprintTidy k <$> as)) <+> "." 
+ppVars k as = "forall" <+> hcat (punctuate " " (F.pprintTidy k <$> as)) <+> "."
 
 ppFields :: (PPrint k, PPrint v) => Tidy -> Doc -> [(k, v)] -> Doc
 ppFields k sep kvs = hcat $ punctuate sep (F.pprintTidy k <$> kvs)
@@ -1970,34 +1915,34 @@
 -- | (in positive positions, in negative positions, in undetermined positions)
 -- | undetermined positions are due to type constructors and type application
 -------------------------------------------------------------------------------
-tyVarsPosition :: RType RTyCon tv r -> Positions tv 
+tyVarsPosition :: RType RTyCon tv r -> Positions tv
 tyVarsPosition = go (Just True)
-  where 
+  where
     go p (RVar t _)        = report p t
-    go p (RFun _ _ t1 t2 _)  = go (flip p) t1 <> go p t2 
-    go p (RImpF _ _ t1 t2 _) = go (flip p) t1 <> go p t2 
-    go p (RAllT _ t _)     = go p t 
-    go p (RAllP _ t)       = go p t 
+    go p (RFun _ _ t1 t2 _)  = go (flip p) t1 <> go p t2
+    go p (RImpF _ _ t1 t2 _) = go (flip p) t1 <> go p t2
+    go p (RAllT _ t _)     = go p t
+    go p (RAllP _ t)       = go p t
     go p (RApp c ts _ _)   = mconcat (zipWith go (getPosition p <$> varianceTyArgs (rtc_info c)) ts)
-    go p (RAllE _ t1 t2)   = go p t1 <> go p t2 
+    go p (RAllE _ t1 t2)   = go p t1 <> go p t2
     go p (REx _ t1 t2)     = go p t1 <> go p t2
     go _ (RExprArg _)      = mempty
-    go p (RAppTy t1 t2 _)  = go p t1 <> go p t2 
-    go p (RRTy _ _ _ t)    = go p t 
+    go p (RAppTy t1 t2 _)  = go p t1 <> go p t2
+    go p (RRTy _ _ _ t)    = go p t
     go _ (RHole _)         = mempty
 
     getPosition :: Maybe Bool -> Variance -> Maybe Bool
-    getPosition b Contravariant = not <$> b 
-    getPosition b _             = b  
+    getPosition b Contravariant = not <$> b
+    getPosition b _             = b
 
-    report Nothing v      = (Pos [] [] [v])
-    report (Just True) v  = (Pos [v] [] [])
-    report (Just False) v = (Pos [] [v] [])
+    report Nothing v      = Pos [] [] [v]
+    report (Just True) v  = Pos [v] [] []
+    report (Just False) v = Pos [] [v] []
     flip = fmap not
 
 data Positions a = Pos {ppos :: [a], pneg ::  [a], punknown :: [a]}
 
-instance Monoid (Positions a) where 
+instance Monoid (Positions a) where
   mempty = Pos [] [] []
-instance Semigroup (Positions a) where 
+instance Semigroup (Positions a) where
   (Pos x1 x2 x3) <> (Pos y1 y2 y3) = Pos (x1 ++ y1) (x2 ++ y2) (x3 ++ y3)
diff --git a/src/Language/Haskell/Liquid/Types/Specs.hs b/src/Language/Haskell/Liquid/Types/Specs.hs
--- a/src/Language/Haskell/Liquid/Types/Specs.hs
+++ b/src/Language/Haskell/Liquid/Types/Specs.hs
@@ -2,15 +2,13 @@
 -- | This module contains the top-level structures that hold 
 --   information about specifications.
 
-{-# LANGUAGE TypeSynonymInstances       #-}
 {-# LANGUAGE FlexibleInstances          #-}
 {-# LANGUAGE FlexibleContexts           #-}
 {-# LANGUAGE DeriveGeneric              #-}
-{-# LANGUAGE DerivingStrategies         #-}
 {-# LANGUAGE DerivingVia                #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE RecordWildCards            #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+
 module Language.Haskell.Liquid.Types.Specs (
   -- * Different types of specifications
   -- $differentSpecTypes
@@ -80,8 +78,8 @@
 import           Language.Haskell.Liquid.Types.Generics
 import           Language.Haskell.Liquid.Types.Variance
 import           Language.Haskell.Liquid.Types.Bounds 
-import           Language.Haskell.Liquid.GHC.API hiding (text, (<+>))
-import           Language.Haskell.Liquid.GHC.Types
+import           Liquid.GHC.API hiding (text, (<+>))
+import           Liquid.GHC.Types
 import           Text.PrettyPrint.HughesPJ              (text, (<+>))
 
 
@@ -236,6 +234,8 @@
   , gsDicts    :: !(DEnv Var LocSpecType)            -- ^ Refined Classes from Instances 
   , gsMethods  :: ![(Var, MethodType LocSpecType)]   -- ^ Refined Classes from Classes 
   , gsTexprs   :: ![(Var, LocSpecType, [F.Located F.Expr])]  -- ^ Lexicographically ordered expressions for termination
+  , gsRelation :: ![(Var, Var, LocSpecType, LocSpecType, RelExpr, RelExpr)]
+  , gsAsmRel   :: ![(Var, Var, LocSpecType, LocSpecType, RelExpr, RelExpr)]
   }
 
 instance Semigroup GhcSpecSig where
@@ -248,7 +248,8 @@
     , gsDicts    = gsDicts x    <> gsDicts y   
     , gsMethods  = gsMethods x  <> gsMethods y   
     , gsTexprs   = gsTexprs x   <> gsTexprs y   
-
+    , gsRelation = gsRelation x <> gsRelation y
+    , gsAsmRel   = gsAsmRel x   <> gsAsmRel y
     }
 
 
@@ -258,7 +259,7 @@
 
 
 instance Monoid GhcSpecSig where
-  mempty = SpSig mempty mempty mempty mempty mempty mempty mempty mempty  
+  mempty = SpSig mempty mempty mempty mempty mempty mempty mempty mempty mempty mempty  
 
 data GhcSpecData = SpData 
   { gsCtors      :: ![(Var, LocSpecType)]         -- ^ Data Constructor Measure Sigs
@@ -328,7 +329,7 @@
                   mempty mempty mempty
                   mempty mempty mempty
 data GhcSpecLaws = SpLaws 
-  { gsLawDefs :: !([(Class, [(Var, LocSpecType)])])
+  { gsLawDefs :: ![(Class, [(Var, LocSpecType)])]
   , gsLawInst :: ![LawInstance]
   }
 
@@ -408,10 +409,13 @@
   , imeasures  :: ![Measure ty bndr]              -- ^ Mappings from (measure,type) -> measure
   , classes    :: ![RClass ty]                    -- ^ Refined Type-Classes
   , claws      :: ![RClass ty]                    -- ^ Refined Type-Classe Laws
+  , relational :: ![(LocSymbol, LocSymbol, ty, ty, RelExpr, RelExpr)] -- ^ Relational types
+  , asmRel     :: ![(LocSymbol, LocSymbol, ty, ty, RelExpr, RelExpr)] -- ^ Assumed relational types
   , termexprs  :: ![(F.LocSymbol, [F.Located F.Expr])] -- ^ Terminating Conditions for functions
   , rinstance  :: ![RInstance ty]
   , ilaws      :: ![RILaws ty]
   , dvariance  :: ![(F.LocSymbol, [Variance])]         -- ^ ? Where do these come from ?!
+  , dsize      :: ![([ty], F.LocSymbol)]      -- ^ Size measure to enforce fancy termination 
   , bounds     :: !(RRBEnv ty)
   , defs       :: !(M.HashMap F.LocSymbol F.Symbol)    -- ^ Temporary (?) hack to deal with dictionaries in specifications
                                                        --   see tests/pos/NatClass.hs
@@ -449,10 +453,13 @@
            , imeasures  =           imeasures  s1 ++ imeasures  s2
            , classes    =           classes    s1 ++ classes    s2
            , claws      =           claws      s1 ++ claws      s2
+           , relational =           relational s1 ++ relational s2 
+           , asmRel     =           asmRel     s1 ++ asmRel     s2 
            , termexprs  =           termexprs  s1 ++ termexprs  s2
            , rinstance  =           rinstance  s1 ++ rinstance  s2
            , ilaws      =               ilaws  s1 ++ ilaws      s2 
            , dvariance  =           dvariance  s1 ++ dvariance  s2
+           , dsize      =               dsize  s1 ++ dsize      s2
            , axeqs      =           axeqs s1      ++ axeqs s2
            , embeds     = mappend   (embeds   s1)  (embeds   s2)
            , lvars      = S.union   (lvars    s1)  (lvars    s2)
@@ -508,11 +515,14 @@
            , cmeasures  = []
            , imeasures  = []
            , classes    = []
-           , claws      = [] 
+           , claws      = []
+           , relational = []  
+           , asmRel     = []  
            , termexprs  = []
            , rinstance  = []
            , ilaws      = [] 
            , dvariance  = []
+           , dsize      = []
            , axeqs      = []
            , bounds     = M.empty
            , defs       = M.empty
@@ -589,6 +599,7 @@
     -- ^ Refined Type-Classe Laws
   , liftedRinstance  :: HashSet (RInstance LocBareType)
   , liftedIlaws      :: HashSet (RILaws LocBareType)
+  , liftedDsize      :: [([LocBareType], F.LocSymbol)]
   , liftedDvariance  :: HashSet (F.LocSymbol, [Variance])
     -- ^ ? Where do these come from ?!
   , liftedBounds     :: RRBEnv LocBareType
@@ -630,6 +641,7 @@
   , liftedRinstance  = mempty
   , liftedIlaws      = mempty
   , liftedDvariance  = mempty
+  , liftedDsize      = mempty
   , liftedBounds     = mempty
   , liftedDefs       = mempty
   , liftedAxeqs      = mempty
@@ -817,6 +829,7 @@
       , liftedRinstance  = S.fromList . rinstance $ a
       , liftedIlaws      = S.fromList . ilaws $ a
       , liftedDvariance  = S.fromList . dvariance $ a
+      , liftedDsize      = dsize a 
       , liftedBounds     = bounds a
       , liftedDefs       = defs a
       , liftedAxeqs      = S.fromList . axeqs $ a
@@ -833,6 +846,8 @@
   , sigs       = S.toList . liftedSigs $ a
   , localSigs  = mempty
   , reflSigs   = mempty
+  , relational = mempty 
+  , asmRel     = mempty 
   , invariants = S.toList . liftedInvariants $ a
   , ialiases   = S.toList . liftedIaliases $ a
   , imports    = S.toList . liftedImports $ a
@@ -865,6 +880,7 @@
   , rinstance  = S.toList . liftedRinstance $ a
   , ilaws      = S.toList . liftedIlaws $ a
   , dvariance  = S.toList . liftedDvariance $ a
+  , dsize      = liftedDsize  a
   , bounds     = liftedBounds a
   , defs       = liftedDefs a
   , axeqs      = S.toList . liftedAxeqs $ a
diff --git a/src/Language/Haskell/Liquid/Types/Types.hs b/src/Language/Haskell/Liquid/Types/Types.hs
--- a/src/Language/Haskell/Liquid/Types/Types.hs
+++ b/src/Language/Haskell/Liquid/Types/Types.hs
@@ -1,23 +1,19 @@
-{-# LANGUAGE StandaloneDeriving         #-}
 {-# LANGUAGE DeriveDataTypeable         #-}
-{-# LANGUAGE DeriveFunctor              #-}
-{-# LANGUAGE DeriveFoldable             #-}
 {-# LANGUAGE DeriveGeneric              #-}
 {-# LANGUAGE DeriveTraversable          #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE MultiParamTypeClasses      #-}
-{-# LANGUAGE TypeSynonymInstances       #-}
 {-# LANGUAGE FlexibleInstances          #-}
 {-# LANGUAGE FlexibleContexts           #-}
 {-# LANGUAGE UndecidableInstances       #-}
 {-# LANGUAGE OverloadedStrings          #-}
 {-# LANGUAGE RecordWildCards            #-}
 {-# LANGUAGE ConstraintKinds            #-}
-{-# LANGUAGE BangPatterns               #-}
-{-# LANGUAGE TupleSections              #-}
-{-# LANGUAGE DerivingStrategies         #-}
 {-# LANGUAGE DerivingVia                #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- | This module should contain all the global type definitions and basic instances.
 
 module Language.Haskell.Liquid.Types.Types (
@@ -86,6 +82,9 @@
   -- * Refinements
   , UReft(..)
 
+  -- * Relational predicates
+  , RelExpr (..)
+
   -- * Parse-time entities describing refined data types
   , SizeFun  (..), szFun
   , DataDecl (..)
@@ -125,7 +124,7 @@
   , isBase
   , isFunTy
   , isTrivial
-  , hasHole 
+  , hasHole
 
   -- * Traversing `RType`
   , efoldReft, foldReft, foldReft'
@@ -144,7 +143,7 @@
   , AnnInfo (..)
   , Annot (..)
 
-  -- * Hole Information 
+  -- * Hole Information
   , HoleInfo(..)
 
   -- * Overall Output
@@ -204,7 +203,7 @@
   , Def (..)
   , Body (..)
   , MSpec (..)
-  
+
   -- * Scoping Info
   , BScope
 
@@ -239,14 +238,14 @@
   -- , rtyVarUniqueSymbol, tyVarUniqueSymbol
   , rtyVarType, tyVarVar
 
-  -- * Refined Function Info 
+  -- * Refined Function Info
   , RFInfo(..), defRFInfo, mkRFInfo, classRFInfo, classRFInfoType
 
   , ordSrcSpan
   )
   where
 
-import           Language.Haskell.Liquid.GHC.API as Ghc hiding ( Expr
+import           Liquid.GHC.API as Ghc hiding ( Expr
                                                                , Target
                                                                , isFunTy
                                                                , LM
@@ -278,7 +277,7 @@
 import           Prelude                          hiding  (error)
 import qualified Prelude
 
-import           Control.Monad                          (liftM, liftM2, liftM3, liftM4)
+import           Control.Monad                          (liftM2, liftM3, liftM4, void)
 import           Control.DeepSeq
 import           Data.Bifunctor
 import           Data.Typeable                          (Typeable)
@@ -289,19 +288,19 @@
 import qualified Data.HashMap.Strict                    as M
 import qualified Data.HashSet                           as S
 import qualified Data.List                              as L
-import           Data.Maybe                             (fromMaybe, mapMaybe)
+import           Data.Maybe                             (mapMaybe)
 import           Data.Function                          (on)
 import           Data.List                              as L (foldl', nub, null)
 import           Data.Text                              (Text)
-import           Text.PrettyPrint.HughesPJ              hiding (first, (<>)) 
+import           Text.PrettyPrint.HughesPJ              hiding (first, (<>))
 import           Text.Printf
 import           Language.Fixpoint.Misc
 
 import qualified Language.Fixpoint.Types as F
 
 import           Language.Haskell.Liquid.Types.Generics
-import           Language.Haskell.Liquid.GHC.Misc
-import           Language.Haskell.Liquid.GHC.Logging as GHC
+import           Liquid.GHC.Misc
+import           Liquid.GHC.Logging as GHC
 import           Language.Haskell.Liquid.Types.Variance
 import           Language.Haskell.Liquid.Types.Errors
 import           Language.Haskell.Liquid.Misc
@@ -317,25 +316,25 @@
 If BScope = False, then the outer binder out is not in scope on ri
 -}
 
-type BScope = Bool    
+type BScope = Bool
 -----------------------------------------------------------------------------
 -- | Information about Type Constructors
 -----------------------------------------------------------------------------
-data TyConMap = TyConMap 
-  { tcmTyRTy    :: M.HashMap TyCon             RTyCon  -- ^ Map from GHC TyCon to RTyCon 
+data TyConMap = TyConMap
+  { tcmTyRTy    :: M.HashMap TyCon             RTyCon  -- ^ Map from GHC TyCon to RTyCon
   , tcmFIRTy    :: M.HashMap (TyCon, [F.Sort]) RTyCon  -- ^ Map from GHC Family-Instances to RTyCon
-  , tcmFtcArity :: M.HashMap TyCon             Int     -- ^ Arity of each Family-Tycon 
+  , tcmFtcArity :: M.HashMap TyCon             Int     -- ^ Arity of each Family-Tycon
   }
- 
 
-data RFInfo = RFInfo {permitTC :: Maybe Bool }
+
+newtype RFInfo = RFInfo {permitTC :: Maybe Bool }
   deriving (Generic, Data, Typeable, Show, Eq)
 
 defRFInfo :: RFInfo
-defRFInfo = RFInfo Nothing 
+defRFInfo = RFInfo Nothing
 
 classRFInfo :: Bool -> RFInfo
-classRFInfo b = RFInfo (Just b) 
+classRFInfo b = RFInfo (Just b)
 
 classRFInfoType :: Bool -> RType c tv r -> RType c tv r
 classRFInfoType b = fromRTypeRep .
@@ -343,7 +342,7 @@
                     toRTypeRep
 
 mkRFInfo :: Config  -> RFInfo
-mkRFInfo cfg = RFInfo $ Just (typeclass cfg)  
+mkRFInfo cfg = RFInfo $ Just (typeclass cfg)
 
 instance Hashable RFInfo
 instance NFData RFInfo
@@ -353,17 +352,17 @@
 -- | Printer ----------------------------------------------------------------
 -----------------------------------------------------------------------------
 
-data PPEnv = PP 
-  { ppPs    :: Bool -- ^ print abstract-predicates 
+data PPEnv = PP
+  { ppPs    :: Bool -- ^ print abstract-predicates
   , ppTyVar :: Bool -- ^ print the unique suffix for each tyvar
-  , ppShort :: Bool -- ^ print the tycons without qualification 
+  , ppShort :: Bool -- ^ print the tycons without qualification
   , ppDebug :: Bool -- ^ gross with full info
   }
   deriving (Show)
 
 ppEnv :: PPEnv
-ppEnv = ppEnvDef 
-          { ppPs    = True }   
+ppEnv = ppEnvDef
+          { ppPs    = True }
           { ppDebug = True }   -- RJ: needed for resolution, because pp is used for serialization?
 
 {- | [NOTE:ppEnv] For some mysterious reason, `ppDebug` must equal `True`
@@ -457,7 +456,7 @@
 -- TODO: just use Located instead of dc_loc, dc_locE
 data DataConP = DataConP
   { dcpLoc        :: !F.SourcePos
-  , dcpCon        :: !DataCon                -- ^ Corresponding GHC DataCon 
+  , dcpCon        :: !DataCon                -- ^ Corresponding GHC DataCon
   , dcpFreeTyVars :: ![RTyVar]               -- ^ Type parameters
   , dcpFreePred   :: ![PVar RSort]           -- ^ Abstract Refinement parameters
   , dcpTyConstrs  :: ![SpecType]             -- ^ ? Class constraints (via `dataConStupidTheta`)
@@ -533,7 +532,7 @@
 
 type UsedPVar      = PVar ()
 
-newtype Predicate  = Pr [UsedPVar] 
+newtype Predicate  = Pr [UsedPVar]
   deriving (Generic, Data, Typeable)
   deriving Hashable via Generically Predicate
 
@@ -590,7 +589,16 @@
 
 instance NFData r => NFData (UReft r)
 
+data RelExpr = ERBasic F.Expr | ERChecked Expr RelExpr | ERUnChecked Expr RelExpr
+  deriving (Eq, Show, Data, Generic)
 
+instance B.Binary RelExpr
+
+instance F.PPrint RelExpr where
+  pprintTidy k (ERBasic e)       = F.pprintTidy k e
+  pprintTidy k (ERChecked e r)   = F.pprintTidy k e <+> "!=>" <+> F.pprintTidy k r
+  pprintTidy k (ERUnChecked e r) = F.pprintTidy k e <+> ":=>" <+> F.pprintTidy k r
+
 newtype BTyVar = BTV Symbol deriving (Show, Generic, Data, Typeable)
 
 newtype RTyVar = RTV TyVar deriving (Generic, Data, Typeable)
@@ -640,7 +648,7 @@
   deriving (Generic, Data, Typeable)
 
 instance F.Symbolic RTyCon where
-  symbol = F.symbol . rtc_tc 
+  symbol = F.symbol . rtc_tc
 
 instance F.Symbolic BTyCon where
   symbol = F.val . btc_tc
@@ -664,7 +672,7 @@
 -- | Accessors for @RTyCon@
 
 isBool :: RType RTyCon t t1 -> Bool
-isBool (RApp (RTyCon{rtc_tc = c}) _ _ _) = c == boolTyCon
+isBool (RApp RTyCon{rtc_tc = c} _ _ _) = c == boolTyCon
 isBool _                                 = False
 
 isRVar :: RType c tv r -> Bool
@@ -782,7 +790,7 @@
   -- | "forall x y <z :: Nat, w :: Int> . TYPE"
   --               ^^^^^^^^^^^^^^^^^^^ (rt_pvbind)
   | RAllP {
-      rt_pvbind :: !(PVU c tv)  -- ar (RType c tv ()))
+      rt_pvbind :: !(PVU c tv)
     , rt_ty     :: !(RType c tv r)
     }
 
@@ -855,7 +863,7 @@
 makeRTVar a = RTVar a (RTVNoInfo True)
 
 instance (Eq tv) => Eq (RTVar tv s) where
-  t1 == t2 = (ty_var_value t1) == (ty_var_value t2)
+  t1 == t2 = ty_var_value t1 == ty_var_value t2
 
 data RTVar tv s = RTVar
   { ty_var_value :: tv
@@ -874,28 +882,28 @@
   | RTVInfo { rtv_name   :: Symbol
             , rtv_kind   :: s
             , rtv_is_val :: Bool
-            , rtv_is_pol :: Bool -- true iff the type variable gets instantiated with 
-                                 -- any refinement (ie is polymorphic on refinements), 
-                                 -- false iff instantiation is with true refinement 
+            , rtv_is_pol :: Bool -- true iff the type variable gets instantiated with
+                                 -- any refinement (ie is polymorphic on refinements),
+                                 -- false iff instantiation is with true refinement
             } deriving (Generic, Data, Typeable, Functor)
               deriving Hashable via Generically (RTVInfo s)
 
 
-setRtvPol :: RTVar tv a -> Bool -> RTVar tv a 
+setRtvPol :: RTVar tv a -> Bool -> RTVar tv a
 setRtvPol (RTVar a i) b = RTVar a (i{rtv_is_pol = b})
 
 rTVarToBind :: RTVar RTyVar s  -> Maybe (Symbol, s)
 rTVarToBind = go . ty_var_info
   where
-    go (RTVInfo {..}) | rtv_is_val = Just (rtv_name, rtv_kind)
-    go _                           = Nothing
+    go RTVInfo{..} | rtv_is_val = Just (rtv_name, rtv_kind)
+    go _                        = Nothing
 
-ty_var_is_val :: RTVar tv s -> Bool
-ty_var_is_val = rtvinfo_is_val . ty_var_info
+tyVarIsVal :: RTVar tv s -> Bool
+tyVarIsVal = rtvinfoIsVal . ty_var_info
 
-rtvinfo_is_val :: RTVInfo s -> Bool
-rtvinfo_is_val (RTVNoInfo {..}) = False
-rtvinfo_is_val (RTVInfo {..})   = rtv_is_val
+rtvinfoIsVal :: RTVInfo s -> Bool
+rtvinfoIsVal RTVNoInfo{} = False
+rtvinfoIsVal RTVInfo{..} = rtv_is_val
 
 instance (B.Binary tv, B.Binary s) => B.Binary (RTVar tv s)
 instance (NFData tv, NFData s)     => NFData   (RTVar tv s)
@@ -964,16 +972,16 @@
 type SpecProp    = RRProp    RReft
 type RRProp r    = Ref       RSort (RRType r)
 type BRProp r    = Ref       BSort (BRType r)
-type SpecRTVar   = RTVar     RTyVar RSort 
+type SpecRTVar   = RTVar     RTyVar RSort
 
 
 
 type LocBareType = F.Located BareType
 type LocSpecType = F.Located SpecType
 
-type SpecRTEnv   = RTEnv RTyVar SpecType 
-type BareRTEnv   = RTEnv Symbol BareType 
-type BareRTAlias = RTAlias Symbol BareType 
+type SpecRTEnv   = RTEnv RTyVar SpecType
+type BareRTEnv   = RTEnv Symbol BareType
+type BareRTAlias = RTAlias Symbol BareType
 type SpecRTAlias = RTAlias RTyVar SpecType
 
 
@@ -1042,9 +1050,9 @@
   ppTycon    = text . showPpr
 
   isNumCls c  = maybe False (isClassOrSubClass isNumericClass)
-                (tyConClass_maybe $ c)
+                (tyConClass_maybe c)
   isFracCls c = maybe False (isClassOrSubClass isFractionalClass)
-                (tyConClass_maybe $ c)
+                (tyConClass_maybe c)
   isOrdCls c  = maybe False isOrdClass
                 (tyConClass_maybe c)
   isEqCls  c  = isPrelEqTyCon c
@@ -1081,7 +1089,7 @@
 instance Eq BTyCon where
   x == y = btc_tc x == btc_tc y
 
-instance Ord BTyCon where 
+instance Ord BTyCon where
   compare x y = compare (btc_tc x) (btc_tc y)
 
 instance F.Fixpoint RTyCon where
@@ -1097,12 +1105,12 @@
   show = show . F.toFix
 
 instance F.PPrint RTyCon where
-  pprintTidy k c 
-    | ppDebug ppEnv = F.pprintTidy k tc  <-> (angleBrackets $ F.pprintTidy k pvs)
+  pprintTidy k c
+    | ppDebug ppEnv = F.pprintTidy k tc  <-> angleBrackets (F.pprintTidy k pvs)
     | otherwise     = text . showPpr . rtc_tc $ c
-    where 
-      tc            = F.symbol (rtc_tc c) 
-      pvs           = rtc_pvars c 
+    where
+      tc            = F.symbol (rtc_tc c)
+      pvs           = rtc_pvars c
 
 instance F.PPrint BTyCon where
   pprintTidy _ = text . F.symbolString . F.val . btc_tc
@@ -1116,8 +1124,8 @@
 instance Show BTyCon where
   show = F.showpp
 
-instance F.Loc BTyCon where 
-  srcSpan = F.srcSpan . btc_tc 
+instance F.Loc BTyCon where
+  srcSpan = F.srcSpan . btc_tc
 
 --------------------------------------------------------------------------------
 -- | Refined Instances ---------------------------------------------------------
@@ -1144,16 +1152,16 @@
   deriving Hashable via Generically (RISig t)
 
 instance F.PPrint t => F.PPrint (RISig t) where
-  pprintTidy k = ppRISig k (empty :: Doc) 
+  pprintTidy k = ppRISig k (empty :: Doc)
 
 ppRISig :: (F.PPrint k, F.PPrint t) => F.Tidy -> k -> RISig t -> Doc
-ppRISig k x (RIAssumed t) = "assume" <+> F.pprintTidy k x <+> "::" <+> F.pprintTidy k t 
-ppRISig k x (RISig t)     =              F.pprintTidy k x <+> "::" <+> F.pprintTidy k t 
+ppRISig k x (RIAssumed t) = "assume" <+> F.pprintTidy k x <+> "::" <+> F.pprintTidy k t
+ppRISig k x (RISig t)     =              F.pprintTidy k x <+> "::" <+> F.pprintTidy k t
 
 instance F.PPrint t => F.PPrint (RInstance t) where
-  pprintTidy k (RI n ts mts) = ppMethods k "instance" n ts mts 
+  pprintTidy k (RI n ts mts) = ppMethods k "instance" n ts mts
 
-  
+
 instance (B.Binary t) => B.Binary (RInstance t)
 instance (B.Binary t) => B.Binary (RISig t)
 instance (B.Binary t) => B.Binary (RILaws t)
@@ -1166,9 +1174,9 @@
 data MethodType t = MT {tyInstance :: !(Maybe t), tyClass :: !(Maybe t) }
   deriving (Show)
 
-getMethodType :: MethodType t -> Maybe t 
-getMethodType (MT (Just t) _ ) = Just t 
-getMethodType (MT _ t) = t 
+getMethodType :: MethodType t -> Maybe t
+getMethodType (MT (Just t) _ ) = Just t
+getMethodType (MT _ t) = t
 
 --------------------------------------------------------------------------
 -- | Values Related to Specifications ------------------------------------
@@ -1189,13 +1197,13 @@
 
 instance Show (Axiom Var Type CoreExpr) where
   show (Axiom (n, c) v bs _ts lhs rhs) = "Axiom : " ++
-                                         "\nFun Name: " ++ (showPpr n) ++
-                                         "\nReal Name: " ++ (showPpr v) ++
-                                         "\nData Con: " ++ (showPpr c) ++
-                                         "\nArguments:" ++ (showPpr bs)  ++
+                                         "\nFun Name: " ++ showPpr n ++
+                                         "\nReal Name: " ++ showPpr v ++
+                                         "\nData Con: " ++ showPpr c ++
+                                         "\nArguments:" ++ showPpr bs  ++
                                          -- "\nTypes    :" ++ (showPpr ts)  ++
-                                         "\nLHS      :" ++ (showPpr lhs) ++
-                                         "\nRHS      :" ++ (showPpr rhs)
+                                         "\nLHS      :" ++ showPpr lhs ++
+                                         "\nRHS      :" ++ showPpr rhs
 
 --------------------------------------------------------------------------------
 -- | Data type refinements
@@ -1223,7 +1231,7 @@
   { dcName   :: F.LocSymbol            -- ^ DataCon name
   , dcTyVars :: [F.Symbol]             -- ^ Type parameters
   , dcTheta  :: [BareType]             -- ^ The GHC ThetaType corresponding to DataCon.dataConSig
-  , dcFields :: [(Symbol, BareType)]   -- ^ field-name and field-Type pairs 
+  , dcFields :: [(Symbol, BareType)]   -- ^ field-name and field-Type pairs
   , dcResult :: Maybe BareType         -- ^ Possible output (if in GADT form)
   } deriving (Data, Typeable, Generic)
     deriving Hashable via Generically DataCtor
@@ -1311,7 +1319,7 @@
   show (DnCon  c) = "datacon:" ++ show (F.val c)
 
 instance F.PPrint SizeFun where
-  pprintTidy _ (IdSizeFun)    = "[id]"
+  pprintTidy _ IdSizeFun      = "[id]"
   pprintTidy _ (SymSizeFun x) = brackets (F.pprint (F.val x))
 
 instance F.Symbolic DataName where
@@ -1367,11 +1375,11 @@
   , ty_info   :: [RFInfo]
   , ty_refts  :: [r]
   , ty_args   :: [RType c tv r]
-  , ty_res    :: (RType c tv r)
+  , ty_res    :: RType c tv r
   }
 
 fromRTypeRep :: RTypeRep c tv r -> RType c tv r
-fromRTypeRep (RTypeRep {..})
+fromRTypeRep RTypeRep{..}
   = mkArrow ty_vars ty_preds earrs arrs ty_res
   where
     arrs  = safeZip4WithError ("fromRTypeRep: " ++ show (length ty_binds, length ty_info, length ty_args, length ty_refts)) ty_binds ty_info ty_args ty_refts
@@ -1407,7 +1415,7 @@
                            , ([Symbol], [RFInfo], [RType t t1 a], [a])
                            , RType t t1 a )
 bkArrow t                = ((xs,is,ts,rs),(xs',is',ts',rs'),t'')
-  where 
+  where
     (xs, is, ts, rs, t')     = bkImp t
     (xs', is', ts', rs', t'') = bkFun t'
 
@@ -1420,11 +1428,11 @@
 bkImp (RImpF x i t t' r) = let (xs, is, ts, rs, t'') = bkImp t'  in (x:xs, i:is, t:ts, r:rs, t'')
 bkImp t                  = ([], [], [], [], t)
 
-safeBkArrow ::(F.PPrint (RType t t1 a)) 
+safeBkArrow ::(F.PPrint (RType t t1 a))
             => RType t t1 a -> ( ([Symbol], [RFInfo], [RType t t1 a], [a])
                                , ([Symbol], [RFInfo], [RType t t1 a], [a])
                                , RType t t1 a )
-safeBkArrow t@(RAllT _ _ _) = Prelude.error {- panic Nothing -} $ "safeBkArrow on RAllT" ++ F.showpp t
+safeBkArrow t@RAllT {} = Prelude.error {- panic Nothing -} $ "safeBkArrow on RAllT" ++ F.showpp t
 safeBkArrow (RAllP _ _)     = Prelude.error {- panic Nothing -} "safeBkArrow on RAllP"
 safeBkArrow t               = bkArrow t
 
@@ -1436,8 +1444,8 @@
 mkUnivs αs πs t = foldr (\(a,r) t -> RAllT a t r) (foldr RAllP t πs) αs
 
 bkUnivClass :: SpecType -> ([(SpecRTVar, RReft)],[PVar RSort], [(RTyCon, [SpecType])], SpecType )
-bkUnivClass t        = (as, ps, cs, t2) 
-  where 
+bkUnivClass t        = (as, ps, cs, t2)
+  where
     (as, ps, t1) = bkUniv  t
     (cs, t2)     = bkClass t1
 
@@ -1530,8 +1538,8 @@
    ofUReft _ = mempty
 
 instance (F.PPrint r, F.Reftable r) => F.Reftable (UReft r) where
-  isTauto               = isTauto_ureft
-  ppTy                  = ppTy_ureft
+  isTauto               = isTautoUreft
+  ppTy                  = ppTyUreft
   toReft (MkUReft r ps) = F.toReft r `F.meet` F.toReft ps
   params (MkUReft r _)  = F.params r
   bot (MkUReft r _)     = MkUReft (F.bot r) (Pr [])
@@ -1543,24 +1551,24 @@
 
 
 
-isTauto_ureft :: F.Reftable r => UReft r -> Bool
-isTauto_ureft u      = F.isTauto (ur_reft u) && F.isTauto (ur_pred u) 
+isTautoUreft :: F.Reftable r => UReft r -> Bool
+isTautoUreft u = F.isTauto (ur_reft u) && F.isTauto (ur_pred u)
 
-ppTy_ureft :: F.Reftable r => UReft r -> Doc -> Doc
-ppTy_ureft u@(MkUReft r p) d
-  | isTauto_ureft  u  = d
-  | otherwise         = ppr_reft r (F.ppTy p d)
+ppTyUreft :: F.Reftable r => UReft r -> Doc -> Doc
+ppTyUreft u@(MkUReft r p) d
+  | isTautoUreft u = d
+  | otherwise      = pprReft r (F.ppTy p d)
 
-ppr_reft :: (F.Reftable r) => r -> Doc -> Doc
-ppr_reft r d = braces (F.pprint v <+> colon <+> d <+> text "|" <+> F.pprint r')
+pprReft :: (F.Reftable r) => r -> Doc -> Doc
+pprReft r d = braces (F.pprint v <+> colon <+> d <+> text "|" <+> F.pprint r')
   where
     r'@(F.Reft (v, _)) = F.toReft r
 
 instance F.Subable r => F.Subable (UReft r) where
   syms (MkUReft r p)     = F.syms r ++ F.syms p
-  subst s (MkUReft r z)  = MkUReft (F.subst s r)  (F.subst s z)  
-  substf f (MkUReft r z) = MkUReft (F.substf f r) (F.substf f z) 
-  substa f (MkUReft r z) = MkUReft (F.substa f r) (F.substa f z) 
+  subst s (MkUReft r z)  = MkUReft (F.subst s r)  (F.subst s z)
+  substf f (MkUReft r z) = MkUReft (F.substf f r) (F.substf f z)
+  substa f (MkUReft r z) = MkUReft (F.substa f r) (F.substa f z)
 
 instance (F.Reftable r, TyConable c) => F.Subable (RTProp c tv r) where
   syms (RProp  ss r)     = (fst <$> ss) ++ F.syms r
@@ -1591,7 +1599,7 @@
   bot (Pr _)           = panic Nothing "No BOT instance for Predicate"
   ppTy r d | F.isTauto r      = d
            | not (ppPs ppEnv) = d
-           | otherwise        = d <-> (angleBrackets $ F.pprint r)
+           | otherwise        = d <-> angleBrackets (F.pprint r)
 
   toReft (Pr ps@(p:_))        = F.Reft (parg p, F.pAnd $ pToRef <$> ps)
   toReft _                    = mempty
@@ -1600,7 +1608,7 @@
   ofReft = todo Nothing "TODO: Predicate.ofReft"
 
 pToRef :: PVar a -> F.Expr
-pToRef p = pApp (pname p) $ (F.EVar $ parg p) : (thd3 <$> pargs p)
+pToRef p = pApp (pname p) $ F.EVar (parg p) : (thd3 <$> pargs p)
 
 pApp      :: Symbol -> [Expr] -> Expr
 pApp p es = F.mkEApp fn (F.EVar p:es)
@@ -1622,7 +1630,7 @@
 -- const False (not dropping dict) is probably fine since there will not be refinement on
 -- dictionaries
 isTrivial :: (F.Reftable r, TyConable c) => RType c tv r -> Bool
-isTrivial t = foldReft False (\_ r b -> F.isTauto r && b) True t
+isTrivial = foldReft False (\_ r b -> F.isTauto r && b) True
 
 mapReft ::  (r1 -> r2) -> RType c tv r1 -> RType c tv r2
 mapReft f = emapReft (const f) []
@@ -1648,9 +1656,9 @@
 emapExprArg :: ([Symbol] -> Expr -> Expr) -> [Symbol] -> RType c tv r -> RType c tv r
 emapExprArg f = go
   where
-    go _ t@(RVar {})        = t
-    go _ t@(RHole {})       = t
-    go γ (RAllT α t r)      = RAllT α (go γ t) r 
+    go _ t@RVar{}           = t
+    go _ t@RHole{}          = t
+    go γ (RAllT α t r)      = RAllT α (go γ t) r
     go γ (RAllP π t)        = RAllP π (go γ t)
     go γ (RImpF x i t t' r) = RImpF x i (go γ t) (go (x:γ) t') r
     go γ (RFun x i t t' r)  = RFun  x i (go γ t) (go (x:γ) t') r
@@ -1660,18 +1668,18 @@
     go γ (RExprArg e)       = RExprArg (f γ <$> F.notracepp "RExprArg" e) -- <---- actual substitution
     go γ (RAppTy t t' r)    = RAppTy (go γ t) (go γ t') r
     go γ (RRTy e r o t)     = RRTy  (mapSnd (go γ) <$> e) r o (go γ t)
-    mo _ t@(RProp _ (RHole {})) = t
-    mo γ (RProp s t)            = RProp s (go γ t)
+    mo _ t@(RProp _ RHole{}) = t
+    mo γ (RProp s t)        = RProp s (go γ t)
 
 foldRType :: (acc -> RType c tv r -> acc) -> acc -> RType c tv r -> acc
 foldRType f = go
   where
     step a t                = go (f a t) t
-    prep a (RProp _ (RHole {})) = a
+    prep a (RProp _ RHole{}) = a
     prep a (RProp _ t)      = step a t
-    go a (RVar {})          = a
-    go a (RHole {})         = a
-    go a (RExprArg {})      = a
+    go a RVar{}             = a
+    go a RHole{}            = a
+    go a RExprArg{}         = a
     go a (RAllT _ t _)      = step a t
     go a (RAllP _ t)        = step a t
     go a (RImpF _ _ t t' _) = foldl' step a [t, t']
@@ -1696,8 +1704,8 @@
 isBase (RAllP _ t)      = isBase t
 isBase (RVar _ _)       = True
 isBase (RApp _ ts _ _)  = all isBase ts
-isBase (RImpF _ _ _ _ _)  = False
-isBase (RFun _ _ _ _ _)   = False
+isBase RImpF{}          = False
+isBase RFun{}           = False
 isBase (RAppTy t1 t2 _) = isBase t1 && isBase t2
 isBase (RRTy _ _ _ t)   = isBase t
 isBase (RAllE _ _ t)    = isBase t
@@ -1705,17 +1713,17 @@
 isBase _                = False
 
 hasHoleTy :: RType t t1 t2 -> Bool
-hasHoleTy (RVar _ _)       = False 
-hasHoleTy (RAllT _ t _)    = hasHoleTy t 
+hasHoleTy (RVar _ _)       = False
+hasHoleTy (RAllT _ t _)    = hasHoleTy t
 hasHoleTy (RAllP _ t)      = hasHoleTy t
 hasHoleTy (RImpF _ _ t t' _) = hasHoleTy t || hasHoleTy t'
 hasHoleTy (RFun _ _ t t' _)  = hasHoleTy t || hasHoleTy t'
-hasHoleTy (RApp _ ts _ _)  = any hasHoleTy ts 
+hasHoleTy (RApp _ ts _ _)  = any hasHoleTy ts
 hasHoleTy (RAllE _ t t')   = hasHoleTy t || hasHoleTy t'
 hasHoleTy (REx _ t t')     = hasHoleTy t || hasHoleTy t'
-hasHoleTy (RExprArg _)     = False 
+hasHoleTy (RExprArg _)     = False
 hasHoleTy (RAppTy t t' _)  = hasHoleTy t || hasHoleTy t'
-hasHoleTy (RHole _)        = True 
+hasHoleTy (RHole _)        = True
 hasHoleTy (RRTy xts _ _ t) = hasHoleTy t || any hasHoleTy (snd <$> xts)
 
 
@@ -1724,15 +1732,15 @@
 isFunTy (RAllE _ _ t)    = isFunTy t
 isFunTy (RAllT _ t _)    = isFunTy t
 isFunTy (RAllP _ t)      = isFunTy t
-isFunTy (RImpF _ _ _ _ _)= True
-isFunTy (RFun _ _ _ _ _) = True
+isFunTy RImpF{}          = True
+isFunTy RFun{}           = True
 isFunTy _                = False
 
 
 mapReftM :: (Monad m) => (r1 -> m r2) -> RType c tv r1 -> m (RType c tv r2)
-mapReftM f (RVar α r)         = liftM   (RVar  α)   (f r)
+mapReftM f (RVar α r)         = fmap    (RVar  α)   (f r)
 mapReftM f (RAllT α t r)      = liftM2  (RAllT α)   (mapReftM f t)          (f r)
-mapReftM f (RAllP π t)        = liftM   (RAllP π)   (mapReftM f t)
+mapReftM f (RAllP π t)        = fmap    (RAllP π)   (mapReftM f t)
 mapReftM f (RImpF x i t t' r) = liftM3  (RImpF x i) (mapReftM f t)          (mapReftM f t')       (f r)
 mapReftM f (RFun x i t t' r)  = liftM3  (RFun x i)  (mapReftM f t)          (mapReftM f t')       (f r)
 mapReftM f (RApp c ts rs r)   = liftM3  (RApp  c)   (mapM (mapReftM f) ts)  (mapM (mapRefM f) rs) (f r)
@@ -1740,16 +1748,16 @@
 mapReftM f (REx z t t')       = liftM2  (REx z)     (mapReftM f t)          (mapReftM f t')
 mapReftM _ (RExprArg e)       = return  $ RExprArg e
 mapReftM f (RAppTy t t' r)    = liftM3  RAppTy (mapReftM f t) (mapReftM f t') (f r)
-mapReftM f (RHole r)          = liftM   RHole       (f r)
+mapReftM f (RHole r)          = fmap    RHole       (f r)
 mapReftM f (RRTy xts r o t)   = liftM4  RRTy (mapM (mapSndM (mapReftM f)) xts) (f r) (return o) (mapReftM f t)
 
-mapRefM  :: (Monad m) => (t -> m s) -> (RTProp c tv t) -> m (RTProp c tv s)
-mapRefM  f (RProp s t)         = liftM   (RProp s)      (mapReftM f t)
+mapRefM  :: (Monad m) => (t -> m s) -> RTProp c tv t -> m (RTProp c tv s)
+mapRefM  f (RProp s t)        = fmap    (RProp s)      (mapReftM f t)
 
 mapPropM :: (Monad m) => (RTProp c tv r -> m (RTProp c tv r)) -> RType c tv r -> m (RType c tv r)
 mapPropM _ (RVar α r)         = return $ RVar  α r
 mapPropM f (RAllT α t r)      = liftM2  (RAllT α)   (mapPropM f t)          (return r)
-mapPropM f (RAllP π t)        = liftM   (RAllP π)   (mapPropM f t)
+mapPropM f (RAllP π t)        = fmap    (RAllP π)   (mapPropM f t)
 mapPropM f (RImpF x i t t' r) = liftM3  (RImpF x i)    (mapPropM f t)         (mapPropM f t') (return r)
 mapPropM f (RFun x i t t' r)  = liftM3  (RFun x i)    (mapPropM f t)          (mapPropM f t') (return r)
 mapPropM f (RApp c ts rs r)   = liftM3  (RApp  c)   (mapM (mapPropM f) ts)  (mapM f rs)     (return r)
@@ -1779,10 +1787,10 @@
           -> (F.SEnv b -> Maybe (RType c tv r) -> r -> a -> a)
           -> a -> RType c tv r -> a
 --------------------------------------------------------------------------------
-foldReft' logicBind bsc g f 
-  = efoldReft logicBind bsc 
+foldReft' logicBind bsc g f
+  = efoldReft logicBind bsc
               (\_ _ -> [])
-              (\_ -> [])
+              (const [])
               g
               (\γ t r z -> f γ t r z)
               (\_ γ -> γ)
@@ -1808,10 +1816,10 @@
     -- folding over RType
     go γ z me@(RVar _ r)                = f γ (Just me) r z
     go γ z me@(RAllT a t r)
-       | ty_var_is_val a                = f γ (Just me) r (go (insertsSEnv γ (dty a)) z t)
+       | tyVarIsVal a                   = f γ (Just me) r (go (insertsSEnv γ (dty a)) z t)
        | otherwise                      = f γ (Just me) r (go γ z t)
     go γ z (RAllP p t)                  = go (fp p γ) z t
-    go γ z (RImpF x i t t' r)             = go γ z (RFun x i t t' r)
+    go γ z (RImpF x i t t' r)           = go γ z (RFun x i t t' r)
     go γ z me@(RFun _ RFInfo{permitTC = permitTC} (RApp c ts _ _) t' r)
        | (if permitTC == Just True then isEmbeddedDict else isClass)
          c  = f γ (Just me) r (go (insertsSEnv γ (cb c ts)) (go' γ z ts) t')
@@ -1821,7 +1829,7 @@
        where
          γ'                             = insertSEnv x (g t) γ
     go γ z me@(RApp _ ts rs r)          = f γ (Just me) r (ho' γ (go' γ' z ts) rs)
-       where γ' = if bsc then insertSEnv (rTypeValueVar me) (g me) γ else γ 
+       where γ' = if bsc then insertSEnv (rTypeValueVar me) (g me) γ else γ
 
     go γ z (RAllE x t t')               = go (insertSEnv x (g t) γ) (go γ z t) t'
     go γ z (REx x t t')                 = go (insertSEnv x (g t) γ) (go γ z t) t'
@@ -1833,7 +1841,7 @@
 
     -- folding over Ref
     ho  γ z (RProp ss (RHole r))       = f (insertsSEnv γ (mapSnd (g . ofRSort) <$> ss)) Nothing r z
-    ho  γ z (RProp ss t)               = go (insertsSEnv γ ((mapSnd (g . ofRSort)) <$> ss)) z t
+    ho  γ z (RProp ss t)               = go (insertsSEnv γ (mapSnd (g . ofRSort) <$> ss)) z t
 
     -- folding over [RType]
     go' γ z ts                 = foldr (flip $ go γ) z ts
@@ -1902,7 +1910,7 @@
 ofRSort = fmap mempty
 
 toRSort :: RType c tv r -> RType c tv ()
-toRSort = stripAnnotations . mapBind (const F.dummySymbol) . fmap (const ())
+toRSort = stripAnnotations . mapBind (const F.dummySymbol) . void
 
 stripAnnotations :: RType c tv r -> RType c tv r
 stripAnnotations (RAllT α t r)    = RAllT α (stripAnnotations t) r
@@ -1930,7 +1938,7 @@
 rTypeValueVar t = vv where F.Reft (vv,_) =  rTypeReft t
 
 rTypeReft :: (F.Reftable r) => RType c tv r -> F.Reft
-rTypeReft = fromMaybe F.trueReft . fmap F.toReft . stripRTypeBase
+rTypeReft = maybe F.trueReft F.toReft . stripRTypeBase
 
 -- stripRTypeBase ::  RType a -> Maybe a
 stripRTypeBase :: RType c tv r -> Maybe r
@@ -1945,7 +1953,7 @@
 stripRTypeBase (RAppTy _ _ x)
   = Just x
 stripRTypeBase (RAllT _ _ x)
-  = Just x 
+  = Just x
 stripRTypeBase _
   = Nothing
 
@@ -1965,12 +1973,12 @@
 -----------------------------------------------------------------------------
 
 instance F.PPrint (PVar a) where
-  pprintTidy _ = ppr_pvar
+  pprintTidy _ = pprPvar
 
-ppr_pvar :: PVar a -> Doc
-ppr_pvar (PV s _ _ xts) = F.pprint s <+> hsep (F.pprint <$> dargs xts)
+pprPvar :: PVar a -> Doc
+pprPvar (PV s _ _ xts) = F.pprint s <+> hsep (F.pprint <$> dargs xts)
   where
-    dargs               = map thd3 . takeWhile (\(_, x, y) -> F.EVar x /= y)
+    dargs              = map thd3 . takeWhile (\(_, x, y) -> F.EVar x /= y)
 
 
 instance F.PPrint Predicate where
@@ -1985,14 +1993,14 @@
 --   + global : many bindings, shared across all constraints
 --   + local  : few bindings, relevant to particular constraints
 
-type REnv = AREnv SpecType 
+type REnv = AREnv SpecType
 
 data AREnv t = REnv
   { reGlobal :: M.HashMap Symbol t -- ^ the "global" names for module
   , reLocal  :: M.HashMap Symbol t -- ^ the "local" names for sub-exprs
   }
 
-instance Functor AREnv where 
+instance Functor AREnv where
   fmap f (REnv g l) = REnv (fmap f g) (fmap f l)
 
 instance (F.PPrint t) => F.PPrint (AREnv t) where
@@ -2011,14 +2019,14 @@
     $+$
     F.pprintTidy k (reGlobal re)
 
-instance Semigroup REnv where 
-  REnv g1 l1 <> REnv g2 l2 = REnv (g1 <> g2) (l1 <> l2)  
+instance Semigroup REnv where
+  REnv g1 l1 <> REnv g2 l2 = REnv (g1 <> g2) (l1 <> l2)
 
-instance Monoid REnv where 
+instance Monoid REnv where
   mempty = REnv mempty mempty
 
 instance NFData REnv where
-  rnf (REnv {}) = ()
+  rnf REnv{} = ()
 
 --------------------------------------------------------------------------------
 -- | Diagnostic info -----------------------------------------------------------
@@ -2080,11 +2088,12 @@
 -- | Source Information Associated With Constraints ----------------------------
 --------------------------------------------------------------------------------
 
-data Cinfo    = Ci { ci_loc :: !SrcSpan
-                   , ci_err :: !(Maybe Error)
-                   , ci_var :: !(Maybe Var)
-                   }
-                deriving (Eq, Generic)
+data Cinfo    = Ci
+  { ci_loc :: !SrcSpan
+  , ci_err :: !(Maybe Error)
+  , ci_var :: !(Maybe Var)
+  }
+  deriving (Eq, Generic)
 
 instance F.Loc Cinfo where
   srcSpan = srcSpanFSrcSpan . ci_loc
@@ -2095,16 +2104,16 @@
 -- | Module Names --------------------------------------------------------------
 --------------------------------------------------------------------------------
 
-data ModName = ModName !ModType !ModuleName 
+data ModName = ModName !ModType !ModuleName
   deriving (Eq, Ord, Show, Generic, Data, Typeable)
 
-data ModType = Target | SrcImport | SpecImport 
+data ModType = Target | SrcImport | SpecImport
   deriving (Eq, Ord, Show, Generic, Data, Typeable)
 
--- instance B.Binary ModType 
--- instance B.Binary ModName 
+-- instance B.Binary ModType
+-- instance B.Binary ModName
 
-instance Hashable ModType 
+instance Hashable ModType
 
 instance Hashable ModName where
   hashWithSalt i (ModName t n) = hashWithSalt i (t, show n)
@@ -2119,9 +2128,9 @@
   symbol = F.symbol . moduleNameFS
 
 
-isTarget :: ModName -> Bool 
-isTarget (ModName Target _) = True 
-isTarget _                  = False 
+isTarget :: ModName -> Bool
+isTarget (ModName Target _) = True
+isTarget _                  = False
 
 isSrcImport :: ModName -> Bool
 isSrcImport (ModName SrcImport _) = True
@@ -2158,7 +2167,7 @@
 instance Semigroup (RTEnv tv t) where
   RTE x y <> RTE x' y' = RTE (x `M.union` x') (y `M.union` y')
 
--- mapRT :: (M.HashMap Symbol (RTAlias tv t) -> M.HashMap Symbol (RTAlias tv t)) 
+-- mapRT :: (M.HashMap Symbol (RTAlias tv t) -> M.HashMap Symbol (RTAlias tv t))
 --      -> RTEnv tv t -> RTEnv tv t
 -- mapRT f e = e { typeAliases = f (typeAliases e) }
 
@@ -2191,7 +2200,7 @@
   { msName :: F.LocSymbol
   , msSort :: ty
   , msEqns :: [Def ty ctor]
-  , msKind :: !MeasureKind 
+  , msKind :: !MeasureKind
   , msUnSorted :: !UnSortedExprs -- potential unsorted expressions used at measure denifinitions
   } deriving (Eq, Data, Typeable, Generic, Functor)
     deriving Hashable via Generically (Measure ty ctor)
@@ -2199,32 +2208,32 @@
 type UnSortedExprs = [UnSortedExpr] -- mempty = []
 type UnSortedExpr  = ([F.Symbol], F.Expr)
 
-data MeasureKind 
-  = MsReflect     -- ^ due to `reflect foo` 
+data MeasureKind
+  = MsReflect     -- ^ due to `reflect foo`
   | MsMeasure     -- ^ due to `measure foo` with old-style (non-haskell) equations
   | MsLifted      -- ^ due to `measure foo` with new-style haskell equations
-  | MsClass       -- ^ due to `class measure` definition 
+  | MsClass       -- ^ due to `class measure` definition
   | MsAbsMeasure  -- ^ due to `measure foo` without equations c.f. tests/pos/T1223.hs
-  | MsSelector    -- ^ due to selector-fields e.g. `data Foo = Foo { fld :: Int }` 
-  | MsChecker     -- ^ due to checkers  e.g. `is-F` for `data Foo = F ... | G ...` 
+  | MsSelector    -- ^ due to selector-fields e.g. `data Foo = Foo { fld :: Int }`
+  | MsChecker     -- ^ due to checkers  e.g. `is-F` for `data Foo = F ... | G ...`
   deriving (Eq, Ord, Show, Data, Typeable, Generic)
   deriving Hashable via Generically MeasureKind
 
-instance F.Loc (Measure a b) where 
+instance F.Loc (Measure a b) where
   srcSpan = F.srcSpan . msName
 
 instance Bifunctor Def where
   -- first f  (Def m ps c s bs b) = Def m (second f <$> ps) c (f <$> s) ((second (fmap f)) <$> bs) b
   -- second f (Def m ps c s bs b) = Def m ps (f c) s bs b
-  first f  (Def m c s bs b) = Def m c (f <$> s) ((second (fmap f)) <$> bs) b
+  first f  (Def m c s bs b) = Def m c (f <$> s) (second (fmap f) <$> bs) b
   second f (Def m c s bs b) = Def m (f c) s bs b
 
 
 instance Bifunctor Measure where
   first  f (M n s es k u) = M n (f s) (first f <$> es) k u
-  second f (M n s es k u) = M n s (second f <$> es)    k u 
+  second f (M n s es k u) = M n s (second f <$> es)    k u
 
-instance                             B.Binary MeasureKind 
+instance                             B.Binary MeasureKind
 instance                             B.Binary Body
 instance (B.Binary t, B.Binary c) => B.Binary (Def     t c)
 instance (B.Binary t, B.Binary c) => B.Binary (Measure t c)
@@ -2266,7 +2275,7 @@
 
 
 instance F.Subable (Measure ty ctor) where
-  syms  m     = concatMap F.syms (msEqns m) 
+  syms  m     = concatMap F.syms (msEqns m)
   substa f m  = m { msEqns = F.substa f  <$> msEqns m }
   substf f m  = m { msEqns = F.substf f  <$> msEqns m }
   subst  su m = m { msEqns = F.subst  su <$> msEqns m }
@@ -2313,44 +2322,44 @@
     deriving Hashable via Generically (RClass ty)
 
 
-instance F.PPrint t => F.PPrint (RClass t) where 
-  pprintTidy k (RClass n ts as mts) 
-                = ppMethods k ("class" <+> supers ts) n as [(m, RISig t) | (m, t) <- mts] 
-    where 
-      supers [] = "" 
+instance F.PPrint t => F.PPrint (RClass t) where
+  pprintTidy k (RClass n ts as mts)
+                = ppMethods k ("class" <+> supers ts) n as [(m, RISig t) | (m, t) <- mts]
+    where
+      supers [] = ""
       supers ts = tuplify (F.pprintTidy k   <$> ts) <+> "=>"
       tuplify   = parens . hcat . punctuate ", "
 
 
 instance F.PPrint t => F.PPrint (RILaws t) where
-  pprintTidy k (RIL n ss ts mts _) = ppEqs k ("instance laws" <+> supers ss) n ts mts 
-   where 
-    supers [] = "" 
+  pprintTidy k (RIL n ss ts mts _) = ppEqs k ("instance laws" <+> supers ss) n ts mts
+   where
+    supers [] = ""
     supers ts = tuplify (F.pprintTidy k   <$> ts) <+> "=>"
     tuplify   = parens . hcat . punctuate ", "
 
 
-ppEqs :: (F.PPrint x, F.PPrint t, F.PPrint a, F.PPrint n) 
+ppEqs :: (F.PPrint x, F.PPrint t, F.PPrint a, F.PPrint n)
           => F.Tidy -> Doc -> n -> [a] -> [(x, t)] -> Doc
-ppEqs k hdr name args mts 
-  = vcat $ hdr <+> dName <+> "where" 
-         : [ nest 4 (bind m t) | (m, t) <- mts ] 
-    where 
+ppEqs k hdr name args mts
+  = vcat $ hdr <+> dName <+> "where"
+         : [ nest 4 (bind m t) | (m, t) <- mts ]
+    where
       dName    = parens  (F.pprintTidy k name <+> dArgs)
       dArgs    = gaps    (F.pprintTidy k      <$> args)
       gaps     = hcat . punctuate " "
-      bind m t = F.pprintTidy k m <+> "=" <+> F.pprintTidy k t 
+      bind m t = F.pprintTidy k m <+> "=" <+> F.pprintTidy k t
 
-ppMethods :: (F.PPrint x, F.PPrint t, F.PPrint a, F.PPrint n) 
+ppMethods :: (F.PPrint x, F.PPrint t, F.PPrint a, F.PPrint n)
           => F.Tidy -> Doc -> n -> [a] -> [(x, RISig t)] -> Doc
-ppMethods k hdr name args mts 
-  = vcat $ hdr <+> dName <+> "where" 
-         : [ nest 4 (bind m t) | (m, t) <- mts ] 
-    where 
+ppMethods k hdr name args mts
+  = vcat $ hdr <+> dName <+> "where"
+         : [ nest 4 (bind m t) | (m, t) <- mts ]
+    where
       dName    = parens  (F.pprintTidy k name <+> dArgs)
       dArgs    = gaps    (F.pprintTidy k      <$> args)
       gaps     = hcat . punctuate " "
-      bind m t = ppRISig k m t -- F.pprintTidy k m <+> "::" <+> F.pprintTidy k t 
+      bind m t = ppRISig k m t -- F.pprintTidy k m <+> "::" <+> F.pprintTidy k t
 
 instance B.Binary ty => B.Binary (RClass ty)
 
@@ -2361,12 +2370,12 @@
 
 data HoleInfo i t = HoleInfo {htype :: t, hloc :: SrcSpan, henv :: AREnv t, info :: i }
 
-instance Functor (HoleInfo i) where 
+instance Functor (HoleInfo i) where
   fmap f hinfo = hinfo{htype = f (htype hinfo), henv = fmap f (henv hinfo)}
 
 instance (F.PPrint t) => F.PPrint (HoleInfo  i t) where
-  pprintTidy k hinfo = text "type:" <+> F.pprintTidy k (htype hinfo) 
-                       <+> text "\n loc:" <+> F.pprintTidy k (hloc hinfo) 
+  pprintTidy k hinfo = text "type:" <+> F.pprintTidy k (htype hinfo)
+                       <+> text "\n loc:" <+> F.pprintTidy k (hloc hinfo)
   -- to print the hole environment uncomment the following
   --                     <+> text "\n env:" <+> F.pprintTidy k (henv hinfo)
 
@@ -2476,8 +2485,8 @@
 hole = F.PKVar "HOLE" mempty
 
 isHole :: Expr -> Bool
-isHole (F.PKVar ("HOLE") _) = True
-isHole _                    = False
+isHole (F.PKVar "HOLE" _) = True
+isHole _                  = False
 
 hasHole :: F.Reftable r => r -> Bool
 hasHole = any isHole . F.conjuncts . F.reftPred . F.toReft
@@ -2488,20 +2497,20 @@
 instance F.PPrint DataCon where
   pprintTidy _ = text . showPpr
 
-instance Ord TyCon where 
-  compare = compare `on` F.symbol 
+instance Ord TyCon where
+  compare = compare `on` F.symbol
 
-instance Ord DataCon where 
-  compare = compare `on` F.symbol 
+instance Ord DataCon where
+  compare = compare `on` F.symbol
 
-instance F.PPrint TyThing where 
-  pprintTidy _ = text . showPpr 
+instance F.PPrint TyThing where
+  pprintTidy _ = text . showPpr
 
 instance Show DataCon where
   show = F.showpp
 
--- instance F.Symbolic TyThing where 
---  symbol = tyThingSymbol 
+-- instance F.Symbolic TyThing where
+--  symbol = tyThingSymbol
 
 liquidBegin :: String
 liquidBegin = ['{', '-', '@']
@@ -2524,7 +2533,7 @@
   second                    = fmap
 
 instance (F.PPrint t, F.PPrint a) => F.PPrint (MSpec t a) where
-  pprintTidy k =  vcat . fmap (F.pprintTidy k) . fmap snd . M.toList . measMap
+  pprintTidy k =  vcat . fmap (F.pprintTidy k . snd) . M.toList . measMap
 
 instance (Show ty, Show ctor, F.PPrint ctor, F.PPrint ty) => Show (MSpec ty ctor) where
   show (MSpec ct m cm im)
diff --git a/src/Language/Haskell/Liquid/Types/Variance.hs b/src/Language/Haskell/Liquid/Types/Variance.hs
--- a/src/Language/Haskell/Liquid/Types/Variance.hs
+++ b/src/Language/Haskell/Liquid/Types/Variance.hs
@@ -1,21 +1,33 @@
 {-# LANGUAGE DeriveDataTypeable #-}
 {-# LANGUAGE DeriveGeneric      #-}
-{-# LANGUAGE DerivingStrategies #-}
-{-# LANGUAGE DerivingVia #-}
+{-# LANGUAGE DerivingVia        #-}
 
-module Language.Haskell.Liquid.Types.Variance ( Variance(..), VarianceInfo ) where
+{-# OPTIONS_GHC -Wno-incomplete-patterns #-} -- TODO(#1918): Only needed for GHC <9.0.1.
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
 
+module Language.Haskell.Liquid.Types.Variance (
+  Variance(..), VarianceInfo, makeTyConVariance, flipVariance
+  ) where
+
 import Prelude hiding (error)
 import Control.DeepSeq
-import Data.Typeable
-import Data.Data
+import Data.Typeable hiding (TyCon)
+import Data.Data     hiding (TyCon)
 import GHC.Generics
 import Data.Binary
 import Data.Hashable
 import Text.PrettyPrint.HughesPJ
+
+import           Data.Maybe                (fromJust)
+import qualified Data.List               as L
+import qualified Data.HashSet            as S
+
 import qualified Language.Fixpoint.Types as F
 
-import Language.Haskell.Liquid.Types.Generics
+import           Language.Haskell.Liquid.Types.Generics
+import qualified Liquid.GHC.Misc as GM
+import           Liquid.GHC.API        as Ghc hiding (text)
 
 type VarianceInfo = [Variance]
 
@@ -23,7 +35,89 @@
               deriving (Eq, Data, Typeable, Show, Generic)
               deriving Hashable via Generically Variance
 
+flipVariance :: Variance -> Variance
+flipVariance Invariant     = Invariant
+flipVariance Bivariant     = Bivariant
+flipVariance Contravariant = Covariant
+flipVariance Covariant     = Contravariant
+
+instance Semigroup Variance where
+  Bivariant     <> _         = Bivariant
+  _             <> Bivariant = Bivariant
+  Invariant     <> v         = v
+  v             <> Invariant = v
+  Covariant     <> v         = v
+  Contravariant <> v         = flipVariance v
+
+instance Monoid Variance where
+  mempty = Bivariant
+
 instance Binary Variance
 instance NFData Variance
 instance F.PPrint Variance where
   pprintTidy _ = text . show
+
+
+
+makeTyConVariance :: TyCon -> VarianceInfo
+makeTyConVariance c = varSignToVariance <$> tvs
+  where
+    tvs = GM.tyConTyVarsDef c
+
+    varsigns = if Ghc.isTypeSynonymTyCon c
+                  then go True (fromJust $ Ghc.synTyConRhs_maybe c)
+                  else L.nub $ concatMap goDCon $ Ghc.tyConDataCons c
+
+    varSignToVariance v = case filter (\p -> GM.showPpr (fst p) == GM.showPpr v) varsigns of
+                            []       -> Invariant
+                            [(_, b)] -> if b then Covariant else Contravariant
+                            _        -> Bivariant
+
+
+    goDCon dc = concatMap (go True . irrelevantMult) (Ghc.dataConOrigArgTys dc)
+
+    go pos (FunTy _ _ t1 t2) = go (not pos) t1 ++ go pos t2
+    go pos (ForAllTy _ t)    = go pos t
+    go pos (TyVarTy v)       = [(v, pos)]
+    go pos (AppTy t1 t2)     = go pos t1 ++ go pos t2
+    go pos (TyConApp c' ts)
+       | c == c'
+       = []
+
+-- NV fix that: what happens if we have mutually recursive data types?
+-- now just provide "default" Bivariant for mutually rec types.
+-- but there should be a finer solution
+       | mutuallyRecursive c c'
+       = concatMap (goTyConApp pos Bivariant) ts
+       | otherwise
+       = concat $ zipWith (goTyConApp pos) (makeTyConVariance c') ts
+
+    go _   (LitTy _)       = []
+    go _   (CoercionTy _)  = []
+    go pos (CastTy t _)    = go pos t
+
+    goTyConApp _   Invariant     _ = []
+    goTyConApp pos Bivariant     t = goTyConApp pos Contravariant t ++ goTyConApp pos Covariant t
+    goTyConApp pos Covariant     t = go pos       t
+    goTyConApp pos Contravariant t = go (not pos) t
+
+    mutuallyRecursive c c' = c `S.member` dataConsOfTyCon c'
+
+
+dataConsOfTyCon :: TyCon -> S.HashSet TyCon
+dataConsOfTyCon = dcs S.empty
+  where
+    dcs vis c                 = mconcat $ go vis <$> [irrelevantMult t | dc <- Ghc.tyConDataCons c, t <- Ghc.dataConOrigArgTys dc]
+    go  vis (FunTy _ _ t1 t2) = go vis t1 `S.union` go vis t2
+    go  vis (ForAllTy _ t)    = go vis t
+    go  _   (TyVarTy _)       = S.empty
+    go  vis (AppTy t1 t2)     = go vis t1 `S.union` go vis t2
+    go  vis (TyConApp c ts)
+      | c `S.member` vis
+      = S.empty
+      | otherwise
+      = S.insert c (mconcat $ go vis <$> ts) `S.union` dcs (S.insert c vis) c
+    go  _   (LitTy _)       = S.empty
+    go  _   (CoercionTy _)  = S.empty
+    go  vis (CastTy t _)    = go vis t
+
diff --git a/src/Language/Haskell/Liquid/Types/Visitors.hs b/src/Language/Haskell/Liquid/Types/Visitors.hs
--- a/src/Language/Haskell/Liquid/Types/Visitors.hs
+++ b/src/Language/Haskell/Liquid/Types/Visitors.hs
@@ -1,18 +1,15 @@
 {-# LANGUAGE NoMonomorphismRestriction #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE FlexibleInstances         #-}
 {-# LANGUAGE FlexibleContexts          #-}
-{-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE DeriveDataTypeable        #-}
 {-# LANGUAGE ScopedTypeVariables       #-}
-
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
 
 module Language.Haskell.Liquid.Types.Visitors (
-  
+
   CBVisitable (..)
-  
+
   -- * visitors
-  , coreVisitor 
+  , coreVisitor
   , CoreVisitor (..)
 
   ) where
@@ -23,8 +20,8 @@
 import qualified Data.HashSet                     as S
 import           Prelude                          hiding (error)
 import           Language.Fixpoint.Misc
-import           Language.Haskell.Liquid.GHC.API
-import           Language.Haskell.Liquid.GHC.Misc ()
+import           Liquid.GHC.API
+import           Liquid.GHC.Misc ()
 
 
 ------------------------------------------------------------------------------
@@ -75,7 +72,7 @@
 exprFreeVars :: S.HashSet Id -> Expr Id -> [Id]
 exprFreeVars = go
   where
-    go env (Var x)         = if x `S.member` env then [] else [x]
+    go env (Var x)         = [x | not (x `S.member` env)]
     go env (App e a)       = go env e ++ go env a
     go env (Lam x e)       = go (extendEnv env [x]) e
     go env (Let b e)       = freeVars env b ++ go (extendEnv env (bindings b)) e
@@ -155,22 +152,22 @@
 ----------------------------------------------------------------------------------------
 -- | @BindVisitor@ allows for generic, context sensitive traversals over the @CoreBinds@ 
 ----------------------------------------------------------------------------------------
-data CoreVisitor env acc = CoreVisitor 
-  { envF  :: env -> Var             -> env 
-  , bindF :: env -> acc -> Var      -> acc  
-  , exprF :: env -> acc -> CoreExpr -> acc 
+data CoreVisitor env acc = CoreVisitor
+  { envF  :: env -> Var             -> env
+  , bindF :: env -> acc -> Var      -> acc
+  , exprF :: env -> acc -> CoreExpr -> acc
   }
 
-coreVisitor :: (CoreVisitor env acc) -> env -> acc -> [CoreBind] -> acc
-coreVisitor vis env acc cbs   = snd (foldl' step (env, acc) cbs) 
+coreVisitor :: CoreVisitor env acc -> env -> acc -> [CoreBind] -> acc
+coreVisitor vis env acc cbs   = snd (foldl' step (env, acc) cbs)
   where
-    stepXE (env, acc) (x,e)   = (env', stepE env' acc'   e)  
-      where 
-        env'                  = envF  vis env     x 
-        acc'                  = bindF vis env acc x  
+    stepXE (env, acc) (x,e)   = (env', stepE env' acc'   e)
+      where
+        env'                  = envF  vis env     x
+        acc'                  = bindF vis env acc x
 
-    step ea (NonRec x e)      = stepXE ea (x, e) 
-    step ea (Rec    xes)      = foldl' stepXE ea xes 
+    step ea (NonRec x e)      = stepXE ea (x, e)
+    step ea (Rec    xes)      = foldl' stepXE ea xes
 
     -- step (env, acc) (NonRec x e) = stepXE env acc x e 
     -- step (env, acc) (Rec    xes) = (env', foldl' (stepE env') acc' es) 
@@ -181,18 +178,18 @@
         -- es                       = snd <$> xes
         -- foldl' (\(env, acc) (x, e) ->  )
 
-    stepE env acc e              = goE env (exprF vis env acc e) e 
+    stepE env acc e              = goE env (exprF vis env acc e) e
 
-    goE _   acc (Var _)          = acc 
-    goE env acc (App e1 e2)      = stepE  env (stepE env acc e1) e2 
-    goE env acc (Tick _ e)       = stepE  env acc e 
-    goE env acc (Cast e _)       = stepE  env acc e  
+    goE _   acc (Var _)          = acc
+    goE env acc (App e1 e2)      = stepE  env (stepE env acc e1) e2
+    goE env acc (Tick _ e)       = stepE  env acc e
+    goE env acc (Cast e _)       = stepE  env acc e
     goE env acc (Lam x e)        = snd (stepXE (env, acc) (x, e))
-    goE env acc (Let b e)        = stepE env' acc' e where (env', acc') = step (env, acc) b 
+    goE env acc (Let b e)        = stepE env' acc' e where (env', acc') = step (env, acc) b
     goE env acc (Case e _ _ cs)  = foldl' (goC env) (stepE env acc e) cs
-    goE _   acc _                = acc 
+    goE _   acc _                = acc
 
-    goC env acc (_, xs, e)       = stepE  env' acc' e 
+    goC env acc (_, xs, e)       = stepE  env' acc' e
       where
-        env'                     = foldl' (envF  vis)     env xs 
+        env'                     = foldl' (envF  vis)     env xs
         acc'                     = foldl' (bindF vis env) acc xs
diff --git a/src/Language/Haskell/Liquid/UX/ACSS.hs b/src/Language/Haskell/Liquid/UX/ACSS.hs
--- a/src/Language/Haskell/Liquid/UX/ACSS.hs
+++ b/src/Language/Haskell/Liquid/UX/ACSS.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- | Formats Haskell source code as HTML with CSS and Mouseover Type Annotations
 module Language.Haskell.Liquid.UX.ACSS (
     hscolour
@@ -10,7 +12,7 @@
   ) where
 
 import Prelude hiding (error)
-import qualified Language.Haskell.Liquid.GHC.API as SrcLoc
+import qualified Liquid.GHC.API as SrcLoc
 
 import Language.Haskell.HsColour.Anchors
 import Language.Haskell.HsColour.Classify as Classify
@@ -20,13 +22,13 @@
 import Data.Either (partitionEithers)
 import Data.Maybe  (fromMaybe)
 import qualified Data.HashMap.Strict as M
-import Data.List   (find, isPrefixOf, findIndex, elemIndices, intercalate)
+import Data.List   (find, isPrefixOf, findIndex, elemIndices, intercalate, elemIndex)
 import Data.Char   (isSpace)
 import Text.Printf
-import Language.Haskell.Liquid.GHC.Misc
+import Liquid.GHC.Misc
 import Language.Haskell.Liquid.Types.Errors (panic, impossible)
 
-data AnnMap  = Ann 
+data AnnMap  = Ann
   { types   :: M.HashMap Loc (String, String) -- ^ Loc -> (Var, Type)
   , errors  :: [(Loc, Loc, String)]           -- ^ List of error intervals
   , status  :: !Status
@@ -79,7 +81,7 @@
     . annotTokenise baseLoc tx
 
 tokeniseWithLoc :: CommentTransform -> String -> [(TokenType, String, Loc)]
-tokeniseWithLoc tx str = zipWith (\(x,y) z -> (x, y, z)) toks spans  
+tokeniseWithLoc tx str = zipWith (\(x,y) z -> (x, y, z)) toks spans
   where
     toks       = tokeniseWithCommentTransform tx str
     spans      = tokenSpans Nothing $ map snd toks
@@ -98,7 +100,7 @@
 spanAnnot w (Ann ts es _ _) span = A t e b
   where
     t = fmap snd (M.lookup span ts)
-    e = fmap (\_ -> "ERROR") $ find (span `inRange`) [(x,y) | (x,y,_) <- es]
+    e = "ERROR" <$ find (span `inRange`) [(x,y) | (x,y,_) <- es]
     b = spanLine w span
 
 spanLine :: t -> Loc -> Maybe (Int, t)
@@ -122,8 +124,8 @@
 plusLoc :: Loc -> String -> Loc
 plusLoc (L (l, c)) s
   = case '\n' `elemIndices` s of
-      [] -> L (l, (c + n))
-      is -> L ((l + length is), (n - maximum is))
+      [] -> L (l, c + n)
+      is -> L (l + length is, n - maximum is)
     where n = length s
 
 renderAnnotToken :: (TokenType, String, Annotation) -> String
@@ -148,7 +150,7 @@
 renderLinAnnot Nothing  s   = s
 
 lineString :: Show t => (t, Int) -> [Char]
-lineString (i, w) = (replicate (w - (length is)) ' ') ++ is
+lineString (i, w) = replicate (w - length is) ' ' ++ is
   where is        = show i
 
 {- Example Annotation:
@@ -164,10 +166,10 @@
 
 stitch ::  Eq b => [(b, c)] -> [Either a b] -> [Either a c]
 stitch xys ((Left a) : rest)
-  = (Left a) : stitch xys rest
+  = Left a : stitch xys rest
 stitch ((x,y):xys) ((Right x'):rest)
   | x == x'
-  = (Right y) : stitch xys rest
+  = Right y : stitch xys rest
   | otherwise
   = panic Nothing "stitch"
 stitch _ []
@@ -178,7 +180,7 @@
 splitSrcAndAnns ::  String -> (String, AnnMap)
 splitSrcAndAnns s =
   let ls = lines s in
-  case findIndex (breakS ==) ls of
+  case elemIndex breakS ls of
     Nothing -> (s, Ann M.empty [] Safe mempty)
     Just i  -> (src, ann)
                where (codes, _:mname:annots) = splitAt i ls
@@ -190,7 +192,7 @@
 
 tokenModule :: [(TokenType, [Char])] -> Maybe [Char]
 tokenModule toks
-  = do i <- findIndex ((Keyword, "module") ==) toks
+  = do i <- elemIndex (Keyword, "module") toks
        let (_, toks')  = splitAt (i+2) toks
        j <- findIndex ((Space ==) . fst) toks'
        let (toks'', _) = splitAt j toks'
@@ -217,19 +219,19 @@
 
 parseLines mname i (_:_:l:c:"0":l':c':rest')
   = Right (L (line, col), L (line', col')) : parseLines mname (i + 7) rest'
-    where line  = (read l)  :: Int
-          col   = (read c)  :: Int
-          line' = (read l') :: Int
-          col'  = (read c') :: Int
+    where line  = read l  :: Int
+          col   = read c  :: Int
+          line' = read l' :: Int
+          col'  = read c' :: Int
 
 parseLines mname i (x:f:l:c:n:rest)
   | f /= mname
   = parseLines mname (i + 5 + num) rest'
   | otherwise
   = Left (L (line, col), (x, anns)) : parseLines mname (i + 5 + num) rest'
-    where line  = (read l) :: Int
-          col   = (read c) :: Int
-          num   = (read n) :: Int
+    where line  = read l :: Int
+          col   = read c :: Int
+          num   = read n :: Int
           anns  = intercalate "\n" $ take num rest
           rest' = drop num rest
 
@@ -237,9 +239,9 @@
   = panic Nothing $ "Error Parsing Annot Input on Line: " ++ show i
 
 instance Show AnnMap where
-  show (Ann ts es _ _) =  "\n\n" 
-                      ++ (concatMap ppAnnotTyp $ M.toList ts)
-                      ++ (concatMap ppAnnotErr [(x,y) | (x,y,_) <- es])
+  show (Ann ts es _ _) =  "\n\n"
+                      ++ concatMap ppAnnotTyp (M.toList ts)
+                      ++ concatMap ppAnnotErr [(x,y) | (x,y,_) <- es]
 
 ppAnnotTyp :: (PrintfArg t, PrintfType t1) => (Loc, (t, String)) -> t1
 ppAnnotTyp (L (l, c), (x, s))     = printf "%s\n%d\n%d\n%d\n%s\n\n\n" x l c (length $ lines s) s
diff --git a/src/Language/Haskell/Liquid/UX/Annotate.hs b/src/Language/Haskell/Liquid/UX/Annotate.hs
--- a/src/Language/Haskell/Liquid/UX/Annotate.hs
+++ b/src/Language/Haskell/Liquid/UX/Annotate.hs
@@ -1,10 +1,10 @@
 {-# LANGUAGE FlexibleContexts           #-}
-{-# LANGUAGE TupleSections              #-}
 {-# LANGUAGE NoMonomorphismRestriction  #-}
 {-# LANGUAGE OverloadedStrings          #-}
-{-# LANGUAGE TypeSynonymInstances       #-}
 {-# LANGUAGE FlexibleInstances          #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
 
 ---------------------------------------------------------------------------
 -- | This module contains the code that uses the inferred types to generate
@@ -51,13 +51,13 @@
 import qualified Data.ByteString.Lazy                         as B
 import qualified Data.Text                                    as T
 import qualified Data.HashMap.Strict                          as M
-import qualified Language.Haskell.Liquid.Misc                 as Misc 
+import qualified Language.Haskell.Liquid.Misc                 as Misc
 import qualified Language.Haskell.Liquid.UX.ACSS              as ACSS
 import           Language.Haskell.HsColour.Classify
 import           Language.Fixpoint.Utils.Files
 import           Language.Fixpoint.Misc
-import           Language.Haskell.Liquid.GHC.Misc
-import qualified Language.Haskell.Liquid.GHC.API              as SrcLoc
+import           Liquid.GHC.Misc
+import qualified Liquid.GHC.API              as SrcLoc
 import           Language.Fixpoint.Types                      hiding (panic, Error, Loc, Constant (..), Located (..))
 import           Language.Haskell.Liquid.Misc
 import           Language.Haskell.Liquid.Types.PrettyPrint
@@ -91,6 +91,7 @@
 annotate :: Config -> [FilePath] -> Output Doc -> IO ACSS.AnnMap
 -------------------------------------------------------------------
 annotate cfg srcFs out
+  -- TODO(matt.walker): Make this obey json!
   = do when showWarns  $ forM_ bots (printf "WARNING: Found false in %s\n" . showPpr)
        when doAnnotate $ mapM_ (doGenerate cfg tplAnnMap typAnnMap annTyp) srcFs
        return typAnnMap
@@ -106,11 +107,12 @@
 
 doGenerate :: Config -> ACSS.AnnMap -> ACSS.AnnMap -> AnnInfo Doc -> FilePath -> IO ()
 doGenerate cfg tplAnnMap typAnnMap annTyp srcF
-  = do generateHtml srcF tpHtmlF tplAnnMap
-       generateHtml srcF tyHtmlF typAnnMap
+  = do generateHtml pandocF srcF tpHtmlF tplAnnMap
+       generateHtml pandocF srcF tyHtmlF typAnnMap
        writeFile         vimF  $ vimAnnot cfg annTyp
        B.writeFile       jsonF $ encode typAnnMap
     where
+       pandocF    = pandocHtml cfg
        tyHtmlF    = extFileName Html                   srcF
        tpHtmlF    = extFileName Html $ extFileName Cst srcF
        _annF      = extFileName Annot srcF
@@ -121,7 +123,7 @@
 mkBots (AI m) = [ src | (src, (Just _, t) : _) <- sortBy (ordSrcSpan `on` fst) $ M.toList m
                       , isFalse (rTypeReft t) ]
 
--- | Like 'copyFile' from 'System.Directory', but ensure that the parent /temporary/ directory 
+-- | Like 'copyFile' from 'System.Directory', but ensure that the parent /temporary/ directory
 -- (i.e. \".liquid\") exists on disk, creating it if necessary.
 copyFileCreateParentDirIfMissing :: FilePath -> FilePath -> IO ()
 copyFileCreateParentDirIfMissing src tgt = do
@@ -131,14 +133,14 @@
 writeFilesOrStrings :: FilePath -> [Either FilePath String] -> IO ()
 writeFilesOrStrings tgtFile = mapM_ $ either (`copyFileCreateParentDirIfMissing` tgtFile) (tgtFile `appendFile`)
 
-generateHtml :: FilePath -> FilePath -> ACSS.AnnMap -> IO ()
-generateHtml srcF htmlF annm
-  = do src     <- Misc.sayReadFile srcF
-       let lhs  = isExtFile LHs srcF
-       let body = {-# SCC "hsannot" #-} ACSS.hsannot False (Just tokAnnot) lhs (src, annm)
-       cssFile <- getCssPath
-       copyFileCreateParentDirIfMissing cssFile (dropFileName htmlF </> takeFileName cssFile)
-       renderHtml lhs htmlF srcF (takeFileName cssFile) body
+generateHtml :: Bool -> FilePath -> FilePath -> ACSS.AnnMap -> IO ()
+generateHtml pandocF srcF htmlF annm = do
+  src     <- Misc.sayReadFile srcF
+  let lhs  = isExtFile LHs srcF
+  let body      = {-# SCC "hsannot" #-} ACSS.hsannot False (Just tokAnnot) lhs (src, annm)
+  cssFile <- getCssPath
+  copyFileCreateParentDirIfMissing cssFile (dropFileName htmlF </> takeFileName cssFile)
+  renderHtml (pandocF && lhs) htmlF srcF (takeFileName cssFile) body
 
 renderHtml :: Bool -> FilePath -> String -> String -> String -> IO ()
 renderHtml True  = renderPandoc
@@ -163,7 +165,7 @@
     cmd    = pandocCmd pandocPath mdFile htmlFile
 
 checkExitCode :: Monad m => String -> ExitCode -> m ()
-checkExitCode _   (ExitSuccess)   = return ()
+checkExitCode _    ExitSuccess    = return ()
 checkExitCode cmd (ExitFailure n) = panic Nothing $ "cmd: " ++ cmd ++ " failure code " ++ show n
 
 pandocCmd :: FilePath -> FilePath -> FilePath -> String
@@ -235,10 +237,10 @@
 --   annotations.
 
 mkAnnMap :: Config -> ErrorResult -> AnnInfo Doc -> ACSS.AnnMap
-mkAnnMap cfg res ann     = ACSS.Ann 
-                             { ACSS.types   = mkAnnMapTyp cfg ann 
-                             , ACSS.errors  = mkAnnMapErr res 
-                             , ACSS.status  = mkStatus res 
+mkAnnMap cfg res ann     = ACSS.Ann
+                             { ACSS.types   = mkAnnMapTyp cfg ann
+                             , ACSS.errors  = mkAnnMapErr res
+                             , ACSS.status  = mkStatus res
                              , ACSS.sptypes = mkAnnMapBinders cfg ann
                              }
 
@@ -252,7 +254,7 @@
 mkAnnMapErr :: PPrint (TError t)
             => FixResult (TError t) -> [(Loc, Loc, String)]
 mkAnnMapErr (Unsafe _ ls) = mapMaybe cinfoErr ls
-mkAnnMapErr (Crash ls _)  = mapMaybe cinfoErr ls
+mkAnnMapErr (Crash ls _)  = mapMaybe (cinfoErr . fst) ls
 mkAnnMapErr _             = []
 
 cinfoErr :: PPrint (TError t) => TError t -> Maybe (Loc, Loc, String)
@@ -380,7 +382,7 @@
 -- | JSON: Annotation Data Types ---------------------------------------
 ------------------------------------------------------------------------
 
-data Assoc k a    = Asc (M.HashMap k a)
+newtype Assoc k a = Asc (M.HashMap k a)
 type AnnTypes     = Assoc Int (Assoc Int Annot1)
 newtype AnnErrors = AnnErrors [(Loc, Loc, String)]
 data Annot1       = A1  { ident :: String
@@ -451,15 +453,15 @@
   toJSON a = object [ "types"   .= toJSON (annTypes     a)
                     , "errors"  .= toJSON (annErrors    a)
                     , "status"  .= toJSON (ACSS.status  a)
-                    , "sptypes" .= (toJ <$> ACSS.sptypes a) 
+                    , "sptypes" .= (toJ <$> ACSS.sptypes a)
                     ]
-    where 
-      toJ (sp, (x,t)) = object [ "start" .= toJSON (srcSpanStartLoc sp) 
-                               , "stop"  .= toJSON (srcSpanEndLoc   sp) 
-                               , "ident" .= toJSON x 
-                               , "ann"  .= toJSON t 
-                               ] 
-                      
+    where
+      toJ (sp, (x,t)) = object [ "start" .= toJSON (srcSpanStartLoc sp)
+                               , "stop"  .= toJSON (srcSpanEndLoc   sp)
+                               , "ident" .= toJSON x
+                               , "ann"  .= toJSON t
+                               ]
+
 annErrors :: ACSS.AnnMap -> AnnErrors
 annErrors = AnnErrors . ACSS.errors
 
diff --git a/src/Language/Haskell/Liquid/UX/CTags.hs b/src/Language/Haskell/Liquid/UX/CTags.hs
--- a/src/Language/Haskell/Liquid/UX/CTags.hs
+++ b/src/Language/Haskell/Liquid/UX/CTags.hs
@@ -28,7 +28,7 @@
 import qualified Data.Graph             as G
 
 import Language.Fixpoint.Types          (Tag)
-import Language.Haskell.Liquid.GHC.API
+import Liquid.GHC.API
 import Language.Haskell.Liquid.Types.Visitors (freeVars)
 import Language.Haskell.Liquid.Types.PrettyPrint ()
 import Language.Fixpoint.Misc     (mapSnd)
diff --git a/src/Language/Haskell/Liquid/UX/CmdLine.hs b/src/Language/Haskell/Liquid/UX/CmdLine.hs
--- a/src/Language/Haskell/Liquid/UX/CmdLine.hs
+++ b/src/Language/Haskell/Liquid/UX/CmdLine.hs
@@ -3,11 +3,14 @@
 {-# LANGUAGE ScopedTypeVariables       #-}
 {-# LANGUAGE TemplateHaskell           #-}
 {-# LANGUAGE TupleSections             #-}
-{-# LANGUAGE TypeSynonymInstances      #-}
 {-# LANGUAGE NamedFieldPuns            #-}
-{-# LANGUAGE MultiWayIf                #-}
 {-# LANGUAGE ViewPatterns              #-}
+
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wwarn=deprecations #-}
 {-# OPTIONS_GHC -fno-cse #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+{-# LANGUAGE FlexibleContexts #-}
 
 -- | This module contains all the code needed to output the result which
 --   is either: `SAFE` or `WARNING` with some reasonable error message when
@@ -47,10 +50,10 @@
 import Control.Monad
 import Control.Monad.IO.Class
 import Data.Maybe
+import Data.Functor ((<&>))
 import Data.Aeson (encode)
 import qualified Data.ByteString.Lazy.Char8 as B
 import Development.GitRev (gitCommitCount)
-import Options.Applicative.Simple (simpleVersion)
 import qualified Paths_liquidhaskell as Meta
 import System.Directory
 import System.Exit
@@ -74,13 +77,14 @@
 import Language.Fixpoint.Solver.Stats as Solver
 import Language.Haskell.Liquid.UX.Annotate
 import Language.Haskell.Liquid.UX.Config
-import Language.Haskell.Liquid.GHC.Misc
+import Language.Haskell.Liquid.UX.SimpleVersion (simpleVersion)
+import Liquid.GHC.Misc
 import Language.Haskell.Liquid.Misc
 import Language.Haskell.Liquid.Types.PrettyPrint ()
 import Language.Haskell.Liquid.Types       hiding (typ)
 import qualified Language.Haskell.Liquid.UX.ACSS as ACSS
 
-import qualified Language.Haskell.Liquid.GHC.API as GHC
+import qualified Liquid.GHC.API as GHC
 import           Language.Haskell.TH.Syntax.Compat (fromCode, toCode)
 
 import Text.PrettyPrint.HughesPJ           hiding (Mode, (<>))
@@ -158,6 +162,11 @@
           &= help "Disable Termination Check"
           &= name "no-termination-check"
 
+ , nopositivity
+    = def
+          &= help "Disable Data Type Positivity Check"
+          &= name "no-positivity-check"
+
  , rankNTypes
     = def &= help "Adds precise reasoning on presence of rankNTypes"
           &= name "rankNTypes"
@@ -181,7 +190,7 @@
 
  , gdepth
     = 1
-    &= help ("Size of gradual conretizations, 1 by default")
+    &= help "Size of gradual conretizations, 1 by default"
     &= name "gradual-depth"
 
  , ginteractive
@@ -275,6 +284,14 @@
     = def &= help "Do not generate ADT representations in refinement logic"
           &= name "no-adt"
 
+ , expectErrorContaining
+    = def &= help "Expect an error which containing the provided string from verification (can be provided more than once)"
+          &= name "expect-error-containing"
+
+ , expectAnyError
+    = def &= help "Expect an error, no matter which kind or what it contains"
+          &= name "expect-any-error"
+
  , scrapeImports
     = False &= help "Scrape qualifiers from imported specifications"
             &= name "scrape-imports"
@@ -348,11 +365,22 @@
         &= help "Enable Proof-by-Logical-Evaluation"
         &= name "ple"
 
+  , pleWithUndecidedGuards
+    = def
+        &= help "Unfold invocations with undecided guards in PLE"
+        &= name "ple-with-undecided-guards"
+        &= explicit
+
   , oldPLE
     = def
         &= help "Enable Proof-by-Logical-Evaluation"
         &= name "oldple"
 
+  , interpreter
+    = def
+        &= help "Use an interpreter to assist PLE in solving constraints"
+        &= name "interpreter"
+
   , proofLogicEvalLocal
     = def
         &= help "Enable Proof-by-Logical-Evaluation locally, per function"
@@ -409,10 +437,10 @@
     rwTerminationCheck
     = def
         &= name "rw-termination-check"
-        &= help (   "Enable the rewrite divergence checker. " 
+        &= help (   "Enable the rewrite divergence checker. "
                  ++ "Can speed up verification if rewriting terminates, but can also cause divergence."
                 )
-  , 
+  ,
     skipModule
     = def
         &= name "skip-module"
@@ -422,9 +450,9 @@
     = def
         &= name "no-lazy-ple"
         &= help "Don't use Lazy PLE"
- 
-  , fuel 
-    = Nothing 
+
+  , fuel
+    = Nothing
         &= help "Maximum fuel (per-function unfoldings) for PLE"
 
   , environmentReduction
@@ -446,6 +474,10 @@
           , "Sometimes improves performance and sometimes worsens it."
           , "Disabled by --no-environment-reduction"
           ])
+  , pandocHtml
+    = False
+      &= name "pandoc-html"
+      &= help "Use pandoc to generate html."
   } &= program "liquid"
     &= help    "Refinement Types for Haskell"
     &= summary copyright
@@ -607,19 +639,27 @@
 withPragmas :: MonadIO m => Config -> FilePath -> [Located String] -> (Config -> m a) -> m a
 --------------------------------------------------------------------------------
 withPragmas cfg fp ps action
-  = do cfg' <- liftIO $ foldM withPragma cfg ps >>= canonicalizePaths fp >>= (return . canonConfig)
+  = do cfg' <- liftIO $ (processPragmas cfg ps >>= canonicalizePaths fp) <&> canonConfig
        -- As the verbosity is set /globally/ via the cmdargs lib, re-set it.
        liftIO $ setVerbosity (loggingVerbosity cfg')
        res <- action cfg'
        liftIO $ setVerbosity (loggingVerbosity cfg) -- restore the original verbosity.
        pure res
-
+  where
+    processPragmas :: Config -> [Located String] -> IO Config
+    processPragmas c pragmas =
+      withArgs (val <$> pragmas) $
+        cmdArgsRun config { modeValue = (modeValue config) { cmdArgsValue = c } }
 
+-- | Note that this function doesn't process list arguments properly, like
+-- 'cFiles' or 'expectErrorContaining'
+-- TODO: This is only used to parse the contents of the env var LIQUIDHASKELL_OPTS
+-- so it should be able to parse multiple arguments instead. See issue #1990.
 withPragma :: Config -> Located String -> IO Config
 withPragma c s = withArgs [val s] $ cmdArgsRun
-          config { modeValue = (modeValue config) { cmdArgsValue = c } }
+                   config { modeValue = (modeValue config) { cmdArgsValue = c } }
 
-parsePragma   :: Located String -> IO Config
+parsePragma :: Located String -> IO Config
 parsePragma = withPragma defConfig
 
 defConfig :: Config
@@ -639,6 +679,7 @@
   , nostructuralterm         = def
   , noCheckUnknown           = def
   , notermination            = False
+  , nopositivity             = False
   , rankNTypes               = False
   , noclasscheck             = False
   , gradual                  = False
@@ -655,6 +696,8 @@
   , pruneUnsorted            = def
   , exactDC                  = def
   , noADT                    = def
+  , expectErrorContaining    = def
+  , expectAnyError           = False
   , cores                    = def
   , minPartSize              = FC.defaultMinPartSize
   , maxPartSize              = FC.defaultMaxPartSize
@@ -682,7 +725,9 @@
   , noslice                  = False
   , noLiftedImport           = False
   , proofLogicEval           = False
+  , pleWithUndecidedGuards   = False
   , oldPLE                   = False
+  , interpreter              = False
   , proofLogicEvalLocal      = False
   , reflection               = False
   , extensionality           = False
@@ -702,11 +747,12 @@
   , environmentReduction     = False
   , noEnvironmentReduction   = False
   , inlineANFBindings        = False
+  , pandocHtml               = False
   }
 
-
--- | Writes the annotations (i.e. the files in the \".liquid\" hidden folder) and report the result
--- of the checking using a supplied function.
+-- | Write the annotations (i.e. the files in the \".liquid\" hidden folder) and
+-- report the result of the checking using a supplied function, or using an
+-- implicit JSON function, if @json@ flag is set.
 reportResult :: MonadIO m
              => (OutputResult -> m ())
              -> Config
@@ -716,8 +762,9 @@
 reportResult logResultFull cfg targets out = do
   annm <- {-# SCC "annotate" #-} liftIO $ annotate cfg targets out
   liftIO $ whenNormal $ donePhase Loud "annotate"
-  if | json cfg  -> liftIO $ reportResultJson annm
-     | otherwise -> do
+  if json cfg then
+    liftIO $ reportResultJson annm
+   else do
          let r = o_result out
          liftIO $ writeCheckVars $ o_vars out
          cr <- liftIO $ resultWithContext r
@@ -726,7 +773,6 @@
          -- passed as input.
          liftIO $ printHeader (colorResult r) (orHeader outputResult)
          logResultFull outputResult
-  pure ()
   where
     tidy :: F.Tidy
     tidy = if shortErrors cfg then F.Lossy else F.Full
@@ -734,11 +780,10 @@
     printHeader :: Moods -> Doc -> IO ()
     printHeader mood d = colorPhaseLn mood "" (render d)
 
-
 ------------------------------------------------------------------------
 exitWithResult :: Config -> [FilePath] -> Output Doc -> IO ()
 ------------------------------------------------------------------------
-exitWithResult cfg = reportResult writeResultStdout cfg
+exitWithResult cfg targets out = void $ reportResult writeResultStdout cfg targets out
 
 reportResultJson :: ACSS.AnnMap -> IO ()
 reportResultJson annm = do
@@ -747,14 +792,20 @@
 
 resultWithContext :: F.FixResult UserError -> IO (FixResult CError)
 resultWithContext (F.Unsafe s es)  = F.Unsafe s    <$> errorsWithContext es
-resultWithContext (F.Crash  es s)  = (`F.Crash` s) <$> errorsWithContext es
 resultWithContext (F.Safe   stats) = return (F.Safe stats)
+resultWithContext (F.Crash  es s)  = do
+  let (errs, msgs) = unzip es
+  errs' <- errorsWithContext errs
+  return (F.Crash (zip errs' msgs) s)
 
+
+
+
 instance Show (CtxError Doc) where
   show = showpp
 
 writeCheckVars :: Symbolic a => Maybe [a] -> IO ()
-writeCheckVars Nothing     = return ()
+writeCheckVars Nothing    = return ()
 writeCheckVars (Just [])   = colorPhaseLn Loud "Checked Binders: None" ""
 writeCheckVars (Just ns)   = colorPhaseLn Loud "Checked Binders:" ""
                           >> forM_ ns (putStrLn . symbolString . dropModuleNames . symbol)
@@ -775,12 +826,12 @@
   forM_ messages $ \(sSpan, doc) -> putStrLn (render $ mkErrorDoc sSpan doc {- pprint sSpan <> (text ": error: " <+> doc)-})
 
 mkErrorDoc :: PPrint a => a -> Doc -> Doc
-mkErrorDoc sSpan doc = 
+mkErrorDoc sSpan doc =
   -- Gross on screen, nice for Ghcid
   -- pprint sSpan <> (text ": error: " <+> doc)
 
   -- Nice on screen, invisible in Ghcid ...
-  (pprint sSpan <> text ": error: ") $+$ (nest 4 doc)
+  (pprint sSpan <> text ": error: ") $+$ nest 4 doc
 
 
 -- | Given a 'FixResult' parameterised over a 'CError', this function returns the \"header\" to show to
@@ -791,9 +842,14 @@
     orHeader   = text $ "LIQUID: SAFE (" <> show (Solver.numChck stats) <> " constraints checked)"
   , orMessages = mempty
   }
+resDocs _k (F.Crash [] s)  =
+  OutputResult {
+    orHeader = text "LIQUID: ERROR"
+  , orMessages = [(GHC.noSrcSpan, text s)]
+  }
 resDocs k (F.Crash xs s)  =
   OutputResult {
-    orHeader = text "LIQUID: ERROR" <+> text s
+    orHeader = text "LIQUID: ERROR:" <+> text s
   , orMessages = map (cErrToSpanned k . errToFCrash) xs
   }
 resDocs k (F.Unsafe _ xs)   =
@@ -806,11 +862,15 @@
 cErrToSpanned :: F.Tidy -> CError -> (GHC.SrcSpan, Doc)
 cErrToSpanned k CtxError{ctErr} = (pos ctErr, pprintTidy k ctErr)
 
-errToFCrash :: CtxError a -> CtxError a
-errToFCrash ce = ce { ctErr    = tx $ ctErr ce}
+errToFCrash :: (CError, Maybe String) -> CError
+errToFCrash (ce, Just msg) = ce { ctErr = ErrOther (pos (ctErr ce)) (fixMessageDoc msg) }
+errToFCrash (ce, Nothing)  = ce { ctErr = tx $ ctErr ce}
   where
     tx (ErrSubType l m _ g t t') = ErrFCrash l m g t t'
-    tx e                       = e
+    tx e                         = F.notracepp "errToFCrash?" e
+
+fixMessageDoc :: String -> Doc
+fixMessageDoc msg = vcat (text <$> lines msg)
 
 {-
    TODO: Never used, do I need to exist?
diff --git a/src/Language/Haskell/Liquid/UX/Config.hs b/src/Language/Haskell/Liquid/UX/Config.hs
--- a/src/Language/Haskell/Liquid/UX/Config.hs
+++ b/src/Language/Haskell/Liquid/UX/Config.hs
@@ -39,6 +39,7 @@
   , checks                   :: [String]   -- ^ set of binders to check
   , noCheckUnknown           :: Bool       -- ^ whether to complain about specifications for unexported and unused values
   , notermination            :: Bool       -- ^ disable termination check
+  , nopositivity             :: Bool       -- ^ disable positivity check
   , rankNTypes               :: Bool       -- ^ Adds precise reasoning on presence of rankNTypes
   , noclasscheck             :: Bool       -- ^ disable checking class instances
   -- , structuralTerm        :: Bool       -- ^ use structural termination checker
@@ -69,6 +70,8 @@
   , port                     :: Int        -- ^ port at which lhi should listen
   , exactDC                  :: Bool       -- ^ Automatically generate singleton types for data constructors
   , noADT                    :: Bool       -- ^ Disable ADTs (only used with exactDC)
+  , expectErrorContaining    :: [String]   -- ^ expect failure from Liquid with at least one of the following messages
+  , expectAnyError           :: Bool       -- ^ expect failure from Liquid with any message
   , scrapeImports            :: Bool       -- ^ scrape qualifiers from imported specifications
   , scrapeInternals          :: Bool       -- ^ scrape qualifiers from auto specifications
   , scrapeUsedImports        :: Bool       -- ^ scrape qualifiers from used, imported specifications
@@ -84,7 +87,9 @@
   , noslice                  :: Bool       -- ^ Disable non-concrete KVar slicing
   , noLiftedImport           :: Bool       -- ^ Disable loading lifted specifications (for "legacy" libs)
   , proofLogicEval           :: Bool       -- ^ Enable proof-by-logical-evaluation
+  , pleWithUndecidedGuards   :: Bool       -- ^ Unfold invocations with undecided guards in PLE
   , oldPLE                   :: Bool       -- ^ Enable proof-by-logical-evaluation
+  , interpreter              :: Bool       -- ^ Use an interpreter to assist PLE
   , proofLogicEvalLocal      :: Bool       -- ^ Enable proof-by-logical-evaluation locally, per function
   , extensionality           :: Bool       -- ^ Enable extensional interpretation of function equality
   , nopolyinfer              :: Bool       -- ^ No inference of polymorphic type application.
@@ -105,6 +110,7 @@
   , noEnvironmentReduction   :: Bool       -- ^ Don't perform environment reduction
   , inlineANFBindings        :: Bool       -- ^ Inline ANF bindings.
                                            -- Sometimes improves performance and sometimes worsens it.
+  , pandocHtml               :: Bool       -- ^ Use pandoc to generate html
   } deriving (Generic, Data, Typeable, Show, Eq)
 
 allowPLE :: Config -> Bool
@@ -153,11 +159,10 @@
 terminationCheck = terminationCheck' . getConfig
 
 totalityCheck' :: Config -> Bool
-totalityCheck' cfg = (not (nototality cfg)) || totalHaskell cfg
+totalityCheck' cfg = not (nototality cfg) || totalHaskell cfg
 
 terminationCheck' :: Config -> Bool
-terminationCheck' cfg = (totalHaskell cfg || not (notermination cfg))
+terminationCheck' cfg = totalHaskell cfg || not (notermination cfg)
 
 structuralTerm :: (HasConfig a) => a -> Bool
 structuralTerm = not . nostructuralterm . getConfig
-
diff --git a/src/Language/Haskell/Liquid/UX/DiffCheck.hs b/src/Language/Haskell/Liquid/UX/DiffCheck.hs
--- a/src/Language/Haskell/Liquid/UX/DiffCheck.hs
+++ b/src/Language/Haskell/Liquid/UX/DiffCheck.hs
@@ -7,6 +7,10 @@
 {-# LANGUAGE FlexibleContexts  #-}
 {-# LANGUAGE FlexibleInstances #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+{-# LANGUAGE TupleSections #-}
+
 module Language.Haskell.Liquid.UX.DiffCheck (
 
    -- * Changed binders + Unchanged Errors
@@ -47,10 +51,10 @@
 import           Language.Fixpoint.Types                (atLoc, FixResult (..), SourcePos(..), safeSourcePos, unPos)
 -- import qualified Language.Fixpoint.Misc                 as Misc
 import           Language.Fixpoint.Utils.Files
-import           Language.Fixpoint.Solver.Stats ()     
+import           Language.Fixpoint.Solver.Stats ()
 import           Language.Haskell.Liquid.Misc           (mkGraph)
-import           Language.Haskell.Liquid.GHC.Misc
-import           Language.Haskell.Liquid.GHC.API        as Ghc hiding ( Located
+import           Liquid.GHC.Misc
+import           Liquid.GHC.API        as Ghc hiding ( Located
                                                                       , sourceName
                                                                       , text
                                                                       , panic
@@ -58,7 +62,7 @@
                                                                       )
 import           Text.PrettyPrint.HughesPJ              (text, render, Doc)
 import qualified Data.ByteString                        as B
-import qualified Data.ByteString.Lazy                   as LB                                               
+import qualified Data.ByteString.Lazy                   as LB
 
 import           Language.Haskell.Liquid.Types          hiding (Def, LMap)
 
@@ -67,7 +71,7 @@
 --------------------------------------------------------------------------------
 
 -- | Main type of value returned for diff-check.
-data DiffCheck = DC 
+data DiffCheck = DC
   { newBinds  :: [CoreBind]
   , oldOutput :: !(Output Doc)
   , newSpec   :: !TargetSpec
@@ -78,7 +82,7 @@
 
 
 -- | Variable definitions
-data Def  = D 
+data Def  = D
   { start  :: Int -- ^ line at which binder definition starts
   , end    :: Int -- ^ line at which binder definition ends
   , binder :: Var -- ^ name of binder
@@ -113,10 +117,10 @@
 --------------------------------------------------------------------------------
 slice :: FilePath -> [CoreBind] -> TargetSpec -> IO (Maybe DiffCheck)
 --------------------------------------------------------------------------------
-slice target cbs sp = do 
+slice target cbs sp = do
   ex <- doesFileExist savedFile
-  if ex 
-    then doDiffCheck 
+  if ex
+    then doDiffCheck
     else return Nothing
   where
     savedFile       = extFileName Saved target
@@ -148,7 +152,7 @@
 assumeSpec :: M.HashMap Var LocSpecType -> TargetSpec -> TargetSpec
 assumeSpec sigm sp = sp { gsSig = gsig { gsAsmSigs = M.toList $ M.union sigm assm } }
   where
-    assm           = M.fromList (gsAsmSigs gsig) 
+    assm           = M.fromList (gsAsmSigs gsig)
     gsig           = gsSig sp
 
 diffVars :: [Int] -> [Def] -> [Var]
@@ -208,7 +212,7 @@
 thinWith sigs cbs xs = filterBinds cbs calls
   where
     calls    = txClosure cbDeps sigs (S.fromList xs)
-    cbDeps   = coreDeps cbs 
+    cbDeps   = coreDeps cbs
 
 coreDeps    :: [CoreBind] -> Deps
 coreDeps bs = mkGraph $ calls ++ calls'
@@ -217,7 +221,7 @@
     calls'  = [(y, x) | (x, y) <- calls]
     deps b  = [(x, y) | x <- bindersOf b
                       , y <- freeVars S.empty b
-                      , S.member y defVars 
+                      , S.member y defVars
               ]
     defVars = S.fromList (letVars bs)
 
@@ -265,8 +269,8 @@
     sameFile   = (srcF ==) . file . snd
 
 specSigs :: TargetSpec -> [(Var, LocSpecType)]
-specSigs sp = gsTySigs  (gsSig  sp) 
-           ++ gsAsmSigs (gsSig  sp) 
+specSigs sp = gsTySigs  (gsSig  sp)
+           ++ gsAsmSigs (gsSig  sp)
            ++ gsCtors   (gsData sp)
 
 instance PPrint Def where
@@ -282,9 +286,9 @@
     xm       = varBounds xes
 
 coreExprDefs :: M.HashMap Var (Int, Int) -> [(Var, CoreExpr)]-> [Def]
-coreExprDefs xm xes = 
-  L.sort 
-    [ D l l' x 
+coreExprDefs xm xes =
+  L.sort
+    [ D l l' x
       | (x, e) <- xes
       , (l, l') <- maybeToList $ coreExprDef xm (x, e)
     ]
@@ -299,43 +303,43 @@
 coreVarExprs :: [CoreBind] -> [(Var, CoreExpr)]
 coreVarExprs = filter ok . concatMap varExprs
   where
-    ok       = isGoodSrcSpan . getSrcSpan . fst 
+    ok       = isGoodSrcSpan . getSrcSpan . fst
 
 varExprs :: Bind a -> [(a, Expr a)]
 varExprs (NonRec x e) = [(x, e)]
 varExprs (Rec xes)    = xes
 
--- | varBounds computes upper and lower bounds on where each top-level binder's 
+-- | varBounds computes upper and lower bounds on where each top-level binder's
 --   definition can be by using ONLY the lines where the binder is defined.
 varBounds :: [(Var, CoreExpr)] -> M.HashMap Var (Int, Int)
-varBounds = M.fromList . defBounds . varDefs 
+varBounds = M.fromList . defBounds . varDefs
 
 varDefs :: [(Var, CoreExpr)] -> [(Int, Var)]
-varDefs xes = 
+varDefs xes =
   L.sort [ (l, x) | (x,_) <- xes, let Just (l, _) = lineSpan x (getSrcSpan x) ]
 
 defBounds :: [(Int, Var)] -> [(Var, (Int, Int) )]
 defBounds ((l, x) : lxs@((l', _) : _ )) = (x, (l, l' - 1)) : defBounds lxs
 defBounds _                             = []
 
-{- 
+{-
 --------------------------------------------------------------------------------
 coreDefs     :: [CoreBind] -> [Def]
 --------------------------------------------------------------------------------
-coreDefs cbs = tracepp "coreDefs" $ 
+coreDefs cbs = tracepp "coreDefs" $
                L.sort [D l l' x | b <- cbs
                                 , x <- bindersOf b
                                 , isGoodSrcSpan (getSrcSpan x)
                                 , (l, l') <- coreDef b]
 
 coreDef :: CoreBind -> [(Int, Int)]
-coreDef b 
+coreDef b
   | True  = tracepp ("coreDef: " ++ showpp (vs, vSp)) $ maybeToList vSp
   | False = tracepp ("coreDef: " ++ showpp (b, eSp, vSp)) $ meetSpans b eSp vSp
   where
     eSp   = lineSpan b $ catSpans b $ bindSpans b
     vSp   = lineSpan b $ catSpans b $ getSrcSpan <$> vs
-    vs    = bindersOf b 
+    vs    = bindersOf b
 
 meetSpans :: Maybe (Int, Int) -> Maybe (Int, Int) -> Maybe (Int, Int)
 meetSpans Nothing       _
@@ -475,7 +479,7 @@
 --------------------------------------------------------------------------------
 saveResult :: FilePath -> Output Doc -> IO ()
 --------------------------------------------------------------------------------
-saveResult target res = do 
+saveResult target res = do
   copyFile target saveF
   B.writeFile errF $ LB.toStrict $ encode res
   where
@@ -485,13 +489,13 @@
 --------------------------------------------------------------------------------
 loadResult   :: FilePath -> IO (Output Doc)
 --------------------------------------------------------------------------------
-loadResult f = do 
+loadResult f = do
   ex <- doesFileExist jsonF
-  if ex 
+  if ex
     then convert <$> B.readFile jsonF
     else return mempty
   where
-    convert  = fromMaybe mempty . decode . LB.fromStrict 
+    convert  = fromMaybe mempty . decode . LB.fromStrict
     jsonF    = extFileName Cache f
 
 --------------------------------------------------------------------------------
@@ -506,20 +510,18 @@
                                               , Just sp' <- [adjustSrcSpan lm cm sp]]
 
 adjustResult :: LMap -> ChkItv -> ErrorResult -> ErrorResult
-adjustResult lm cm (Unsafe s es)  = errorsResult (Unsafe s)  $ adjustErrors lm cm es
-adjustResult lm cm (Crash es z)   = errorsResult (`Crash` z) $ adjustErrors lm cm es
+adjustResult lm cm (Unsafe s es)  = errorsResult (Unsafe s)  $ mapMaybe (adjustError  lm cm) es
+adjustResult lm cm (Crash es z)   = errorsResult (`Crash` z) $ (, Nothing) <$>mapMaybe (adjustError lm cm . fst) es
 adjustResult _  _  r              = r
 
 errorsResult :: ([a] -> FixResult b) -> [a] -> FixResult b
 errorsResult _ []                 = Safe mempty
 errorsResult f es                 = f es
 
-adjustErrors :: (PPrint (TError a)) => LMap -> ChkItv -> [TError a] -> [TError a]
-adjustErrors lm cm                = mapMaybe adjustError
-  where
-    adjustError e                = case adjustSrcSpan lm cm (pos e) of
-                                     Just sp' -> Just (e {pos = sp'})
-                                     Nothing  -> Nothing
+adjustError :: (PPrint (TError a)) => LMap -> ChkItv -> TError a -> Maybe (TError a)
+adjustError lm cm e = case adjustSrcSpan lm cm (pos e) of
+  Just sp' -> Just (e {pos = sp'})
+  Nothing  -> Nothing
 
 --------------------------------------------------------------------------------
 adjustSrcSpan :: LMap -> ChkItv -> SrcSpan -> Maybe SrcSpan
diff --git a/src/Language/Haskell/Liquid/UX/Errors.hs b/src/Language/Haskell/Liquid/UX/Errors.hs
--- a/src/Language/Haskell/Liquid/UX/Errors.hs
+++ b/src/Language/Haskell/Liquid/UX/Errors.hs
@@ -3,6 +3,8 @@
 {-# LANGUAGE TupleSections     #-}
 {-# LANGUAGE BangPatterns      #-}
 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
 -- | This module contains the functions related to @Error@ type,
 -- in particular, to @tidyError@ using a solution, and @pprint@ errors.
 
@@ -14,14 +16,14 @@
 import qualified Data.List                           as L
 import           Data.Hashable
 import           Data.Maybe                          (maybeToList)
-import qualified Language.Fixpoint.Types             as F 
+import qualified Language.Fixpoint.Types             as F
 import           Language.Haskell.Liquid.Types.RefType
 import           Language.Haskell.Liquid.Transforms.Simplify
 import           Language.Haskell.Liquid.UX.Tidy
 import           Language.Haskell.Liquid.Types
-import qualified Language.Haskell.Liquid.GHC.Misc    as GM 
-import qualified Language.Haskell.Liquid.Misc        as Misc 
-import qualified Language.Fixpoint.Misc              as Misc 
+import qualified Liquid.GHC.Misc    as GM
+import qualified Language.Haskell.Liquid.Misc        as Misc
+import qualified Language.Fixpoint.Misc              as Misc
 
 -- import Debug.Trace
 
@@ -32,15 +34,15 @@
 tidyError :: Config -> F.FixSolution -> Error -> Error
 ------------------------------------------------------------------------
 tidyError cfg sol
-  = fmap (tidySpecType tidy) 
+  = fmap (tidySpecType tidy)
   . tidyErrContext tidy sol
-  where 
-    tidy = configTidy cfg 
+  where
+    tidy = configTidy cfg
 
-configTidy :: Config -> F.Tidy 
-configTidy cfg 
-  | shortNames cfg = F.Lossy 
-  | otherwise      = F.Full 
+configTidy :: Config -> F.Tidy
+configTidy cfg
+  | shortNames cfg = F.Lossy
+  | otherwise      = F.Full
 
 tidyErrContext :: F.Tidy -> F.FixSolution -> Error -> Error
 tidyErrContext k _ e@(ErrSubType {})
@@ -76,9 +78,9 @@
 tidyCtx k xs m = (θ1 `mappend` θ2, M.fromList yts)
   where
     yts        = [tBind x (tidySpecType k t) | (x, t) <- xt2s]
-    (θ2, xt2s) = tidyREnv xt1s 
-    (θ1, xt1s) = tidyTemps xts  
-    xts        = sliceREnv xs m 
+    (θ2, xt2s) = tidyREnv xt1s
+    (θ1, xt1s) = tidyTemps xts
+    xts        = sliceREnv xs m
     tBind x t  = (x', shiftVV t x') where x' = F.tidySymbol x
 
 tidyCtxM       :: [F.Symbol] -> CtxM -> (F.Subst, CtxM)
@@ -86,13 +88,13 @@
   where
     yts       = [tBind x t | (x, t) <- xts]
     (θ, xts)  = tidyTemps $ second (fmap stripReft) <$> tidyREnvM xs m
-    tBind x t = (x', fmap (\t -> shiftVV t x') t) where x' = F.tidySymbol x
+    tBind x t = (x', fmap (`shiftVV` x') t) where x' = F.tidySymbol x
 
 tidyREnv :: [(F.Symbol, SpecType)] -> (F.Subst, [(F.Symbol, SpecType)])
 tidyREnv xts    = (θ, second (F.subst θ) <$> zts)
-  where 
-    θ           = expandVarDefs yes 
-    (yes, zts)  = Misc.mapEither isInline xts 
+  where
+    θ           = expandVarDefs yes
+    (yes, zts)  = Misc.mapEither isInline xts
 
 -- | 'expandVarDefs [(x1, e1), ... ,(xn, en)] returns a `Subst` that  
 --   contains the fully substituted definitions for each `xi`. For example, 
@@ -100,30 +102,30 @@
 --   should return 
 --     [x1 := 'x2 + x3, x5 := (x2 + x3) + 1]
 
-expandVarDefs :: [(F.Symbol, F.Expr)] -> F.Subst 
-expandVarDefs      = go mempty 
-  where 
-    go !su xes     
-      | null yes   = su `mappend` (F.mkSubst xes)
+expandVarDefs :: [(F.Symbol, F.Expr)] -> F.Subst
+expandVarDefs      = go mempty
+  where
+    go !su xes
+      | null yes   = su `mappend` F.mkSubst xes
       | otherwise  = go (su `mappend` su') xes''
-      where  
-       xes''       = [(z, F.subst su' e) | (z, e) <- zes] 
-       xs          = S.fromList [x | (x, _) <- xes] 
+      where
+       xes''       = [(z, F.subst su' e) | (z, e) <- zes]
+       xs          = S.fromList [x | (x, _) <- xes]
        su'         = F.mkSubst yes
-       (yes, zes)  = L.partition (isDef xs . snd) xes 
-    isDef xs e     = all (not . (`S.member` xs)) (F.syms e) 
+       (yes, zes)  = L.partition (isDef xs . snd) xes
+    isDef xs e     = not (any (`S.member` xs) (F.syms e))
 
-isInline :: (a, SpecType) -> Either (a, F.Expr) (a, SpecType) 
-isInline (x, t) = either (Left . (x,)) (Right . (x,)) (isInline' t) 
+isInline :: (a, SpecType) -> Either (a, F.Expr) (a, SpecType)
+isInline (x, t) = either (Left . (x,)) (Right . (x,)) (isInline' t)
 
-isInline' :: SpecType -> Either F.Expr SpecType 
-isInline' t = case ro of 
-                Nothing -> Right t' 
-                Just rr -> case F.isSingletonReft (ur_reft rr) of 
+isInline' :: SpecType -> Either F.Expr SpecType
+isInline' t = case ro of
+                Nothing -> Right t'
+                Just rr -> case F.isSingletonReft (ur_reft rr) of
                              Just e  -> Left e
-                             Nothing -> Right (strengthen t' rr) 
-              where 
-                  (t', ro) = stripRType t 
+                             Nothing -> Right (strengthen t' rr)
+              where
+                  (t', ro) = stripRType t
 
 stripReft     :: SpecType -> SpecType
 stripReft t   = maybe t' (strengthen t') ro
@@ -174,4 +176,4 @@
   where
     mkSymbol  = F.symbol . ('?' :)
     xs        = Misc.single <$> ['a' .. 'z']
-    ys        = ("a" ++) <$> [show n | n <- [0 ..]]
+    ys        = ("a" ++) <$> [show n | n <- [(0::Int) ..]]
diff --git a/src/Language/Haskell/Liquid/UX/QuasiQuoter.hs b/src/Language/Haskell/Liquid/UX/QuasiQuoter.hs
--- a/src/Language/Haskell/Liquid/UX/QuasiQuoter.hs
+++ b/src/Language/Haskell/Liquid/UX/QuasiQuoter.hs
@@ -1,11 +1,12 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE DeriveDataTypeable #-}
-{-# LANGUAGE DeriveFunctor      #-}
-{-# LANGUAGE TemplateHaskell    #-}
-{-# LANGUAGE TupleSections      #-}
-{-# LANGUAGE OverloadedStrings  #-}
+{-# LANGUAGE DeriveDataTypeable    #-}
+{-# LANGUAGE DeriveFunctor         #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
+{-# LANGUAGE TupleSections         #-}
+{-# LANGUAGE OverloadedStrings     #-}
 
-module Language.Haskell.Liquid.UX.QuasiQuoter 
+{-# OPTIONS_GHC -Wno-name-shadowing #-}
+
+module Language.Haskell.Liquid.UX.QuasiQuoter
 -- (
 --     -- * LiquidHaskell Specification QuasiQuoter
 --     lq
@@ -27,8 +28,8 @@
 import Language.Fixpoint.Types hiding (Error, Loc, SrcSpan)
 import qualified Language.Fixpoint.Types as F
 
-import Language.Haskell.Liquid.GHC.Misc (fSrcSpan)
-import Language.Haskell.Liquid.GHC.API  (SrcSpan)
+import Liquid.GHC.Misc (fSrcSpan)
+import Liquid.GHC.API  (SrcSpan)
 import Language.Haskell.Liquid.Parse
 import Language.Haskell.Liquid.Types
 
@@ -87,16 +88,12 @@
   (\t -> (`SigD` t) . symbolName <$> names)
     <$> simplifyBareType (head names) (quantifyFreeRTy $ val ty)
 mkSpecDecs (Alias rta) =
-  return . (TySynD name tvs) <$> simplifyBareType lsym (rtBody (val rta))
+  return . TySynD name tvs <$> simplifyBareType lsym (rtBody (val rta))
   where
-    lsym = F.atLoc rta n 
-    name = symbolName n 
+    lsym = F.atLoc rta n
+    name = symbolName n
     n    = rtName (val rta)
-#if MIN_VERSION_template_haskell(2,17,0)
     tvs  = (\a -> PlainTV (symbolName a) ()) <$> rtTArgs (val rta)
-#else
-    tvs  = PlainTV . symbolName <$> rtTArgs (val rta)
-#endif
 mkSpecDecs _ =
   Right []
 
@@ -112,10 +109,10 @@
   Simplified t' ->
     Right t'
   FoundExprArg l ->
-    Left $ ErrTySpec l Nothing (pprint $ val s) (pprint t) $ 
+    Left $ ErrTySpec l Nothing (pprint $ val s) (pprint t)
       "Found expression argument in bad location in type"
   FoundHole ->
-    Left $ ErrTySpec (fSrcSpan s) Nothing (pprint $ val s) (pprint t) $ 
+    Left $ ErrTySpec (fSrcSpan s) Nothing (pprint $ val s) (pprint t)
       "Can't write LiquidHaskell type with hole in a quasiquoter"
 
 simplifyBareType' :: BareType -> Simpl Type
@@ -158,11 +155,7 @@
   simplifyBareType'' (ty_var_value tv : tvs, cls) t
 
 simplifyBareType'' (tvs, cls) t =
-#if MIN_VERSION_template_haskell(2,17,0)
   ForallT ((\t -> PlainTV (symbolName t) SpecifiedSpec) <$> reverse tvs)
-#else
-  ForallT (PlainTV . symbolName <$> reverse tvs)
-#endif
     <$> mapM simplifyBareType' (reverse cls)
     <*> simplifyBareType' t
 
@@ -207,7 +200,7 @@
 
 locSourcePos :: Loc -> SourcePos
 locSourcePos loc =
-  safeSourcePos (loc_filename loc) (fst $ loc_start loc) (snd $ loc_start loc)
+  uncurry (safeSourcePos (loc_filename loc)) (loc_start loc)
 
 dataToExpQ' :: Data a => a -> Q Exp
 dataToExpQ' = dataToExpQ (const Nothing `extQ` textToExpQ)
diff --git a/src/Language/Haskell/Liquid/UX/SimpleVersion.hs b/src/Language/Haskell/Liquid/UX/SimpleVersion.hs
new file mode 100644
--- /dev/null
+++ b/src/Language/Haskell/Liquid/UX/SimpleVersion.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module Language.Haskell.Liquid.UX.SimpleVersion (simpleVersion) where
+
+import Data.Version (Version, showVersion)
+import GitHash (GitInfo, giDirty, giHash, tGitInfoCwdTry)
+import Language.Haskell.TH (Exp, Q)
+import qualified Language.Haskell.TH.Syntax as TH.Syntax
+import qualified Language.Haskell.TH.Syntax.Compat as TH.Syntax.Compat
+
+-- | Generate a string like @Version 1.2, Git revision 1234@.
+--
+-- @$(simpleVersion …)@ @::@ 'String'
+-- Taken from <https://hackage.haskell.org/package/optparse-simple-0.1.1.4/docs/Options-Applicative-Simple.html#v:simpleVersion>
+-- so we can drop the dependency on optparse-simple.
+simpleVersion :: Version -> Q Exp
+simpleVersion version =
+  [|
+    concat
+      ( [ "Version ",
+          $(TH.Syntax.lift $ showVersion version)
+        ]
+          ++ case $(TH.Syntax.Compat.unTypeSplice tGitInfoCwdTry) :: Either String GitInfo of
+            Left _ -> []
+            Right gi ->
+              [ ", Git revision ",
+                giHash gi,
+                if giDirty gi then " (dirty)" else ""
+              ]
+      )
+    |]
diff --git a/src/Language/Haskell/Liquid/UX/Tidy.hs b/src/Language/Haskell/Liquid/UX/Tidy.hs
--- a/src/Language/Haskell/Liquid/UX/Tidy.hs
+++ b/src/Language/Haskell/Liquid/UX/Tidy.hs
@@ -1,8 +1,9 @@
-
 {-# LANGUAGE FlexibleContexts  #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE FlexibleInstances #-}
 
+{-# OPTIONS_GHC -Wno-orphans #-}
+
 ---------------------------------------------------------------------
 -- | This module contains functions for cleaning up types before
 --   they are rendered, e.g. in error messages or annoations,
@@ -35,11 +36,11 @@
 import qualified Data.List                                 as L
 import qualified Data.Text                                 as T
 import qualified Control.Exception                         as Ex
-import qualified Language.Haskell.Liquid.GHC.Misc          as GM 
+import qualified Liquid.GHC.Misc          as GM
 -- (dropModuleNames, showPpr, stringTyVar)
 import           Language.Fixpoint.Types                   hiding (Result, SrcSpan, Error)
 import           Language.Haskell.Liquid.Types.Types
-import           Language.Haskell.Liquid.Types.RefType     (rVar, subsTyVars_meet, FreeVar)
+import           Language.Haskell.Liquid.Types.RefType     (rVar, subsTyVarsMeet, FreeVar)
 import           Language.Haskell.Liquid.Types.PrettyPrint
 import           Data.Generics                             (everywhere, mkT)
 import           Text.PrettyPrint.HughesPJ
@@ -53,10 +54,10 @@
   result :: a -> FixResult UserError
 
 instance Result UserError where
-  result e = Crash [e] ""
+  result e = Crash [(e, Nothing)] ""
 
 instance Result [Error] where
-  result es = Crash (errorToUserError <$> es) ""
+  result es = Crash ([ (errorToUserError e, Nothing) | e <- es]) ""
 
 instance Result Error where
   result e  = result [e] --  Crash [pprint e] ""
@@ -70,16 +71,16 @@
 -- TODO: move to Types.hs
 cinfoError :: Cinfo -> Error
 cinfoError (Ci _ (Just e) _) = e
-cinfoError (Ci l _ _)        = ErrOther l (text $ "Cinfo:" ++ GM.showPpr l)
+cinfoError (Ci l _ _)        = ErrOther l (text $ "Cinfo: " ++ GM.showPpr l)
 
 -------------------------------------------------------------------------
 tidySpecType :: Tidy -> SpecType -> SpecType
 -------------------------------------------------------------------------
-tidySpecType k 
-  = tidyEqual 
+tidySpecType k
+  = tidyEqual
   . tidyValueVars
   . tidyDSymbols
-  . tidySymbols k 
+  . tidySymbols k
   . tidyInternalRefas
   . tidyLocalRefas k
   . tidyFunBinds
@@ -104,9 +105,9 @@
     xs          = S.fromList (syms t)
     dropBind x  = if x `S.member` xs then tidySymbol x else nonSymbol
 
-shortSymbol :: Tidy -> Symbol -> Symbol 
-shortSymbol Lossy = GM.dropModuleNames 
-shortSymbol _     = id 
+shortSymbol :: Tidy -> Symbol -> Symbol
+shortSymbol Lossy = GM.dropModuleNames
+shortSymbol _     = id
 
 tidyLocalRefas   :: Tidy -> SpecType -> SpecType
 tidyLocalRefas k = mapReft (txReft' k)
@@ -119,7 +120,7 @@
 
 tidyEqual :: SpecType -> SpecType
 tidyEqual = mapReft txReft
-  where 
+  where
     txReft u                      = u { ur_reft = mapPredReft dropInternals $ ur_reft u }
     dropInternals                 = pAnd . L.nub . conjuncts
 
@@ -148,13 +149,13 @@
     αβs  = zipWith (\α β -> (α, toRSort β, β)) αs βs
     αs   = L.nub (tyVars t)
     βs   = map (rVar . GM.stringTyVar) pool
-    pool = [[c] | c <- ['a'..'z']] ++ [ "t" ++ show i | i <- [1..]]
+    pool = [[c] | c <- ['a'..'z']] ++ [ "t" ++ show i | i <- [(1::Int)..]]
 
 
 bindersTx :: [Symbol] -> Symbol -> Symbol
 bindersTx ds   = \y -> M.lookupDefault y y m
   where
-    m          = M.fromList $ zip ds $ var <$> [1..]
+    m          = M.fromList $ zip ds $ var <$> [(1::Int)..]
     var        = symbol . ('x' :) . show
 
 
@@ -185,7 +186,7 @@
   where
     abm            = M.fromList [(a, b) | (a, _, RVar b _) <- ats]
     go (RAllT a t r) = RAllT (makeRTVar $ M.lookupDefault (ty_var_value a) (ty_var_value a) abm) (go t) r
-    go t           = subsTyVars_meet ats t
+    go t           = subsTyVarsMeet ats t
 
 
 funBinds :: RType t t1 t2 -> [Symbol]
@@ -229,7 +230,7 @@
 
 instance PPrint Error where
   pprintTidy k = ppError k empty . fmap ppSpecTypeErr
- 
+
 ppSpecTypeErr :: SpecType -> Doc
 ppSpecTypeErr = ppSpecType Lossy
 
diff --git a/src/Language/Haskell/Liquid/WiredIn.hs b/src/Language/Haskell/Liquid/WiredIn.hs
--- a/src/Language/Haskell/Liquid/WiredIn.hs
+++ b/src/Language/Haskell/Liquid/WiredIn.hs
@@ -26,19 +26,20 @@
 import Prelude                                hiding (error)
 
 -- import Language.Fixpoint.Misc           (mapSnd)
-import Language.Haskell.Liquid.GHC.Misc
-import qualified Language.Haskell.Liquid.GHC.API as Ghc
-import Language.Haskell.Liquid.GHC.API (Var, Arity, TyVar, Bind(..), Boxity(..), Expr(..), ArgFlag(..))
+import Liquid.GHC.Misc
+import qualified Liquid.GHC.API as Ghc
+import Liquid.GHC.API (Var, Arity, TyVar, Bind(..), Boxity(..), Expr(..), ArgFlag(..))
 import Language.Haskell.Liquid.Types.Types
 import Language.Haskell.Liquid.Types.RefType
 import Language.Haskell.Liquid.Types.Variance
 import Language.Haskell.Liquid.Types.PredType
+import Language.Haskell.Liquid.Types.Names (selfSymbol)
 
 -- import Language.Fixpoint.Types hiding (panic)
 import qualified Language.Fixpoint.Types as F
 import qualified Data.HashSet as S 
 
-import Language.Haskell.Liquid.GHC.TypeRep ()
+import Liquid.GHC.TypeRep ()
 
 -- | Horrible hack to support hardwired symbols like
 --      `head`, `tail`, `fst`, `snd`
@@ -50,10 +51,10 @@
 isWiredIn x = isWiredInLoc x  || isWiredInName (val x) || isWiredInShape x
 
 isWiredInLoc :: F.LocSymbol -> Bool
-isWiredInLoc x  = l == l' && l == F.safePos 1 && c == c' && c' == F.safePos 1
+isWiredInLoc sym  = ln == ln' && ln == F.safePos 1 && c == c' && c' == F.safePos 1
   where
-    (l , c)  = spe (loc x)
-    (l', c') = spe (locE x)
+    (ln , c)  = spe (loc sym)
+    (ln', c') = spe (locE sym)
     spe l    = (x, y) where (_, x, y) = F.sourcePosElts l
 
 isWiredInName :: F.Symbol -> Bool
@@ -63,7 +64,7 @@
 wiredInNames = S.fromList [ "head", "tail", "fst", "snd", "len"]
 
 isWiredInShape :: F.LocSymbol -> Bool
-isWiredInShape x = any (`F.isPrefixOfSym` (val x)) [F.anfPrefix, F.tempPrefix, dcPrefix]
+isWiredInShape x = any (`F.isPrefixOfSym` val x) [F.anfPrefix, F.tempPrefix, dcPrefix]
   -- where s        = val x
         -- dcPrefix = "lqdc"
 
@@ -71,8 +72,8 @@
 dcPrefix = "lqdc"
 
 wiredSortedSyms :: [(F.Symbol, F.Sort)]
-wiredSortedSyms = [(pappSym n, pappSort n) | n <- [1..pappArity]]
-
+wiredSortedSyms = (selfSymbol,selfSort):[(pappSym n, pappSort n) | n <- [1..pappArity]]
+  where selfSort = F.FAbs 1 (F.FVar 0)
 --------------------------------------------------------------------------------
 -- | LH Primitive TyCons -------------------------------------------------------
 --------------------------------------------------------------------------------
@@ -126,9 +127,9 @@
     lt = rApp c [] [] mempty
     
 listTyDataCons :: ([TyConP] , [DataConP])
-listTyDataCons   = ( [(TyConP l0 c [RTV tyv] [p] [Covariant] [Covariant] (Just fsize))]
-                   , [(DataConP l0 Ghc.nilDataCon  [RTV tyv] [p] [] []    lt False wiredInName l0)
-                     ,(DataConP l0 Ghc.consDataCon [RTV tyv] [p] [] cargs lt False wiredInName l0)])
+listTyDataCons   = ( [TyConP l0 c [RTV tyv] [p] [Covariant] [Covariant] (Just fsize)]
+                   , [DataConP l0 Ghc.nilDataCon  [RTV tyv] [p] [] []    lt False wiredInName l0
+                   ,  DataConP l0 Ghc.consDataCon [RTV tyv] [p] [] cargs lt False wiredInName l0])
     where
       l0         = F.dummyPos "LH.Bare.listTyDataCons"
       c          = Ghc.listTyCon
@@ -149,8 +150,8 @@
 wiredInName = "WiredIn"
 
 tupleTyDataCons :: Int -> ([TyConP] , [DataConP])
-tupleTyDataCons n = ( [(TyConP   l0 c  (RTV <$> tyvs) ps tyvarinfo pdvarinfo Nothing)]
-                    , [(DataConP l0 dc (RTV <$> tyvs) ps []  cargs  lt False wiredInName l0)])
+tupleTyDataCons n = ( [TyConP   l0 c  (RTV <$> tyvs) ps tyvarinfo pdvarinfo Nothing]
+                    , [DataConP l0 dc (RTV <$> tyvs) ps []  cargs  lt False wiredInName l0])
   where
     tyvarinfo     = replicate n     Covariant
     pdvarinfo     = replicate (n-1) Covariant
diff --git a/src/LiquidHaskell.hs b/src/LiquidHaskell.hs
--- a/src/LiquidHaskell.hs
+++ b/src/LiquidHaskell.hs
@@ -1,20 +1,9 @@
-{-# LANGUAGE CPP #-}
-
 module LiquidHaskell (
     -- * LiquidHaskell Specification QuasiQuoter
     lq
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
     -- * LiquidHaskell as a compiler plugin
   , plugin
-#endif
-#endif
   ) where
 
 import Language.Haskell.Liquid.UX.QuasiQuoter
-
-#ifdef MIN_VERSION_GLASGOW_HASKELL
-#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0)
 import Language.Haskell.Liquid.GHC.Plugin (plugin)
-#endif
-#endif
diff --git a/tests/Parser.hs b/tests/Parser.hs
--- a/tests/Parser.hs
+++ b/tests/Parser.hs
@@ -364,8 +364,15 @@
       , "  {a<q> <: a<r>} "
       , "  Ord a => OList (a<p>) -> OList (a<q>) -> OList a<r> "])
         @?==
-          "assume (++) :: forall <p :: a -> Bool, q :: a -> Bool, r :: a -> Bool> .\n               (Ord a) =>\n               {x :: {VV : a<p> | true} |- {VV : a<q> | true} <: {v : a | x <= v}} =>\n               {|- {VV : a<p> | true} <: {VV : a<r> | true}} =>\n               {|- {VV : a<q> | true} <: {VV : a<r> | true}} =>\n               lq_tmp$db##13:(OList {VV : a<p> | true}) -> lq_tmp$db##15:(OList {VV : a<q> | true}) -> (OList {VV : a<r> | true})"
-
+          -- "assume (++) :: forall <p :: a -> Bool, q :: a -> Bool, r :: a -> Bool> .\n               (Ord a) =>\n               {x :: {VV : a<p> | true} |- {VV : a<q> | true} <: {v : a | x <= v}} =>\n               {|- {VV : a<p> | true} <: {VV : a<r> | true}} =>\n               {|- {VV : a<q> | true} <: {VV : a<r> | true}} =>\n               lq_tmp$db##13:(OList {VV : a<p> | true}) -> lq_tmp$db##15:(OList {VV : a<q> | true}) -> (OList {VV : a<r> | true})"
+         (unlines 
+           [ "assume (++) :: forall <p##1##23 :: a -> Bool, q##1##23 :: a -> Bool, r##1##23 :: a -> Bool>."
+           , "               (Ord a) =>"
+           , "               {x :: {VV : a<p##1##23> | true} |- {VV : a<q##1##23> | true} <: {v : a | x <= v}} =>"
+           , "               {|- {VV : a<p##1##23> | true} <: {VV : a<r##1##23> | true}} =>"
+           , "               {|- {VV : a<q##1##23> | true} <: {VV : a<r##1##23> | true}} =>"
+           , "               lq_tmp$db##13:(OList {VV : a<p##1##23> | true}) -> lq_tmp$db##15:(OList {VV : a<q##1##23> | true}) -> (OList {VV : a<r##1##23> | true})"
+         ])
     , testCase "type spec 9" $
        parseSingleSpec (unlines $
           [ "data AstF f <ix :: AstIndex -> Bool>"
@@ -393,7 +400,13 @@
           , "       {x::Int<q> |- {v:Int| v = x + 1} <: Int<q>}"
           , "       (Int<p> -> ()) -> x:Int<q> -> ()" ])
           @?==
-            "app :: forall <p :: Int -> Bool, q :: Int -> Bool> .\n       {|- (Int <{VV : _<q> | true}>) <: (Int <{VV : _<p> | true}>)} =>\n       {x :: (Int <{VV : _<q> | true}>) |- {v : Int | v == x + 1} <: (Int <{VV : _<q> | true}>)} =>\n       lq_tmp$db##8:(lq_tmp$db##9:(Int <{VV : _<p> | true}>) -> ()) -> x:(Int <{VV : _<q> | true}>) -> ()"
+ --            "app :: forall <p :: Int -> Bool, q :: Int -> Bool> .\n       {|- (Int <{VV : _<q> | true}>) <: (Int <{VV : _<p> | true}>)} =>\n       {x :: (Int <{VV : _<q> | true}>) |- {v : Int | v == x + 1} <: (Int <{VV : _<q> | true}>)} =>\n       lq_tmp$db##8:(lq_tmp$db##9:(Int <{VV : _<p> | true}>) -> ()) -> x:(Int <{VV : _<q> | true}>) -> ()"
+            (unlines 
+              [ "app :: forall <p##1##15 :: Int -> Bool, q##1##15 :: Int -> Bool>."
+              , "       {|- (Int <{VV : _<q##1##15> | true}>) <: (Int <{VV : _<p##1##15> | true}>)} =>"
+              , "       {x :: (Int <{VV : _<q##1##15> | true}>) |- {v : Int | v == x + 1} <: (Int <{VV : _<q##1##15> | true}>)} =>"
+              , "       lq_tmp$db##8:(lq_tmp$db##9:(Int <{VV : _<p##1##15> | true}>) -> ()) -> x:(Int <{VV : _<q##1##15> | true}>) -> ()"
+            ])
 
     , testCase "type spec 12" $
        parseSingleSpec (unlines $
@@ -402,8 +415,14 @@
           , "         {x::a<p> |- {v:a | x <= v} <: a<q>}"
           , "         xs:[{v:a<p> | 0 <= v}] -> {v:a<q> | len xs >= 0 && 0 <= v } "])
           @?==
-            "ssum :: forall <p :: a -> Bool, q :: a -> Bool> .\n        {|- {v : a | v == 0} <: {VV : a<q> | true}} =>\n        {x :: {VV : a<p> | true} |- {v : a | x <= v} <: {VV : a<q> | true}} =>\n        xs:[{v : a<p> | 0 <= v}] -> {v : a<q> | len xs >= 0\n                                                && 0 <= v}"
-
+            -- "ssum :: forall <p :: a -> Bool, q :: a -> Bool> .\n        {|- {v : a | v == 0} <: {VV : a<q> | true}} =>\n        {x :: {VV : a<p> | true} |- {v : a | x <= v} <: {VV : a<q> | true}} =>\n        xs:[{v : a<p> | 0 <= v}] -> {v : a<q> | len xs >= 0\n                                                && 0 <= v}"
+           (unlines 
+              [ "ssum :: forall <p##1##16 :: a -> Bool, q##1##16 :: a -> Bool>."
+              , "        {|- {v : a | v == 0} <: {VV : a<q##1##16> | true}} =>"
+              , "        {x :: {VV : a<p##1##16> | true} |- {v : a | x <= v} <: {VV : a<q##1##16> | true}} =>"
+              , "        xs:[{v : a<p##1##16> | 0 <= v}] -> {v : a<q##1##16> | len xs >= 0"
+              , "                                                              && 0 <= v}"
+           ])
     , testCase "type spec 13" $
        -- removing duplicate conjuncts also affects the order in which the
        -- surviving conjuncts are returned
@@ -450,8 +469,11 @@
 
     , testCase "type spec 21" $
        parseSingleSpec "newRGRef :: forall <p :: a -> Bool, r :: a -> a -> Bool >.\n   e:a<p> ->\n  e2:a<r e> ->\n  f:(x:a<p> -> y:a<r x> -> {v:a<p> | (v = y)}) ->\n IO (RGRef <p, r> a)" @?==
-            "newRGRef :: forall <p :: a -> Bool, r :: a a -> Bool> .\n            e:{VV : a<p> | true} -> e2:{VV : a<r e> | true} -> f:(x:{VV : a<p> | true} -> y:{VV : a<r x> | true} -> {v : a<p> | v == y}) -> (IO (RGRef <{VV : _<p> | true}, {VV : _<r> | true}> a))"
-
+            -- "newRGRef :: forall <p :: a -> Bool, r :: a a -> Bool> .\n            e:{VV : a<p> | true} -> e2:{VV : a<r e> | true} -> f:(x:{VV : a<p> | true} -> y:{VV : a<r x> | true} -> {v : a<p> | v == y}) -> (IO (RGRef <{VV : _<p> | true}, {VV : _<r> | true}> a))"
+            (unlines [ "newRGRef :: forall <p##1##20 :: a -> Bool, r##1##20 :: a a -> Bool>."
+                     , "            e:{VV : a<p##1##20> | true} -> e2:{VV : a<r##1##20 e> | true} -> f:(x:{VV : a<p##1##20> | true} -> y:{VV : a<r##1##20 x> | true} -> {v : a<p##1##20> | v == y}) -> (IO (RGRef <{VV : _<p##1##20> | true}, {VV : _<r##1##20> | true}> a))"
+                     ]
+            )
     , testCase "type spec 21" $
        parseSingleSpec "cycle        :: {v: [a] | len(v) > 0 } -> [a]" @?==
             "cycle :: v:{v : [a] | len v > 0} -> [a]"
diff --git a/tests/errors/AmbiguousInline.hs b/tests/errors/AmbiguousInline.hs
--- a/tests/errors/AmbiguousInline.hs
+++ b/tests/errors/AmbiguousInline.hs
@@ -6,7 +6,7 @@
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 
-module MatchIdxs where
+module AmbiguousInline where
 
 import qualified Data.ByteString as BS
 -- RJ import qualified Data.ByteString.Search as BS
diff --git a/tests/errors/AmbiguousReflect.hs b/tests/errors/AmbiguousReflect.hs
--- a/tests/errors/AmbiguousReflect.hs
+++ b/tests/errors/AmbiguousReflect.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--reflection"  @-}
 
-module StringIndexing where
+module AmbiguousReflect where
 
 -- ISSUE: Uncomment the below to make this test pass
 --
diff --git a/tests/errors/BadAliasApp.hs b/tests/errors/BadAliasApp.hs
--- a/tests/errors/BadAliasApp.hs
+++ b/tests/errors/BadAliasApp.hs
@@ -1,4 +1,5 @@
-module BadExprArg where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `ListN`" @-}
+module BadAliasApp where
 
 {-@ type ListN a N = {v:[a] | len v = N} @-}
 
diff --git a/tests/errors/BadAnnotation.hs b/tests/errors/BadAnnotation.hs
--- a/tests/errors/BadAnnotation.hs
+++ b/tests/errors/BadAnnotation.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Malformed annotation" @-}
+module BadAnnotation where
 
 {-@ incr :: x:Int -> {v:Int | x < v } -}
 incr :: Int -> Int
diff --git a/tests/errors/BadAnnotation1.hs b/tests/errors/BadAnnotation1.hs
--- a/tests/errors/BadAnnotation1.hs
+++ b/tests/errors/BadAnnotation1.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Malformed annotation" @-}
+module BadAnnotation1 where
 
 {-@ incr :: x:Int 
          -> {v:Int | x < v } 
diff --git a/tests/errors/BadData0.hs b/tests/errors/BadData0.hs
--- a/tests/errors/BadData0.hs
+++ b/tests/errors/BadData0.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Unknown type constructor `Zoog`" @-}
 module BadData0 where
 
 data Zog = Z Int
diff --git a/tests/errors/BadData1.hs b/tests/errors/BadData1.hs
--- a/tests/errors/BadData1.hs
+++ b/tests/errors/BadData1.hs
@@ -1,7 +1,10 @@
+{-@ LIQUID "--expect-error-containing=Data constructors in refinement do not match original datatype for `EntityField`" @-}
 {-@ LIQUID "--no-adt"         @-}
 {-@ LIQUID "--exact-data-con" @-}
 
 {-# LANGUAGE ExistentialQuantification, KindSignatures, TypeFamilies, GADTs #-}
+
+module BadData1 where
 
 class PersistEntity record where
     data EntityField record :: * -> *
diff --git a/tests/errors/BadData2.hs b/tests/errors/BadData2.hs
--- a/tests/errors/BadData2.hs
+++ b/tests/errors/BadData2.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Data constructors in refinement do not match original datatype for `Hog`" @-}
 {-@ LIQUID "--exact-data-cons" @-}
 
-module Boo where
+module BadData2 where
 
 -- The reason this fails is because the constructor we use in the
 -- refinement for Hog is in fact a constructor of T.
diff --git a/tests/errors/BadDataCon2.hs b/tests/errors/BadDataCon2.hs
--- a/tests/errors/BadDataCon2.hs
+++ b/tests/errors/BadDataCon2.hs
@@ -1,4 +1,5 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=GHC and Liquid specifications have different numbers of fields for `BadDataCon2.Cuthb`" @-}
+module BadDataCon2 where
 
 {-@ data T = Cuthb { fldX :: Int, fldY :: Int } @-}
 
diff --git a/tests/errors/BadDataConType.hs b/tests/errors/BadDataConType.hs
--- a/tests/errors/BadDataConType.hs
+++ b/tests/errors/BadDataConType.hs
@@ -1,4 +1,6 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `BadDataConType.fldY`" @-}
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `BadDataConType.fldY`" @-}
+module BadDataConType where
 
 {-@ data T = C { fldX :: Int, fldY :: Bool } @-}
 
diff --git a/tests/errors/BadDataConType1.hs b/tests/errors/BadDataConType1.hs
--- a/tests/errors/BadDataConType1.hs
+++ b/tests/errors/BadDataConType1.hs
@@ -1,4 +1,5 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `BadDataConType1.C`" @-}
+module BadDataConType1 where
 
 {-@ data T = C { fldX :: Int, fldY :: String } @-}
 
diff --git a/tests/errors/BadDataConType2.hs b/tests/errors/BadDataConType2.hs
--- a/tests/errors/BadDataConType2.hs
+++ b/tests/errors/BadDataConType2.hs
@@ -1,4 +1,5 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=different numbers of fields for `BadDataConType2.C`" @-}
+module BadDataConType2 where
 
 {-@ data T = C { fldX :: Int } @-}
 
diff --git a/tests/errors/BadDataDeclTyVars.hs b/tests/errors/BadDataDeclTyVars.hs
--- a/tests/errors/BadDataDeclTyVars.hs
+++ b/tests/errors/BadDataDeclTyVars.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Mismatch in number of type variables for `L`" @-}
 -- | With ADTs, the below fails with a nasty 'elaborate' error, when
 --   the actual problem is a malformed refined data-declaration where
 --   the type variable 'a' has been left out.
@@ -7,7 +8,7 @@
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple"        @-} 
 
-module MonoidList where
+module BadDataDeclTyVars where
 
 {-@ data L = Emp | Cons {x::a, xs:: (L a)} @-}
 --       ^ whoops, missing a tyvar!
diff --git a/tests/errors/BadGADT.hs b/tests/errors/BadGADT.hs
--- a/tests/errors/BadGADT.hs
+++ b/tests/errors/BadGADT.hs
@@ -1,6 +1,9 @@
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `BadGADT.Nil2`" @-}
 {-# LANGUAGE GADTs #-}
 
 {-@ LIQUID "--no-termination" @-}
+
+module BadGADT where
 
 {-@ data List a where
        Nil  :: List a
diff --git a/tests/errors/BadPragma0.hs b/tests/errors/BadPragma0.hs
--- a/tests/errors/BadPragma0.hs
+++ b/tests/errors/BadPragma0.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Illegal pragma" @-}
 {-@ LIQUID "--idirs=.." @-}
 
-module Bad where 
+module BadPragma0 where
 
 i :: Int
 i = 1
diff --git a/tests/errors/BadPragma1.hs b/tests/errors/BadPragma1.hs
--- a/tests/errors/BadPragma1.hs
+++ b/tests/errors/BadPragma1.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Illegal pragma" @-}
 {-@ LIQUID "--c-files=./wow.c" @-}
 
-module Bad where 
+module BadPragma1 where
 
 i :: Int
 i = 1
diff --git a/tests/errors/BadPragma2.hs b/tests/errors/BadPragma2.hs
--- a/tests/errors/BadPragma2.hs
+++ b/tests/errors/BadPragma2.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Illegal pragma" @-}
 {-@ LIQUID "--ghc-option=-O0" @-}
 
-module Bad where 
+module BadPragma2 where
 
 i :: Int
 i = 1
diff --git a/tests/errors/BadPredApp.hs b/tests/errors/BadPredApp.hs
--- a/tests/errors/BadPredApp.hs
+++ b/tests/errors/BadPredApp.hs
@@ -1,4 +1,5 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=Malformed predicate application" @-}
+module BadPredApp where
 
 {-@ data X <q :: Int -> Int -> Bool> = X (x0 :: Int) (x1 :: Int<q x0>) @-}  
 data X = X Int Int  
diff --git a/tests/errors/BadQualifier.hs b/tests/errors/BadQualifier.hs
--- a/tests/errors/BadQualifier.hs
+++ b/tests/errors/BadQualifier.hs
@@ -1,4 +1,4 @@
-module RG where
+module BadQualifier where
 data RGRef a
 {-@ measure tv :: RGRef a -> a @-}
 {-@ qualif TERMINALVALUE(r:RGRef a): (tv r) @-}
diff --git a/tests/errors/BadSig0.hs b/tests/errors/BadSig0.hs
--- a/tests/errors/BadSig0.hs
+++ b/tests/errors/BadSig0.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `BadSig0.foo`" @-}
+module BadSig0 where
 
 {-@ measure prop :: a -> b @-}
 {-@ type Prop E = {v:_ | pro v = E} @-}
diff --git a/tests/errors/BadSig1.hs b/tests/errors/BadSig1.hs
--- a/tests/errors/BadSig1.hs
+++ b/tests/errors/BadSig1.hs
@@ -1,8 +1,9 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `BadSig1.EZ`" @-}
 {-# LANGUAGE GADTs #-}
 
 {-@ LIQUID "--exact-data-con" @-}
 
-module Ev where
+module BadSig1 where
 
 data Peano where
   Z :: Peano
diff --git a/tests/errors/BadSyn1.hs b/tests/errors/BadSyn1.hs
--- a/tests/errors/BadSyn1.hs
+++ b/tests/errors/BadSyn1.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `Fooz`" @-}
+module BadSyn1 where
 
 type Foo = Int
 
diff --git a/tests/errors/BadSyn2.hs b/tests/errors/BadSyn2.hs
--- a/tests/errors/BadSyn2.hs
+++ b/tests/errors/BadSyn2.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `BadSyn2.Foo`" @-}
+module BadSyn2 where
 
 type Foo = Int
 
diff --git a/tests/errors/BadSyn3.hs b/tests/errors/BadSyn3.hs
--- a/tests/errors/BadSyn3.hs
+++ b/tests/errors/BadSyn3.hs
@@ -1,4 +1,5 @@
-module Zoo where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `BadSyn3.Foo`" @-}
+module BadSyn3 where
 
 type Foo = Int
 
diff --git a/tests/errors/BadSyn4.hs b/tests/errors/BadSyn4.hs
--- a/tests/errors/BadSyn4.hs
+++ b/tests/errors/BadSyn4.hs
@@ -1,4 +1,5 @@
-module Foo where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `BadSyn4.Point`" @-}
+module BadSyn4 where
 
 type List a = [a]
 type Point  = List Double
diff --git a/tests/errors/CyclicExprAlias0.hs b/tests/errors/CyclicExprAlias0.hs
--- a/tests/errors/CyclicExprAlias0.hs
+++ b/tests/errors/CyclicExprAlias0.hs
@@ -1,4 +1,5 @@
-module Test0 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition" @-}
+module CyclicExprAlias0 () where
 
 {-@ expression CyclicA1 Q = CyclicA1 Q @-}
 
diff --git a/tests/errors/CyclicExprAlias1.hs b/tests/errors/CyclicExprAlias1.hs
--- a/tests/errors/CyclicExprAlias1.hs
+++ b/tests/errors/CyclicExprAlias1.hs
@@ -1,4 +1,5 @@
-module Test2 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition" @-}
+module CyclicExprAlias1 () where
 
 {-@ expression CyclicB1 Q = CyclicB2 Q @-}
 {-@ expression CyclicB2 Q = CyclicB1 Q @-}
diff --git a/tests/errors/CyclicExprAlias2.hs b/tests/errors/CyclicExprAlias2.hs
--- a/tests/errors/CyclicExprAlias2.hs
+++ b/tests/errors/CyclicExprAlias2.hs
@@ -1,4 +1,5 @@
-module Test3 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition" @-}
+module CyclicExprAlias2 () where
 
 {-@ expression CyclicC1 Q = (CyclicC2 Q) && (CyclicC3 Q) @-}
 {-@ expression CyclicC2 Q = CyclicC1 Q @-}
diff --git a/tests/errors/CyclicExprAlias3.hs b/tests/errors/CyclicExprAlias3.hs
--- a/tests/errors/CyclicExprAlias3.hs
+++ b/tests/errors/CyclicExprAlias3.hs
@@ -1,4 +1,5 @@
-module Test3 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition" @-}
+module CyclicExprAlias3 () where
 
 {-@ expression CyclicD1 Q = CyclicD2 Q @-}
 {-@ expression CyclicD2 Q = CyclicD3 Q @-}
diff --git a/tests/errors/CyclicPredAlias0.hs b/tests/errors/CyclicPredAlias0.hs
--- a/tests/errors/CyclicPredAlias0.hs
+++ b/tests/errors/CyclicPredAlias0.hs
@@ -1,4 +1,5 @@
-module Test0 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicA1`" @-}
+module CyclicPredAlias0 () where
 
 {-@ predicate CyclicA1 Q = CyclicA1 Q @-}
 
diff --git a/tests/errors/CyclicPredAlias1.hs b/tests/errors/CyclicPredAlias1.hs
--- a/tests/errors/CyclicPredAlias1.hs
+++ b/tests/errors/CyclicPredAlias1.hs
@@ -1,4 +1,5 @@
-module Test1 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicB1`" @-}
+module CyclicPredAlias1 () where
 
 {-@ predicate CyclicB1 Q = CyclicB2 Q @-}
 {-@ predicate CyclicB2 Q = CyclicB1 Q @-}
diff --git a/tests/errors/CyclicPredAlias2.hs b/tests/errors/CyclicPredAlias2.hs
--- a/tests/errors/CyclicPredAlias2.hs
+++ b/tests/errors/CyclicPredAlias2.hs
@@ -1,4 +1,6 @@
-module Test2 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicC1`" @-}
+
+module CyclicPredAlias2 () where
 
 {-@ predicate CyclicC1 Q = CyclicC2 Q && CyclicC3 Q @-}
 {-@ predicate CyclicC2 Q = CyclicC1 Q @-}
diff --git a/tests/errors/CyclicPredAlias3.hs b/tests/errors/CyclicPredAlias3.hs
--- a/tests/errors/CyclicPredAlias3.hs
+++ b/tests/errors/CyclicPredAlias3.hs
@@ -1,4 +1,5 @@
-module Test3 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicD1`" @-}
+module CyclicPredAlias3 () where
 
 {-@ predicate CyclicD1 Q = CyclicD2 Q @-}
 {-@ predicate CyclicD2 Q = CyclicD3 Q @-}
diff --git a/tests/errors/CyclicTypeAlias0.hs b/tests/errors/CyclicTypeAlias0.hs
--- a/tests/errors/CyclicTypeAlias0.hs
+++ b/tests/errors/CyclicTypeAlias0.hs
@@ -1,4 +1,5 @@
-module Test0 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicA1`" @-}
+module CyclicTypeAlias0 () where
 
 {-@ type CyclicA1 = CyclicA2 @-}
 {-@ type CyclicA2 = CyclicA1 @-}
diff --git a/tests/errors/CyclicTypeAlias1.hs b/tests/errors/CyclicTypeAlias1.hs
--- a/tests/errors/CyclicTypeAlias1.hs
+++ b/tests/errors/CyclicTypeAlias1.hs
@@ -1,4 +1,5 @@
-module Test1 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicB1`" @-}
+module CyclicTypeAlias1 () where
 
 {-@ type CyclicB1 = CyclicB2 @-}
 {-@ type CyclicB2 = CyclicB3 @-}
diff --git a/tests/errors/CyclicTypeAlias2.hs b/tests/errors/CyclicTypeAlias2.hs
--- a/tests/errors/CyclicTypeAlias2.hs
+++ b/tests/errors/CyclicTypeAlias2.hs
@@ -1,4 +1,5 @@
-module Test2 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicC`" @-}
+module CyclicTypeAlias2 () where
 
 {-@ type CyclicC = [CyclicC] @-}
 
diff --git a/tests/errors/CyclicTypeAlias3.hs b/tests/errors/CyclicTypeAlias3.hs
--- a/tests/errors/CyclicTypeAlias3.hs
+++ b/tests/errors/CyclicTypeAlias3.hs
@@ -1,4 +1,5 @@
-module Test3 () where
+{-@ LIQUID "--expect-error-containing=Cyclic type alias definition for `CyclicD2" @-}
+module CyclicTypeAlias3 () where
 
 {-@ type CyclicD1 = CyclicD2 @-}
 {-@ type CyclicD2 = CyclicD3 @-}
diff --git a/tests/errors/DupAlias.hs b/tests/errors/DupAlias.hs
--- a/tests/errors/DupAlias.hs
+++ b/tests/errors/DupAlias.hs
@@ -1,4 +1,6 @@
-module Goo () where
+{-@ LIQUID "--expect-error-containing=Multiple definitions of Type Alias `BoundedNat`" @-}
+{-@ LIQUID "--expect-error-containing=Multiple definitions of Pred Alias `Foo`" @-}
+module DupAlias () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/errors/DupData.hs b/tests/errors/DupData.hs
--- a/tests/errors/DupData.hs
+++ b/tests/errors/DupData.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `OVec`" @-}
 -- | See https://github.com/ucsd-progsys/liquidhaskell/issues/1175
 
-module BadVec where
+module DupData where
 
 data OVec a = ONil
             | (:>>) {oHd :: a, oTl :: OVec a}
diff --git a/tests/errors/DupFunSigs.hs b/tests/errors/DupFunSigs.hs
--- a/tests/errors/DupFunSigs.hs
+++ b/tests/errors/DupFunSigs.hs
@@ -1,4 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `DupFunSigs.fromWeekDayNum`" @-}
 -- See https://github.com/ucsd-progsys/liquidhaskell/issues/1137
+
+module DupFunSigs where
 
 import Data.List
 
diff --git a/tests/errors/DupMeasure.hs b/tests/errors/DupMeasure.hs
--- a/tests/errors/DupMeasure.hs
+++ b/tests/errors/DupMeasure.hs
@@ -1,4 +1,5 @@
-module DuplicateMeasures where 
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `lenA`" @-}
+module DupMeasure where
 
 
 {-@ measure lenA :: [a] -> Int 
diff --git a/tests/errors/ElabLocation.hs b/tests/errors/ElabLocation.hs
--- a/tests/errors/ElabLocation.hs
+++ b/tests/errors/ElabLocation.hs
@@ -1,13 +1,15 @@
--- | This file tests that LH correctly localizes the elaboration error 
+-- | This file tests that LH correctly localizes the elaboration error
 --   to the '10 / x' term (where we get a sort-error as the 'Ratio Int'
 --   is compared against '0' which appears in the refinement for '/'.)
---   You can fix this by `embed Ratio * as Int` 
+--   You can fix this by `embed Ratio * as Int`
 
+{-@ LIQUID "--expect-error-containing=ElabLocation.hs:15:14" @-}
+
 module ElabLocation where
 
-import Data.Ratio 
+import Data.Ratio
 
 foo :: Ratio Int -> Bool
-foo x = y == y 
-  where 
+foo x = y == y
+  where
     y = 10 / x
diff --git a/tests/errors/ElabLocation2.hs b/tests/errors/ElabLocation2.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/ElabLocation2.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--expect-error-containing=ElabLocation2.hs:18:54-66" @-}
+module ElabLocation2 where
+type Range = (Int,Int)
+
+{-@ measure start @-}
+start :: Range -> Int
+start (a,b) = a
+
+{-@ measure end @-}
+end :: Range -> Int
+end (a,b) = b
+
+{-@ using (Range) as {r:Range | start r <= end r} @-}
+
+-- seemed to work earlier, now fails
+{-@ intsToRanges :: Int -> Int -> Int -> Int -> Maybe (Range,Range) @-}
+intsToRanges :: Int -> Int -> Int -> Int -> Maybe (Range,Range)
+intsToRanges a b c d = if a <= b && c <= d then Just ((a,b),(c,d)) else Nothing
diff --git a/tests/errors/ElabLocation3.hs b/tests/errors/ElabLocation3.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/ElabLocation3.hs
@@ -0,0 +1,210 @@
+module ElabLocation3 where
+{-@ LIQUID "--expect-error-containing=ElabLocation3.hs:174:1-5" @-}
+{-@ LIQUID "--reflection" @-}
+
+import Language.Haskell.Liquid.ProofCombinators
+import Prelude hiding (id)
+
+{-@ type Pos = {v:Int | 0 < v} @-}
+
+{-@ incr :: Pos -> Pos @-}
+incr :: Int -> Int
+incr x = x + 2
+
+
+
+{-@
+data Monkey =
+  M { number :: Nat,
+      items :: [Int],
+      operation :: Int -> Int,
+      testMod :: {n:Int | n > 0 },
+      ifTrue :: Nat,
+      ifFalse :: Nat,
+      count :: Nat
+    }
+@-}
+data Monkey =
+  M { number :: Int,
+      items :: [Int],
+      operation :: Int -> Int,
+      testMod :: Int,
+      ifTrue :: Int,
+      ifFalse :: Int,
+      count :: Int }
+
+{-@ myCount :: _ -> Nat @-}
+myCount :: Monkey -> Int 
+myCount M { count = k}  = k 
+
+
+showMonkey :: Monkey -> String
+showMonkey (M n i o m ifT ifF count) =
+  "#" ++ (show n) ++ " items " ++ (show i) ++ " examined " ++ (show count) ++ "\n"
+
+instance Show Monkey where show = showMonkey
+
+{-@ type MonkeyIR X = {m:Monkey | number m < X && ifTrue m < X && ifFalse m < X } @-}
+
+-- fst = item
+-- snd = destination
+{-@ type MonkeyItem X = (Int, {n:Nat | n < X}) @-}
+
+{-@ turn :: x:Int -> {worry:Int | worry /= 0 } -> {modulus:Int | modulus /= 0} -> m:MonkeyIR x -> {d:[MonkeyItem x] | len d = len (items m)} @-}
+turn :: Int -> Int -> Int -> Monkey -> [(Int, Int)]
+turn _ worry modulus (M _ oldItems op m dTrue dFalse _) =
+  map toDestination oldItems where
+  toDestination i = let newWorry = (( op i ) `div` worry) `mod` modulus in
+    (newWorry, if newWorry `mod` m == 0 then dTrue else dFalse)
+
+-- What I would like to do:
+-- measure countOfItems :: [Monkey] -> Int
+-- countOfItems [] = 0
+-- countOfItems (m:ms) = len (items m) + countOfItems ms
+--
+--      -> {m2:[MonkeyIR x] | len m2 = len m && countOfItems m2 = countOfItems m + len mi} 
+--
+-- But this measure gets applied to all lists, which doesn't work
+
+{-@ data MonkeyList = Empty | MCons { headMonkey :: MonkeyIR 8, barrel :: MonkeyList } @-}
+data MonkeyList =
+  Empty |
+  MCons Monkey MonkeyList
+
+{-@ measure mLen :: MonkeyList -> Int
+      mLen Empty = 0
+      mLen (MCons m ms) = 1 + mLen  ms 
+  @-}
+
+{-@ measure countOfItems :: MonkeyList -> Int
+      countOfItems Empty = 0
+      countOfItems (MCons m ms) = len (items m) + countOfItems ms @-}
+
+{-
+{-@ distribute2 :: m:MonkeyList -> {mi:[MonkeyItem 8] | len mi <= mLen m}
+     -> {m2:MonkeyList | mLen m2 = mLen m && countOfItems m2 = countOfItems m + len mi} @-}
+distribute2 :: MonkeyList -> [(Int,Int)] -> MonkeyList 
+distribute2 Empty [] = Empty
+distribute2 Empty _ = error "Shouldn't happen"
+distribute2 (MCons m ms) destinations =
+  MCons (m {items = (items m) ++ newItems}) (distribute2 ms (filter (notP toMe) destinations)) where
+  newItems = map fst (filter toMe destinations)
+  toMe (_,d) = d == number m
+-}
+
+{-@ distribute :: x:Int -> m:[MonkeyIR x] -> mi:[MonkeyItem x]
+     -> {m2:[MonkeyIR x] | len m2 = len m} @-}
+distribute :: Int -> [Monkey] -> [(Int,Int)] -> [Monkey]
+distribute _ [] _ = []
+distribute x (m:ms) destinations =
+  (m {items = (items m) ++ newItems}):(distribute x ms destinations) where
+  newItems = map fst (filter toMe destinations)
+  toMe (_,d) = d == number m
+
+-- Monkey N's turn in the round
+{-@ roundN :: x:Int -> 
+              {worry:Int | worry /= 0 } -> 
+	      {modulus:Int | modulus /= 0} -> 
+	      {before:[MonkeyIR x] | len before = x} -> 
+	      {n:Nat | n < x } -> 
+	      {after:[m:MonkeyIR x] | len after = x} @-}
+roundN :: Int -> Int -> Int -> [Monkey] -> Int -> [Monkey]
+roundN x worry modulus monkeys n =
+  let m = (monkeys !! n)
+      destinations = turn x worry modulus m
+      newCount = (myCount m) + length (items m)
+      afterRemoval = (take n monkeys) ++ [(m {items = [], count = newCount} )] ++ (drop (n+1) monkeys) in
+    distribute x afterRemoval destinations
+
+-- One round of all monkeys
+-- Complicated by the need to prove termination.
+{-@ round :: x:Int -> {worry:Int | worry /= 0} -> {modulus:Int | modulus /= 0 } -> 
+             {before:[MonkeyIR x] | len before = x} -> 
+	     {after:[MonkeyIR x] | len after = x} @-}
+round :: Int -> Int -> Int -> [Monkey] -> [Monkey]
+round x worry modulus monkeys = go 0 monkeys where
+  {-@ go :: {n:Int | n >= 0 && n <= x} -> {m:[MonkeyIR x] | len m = x} -> {m2:[MonkeyIR x] | len m2 = x} / [ x - n ] @-}
+  go n ms = if n == x then ms
+    else go (n+1) (roundN x worry modulus ms n)
+
+
+{-@ m0 :: MonkeyIR 4 @-}
+m0 = M { number=0, items=[79,98], operation=(\o -> o * 19), testMod=23, ifTrue=2, ifFalse=3, count=0 }
+{-@ m1 :: MonkeyIR 4 @-}
+m1 = M { number=1, items=[54,65,75,74], operation=(\o -> o + 6), testMod=19, ifTrue=2, ifFalse=0, count=0 }
+{-@ m2 :: MonkeyIR 4 @-}
+m2 = M { number=2, items=[79,60,97], operation=(\o -> o * o), testMod=13, ifTrue=1, ifFalse=3, count=0 }
+{-@ m3 :: MonkeyIR 4 @-}
+m3 = M { number=3, items=[74], operation=(\o -> o + 3), testMod=17, ifTrue=0, ifFalse=1, count=0 }
+       
+{-@ example :: {m:[MonkeyIR 4] | len m = 4} @-}
+example :: [Monkey]
+example = [ m0, m1, m2, m3 ]
+
+{-@ i0 :: MonkeyIR 8 @-}
+i0 = M { number=0, items=[59,74,65,86], operation=(\o -> o * 19), testMod=7, ifTrue=6, ifFalse=2, count=0 }
+{-@ i1 :: MonkeyIR 8 @-}
+i1 = M { number=1, items=[62,84,72,91,68,78,51], operation=(\o -> o + 1), testMod=2, ifTrue=2, ifFalse=0, count=0 }
+{-@ i2 :: MonkeyIR 8 @-}
+i2 = M { number=2, items=[78,84,96], operation=(\o -> o + 8), testMod=19, ifTrue=6, ifFalse=5, count=0 }
+{-@ i3 :: MonkeyIR 8 @-}
+i3 = M { number=3, items=[97,86], operation=(\o -> o * o), testMod=3, ifTrue=1, ifFalse=0, count=0 }
+{-@ i4 :: MonkeyIR 8 @-}
+i4 = M { number=4, items=[50], operation=(\o -> o + 6), testMod=13, ifTrue=3, ifFalse=1, count=0 }
+{-@ i5 :: MonkeyIR 8 @-}
+i5 = M { number=5, items=[73,65,69,65,51], operation=(\o -> o * 17), testMod=11, ifTrue=4, ifFalse=7, count=0 }
+{-@ i6 :: MonkeyIR 8 @-}
+i6 = M { number=6, items=[69, 82, 97, 93, 82, 84, 58, 63], operation=(\o -> o + 5), testMod=5, ifTrue=5, ifFalse=7, count=0 }
+{-@ i7 :: MonkeyIR 8 @-}
+i7 = M { number=7, items=[81, 78, 82, 76, 79, 80], operation=(\o -> o + 3), testMod=17, ifTrue=3, ifFalse=4, count=0 }
+       
+{-@ input :: {m:[MonkeyIR 8] | len m = 8} @-}
+input :: [Monkey]
+input = [ i0, i1, i2, i3, i4, i5, i6, i7 ]
+
+{-@ assume iterate :: (a -> a) -> a -> {l:[a] | len l >= 1000000 } @-}
+
+computeModulus :: [Monkey] -> Int
+computeModulus ms = foldl1 (*) (map testMod ms)
+
+
+id z = z
+
+part1 :: () -> IO ()
+part1 _ = do
+  putStrLn "Part 1"
+  let m1 = computeModulus example in do
+    putStrLn $ "Working mod " ++ show m1
+    let allRounds = iterate {- (Main.round 4 3 m1) -} id example in
+      print $ allRounds !! 20
+    
+  let m2 = computeModulus input in do
+    putStrLn $ "Working mod " ++ show m2    
+    let allRounds2 = iterate {- (Main.round 8 3 m2) -} id input in
+      print $ allRounds2 !! 20
+
+part2 :: () -> IO ()
+part2 _ = do
+  putStrLn "Part 2"
+  let m1 = computeModulus example in do
+    putStrLn $ "Working mod " ++ show m1
+    let allRounds = iterate {- (Main.round 4 1 m1) -} id example in do
+      print $ allRounds !! 1000
+      print $ allRounds !! 2000
+      print $ allRounds !! 3000
+      print $ allRounds !! 4000
+      print $ allRounds !! 5000
+      print $ allRounds !! 6000
+      print $ allRounds !! 7000
+      print $ allRounds !! 8000
+      print $ allRounds !! 9000
+      print $ allRounds !! 10000
+      
+  let m2 = computeModulus input in do
+    putStrLn $ "Working mod " ++ show m2    
+    let allRounds2 = iterate {- (Main.round 8 1 m2) -} id input in
+      print $ allRounds2 !! 10000
+
+mymain :: IO ()
+mymain = part1 () >> part2 ()
+
diff --git a/tests/errors/EmptyData.hs b/tests/errors/EmptyData.hs
--- a/tests/errors/EmptyData.hs
+++ b/tests/errors/EmptyData.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=one or more fields in the data declaration for `A`" @-}
 -- | see: https://github.com/ucsd-progsys/liquidhaskell/issues/1169
 
-module Bar where
+module EmptyData where
 
 {-@ data A @-}
 data A = B
diff --git a/tests/errors/EmptySig.hs b/tests/errors/EmptySig.hs
deleted file mode 100644
--- a/tests/errors/EmptySig.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-
-module Blank where
-
-{-@  :: foo -> x:Int -> {v:Int | v > x} @-}
-foo :: Int -> Int 
-foo x = x - 1
diff --git a/tests/errors/ErrLocation.hs b/tests/errors/ErrLocation.hs
--- a/tests/errors/ErrLocation.hs
+++ b/tests/errors/ErrLocation.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=ErrLocation.hs:10:13" @-}
 
 module ErrLocation where
 
diff --git a/tests/errors/ErrLocation2.hs b/tests/errors/ErrLocation2.hs
--- a/tests/errors/ErrLocation2.hs
+++ b/tests/errors/ErrLocation2.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=ErrLocation2.hs:12:20" @-}
 
 module ErrLocation2 where
 
diff --git a/tests/errors/ExportMeasure0.hs b/tests/errors/ExportMeasure0.hs
--- a/tests/errors/ExportMeasure0.hs
+++ b/tests/errors/ExportMeasure0.hs
@@ -1,6 +1,6 @@
 -- FIX: module ExportMeasure (llen) where
     
-module ExportMeasure () where
+module ExportMeasure0 () where
 
 {-@ data LL [llen] @-}
 data LL a = N | C a (LL a)
diff --git a/tests/errors/ExportReflect0.hs b/tests/errors/ExportReflect0.hs
--- a/tests/errors/ExportReflect0.hs
+++ b/tests/errors/ExportReflect0.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--exactdc"     @-}
 {-@ LIQUID "--higherorder" @-}
 
-module Bug (foo, zogbert) where
+module ExportReflect0 (foo, zogbert) where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/errors/Fractional.hs b/tests/errors/Fractional.hs
--- a/tests/errors/Fractional.hs
+++ b/tests/errors/Fractional.hs
@@ -1,4 +1,6 @@
-module Crash where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `Fractional.f`" @-}
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `Fractional.g`" @-}
+module Fractional where
 
 {-@ f :: (Num a) => {v:a | v > 0.0} -> a @-}
 f :: (Num a) => a -> a
diff --git a/tests/errors/Frog.hs b/tests/errors/Frog.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/Frog.hs
@@ -0,0 +1,9 @@
+{-@ LIQUID "--expect-error-containing=Unbound symbol GHC.Err.undefined" @-}
+
+module Frog where
+
+{-@ LIQUID "--reflection" @-}
+
+{-@ reflect frog @-}
+frog :: () -> Bool
+frog () = undefined
diff --git a/tests/errors/HigherOrderBinder.hs b/tests/errors/HigherOrderBinder.hs
--- a/tests/errors/HigherOrderBinder.hs
+++ b/tests/errors/HigherOrderBinder.hs
@@ -1,3 +1,6 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `HigherOrderBinder.foo`" @-}
+module HigherOrderBinder where
+
 {-@ foo :: a: Int -> f: (Int -> Int) -> {v : Int | v = 123 + (f a) } @-}
 foo :: Int -> (Int -> Int) -> Int
 foo a f = f a
diff --git a/tests/errors/HintMismatch.hs b/tests/errors/HintMismatch.hs
--- a/tests/errors/HintMismatch.hs
+++ b/tests/errors/HintMismatch.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=HINT: Use the hole" @-}
 
 {-# LANGUAGE DataKinds #-}
 
diff --git a/tests/errors/HoleCrash1.hs b/tests/errors/HoleCrash1.hs
--- a/tests/errors/HoleCrash1.hs
+++ b/tests/errors/HoleCrash1.hs
@@ -1,4 +1,6 @@
-module ListDemo where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `HoleCrash1.t`" @-}
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `HoleCrash1.C`" @-}
+module HoleCrash1 where
 
 data Poo a = C { t :: Poo a }
 
diff --git a/tests/errors/HoleCrash2.hs b/tests/errors/HoleCrash2.hs
--- a/tests/errors/HoleCrash2.hs
+++ b/tests/errors/HoleCrash2.hs
@@ -1,4 +1,5 @@
-module ListDemo where
+{-@ LIQUID "--expect-error-containing=Malformed application of type alias `Geq`" @-}
+module HoleCrash2 where
 
 data Poo a = C { t :: Poo a }
 
diff --git a/tests/errors/HoleCrash3.hs b/tests/errors/HoleCrash3.hs
--- a/tests/errors/HoleCrash3.hs
+++ b/tests/errors/HoleCrash3.hs
@@ -1,4 +1,5 @@
-module ListDemo where
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `HoleCrash3.countUp`" @-}
+module HoleCrash3 where
 
 data List a = E | (:::) { h :: a, t :: List a }
 
diff --git a/tests/errors/Inconsistent0.hs b/tests/errors/Inconsistent0.hs
--- a/tests/errors/Inconsistent0.hs
+++ b/tests/errors/Inconsistent0.hs
@@ -1,8 +1,11 @@
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `Inconsistent0.id1`" @-}
 -- FAILING TEST: this test SHOULD FAIL BUT DOESN'T
 -- issue #519
 
+{-@ LIQUID "--no-positivity-check" @-}
+
 {-# LANGUAGE DeriveFunctor #-}
-module Ast where
+module Inconsistent0 where
 
 data AstIndex = IxExpr | IxType
 
diff --git a/tests/errors/Inconsistent1.hs b/tests/errors/Inconsistent1.hs
--- a/tests/errors/Inconsistent1.hs
+++ b/tests/errors/Inconsistent1.hs
@@ -1,4 +1,5 @@
-module Boo where
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `Inconsistent1.incr` (Checked)" @-}
+module Inconsistent1 where
 
 {-@ incr :: Int -> Bool @-}
 incr :: Int -> Int 
diff --git a/tests/errors/Inconsistent2.hs b/tests/errors/Inconsistent2.hs
--- a/tests/errors/Inconsistent2.hs
+++ b/tests/errors/Inconsistent2.hs
@@ -1,4 +1,5 @@
-module Mismatch where
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `Inconsistent2.foo` (Checked)" @-}
+module Inconsistent2 where
 
 {-@ foo :: Nat @-}
 foo :: Bool
diff --git a/tests/errors/InlineSubExp0.hs b/tests/errors/InlineSubExp0.hs
--- a/tests/errors/InlineSubExp0.hs
+++ b/tests/errors/InlineSubExp0.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-error-containing=== f B C" @-}
 
 -- https://github.com/ucsd-progsys/liquidhaskell/issues/1258
 
 {-@ LIQUID "--reflection"  @-}
 {-@ LIQUID "--short-names" @-} 
 
-module T1258 where 
+module InlineSubExp0 where
 
 import Language.Haskell.Liquid.ProofCombinators 
 
diff --git a/tests/errors/InlineSubExp1.hs b/tests/errors/InlineSubExp1.hs
--- a/tests/errors/InlineSubExp1.hs
+++ b/tests/errors/InlineSubExp1.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-error-containing== f B (g A)" @-}
 
 -- https://github.com/ucsd-progsys/liquidhaskell/issues/1258
 
 {-@ LIQUID "--reflection"  @-}
 {-@ LIQUID "--short-names" @-}
 
-module T1258 where 
+module InlineSubExp1 where
 
 import Language.Haskell.Liquid.ProofCombinators 
 
diff --git a/tests/errors/IrregularData.hs b/tests/errors/IrregularData.hs
--- a/tests/errors/IrregularData.hs
+++ b/tests/errors/IrregularData.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=is not a subtype of the required type" @-}
 {-@ LIQUID "--reflection" @-}
 
 module IrregularData where
diff --git a/tests/errors/LiftMeasureCase.hs b/tests/errors/LiftMeasureCase.hs
--- a/tests/errors/LiftMeasureCase.hs
+++ b/tests/errors/LiftMeasureCase.hs
@@ -1,16 +1,17 @@
-module Measures where
+{-@ LIQUID "--expect-error-containing=Cannot create measure 'LiftMeasureCase.foo': Does not have a case-of at the top-level" @-}
+module LiftMeasureCase where
 
 llen :: [a] -> Int
 llen [] = 0
 llen (x:xs) = 1 + llen xs
 
 {-@ measure foo @-}
-foo :: a -> a 
+foo :: a -> a
 foo x = x
 
 {-@ measure lllen @-}
 
 {-@ lllen :: xs:[a] -> {v:Int| (lllen xs) = v} @-}
-lllen :: [a] -> Int	
+lllen :: [a] -> Int
 lllen [] = 0
 lllen (x:xs) = 1 + lllen xs
diff --git a/tests/errors/LocalHole.hs b/tests/errors/LocalHole.hs
--- a/tests/errors/LocalHole.hs
+++ b/tests/errors/LocalHole.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `go`" @-}
 {-@ LIQUID "--no-termination" @-}
 
 module LocalHole where
diff --git a/tests/errors/MissingAssume.hs b/tests/errors/MissingAssume.hs
--- a/tests/errors/MissingAssume.hs
+++ b/tests/errors/MissingAssume.hs
@@ -1,4 +1,5 @@
-module OverWrite where
+{-@ LIQUID "--expect-error-containing=Unknown variable `goober`" @-}
+module MissingAssume where
 
 import qualified Data.Set
 
diff --git a/tests/errors/MissingField1.hs b/tests/errors/MissingField1.hs
--- a/tests/errors/MissingField1.hs
+++ b/tests/errors/MissingField1.hs
@@ -1,5 +1,7 @@
 -- TODO-REBARE: LH _should_ (?) complain: "Unknown field `goober` in refined definition of `Foo`"
 
+module MissingField1 where
+
 data Foo = F Int 
 
 {-@ data Foo = F { goober :: Int } @-}
diff --git a/tests/errors/MissingField2.hs b/tests/errors/MissingField2.hs
--- a/tests/errors/MissingField2.hs
+++ b/tests/errors/MissingField2.hs
@@ -1,6 +1,5 @@
--- TODO-REBARE: LH _should_ (?) complain: "Unknown field `fxx` in refined definition of `F`"
-
-module Invariant where
+{-@ LIQUID "--expect-error-containing=Unbound symbol fxx"@-}
+module MissingField2 where
 
 data F a = F {fx :: a, fy :: a, fzz :: a} | G {fx :: a}
 
diff --git a/tests/errors/MissingReflect.hs b/tests/errors/MissingReflect.hs
--- a/tests/errors/MissingReflect.hs
+++ b/tests/errors/MissingReflect.hs
@@ -1,5 +1,8 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `MissingReflect.empty_foo`" @-}
 {-@ LIQUID "--reflection"                     @-}
 {-@ LIQUID "--ple"                                @-}
+
+module MissingReflect where
 
 import Language.Haskell.Liquid.ProofCombinators 
 
diff --git a/tests/errors/MissingSizeFun.hs b/tests/errors/MissingSizeFun.hs
--- a/tests/errors/MissingSizeFun.hs
+++ b/tests/errors/MissingSizeFun.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Unknown variable `llen2`" @-}
 {-@ LIQUID "--nostruct" @-}
 
 module MissingSizeFun where
diff --git a/tests/errors/MultiInstMeasures.hs b/tests/errors/MultiInstMeasures.hs
--- a/tests/errors/MultiInstMeasures.hs
+++ b/tests/errors/MultiInstMeasures.hs
@@ -1,4 +1,5 @@
-module Blank where
+{-@ LIQUID "--expect-error-containing=Multiple instance measures `sizeOf` for type `GHC.Ptr.Ptr`" @-}
+module MultiInstMeasures where
 
 import Data.Word
 import GHC.Ptr
diff --git a/tests/errors/MultiRecSels.hs b/tests/errors/MultiRecSels.hs
--- a/tests/errors/MultiRecSels.hs
+++ b/tests/errors/MultiRecSels.hs
@@ -1,5 +1,6 @@
+{-@ LIQUID "--expect-error-containing=Duplicated definitions for field `left`" @-}
 {-@ LIQUID "--no-termination" @-}
-module RedBlack  where
+module MultiRecSels where
 
 data RBTree a = Leaf
               | Node Color a !(RBTree a) !(RBTree a)
diff --git a/tests/errors/ParseBind.hs b/tests/errors/ParseBind.hs
deleted file mode 100644
--- a/tests/errors/ParseBind.hs
+++ /dev/null
@@ -1,7 +0,0 @@
--- We should reject the below to disallow uppercase binders
-
-module NoUpperCaseBinders where
-
-{-@ id :: Foo:Int -> Int  @-}
-id :: Int -> Int
-id x = x
diff --git a/tests/errors/ParseClass.hs b/tests/errors/ParseClass.hs
deleted file mode 100644
--- a/tests/errors/ParseClass.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Crash where
-
-class Foo a where
-{-@ class Foo where
-      foo :: x:a -> {v:a | v = x}
-  @-}
-  foo :: a -> a       
-
-instance Foo Int where
-  {-@ instance Foo Int where
-       foo :: x:Int -> {v:Int | v = x + 1 == 9} @-}
-  foo x = x + 1
-
-instance Foo Integer where
-  {-@ instance Foo Integer where
-       foo :: x:Integer -> {v:Integer | v = x + 1} @-}
-  foo x = x + 1
diff --git a/tests/errors/Positivity1.hs b/tests/errors/Positivity1.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/Positivity1.hs
@@ -0,0 +1,24 @@
+{-@ LIQUID "--expect-error-containing=Negative occurence of Positivity1.Rec" @-}
+module Positivity1 where
+
+newtype Rec a = In { out :: Rec a -> a }
+
+y :: (a -> a) -> a
+y f = g (In g)
+  where
+    -- ghc would say: Simplifier ticks exhausted
+    -- if we don't prevent this from inlining
+    {-# NOINLINE g #-}
+    g x = f (out x x)
+
+{-@ foo :: n:Nat -> {v:Nat | v < n} @-}
+foo :: Int -> Int
+foo = y go
+  where go f n = if n > 0 then n-1 else f n
+
+prop = let x = 0 in
+       assert ((\n -> 0==1) (foo 0))
+
+{-@ assert :: b:{Bool | b} -> () @-} 
+assert :: Bool -> () 
+assert _ = () 
diff --git a/tests/errors/Positivity2.hs b/tests/errors/Positivity2.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/Positivity2.hs
@@ -0,0 +1,15 @@
+{-@ LIQUID "--expect-error-containing=Negative occurence of Positivity2.Evil in Positivity2.Very" @-}
+module Positivity2 where
+
+data Evil a = Very (Evil a -> a)
+
+{-@ type Bot = {v: () | false} @-}
+
+{-@ bad :: Evil Bot -> Bot @-}
+{-# NOINLINE bad #-}
+bad :: Evil () -> ()
+bad (Very f) = f (Very f)
+
+{-@ worse :: Bot @-}
+worse :: ()
+worse = bad (Very bad)
diff --git a/tests/errors/PositivityCheck.hs b/tests/errors/PositivityCheck.hs
new file mode 100644
--- /dev/null
+++ b/tests/errors/PositivityCheck.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.Bad1" @-}
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.Bad2" @-}
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.Bad3" @-}
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.Bad4" @-}
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.BadRec1" @-}
+{-@ LIQUID "--expect-error-containing=Negative occurence of PositivityCheck.BadRec2" @-}
+module PositivityCheck where
+
+data Bad1 a = No11 (Bad1 a -> Int) | No12 (Bad1 a) 
+data Bad2 a = No2 (Int -> Bad2 a -> Int)
+data Bad3 a = No3 (Bad3 Int -> Int)
+data Bad4 a = Bar (Flip (Flip (Flip (Bad4 a))))
+type Flip a = a -> Int 
+
+data BadRec1 a = NoRec1 (BadRec2 a -> Int)
+data BadRec2 a = NoRec2 (BadRec1 a)
diff --git a/tests/errors/ReWrite5.hs b/tests/errors/ReWrite5.hs
--- a/tests/errors/ReWrite5.hs
+++ b/tests/errors/ReWrite5.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=parameter \"xs\" contains an inner refinement" @-}
 module ReWrite5 where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/errors/ReWrite6.hs b/tests/errors/ReWrite6.hs
--- a/tests/errors/ReWrite6.hs
+++ b/tests/errors/ReWrite6.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Unable to use ReWrite6.bad as a rewrite because it does not prove an equality" @-}
 module ReWrite6 where
 
 -- Reject non equalities
diff --git a/tests/errors/ReWrite7.hs b/tests/errors/ReWrite7.hs
--- a/tests/errors/ReWrite7.hs
+++ b/tests/errors/ReWrite7.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Could not generate any rewrites from equality" @-}
 module ReWrite7 where
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple" @-}
diff --git a/tests/errors/ReWrite8.hs b/tests/errors/ReWrite8.hs
--- a/tests/errors/ReWrite8.hs
+++ b/tests/errors/ReWrite8.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Could not generate any rewrites from equality" @-}
 module ReWrite8 where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/errors/ReflectLam.hs b/tests/errors/ReflectLam.hs
--- a/tests/errors/ReflectLam.hs
+++ b/tests/errors/ReflectLam.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection" @-}
 
 
-module ReflectLam where 
+module ReflectLam where
 
 
 
diff --git a/tests/errors/ShadowFieldInline.hs b/tests/errors/ShadowFieldInline.hs
--- a/tests/errors/ShadowFieldInline.hs
+++ b/tests/errors/ShadowFieldInline.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `pig`" @-}
 {-@ LIQUID "--exactdc" @-}
 
-module Range where
+module ShadowFieldInline where
 
 -- LH should give an error message that the field selectors `pig`
 -- is shadowed and should be renamed.
diff --git a/tests/errors/ShadowFieldReflect.hs b/tests/errors/ShadowFieldReflect.hs
--- a/tests/errors/ShadowFieldReflect.hs
+++ b/tests/errors/ShadowFieldReflect.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `pig`" @-}
 {-@ LIQUID "--exactdc" @-}
 
-module Range where
+module ShadowFieldReflect where
 
 -- LH should give an error message that the field selectors `pig`
 -- is shadowed and should be renamed.
diff --git a/tests/errors/ShadowMeasure.hs b/tests/errors/ShadowMeasure.hs
--- a/tests/errors/ShadowMeasure.hs
+++ b/tests/errors/ShadowMeasure.hs
@@ -1,9 +1,10 @@
+{-@ LIQUID "--expect-error-containing=Multiple specifications for `shadow`" @-}
 
 -- ISSUE: Currently this doesn't CRASH because the two sorts for `shadow` are the
 -- same, but that is a happy coincidence. We should REJECT this program as the
 -- measure has the same name as another binder.
 
-module Shadow where
+module ShadowMeasure where
 
 data Poo = Poo Int
 
diff --git a/tests/errors/ShadowMeasureVar.hs b/tests/errors/ShadowMeasureVar.hs
--- a/tests/errors/ShadowMeasureVar.hs
+++ b/tests/errors/ShadowMeasureVar.hs
@@ -1,6 +1,6 @@
 -- REJECT this program as the measure has the same name as another binder.
 
-module Shadow where
+module ShadowMeasureVar where
 
 data Poo = Poo Int
 
diff --git a/tests/errors/SplitSubtype.hs b/tests/errors/SplitSubtype.hs
--- a/tests/errors/SplitSubtype.hs
+++ b/tests/errors/SplitSubtype.hs
@@ -1,4 +1,5 @@
-module FocusSubtype where 
+{-@ LIQUID "--expect-error-containing=| VV > 5}" @-}
+module SplitSubtype where
 
 {-@ foo :: {v:Int | v > 0 && v > 5 && v < 10 } -> Int @-}
 foo :: Int -> Int
diff --git a/tests/errors/T1140.hs b/tests/errors/T1140.hs
--- a/tests/errors/T1140.hs
+++ b/tests/errors/T1140.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-error-containing=Specified type does not refine Haskell type for `T1140.foo`" @-}
 
-module Blank where 
-	
+module T1140 where
+
 data Label = Label Int 
 
 type Proof = () 
diff --git a/tests/errors/T1498.hs b/tests/errors/T1498.hs
--- a/tests/errors/T1498.hs
+++ b/tests/errors/T1498.hs
@@ -1,4 +1,5 @@
-module T1498 where 
+{-@ LIQUID "--expect-error-containing=Standalone class method refinement" @-}
+module T1498 where
 
 class A a where
   f :: a -> Int
diff --git a/tests/errors/T1498A.hs b/tests/errors/T1498A.hs
--- a/tests/errors/T1498A.hs
+++ b/tests/errors/T1498A.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Bad Data Specification" @-}
 module T1498A where
 
 class A a where
diff --git a/tests/errors/T1708.hs b/tests/errors/T1708.hs
--- a/tests/errors/T1708.hs
+++ b/tests/errors/T1708.hs
@@ -1,3 +1,6 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-}
+{-@ LIQUID "--expect-error-containing=Unbound symbol T1708.bool1" @-}
+{-@ LIQUID "--expect-error-containing=Unbound symbol T1708.bool2" @-}
 {-@ LIQUID "--reflection"  @-}
 {-@ LIQUID "--ple"         @-}
 {-@ LIQUID "--no-totality" @-}
diff --git a/tests/errors/T773.hs b/tests/errors/T773.hs
--- a/tests/errors/T773.hs
+++ b/tests/errors/T773.hs
@@ -1,8 +1,9 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `T773.incr`" @-}
 -- | Right now this gives a rather mysterious error, 
 --   cannot unify `int` with `(a b)` it would be nice 
 --   to actually point out the offending sub-expression, namely `len x`.
 
-module LiquidR where
+module T773 where
 
 {-@ measure goober :: String -> Int @-}
 
diff --git a/tests/errors/T774.hs b/tests/errors/T774.hs
--- a/tests/errors/T774.hs
+++ b/tests/errors/T774.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `T774.incr`" @-}
 
 -- | Why does this NOT fail?! Clearly there is a sort error?!
 
-module LiquidR where
+module T774 where
 
 {-@ measure goober :: String -> Int @-}
 
diff --git a/tests/errors/TODOUnboundAbsRef.hs b/tests/errors/TODOUnboundAbsRef.hs
--- a/tests/errors/TODOUnboundAbsRef.hs
+++ b/tests/errors/TODOUnboundAbsRef.hs
@@ -2,7 +2,7 @@
 -- LH happily chugs along, and just says UNSAT at the end, instead of
 -- pointing out the bogus datatype definition.
 
-module ListRange () where
+module TODOUnboundAbsRef () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/errors/TODOVarInTypeAlias.hs b/tests/errors/TODOVarInTypeAlias.hs
--- a/tests/errors/TODOVarInTypeAlias.hs
+++ b/tests/errors/TODOVarInTypeAlias.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--totality"       @-}
 {-@ LIQUID "--exactdc"        @-}
 
-module RL1015 where
+module TODOVarInTypeAlias where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/errors/TerminationExprNum.hs b/tests/errors/TerminationExprNum.hs
--- a/tests/errors/TerminationExprNum.hs
+++ b/tests/errors/TerminationExprNum.hs
@@ -1,4 +1,5 @@
-module TerminationExpr where
+{-@ LIQUID "--expect-error-containing=Illegal termination specification for `TerminationExprNum.showSep`" @-}
+module TerminationExprNum where
 
 {-@ showSep :: _ -> xs:_ -> _ / [xs] @-} -- use xs as reducing param
 showSep :: String -> [String] -> String
diff --git a/tests/errors/TerminationExprSort.hs b/tests/errors/TerminationExprSort.hs
--- a/tests/errors/TerminationExprSort.hs
+++ b/tests/errors/TerminationExprSort.hs
@@ -1,4 +1,5 @@
-module TerminationExpr where
+{-@ LIQUID "--expect-error-containing=Illegal termination specification for `TerminationExprSort.showSep`" @-}
+module TerminationExprSort where
 
 {-@ showSep :: _ -> xs:_ -> _ / [len ys] @-} -- use xs as reducing param
 showSep :: String -> [String] -> String
diff --git a/tests/errors/TerminationExprUnb.hs b/tests/errors/TerminationExprUnb.hs
--- a/tests/errors/TerminationExprUnb.hs
+++ b/tests/errors/TerminationExprUnb.hs
@@ -1,4 +1,5 @@
-module LocalTermExpr where
+{-@ LIQUID "--expect-error-containing=Illegal termination specification for `go`" @-}
+module TerminationExprUnb where
 
 {- assume (!!) :: xs:[a] -> {v:Nat | v < len xs} -> a @-}
 
diff --git a/tests/errors/UnboundAbsRef.hs b/tests/errors/UnboundAbsRef.hs
--- a/tests/errors/UnboundAbsRef.hs
+++ b/tests/errors/UnboundAbsRef.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-error-containing=Cannot apply unbound abstract refinement `p`" @-}
 
 -- ISSUE: this "crashes" without a decent source location
 -- You can fix this with the signature `ide :: forall <p :: a -> Prop>. a<p> -> a<p>`
 -- but it would be nice to have an error message that pinpoints the location.
 -- https://github.com/ucsd-progsys/liquidhaskell/issues/655
 
-module Ide where
+module UnboundAbsRef where
 
 {-@ ide :: a<p> -> a<p> @-}
 ide x = x
diff --git a/tests/errors/UnboundCheckVar.hs b/tests/errors/UnboundCheckVar.hs
--- a/tests/errors/UnboundCheckVar.hs
+++ b/tests/errors/UnboundCheckVar.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--checks=ink" @-}
 
-module UnboundCheckVar where 
+module UnboundCheckVar where
 
 inc :: Int -> Int 
 inc x = x + 1
diff --git a/tests/errors/UnboundFunInSpec.hs b/tests/errors/UnboundFunInSpec.hs
--- a/tests/errors/UnboundFunInSpec.hs
+++ b/tests/errors/UnboundFunInSpec.hs
@@ -1,4 +1,5 @@
-module Goo () where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundFunInSpec.three`" @-}
+module UnboundFunInSpec () where
 
 cnt   :: Int -> Int
 cnt 0 = 0
diff --git a/tests/errors/UnboundFunInSpec1.hs b/tests/errors/UnboundFunInSpec1.hs
--- a/tests/errors/UnboundFunInSpec1.hs
+++ b/tests/errors/UnboundFunInSpec1.hs
@@ -1,4 +1,5 @@
-module Goo where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundFunInSpec1.foo`" @-}
+module UnboundFunInSpec1 where
 
 {-@ foo :: xs:_ -> {v:_ | this = rubbish } @-}
 foo _ _ = 0
diff --git a/tests/errors/UnboundFunInSpec2.hs b/tests/errors/UnboundFunInSpec2.hs
--- a/tests/errors/UnboundFunInSpec2.hs
+++ b/tests/errors/UnboundFunInSpec2.hs
@@ -1,4 +1,5 @@
-module Goo where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundFunInSpec2.foo`" @-}
+module UnboundFunInSpec2 where
 
 {-@ foo :: Num a => { z : (xs:t -> {v : (t -> a) | this = rubbish }) | wow = hi } @-}
 foo :: Num a => t -> t -> a
diff --git a/tests/errors/UnboundVarInAssume.hs b/tests/errors/UnboundVarInAssume.hs
--- a/tests/errors/UnboundVarInAssume.hs
+++ b/tests/errors/UnboundVarInAssume.hs
@@ -1,4 +1,5 @@
-module Assume where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundVarInAssume.incr`" @-}
+module UnboundVarInAssume where
 
 {-@ assume incr :: Int -> {v : Int | v == x} @-}
 incr :: Int -> Int
diff --git a/tests/errors/UnboundVarInLocSig.hs b/tests/errors/UnboundVarInLocSig.hs
--- a/tests/errors/UnboundVarInLocSig.hs
+++ b/tests/errors/UnboundVarInLocSig.hs
@@ -1,4 +1,5 @@
-module Local02 where 
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `bar`" @-}
+module UnboundVarInLocSig where
 
 {-@ foo :: x:_ -> y:_ -> {v:Int | v = x + y} @-} 
 foo :: Int -> Int -> Int 
diff --git a/tests/errors/UnboundVarInReflect.hs b/tests/errors/UnboundVarInReflect.hs
--- a/tests/errors/UnboundVarInReflect.hs
+++ b/tests/errors/UnboundVarInReflect.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundVarInReflect.frog`" @-}
 module UnboundVarInReflect where
 
 -- see GH #1708
diff --git a/tests/errors/UnboundVarInSpec.hs b/tests/errors/UnboundVarInSpec.hs
--- a/tests/errors/UnboundVarInSpec.hs
+++ b/tests/errors/UnboundVarInSpec.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-error-containing=Illegal type specification for `UnboundVarInSpec.foo`" @-}
+module UnboundVarInSpec where
 
 
 {-@ foo :: forall <p :: s -> s -> Bool>.
diff --git a/tests/errors/frog.hs b/tests/errors/frog.hs
deleted file mode 100644
--- a/tests/errors/frog.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-
-module Frog where
-
-{-@ LIQUID "--reflection" @-}
-
-{-@ reflect frog @-}
-frog :: () -> Bool
-frog () = undefined
diff --git a/tests/import/client/C.hs b/tests/import/client/C.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/client/C.hs
@@ -0,0 +1,9 @@
+{-@ LIQUID "--reflection" @-}
+
+module C where 
+import Language
+import B
+
+{-@ getVal :: {e:Expr l st r | isEFalse e } -> {v:Int | false} @-}
+getVal :: Expr l st r -> Int
+getVal (EFalse v) = v 
diff --git a/tests/import/client/CliAliasGen00.hs b/tests/import/client/CliAliasGen00.hs
--- a/tests/import/client/CliAliasGen00.hs
+++ b/tests/import/client/CliAliasGen00.hs
@@ -1,4 +1,4 @@
-module CliAliasGen00 where 
+module CliAliasGen00 where
 
 import LibAliasGen00 
 
diff --git a/tests/import/client/CliRedBlue.hs b/tests/import/client/CliRedBlue.hs
--- a/tests/import/client/CliRedBlue.hs
+++ b/tests/import/client/CliRedBlue.hs
@@ -1,4 +1,4 @@
-module CliRedBlue where 
+module CliRedBlue where
 
 import           LibBlue 
 import qualified LibRedBlue as RB 
diff --git a/tests/import/client/Client0.hs b/tests/import/client/Client0.hs
--- a/tests/import/client/Client0.hs
+++ b/tests/import/client/Client0.hs
@@ -1,6 +1,6 @@
-module Client0 where 
+module Client0 where
 
-    import Client1 
+    import Client1Lib
     
     a :: Eq a => B a -> Bool 
     a (B x y) = x == y 
diff --git a/tests/import/client/Client1.hs b/tests/import/client/Client1.hs
deleted file mode 100644
--- a/tests/import/client/Client1.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Client1 where 
-
-    import Client2
-    
-    data B a = B {b1 :: a, b2 :: a }
-    {-@ data B a = B {b1 :: a, b2 :: {v:a | cProp b1 v } } @-}
-
-
diff --git a/tests/import/client/Client1Lib.hs b/tests/import/client/Client1Lib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/client/Client1Lib.hs
@@ -0,0 +1,8 @@
+module Client1Lib where 
+
+    import Client2Lib
+    
+    data B a = B {b1 :: a, b2 :: a }
+    {-@ data B a = B {b1 :: a, b2 :: {v:a | cProp b1 v } } @-}
+
+
diff --git a/tests/import/client/Client2.hs b/tests/import/client/Client2.hs
deleted file mode 100644
--- a/tests/import/client/Client2.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Client2 where 
-
-    {-@ reflect cProp @-}
-    
-    cProp :: Eq a => a -> a -> Bool 
-    cProp x y = x == y 
-
-
diff --git a/tests/import/client/Client2Lib.hs b/tests/import/client/Client2Lib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/client/Client2Lib.hs
@@ -0,0 +1,8 @@
+module Client2Lib where 
+
+    {-@ reflect cProp @-}
+    
+    cProp :: Eq a => a -> a -> Bool 
+    cProp x y = x == y 
+
+
diff --git a/tests/import/client/ExactGADT9.hs b/tests/import/client/ExactGADT9.hs
--- a/tests/import/client/ExactGADT9.hs
+++ b/tests/import/client/ExactGADT9.hs
@@ -5,7 +5,7 @@
 
 module ExactGADT9 where
 
-import ExactGADT8
+import ExactGADT8Lib
 
 {-@ reflect bar @-}
 bar :: RefinedFilter Blob typ -> Bool
diff --git a/tests/import/client/FunClashLibLibClient.hs b/tests/import/client/FunClashLibLibClient.hs
--- a/tests/import/client/FunClashLibLibClient.hs
+++ b/tests/import/client/FunClashLibLibClient.hs
@@ -4,7 +4,7 @@
 -- but SOMEHOW block this. [Current workaround: make sure you import-qualified `FunClashLibLib` 
 -- so that the name "attaches" properly. sigh.
 
-module FunClashLibLibClient where  
+module FunClashLibLibClient where
 
 import FunClashLib
 
diff --git a/tests/import/client/LibRedBlue.hs b/tests/import/client/LibRedBlue.hs
--- a/tests/import/client/LibRedBlue.hs
+++ b/tests/import/client/LibRedBlue.hs
@@ -1,4 +1,4 @@
-module LibRedBlue where 
+module LibRedBlue where
 
 import LibRed 
 import qualified LibBlue as Blue 
diff --git a/tests/import/client/LiquidArrayInit.hs b/tests/import/client/LiquidArrayInit.hs
--- a/tests/import/client/LiquidArrayInit.hs
+++ b/tests/import/client/LiquidArrayInit.hs
@@ -3,7 +3,7 @@
 module LiquidArrayInit () where
 
 import Language.Haskell.Liquid.Prelude
-import LiquidArray
+import LiquidArrayLib
 
 {-@ zero ::
       i: {v: Int | v >= 0} ->
diff --git a/tests/import/client/LiquidArrayNullTerm.hs b/tests/import/client/LiquidArrayNullTerm.hs
--- a/tests/import/client/LiquidArrayNullTerm.hs
+++ b/tests/import/client/LiquidArrayNullTerm.hs
@@ -4,7 +4,7 @@
 
 import Language.Haskell.Liquid.Prelude
 
-import LiquidArray
+import LiquidArrayLib
 
 upperCaseString' :: Int -> Int -> (Int -> Int) -> (Int -> Int)
 upperCaseString' n i s =
diff --git a/tests/import/client/NameClashClient.hs b/tests/import/client/NameClashClient.hs
--- a/tests/import/client/NameClashClient.hs
+++ b/tests/import/client/NameClashClient.hs
@@ -1,4 +1,4 @@
-module NameClashClient where 
+module NameClashClient where
 
 import qualified NameClashLib as Lib 
 
diff --git a/tests/import/client/RC1015.hs b/tests/import/client/RC1015.hs
--- a/tests/import/client/RC1015.hs
+++ b/tests/import/client/RC1015.hs
@@ -3,7 +3,7 @@
 
 module RC1015 where
 
-import RL1015
+import RL1015Lib
 
 {-@ car :: f:Foo -> { v: a | fooFirst f 0 == 10 } -> Int @-}
 car :: Foo -> a -> Int
diff --git a/tests/import/client/ReExportClient.hs b/tests/import/client/ReExportClient.hs
--- a/tests/import/client/ReExportClient.hs
+++ b/tests/import/client/ReExportClient.hs
@@ -1,6 +1,6 @@
-module ReExportClient where 
+module ReExportClient where
 
-import ReExport 
+import ReExportLib
 
 {-@ bar :: Foo -> {v:Int | 0 < v} @-} 
 bar :: Foo -> Int 
diff --git a/tests/import/client/ReflectClient1.hs b/tests/import/client/ReflectClient1.hs
--- a/tests/import/client/ReflectClient1.hs
+++ b/tests/import/client/ReflectClient1.hs
@@ -1,4 +1,4 @@
-module ReflectClient0 where
+module ReflectClient1 where
 
 import ReflectLib1
 
diff --git a/tests/import/client/ReflectClient4.hs b/tests/import/client/ReflectClient4.hs
--- a/tests/import/client/ReflectClient4.hs
+++ b/tests/import/client/ReflectClient4.hs
diff --git a/tests/import/client/T1096_Foo.hs b/tests/import/client/T1096_Foo.hs
--- a/tests/import/client/T1096_Foo.hs
+++ b/tests/import/client/T1096_Foo.hs
@@ -1,6 +1,6 @@
 module T1096_Foo where
 
-import T1096_Types 
+import T1096_TypesLib
 
 {-@ foo  :: f:Foo -> Foo / [size f] @-}
 foo  :: Foo -> Foo
diff --git a/tests/import/client/T1180.hs b/tests/import/client/T1180.hs
--- a/tests/import/client/T1180.hs
+++ b/tests/import/client/T1180.hs
@@ -3,9 +3,9 @@
 {-@ LIQUID "--exact-data-con" @-}
 {-@ LIQUID "--noadt" @-}
 
-module Ev where
+module T1180 where
 
-import Peano 
+import PeanoLib
 
 pInt :: Peano -> Int 
 pInt Z     = 0 
diff --git a/tests/import/lib/B.hs b/tests/import/lib/B.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/B.hs
@@ -0,0 +1,8 @@
+{-@ LIQUID "--reflection" @-}
+module B  where 
+import Language
+
+{-@ reflect subst @-}
+subst :: Expr l st r -> Expr l st r 
+subst EUnit  = EUnit
+subst e  = e 
diff --git a/tests/import/lib/ExactGADT8.hs b/tests/import/lib/ExactGADT8.hs
deleted file mode 100644
--- a/tests/import/lib/ExactGADT8.hs
+++ /dev/null
@@ -1,32 +0,0 @@
-{-@ LIQUID "--reflection" @-}
-{-@ LIQUID "--no-adt"     @-}
-
-{-# LANGUAGE ExistentialQuantification, KindSignatures, TypeFamilies, GADTs #-}
-
---------------------------------------------------------------------------------
-module ExactGADT8 where
-
-class PersistEntity record where
-    data EntityField record :: * -> *
-
-{-@ data Blob  = Bingo { xVal :: Int, yVal :: Int } @-}
-data Blob  = Bingo { xVal :: Int, yVal :: Int }
-
-instance PersistEntity Blob where
-  data EntityField Blob typ where
-    BlobXVal :: EntityField Blob Int
-    BlobYVal :: EntityField Blob Int
-
-data RefinedFilter record typ = RefinedFilter
-  { refinedFilterField  :: EntityField record typ
-  }
-
-evalQBlob :: RefinedFilter Blob typ -> Blob -> Bool
-evalQBlob filter blob = case refinedFilterField filter of
-  BlobXVal -> True
-  BlobYVal -> True
-
-{-@ reflect foo @-}
-foo :: RefinedFilter Blob typ -> Blob -> Bool
-foo (RefinedFilter BlobXVal) blob = True
-foo (RefinedFilter BlobYVal) blob = True
diff --git a/tests/import/lib/ExactGADT8Lib.hs b/tests/import/lib/ExactGADT8Lib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/ExactGADT8Lib.hs
@@ -0,0 +1,32 @@
+{-@ LIQUID "--reflection" @-}
+{-@ LIQUID "--no-adt"     @-}
+
+{-# LANGUAGE ExistentialQuantification, KindSignatures, TypeFamilies, GADTs #-}
+
+--------------------------------------------------------------------------------
+module ExactGADT8Lib where
+
+class PersistEntity record where
+    data EntityField record :: * -> *
+
+{-@ data Blob  = Bingo { xVal :: Int, yVal :: Int } @-}
+data Blob  = Bingo { xVal :: Int, yVal :: Int }
+
+instance PersistEntity Blob where
+  data EntityField Blob typ where
+    BlobXVal :: EntityField Blob Int
+    BlobYVal :: EntityField Blob Int
+
+data RefinedFilter record typ = RefinedFilter
+  { refinedFilterField  :: EntityField record typ
+  }
+
+evalQBlob :: RefinedFilter Blob typ -> Blob -> Bool
+evalQBlob filter blob = case refinedFilterField filter of
+  BlobXVal -> True
+  BlobYVal -> True
+
+{-@ reflect foo @-}
+foo :: RefinedFilter Blob typ -> Blob -> Bool
+foo (RefinedFilter BlobXVal) blob = True
+foo (RefinedFilter BlobYVal) blob = True
diff --git a/tests/import/lib/Language.hs b/tests/import/lib/Language.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/Language.hs
@@ -0,0 +1,10 @@
+module Language where
+
+data Expr l st r = EUnit | EFalse Int 
+{-@ data Expr l st r = EUnit | EFalse { elb1 :: {xxx:Int | false}}  @-}
+
+
+{-@ measure isEFalse @-}
+isEFalse :: Expr l st r -> Bool 
+isEFalse (EFalse _ ) = True 
+isEFalse _ = False 
diff --git a/tests/import/lib/LiquidArray.hs b/tests/import/lib/LiquidArray.hs
deleted file mode 100644
--- a/tests/import/lib/LiquidArray.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module LiquidArray where
-
-{-@ set :: forall a <p :: x0: Int -> x1: a -> Bool, r :: x0: Int -> Bool>.
-      i: Int<r> ->
-      x: a<p i> ->
-      a: (j: {v: Int<r> | v != i} -> a<p j>) ->
-      (k: Int<r> -> a<p k>) @-}
-set :: Int -> a -> (Int -> a) -> (Int -> a)
-set i x a = \k -> if k == i then x else a k
-
-{-@ get :: forall a <p :: x0: Int -> x1: a -> Bool, r :: x0: Int -> Bool>.
-             i: Int<r> ->
-             a: (j: Int<r> -> a<p j>) ->
-             a<p i> @-}
-get :: Int -> (Int -> a) -> a
-get i a = a i
-
-{-@ empty :: i: {v: Int | 0 = 1} -> a @-}
-empty :: Int -> a
-empty = const undefined 
diff --git a/tests/import/lib/LiquidArrayLib.hs b/tests/import/lib/LiquidArrayLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/LiquidArrayLib.hs
@@ -0,0 +1,20 @@
+module LiquidArrayLib where
+
+{-@ set :: forall a <p :: x0: Int -> x1: a -> Bool, r :: x0: Int -> Bool>.
+      i: Int<r> ->
+      x: a<p i> ->
+      a: (j: {v: Int<r> | v != i} -> a<p j>) ->
+      (k: Int<r> -> a<p k>) @-}
+set :: Int -> a -> (Int -> a) -> (Int -> a)
+set i x a = \k -> if k == i then x else a k
+
+{-@ get :: forall a <p :: x0: Int -> x1: a -> Bool, r :: x0: Int -> Bool>.
+             i: Int<r> ->
+             a: (j: Int<r> -> a<p j>) ->
+             a<p i> @-}
+get :: Int -> (Int -> a) -> a
+get i a = a i
+
+{-@ empty :: i: {v: Int | 0 = 1} -> a @-}
+empty :: Int -> a
+empty = const undefined 
diff --git a/tests/import/lib/Peano.hs b/tests/import/lib/Peano.hs
deleted file mode 100644
--- a/tests/import/lib/Peano.hs
+++ /dev/null
@@ -1,33 +0,0 @@
-{-# LANGUAGE GADTs #-}
-
-{-@ LIQUID "--exact-data-con" @-}
-{-@ LIQUID "--higherorder"    @-}
-{-@ LIQUID "--ple"            @-}
-{-@ LIQUID "--noadt"          @-}
-
-
-module Peano where
-
---------------------------------------------------------------------------------
--- | Peano Numbers -------------------------------------------------------------
---------------------------------------------------------------------------------
-
-{-@ data Peano [toNat] @-}
-data Peano where
-  Z :: Peano
-  S :: Peano -> Peano
-
-{-@ measure toNat @-}
-{-@ toNat :: Peano -> Nat @-}
-toNat :: Peano -> Int
-toNat Z     = 0
-toNat (S n) = 1 + toNat n
-
-{-@ reflect plus @-}
-plus :: Peano -> Peano -> Peano
-plus Z     n = n
-plus (S m) n = S (plus m n)
-
-{-@ reflect double @-}
-double :: Peano -> Peano
-double n = plus n n
diff --git a/tests/import/lib/PeanoLib.hs b/tests/import/lib/PeanoLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/PeanoLib.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE GADTs #-}
+
+{-@ LIQUID "--exact-data-con" @-}
+{-@ LIQUID "--higherorder"    @-}
+{-@ LIQUID "--ple"            @-}
+{-@ LIQUID "--noadt"          @-}
+
+
+module PeanoLib where
+
+--------------------------------------------------------------------------------
+-- | Peano Numbers -------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+{-@ data Peano [toNat] @-}
+data Peano where
+  Z :: Peano
+  S :: Peano -> Peano
+
+{-@ measure toNat @-}
+{-@ toNat :: Peano -> Nat @-}
+toNat :: Peano -> Int
+toNat Z     = 0
+toNat (S n) = 1 + toNat n
+
+{-@ reflect plus @-}
+plus :: Peano -> Peano -> Peano
+plus Z     n = n
+plus (S m) n = S (plus m n)
+
+{-@ reflect double @-}
+double :: Peano -> Peano
+double n = plus n n
diff --git a/tests/import/lib/RL1015.hs b/tests/import/lib/RL1015.hs
deleted file mode 100644
--- a/tests/import/lib/RL1015.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-{-@ LIQUID "--exactdc" @-}
-{-@ LIQUID "--higherorder" @-}
-
-module RL1015 where
-
-data Foo = Foo { fooFirst :: Int -> Int , fooSnd :: Int}
-
-{-@ data Foo = Foo { fooFirst :: Int -> Int , fooSnd :: Nat } @-}
-
-{-@ bar :: f:Foo -> { v: a | fooFirst f 0 == 10 } -> Int @-}
-bar :: Foo -> a -> Int
-bar f _ = 10
-
-{-@ reflect bling @-}
-bling :: Int -> Int
-bling x = 10
-
-bag = bar (Foo bling 10) (bling 0)
diff --git a/tests/import/lib/RL1015Lib.hs b/tests/import/lib/RL1015Lib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/RL1015Lib.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--exactdc" @-}
+{-@ LIQUID "--higherorder" @-}
+
+module RL1015Lib where
+
+data Foo = Foo { fooFirst :: Int -> Int , fooSnd :: Int}
+
+{-@ data Foo = Foo { fooFirst :: Int -> Int , fooSnd :: Nat } @-}
+
+{-@ bar :: f:Foo -> { v: a | fooFirst f 0 == 10 } -> Int @-}
+bar :: Foo -> a -> Int
+bar f _ = 10
+
+{-@ reflect bling @-}
+bling :: Int -> Int
+bling x = 10
+
+bag = bar (Foo bling 10) (bling 0)
diff --git a/tests/import/lib/ReExport.hs b/tests/import/lib/ReExport.hs
deleted file mode 100644
--- a/tests/import/lib/ReExport.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module ReExport ( module ReExport
-  , module X
-  ) where
-
-
-import Spec as X
diff --git a/tests/import/lib/ReExportLib.hs b/tests/import/lib/ReExportLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/ReExportLib.hs
@@ -0,0 +1,6 @@
+module ReExportLib ( module ReExportLib
+  , module X
+  ) where
+
+
+import SpecLib as X
diff --git a/tests/import/lib/Spec.hs b/tests/import/lib/Spec.hs
deleted file mode 100644
--- a/tests/import/lib/Spec.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Spec where 
-
-data Foo = FooDC Int 
-{-@ data Foo = FooDC {unfoo :: {v:Int | 0 < v }} @-} 
-
-{-@ measure cfun @-}
-{-@ cfun :: Foo -> {v:Int | 0 < v} @-} 
-cfun :: Foo -> Int 
-cfun (FooDC x) = x
diff --git a/tests/import/lib/SpecLib.hs b/tests/import/lib/SpecLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/SpecLib.hs
@@ -0,0 +1,9 @@
+module SpecLib where 
+
+data Foo = FooDC Int 
+{-@ data Foo = FooDC {unfoo :: {v:Int | 0 < v }} @-} 
+
+{-@ measure cfun @-}
+{-@ cfun :: Foo -> {v:Int | 0 < v} @-} 
+cfun :: Foo -> Int 
+cfun (FooDC x) = x
diff --git a/tests/import/lib/T1096_Types.hs b/tests/import/lib/T1096_Types.hs
deleted file mode 100644
--- a/tests/import/lib/T1096_Types.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-module T1096_Types where
-
-data Foo = A Foo | B 
-
-size :: Foo -> Integer 
-
-{-@ measure size @-}
-{- invariant {t:Foo | 0 <= size t} @-}
-{-@ size :: Foo -> {v:Integer |  0 <= v }  @-}
-size (A x) = 1 + size x
-size B     = 0 
diff --git a/tests/import/lib/T1096_TypesLib.hs b/tests/import/lib/T1096_TypesLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/import/lib/T1096_TypesLib.hs
@@ -0,0 +1,13 @@
+{-@ LIQUID "--no-termination" @-}
+
+module T1096_TypesLib where
+
+data Foo = A Foo | B 
+
+size :: Foo -> Integer 
+
+{-@ measure size @-}
+{- invariant {t:Foo | 0 <= size t} @-}
+{-@ size :: Foo -> {v:Integer |  0 <= v }  @-}
+size (A x) = 1 + size x
+size B     = 0 
diff --git a/tests/neg/AbsApp.hs b/tests/neg/AbsApp.hs
--- a/tests/neg/AbsApp.hs
+++ b/tests/neg/AbsApp.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- FAILING TEST: This should be rejected if we wish to disallow applying
 -- concrete refinements to non-refined types (e.g. Int) where they are currently
 -- silently dropped.
diff --git a/tests/neg/AdtPeano0.hs b/tests/neg/AdtPeano0.hs
--- a/tests/neg/AdtPeano0.hs
+++ b/tests/neg/AdtPeano0.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--exact-data-con" @-}
 {-@ LIQUID "--higherorder"    @-}
 
-module Peano where
+module AdtPeano0 where
 
 data Influx = Silly Int
 
diff --git a/tests/neg/AdtPeano1.hs b/tests/neg/AdtPeano1.hs
--- a/tests/neg/AdtPeano1.hs
+++ b/tests/neg/AdtPeano1.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--exact-data-con"                      @-}
 {-@ LIQUID "--higherorder"                         @-}
 
-module Peano where
+module AdtPeano1 where
 
 data Influx = Silly { goo :: Int }
 
diff --git a/tests/neg/Alias00.hs b/tests/neg/Alias00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Alias00.hs
@@ -0,0 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Alias00 () where
+
+{-@ type NegInt = {v: Int | v <= 0} @-}
+{-@ myabs :: Int -> NegInt @-}
+myabs :: Int -> Int
+myabs x = if (x > 0) then x else (0 - x)
+
+{-@ type NNList a = {v: [a] | len(v) = 0} @-}
+{-@ single :: a -> NNList a @-}
+single x = [x] 
diff --git a/tests/neg/Ass0.hs b/tests/neg/Ass0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Ass0.hs
@@ -0,0 +1,15 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Ass0 (testError) where
+
+-- import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ assert foo :: x:a -> {v: a | (v != x) } @-}
+foo x = x 
+
+testError :: Int -> Int 
+testError x = bar x 
+
+
+{-@ bar :: Nat -> Nat @-} 
+bar :: Int -> Int 
+bar x = x
diff --git a/tests/neg/Ast.hs b/tests/neg/Ast.hs
--- a/tests/neg/Ast.hs
+++ b/tests/neg/Ast.hs
@@ -1,8 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- FAILING TEST: this test SHOULD FAIL BUT DOESN'T
 -- issue #519
 
+{-@ LIQUID "--no-positivity-check" @-}
 {-# LANGUAGE DeriveFunctor #-}
-module AST where
+module Ast where
 
 data AstIndex = IxExpr | IxType
 
diff --git a/tests/neg/AutoSize.hs b/tests/neg/AutoSize.hs
--- a/tests/neg/AutoSize.hs
+++ b/tests/neg/AutoSize.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module AutoSize where
 
 import GHC.Base
diff --git a/tests/neg/AutoTerm1.hs b/tests/neg/AutoTerm1.hs
--- a/tests/neg/AutoTerm1.hs
+++ b/tests/neg/AutoTerm1.hs
@@ -1,4 +1,5 @@
-module Isort where
+{-@ LIQUID "--expect-any-error" @-}
+module AutoTerm1 where
 
 data F = F | C Int F  
 
diff --git a/tests/neg/Automate.hs b/tests/neg/Automate.hs
--- a/tests/neg/Automate.hs
+++ b/tests/neg/Automate.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--ple-local" @-}
 module Automate where
 
diff --git a/tests/neg/BadNats.hs b/tests/neg/BadNats.hs
--- a/tests/neg/BadNats.hs
+++ b/tests/neg/BadNats.hs
@@ -1,4 +1,5 @@
-module Nats where
+{-@ LIQUID "--expect-any-error" @-}
+module BadNats where
 
 {-@ poo :: {v:Int | v == 0 } @-}
 poo :: Int 
diff --git a/tests/neg/Bag1.hs b/tests/neg/Bag1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Bag1.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Bag1 where
+
+import qualified Data.Set as S
+import Language.Haskell.Liquid.Bag as B
+
+{-@ zorg :: {v:B.Bag Int | v = B.empty} @-}
+zorg :: B.Bag Int
+zorg = B.empty
+
+{-@ measure elems @-}
+elems :: (Ord a) => [a] -> B.Bag a
+elems []     = B.empty
+elems (x:xs) = B.put x (elems xs)
+
+{-@ prop0 :: x:_ -> TT @-}
+prop0 :: Int -> Bool
+prop0 x = (B.get x b == 3) 
+  where
+    a   = elems [x, x]
+    b   = B.union a a 
diff --git a/tests/neg/Baz.hs b/tests/neg/Baz.hs
--- a/tests/neg/Baz.hs
+++ b/tests/neg/Baz.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--short-names" @-}
 
 module Baz where
diff --git a/tests/neg/BigNum.hs b/tests/neg/BigNum.hs
--- a/tests/neg/BigNum.hs
+++ b/tests/neg/BigNum.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module BigNum where
 
 {-@ type Foo = { v : Integer | 0 <= v && v < 4611686018427387903 * 8 } @-}
diff --git a/tests/neg/BinarySearchOverflow.hs b/tests/neg/BinarySearchOverflow.hs
--- a/tests/neg/BinarySearchOverflow.hs
+++ b/tests/neg/BinarySearchOverflow.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--no-termination" @-}
 
-module BinarySearch where
+module BinarySearchOverflow where
 
 import Prelude hiding (Num(..))
 import CheckedNum 
diff --git a/tests/neg/Books.hs b/tests/neg/Books.hs
--- a/tests/neg/Books.hs
+++ b/tests/neg/Books.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE CPP #-}
 
 #define DISCOUNT_PERCENTAGE   2
diff --git a/tests/neg/CastedTotality.hs b/tests/neg/CastedTotality.hs
--- a/tests/neg/CastedTotality.hs
+++ b/tests/neg/CastedTotality.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-any-error" @-}
+module CastedTotality where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/neg/CharLiterals.hs b/tests/neg/CharLiterals.hs
--- a/tests/neg/CharLiterals.hs
+++ b/tests/neg/CharLiterals.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- see #1286
 
-module Example where
+module CharLiterals where
 
 {-@ fails :: {v:Bool | v} @-}
 fails =  'a' == 'b'
diff --git a/tests/neg/CheckedNum.hs b/tests/neg/CheckedNum.hs
--- a/tests/neg/CheckedNum.hs
+++ b/tests/neg/CheckedNum.hs
@@ -1,30 +1,31 @@
+{-@ LIQUID "--expect-any-error" @-}
 module CheckedNum where
 
 -- Hiding numeric operations, because they get by default translated to SMT equivalent
 import Prelude hiding (Num(..))
 
-import qualified Prelude as Prelude 
+import qualified Prelude as Prelude
 
-class CheckedNum a where 
-  (+) :: a -> a -> a 
-  (-) :: a -> a -> a 
+class CheckedNum a where
+  (+) :: a -> a -> a
+  (-) :: a -> a -> a
 
 {-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
 
 instance CheckedNum Int where
-{-@ instance CheckedNum Int where 
-      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;  
-      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y} 
+{-@ instance CheckedNum Int where
+      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;
+      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y}
   @-}
-	x - y = (Prelude.-) x y  
+    x - y = (Prelude.-) x y
 
-	x + y = (Prelude.+) x y  
+    x + y = (Prelude.+) x y
 
 {-@ good :: {v:Int | v == 9999} @-}
-good :: Int 
-good = 5000 + 4999 
+good :: Int
+good = 5000 + 4999
 
 {-@ bad :: {v:Int | v == 10001} @-}
-bad :: Int 
+bad :: Int
 bad = 5000 + 5001
 
diff --git a/tests/neg/CheckedNumLib.hs b/tests/neg/CheckedNumLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/CheckedNumLib.hs
@@ -0,0 +1,31 @@
+{-@ LIQUID "--expect-any-error" @-}
+module CheckedNumLib where
+
+-- Hiding numeric operations, because they get by default translated to SMT equivalent
+import Prelude hiding (Num(..))
+
+import qualified Prelude as Prelude 
+
+class CheckedNum a where 
+  (+) :: a -> a -> a 
+  (-) :: a -> a -> a 
+
+{-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
+
+instance CheckedNum Int where
+{-@ instance CheckedNum Int where 
+      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;  
+      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y} 
+  @-}
+	x - y = (Prelude.-) x y  
+
+	x + y = (Prelude.+) x y  
+
+{-@ good :: {v:Int | v == 9999} @-}
+good :: Int 
+good = 5000 + 4999 
+
+{-@ bad :: {v:Int | v == 10001} @-}
+bad :: Int 
+bad = 5000 + 5001
+
diff --git a/tests/neg/Class1.hs b/tests/neg/Class1.hs
--- a/tests/neg/Class1.hs
+++ b/tests/neg/Class1.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-@ LIQUID "--no-termination" @-}
-module Class () where
+module Class1 () where
 
 import Language.Haskell.Liquid.Prelude
 import Prelude hiding (sum, length, (!!), Functor(..))
diff --git a/tests/neg/Class2.hs b/tests/neg/Class2.hs
--- a/tests/neg/Class2.hs
+++ b/tests/neg/Class2.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-@ LIQUID "--no-termination" @-}
-module Class () where
+module Class2 () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/neg/Class3.hs b/tests/neg/Class3.hs
--- a/tests/neg/Class3.hs
+++ b/tests/neg/Class3.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-@ LIQUID "--no-termination" @-}
-module Class where
+module Class3 where
 
 import Language.Haskell.Liquid.Prelude
 import Prelude hiding (sum, length, (!!), Functor(..))
diff --git a/tests/neg/Class4.hs b/tests/neg/Class4.hs
--- a/tests/neg/Class4.hs
+++ b/tests/neg/Class4.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/neg/CompareConstraints.hs b/tests/neg/CompareConstraints.hs
--- a/tests/neg/CompareConstraints.hs
+++ b/tests/neg/CompareConstraints.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--no-totality" @-}
 
-module Foo where
+module CompareConstraints where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/neg/Concat.hs b/tests/neg/Concat.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Concat.hs
@@ -0,0 +1,22 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Concat () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo :: [Int]
+foo = [1..10]
+
+concatmap f ls = concat $ map f ls
+
+myconcatmap f []     = []
+myconcatmap f (x:xs) = (f x) ++ (myconcatmap f xs) 
+
+
+chooseList x = [choose x]
+r :: Int
+r = 5
+
+prop x = liquidAssertB (x == r)
+
+propMap  = map prop $ myconcatmap chooseList foo
+propMap1 = map prop $ concatmap   chooseList foo
diff --git a/tests/neg/Concat1.hs b/tests/neg/Concat1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Concat1.hs
@@ -0,0 +1,39 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Concat1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+------------------------------------------------------------
+------------ Longer Version of neg/polypred.hs -------------
+------------------------------------------------------------
+
+foo :: [[Int]]
+foo = [[choose 1], [choose 2]]
+
+-- concatmap f ls = concat $ map f ls
+
+myconcat []     = []
+myconcat (x:xs) = x ++ (myconcat xs) 
+
+
+myconcat1 :: a -> [[Int]] -> [Int]
+myconcat1 _ []     = []
+myconcat1 f (x:xs) = x ++ (myconcat1 f xs) 
+
+concat1 f = concat
+myconcat2 f = myconcat
+
+r :: Int
+r = 5
+
+prop x = liquidAssertB (x == r)
+
+-- ok 
+-- propC0 = map prop $ myconcat foo
+-- this is safe
+-- propC1 = map prop $ myconcat foo
+-- propC2 = map prop $ concat foo
+-- propC3 = map prop $ concat1 id foo
+
+propC4 = map prop $ myconcat1 id foo
+
diff --git a/tests/neg/Concat2.hs b/tests/neg/Concat2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Concat2.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Concat2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo :: [Int]
+foo = [choose 1, choose 2]
+
+-- myconcat1 :: (a -> a) -> [[Int]] -> [Int] 
+-- :: a goes to False -> safe
+myconcat1 :: (a -> [(k,v)]) -> [a] -> [(k, v)]
+myconcat1 _ []     = []
+myconcat1 f (x:xs) = (f x) ++ (myconcat1 f xs) 
+
+r :: Int
+r = 5
+
+prop (x, y) = liquidAssertB (x > r)
+--  where r = 5
+-- this is safe
+propC = map prop $ myconcat1 (\x->[(x, x)]) foo
diff --git a/tests/neg/Constraints.hs b/tests/neg/Constraints.hs
--- a/tests/neg/Constraints.hs
+++ b/tests/neg/Constraints.hs
@@ -1,4 +1,5 @@
-module Compose where
+{-@ LIQUID "--expect-any-error" @-}
+module Constraints where
 
 {-@
 cmp :: forall < pref :: b -> Bool, postf :: b -> c -> Bool
diff --git a/tests/neg/ConstraintsAppend.hs b/tests/neg/ConstraintsAppend.hs
--- a/tests/neg/ConstraintsAppend.hs
+++ b/tests/neg/ConstraintsAppend.hs
@@ -1,4 +1,5 @@
-module ListSort () where
+{-@ LIQUID "--expect-any-error" @-}
+module ConstraintsAppend () where
 
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/neg/Contra0.hs b/tests/neg/Contra0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Contra0.hs
@@ -0,0 +1,19 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+module Contra0 () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+import Data.IORef
+
+
+{-@ data variance IO bivariant @-}
+{-@ data variance IORef bivariant @-}
+
+job :: IO () 
+job = do
+  p <- newIORef (0 :: Int)
+  writeIORef p 10
+  v <- readIORef p
+  liquidAssert (v == 0) $ return ()
diff --git a/tests/neg/Coretologic.hs b/tests/neg/Coretologic.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Coretologic.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Coretologic where
+
+import Data.Set
+
+-- ISSUE: can we please allow things like `empty` to also
+-- appear in type and alias specifications, not just in
+-- measures as in `goo` below?
+
+{-@ type IsEmp a = {v:[a] | listElts v = Data.Set.empty } @-}
+
+{-@ foo :: IsEmp Int @-}
+foo :: [Int]
+foo = []
+
+{-@ bar :: IsEmp Int @-}
+bar :: [Int]
+bar = [1]
+
+{-@ measure goo @-}
+goo        :: (Ord a) => [a] -> Set a
+goo []     = empty
+goo (x:xs) = (singleton x) `union` (goo xs)  
diff --git a/tests/neg/Csv.hs b/tests/neg/Csv.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Csv.hs
@@ -0,0 +1,39 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Csv () where
+
+-- | Using LiquidHaskell for CSV lists
+-- c.f. http://www.reddit.com/r/scala/comments/1nhzi2/using_shapelesss_sized_type_to_eliminate_real/
+
+data CSV = Csv { headers :: [String]
+               , rows    :: [[String]]
+               }
+
+{-@ data CSV = Csv { headers :: [String]
+                   , rows    :: [{v:[String] | (len v) = (len headers)}]
+                   }
+  @-}
+
+-- Eeks, we missed the column name.
+
+csvBad1 = Csv ["Date"] 
+              [ ["Mon", "1"]
+              , ["Tue", "2"]
+              , ["Wed", "3"] 
+              ]
+
+-- Eeks, we missed a column.
+
+csvBad2 = Csv ["Name", "Age"] 
+              [ ["Alice", "32"]
+              , ["Bob"        ]
+              , ["Cris" , "29"] 
+              ]
+                      
+-- All is well! 
+
+csvGood = Csv ["Id", "Name", "Days"]
+              [ ["1", "Jan", "31"]
+              , ["2", "Feb", "28"]
+              , ["3", "Mar", "31"]
+              , ["4", "Apr", "30"] 
+              ]
diff --git a/tests/neg/Datacon_eq.hs b/tests/neg/Datacon_eq.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Datacon_eq.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Datacon_eq (foo) where
+
+-- This is a blank file.
+
+data G = A | B
+
+{-@ foo :: Int -> {v:G | v = A} @-}
+foo  :: Int -> G
+foo _ = B
+
+
diff --git a/tests/neg/DependentTypes.hs b/tests/neg/DependentTypes.hs
--- a/tests/neg/DependentTypes.hs
+++ b/tests/neg/DependentTypes.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE KindSignatures      #-}
 {-# LANGUAGE DataKinds           #-}
 {-# LANGUAGE OverloadedStrings   #-}
 {-# LANGUAGE RankNTypes          #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 
-module DependeTypes where
+module DependentTypes where
 
 import GHC.TypeLits
 
diff --git a/tests/neg/Elim000.hs b/tests/neg/Elim000.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim000.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Elim000 () where
+
+{-@ prop2 :: Int -> Nat @-}
+prop2 :: Int -> Int
+prop2 x = numAbsList x
+
+numAbsList = glap numAbs
+
+{-@ glap :: (a -> b) -> a -> b @-}
+glap :: (a -> b) -> a -> b
+glap = undefined
+
+-- Adding the below signature makes it flag an error...
+-- numAbs :: Int -> Int
+numAbs x = if x > 0 then x else x
diff --git a/tests/neg/Elim_ex_compose.hs b/tests/neg/Elim_ex_compose.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_compose.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Elim_ex_compose (prop) where
+
+{-@ prop :: x:Nat -> {v:Int | v = x + 5} @-}
+prop :: Int -> Int
+prop = incr . incr . incr . incr
+
+{-@ incr :: dog:Int -> {v:Int | v == dog + 1} @-}
+incr :: Int -> Int
+incr cat = cat + 1
diff --git a/tests/neg/Elim_ex_let.hs b/tests/neg/Elim_ex_let.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_let.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_let (prop) where
+
+import LiquidHaskell
+
+[lq| type Nat = {v:Int | 0 <= v} |]
+
+[lq| prop :: a -> Nat |]
+prop _ = let x _ = let y = 0 
+                   in
+                     y - 3
+         in 
+           x () + 2
diff --git a/tests/neg/Elim_ex_list.hs b/tests/neg/Elim_ex_list.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_list.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_list (prop) where
+
+import LiquidHaskell
+import Prelude hiding (head)
+
+--------------------------------------------------------------------------
+[lq| prop :: a -> Even |]
+prop _ = (head ys) - 1
+  where 
+    ys = Cons 1 (Cons 2 (Cons 5 Nil))
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+head :: List a -> a 
+head (Cons x _) = x
+
diff --git a/tests/neg/Elim_ex_map_1.hs b/tests/neg/Elim_ex_map_1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_map_1.hs
@@ -0,0 +1,22 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_1 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop xs = map (+ 2) (map (+ 1) xs)
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/Elim_ex_map_2.hs b/tests/neg/Elim_ex_map_2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_map_2.hs
@@ -0,0 +1,22 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_2 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop = map (+ 2) . map (+ 1)
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/Elim_ex_map_3.hs b/tests/neg/Elim_ex_map_3.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Elim_ex_map_3.hs
@@ -0,0 +1,22 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_3 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop = map ((+ 0) . (+ 1))
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/Errmsg.hs b/tests/neg/Errmsg.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Errmsg.hs
@@ -0,0 +1,24 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--short-names" @-}
+
+module Errmsg where
+
+import Data.Set
+
+{- the "error message" is garbled thanks to all the ill-formatted
+   "Eq [Contravariant]" stuff. Can we remove it, or at least NOT show
+   it when running in --short-names mode. -}
+
+{-@ foo :: (Eq a) => x:a -> xs:[a] -> {v:Bool | v <=> (Data.Set.member x (Data.Set.fromList xs))} @-}
+foo          :: (Eq a) => a -> [a] -> Bool
+foo x (y:ys) = x == y || elem x ys
+foo _ []     = False
+
+{-@ measure elements @-}
+elements  []    = empty
+elements (x:xs) = singleton x `union` elements xs
+
+{- append :: xs:_ -> ys:_ -> {v:_ | elements v = union (elements xs) (elements ys) }@-}
+append :: [a] -> [a] -> [a]
+append = undefined 
+
diff --git a/tests/neg/Errorloc.hs b/tests/neg/Errorloc.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Errorloc.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Errorloc () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ zoo :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
+zoo   :: Int -> Int -> Int 
+zoo x y = liquidAssert (x /= 0) $ x + y 
+
+
+foo = zoo (-1) (-2)
+
diff --git a/tests/neg/Eval.hs b/tests/neg/Eval.hs
--- a/tests/neg/Eval.hs
+++ b/tests/neg/Eval.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module Eval (eval) where
 
 import Language.Haskell.Liquid.Prelude (liquidError)
diff --git a/tests/neg/EvalQuery.hs b/tests/neg/EvalQuery.hs
--- a/tests/neg/EvalQuery.hs
+++ b/tests/neg/EvalQuery.hs
@@ -1,8 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
 
 {-@ LIQUID "--reflection"     @-}
 {-@ LIQUID "--ple"            @-}
 
-module Query where
+module EvalQuery where
 
 data Atom  = VarX
            | VarY
diff --git a/tests/neg/Ex0_unsafe.hs b/tests/neg/Ex0_unsafe.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Ex0_unsafe.hs
@@ -0,0 +1,29 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--pruneunsorted" @-}
+module Ex0_unsafe () where
+
+-- Testing "existential-types"
+
+{-@ foldN :: forall a <p :: x0000:Int -> x1111:a -> Bool>. 
+                (i:Int -> a<p i> -> a<p (i+1)>)
+              -> n:{v: Int | v >= 0}
+              -> a <p 0>
+              -> a <p n>
+  @-}
+
+foldN :: (Int -> a -> a) -> Int -> a -> a
+foldN f n = go 0
+  where go i x | i < n     = go (i+1) (f i x)
+               | otherwise = x
+
+
+fooBar :: (Int -> a -> a) -> Int -> a -> a
+fooBar f n = go 0
+  where go i x | i < n     = go (i+1) (f i x)
+               | otherwise = x
+
+
+{-@ count :: m: {v: Int | v > 0 } -> {v: Int | v = 44 } @-}
+count :: Int -> Int
+count m = foldN (\_ n -> n + 1) m 0
+-- count m = fooBar (\_ n -> n + 1) m 0
diff --git a/tests/neg/Ex1_unsafe.hs b/tests/neg/Ex1_unsafe.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Ex1_unsafe.hs
@@ -0,0 +1,66 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--pruneunsorted" @-}
+
+-- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
+
+module Ex1_unsafe () where
+
+-------------------------------------------------------------------------
+-- | Data types ---------------------------------------------------------
+-------------------------------------------------------------------------
+
+data Vec a = Nil | Cons a (Vec a)
+
+-- | We can encode the notion of length as an inductive measure @llen@
+
+{-@ measure llen     :: forall a. Vec a -> Int
+      llen (Nil)       = 0
+      llen (Cons x xs) = 1 + llen(xs)
+  @-}
+
+
+-- | As a warmup, lets check that a /real/ length function indeed computes
+-- the length of the list.
+
+{-@ sizeOf :: xs:Vec a -> {v: Int | v = llen(xs)} @-}
+sizeOf             :: Vec a -> Int
+sizeOf Nil         = 0
+sizeOf (Cons _ xs) = 1 + sizeOf xs
+
+-------------------------------------------------------------------------
+-- | Higher-order fold --------------------------------------------------
+-------------------------------------------------------------------------
+
+-- | Time to roll up the sleeves. Here's a a higher-order @foldr@ function
+-- for our `Vec` type. Note that the `op` argument takes an extra /ghost/
+-- parameter that will let us properly describe the type of `efoldr`
+
+{-@ efoldr :: forall a b <p :: x0:Vec a -> x1:b -> Bool>. 
+                (xs:Vec a -> x:a -> b <p xs> -> b <p (Ex1_unsafe.Cons x xs)>)
+              -> b <p Ex1_unsafe.Nil>
+              -> ys: Vec a
+              -> b <p ys>
+  @-}
+efoldr :: (Vec a -> a -> b -> b) -> b -> Vec a -> b
+efoldr op b Nil         = b
+efoldr op b (Cons x xs) = op xs x (efoldr op b xs)
+
+-------------------------------------------------------------------------
+-- | Clients of `efold` -------------------------------------------------
+-------------------------------------------------------------------------
+
+-- | Finally, lets write a few /client/ functions that use `efoldr` to
+-- operate on the `Vec`s.
+
+-- | First: Computing the length using `efoldr`
+{-@ size :: xs:Vec a -> {v: Int | v = llen(xs)} @-}
+size :: Vec a -> Int
+size = efoldr (\_ _ n -> n + 1) 0
+
+{-@ suc :: x:Int -> {v: Int | v = x + 1} @-}
+suc :: Int -> Int
+suc x = x + 1
+
+-- | Second: Appending two lists using `efoldr`
+{-@ app  :: xs: Vec a -> ys: Vec a -> {v: Vec a | llen(v) = 1 + llen(xs) + llen(ys) } @-}
+app xs ys = efoldr (\_ z zs -> Cons z zs) ys xs
diff --git a/tests/neg/ExactADT6.hs b/tests/neg/ExactADT6.hs
--- a/tests/neg/ExactADT6.hs
+++ b/tests/neg/ExactADT6.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--no-adt"         @-}
 {-@ LIQUID "--exact-data-con" @-}
 
diff --git a/tests/neg/ExactGADT6.hs b/tests/neg/ExactGADT6.hs
--- a/tests/neg/ExactGADT6.hs
+++ b/tests/neg/ExactGADT6.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--no-adt"         @-}
 {-@ LIQUID "--exact-data-con" @-}
 
diff --git a/tests/neg/ExactGADT7.hs b/tests/neg/ExactGADT7.hs
--- a/tests/neg/ExactGADT7.hs
+++ b/tests/neg/ExactGADT7.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE KindSignatures #-}
 
@@ -5,7 +6,7 @@
 {-@ LIQUID "--no-adt"         @-}
 {-@ LIQUID "--exact-data-con" @-}
 
-module Blank where
+module ExactGADT7 where
 
 data Some a where
   SomeBool  :: Bool -> Some Bool
diff --git a/tests/neg/Fail.hs b/tests/neg/Fail.hs
--- a/tests/neg/Fail.hs
+++ b/tests/neg/Fail.hs
@@ -1,4 +1,5 @@
-module Fail where 
+{-@ LIQUID "--expect-any-error" @-}
+module Fail where
 
 {-@ fail incr @-}
 {-@ incr :: x:Int -> {v:Int |  x < v } @-}
diff --git a/tests/neg/Fail1.hs b/tests/neg/Fail1.hs
--- a/tests/neg/Fail1.hs
+++ b/tests/neg/Fail1.hs
@@ -1,4 +1,5 @@
-module Fail where 
+{-@ LIQUID "--expect-any-error" @-}
+module Fail1 where
 
 -- This should fail because the failing incr is SAFE 
 {-@ fail incr @-}
diff --git a/tests/neg/FancyTerm.hs b/tests/neg/FancyTerm.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/FancyTerm.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE GADTs #-}
+module FancyTerm where 
+
+import Language.Haskell.Liquid.This
+
+data Tree a where 
+    Leaf :: a -> Tree a 
+    Node :: (Int -> (Tree a)) -> Tree a 
+
+{-@ data size (Tree a) tsize @-}
+
+{-@ measure tsize :: Tree a -> Nat @-}
+{-@ data Tree a where 
+      Leaf :: a -> {t:Tree a  | tsize t == 0 } 
+      Node :: f:(Int -> Tree a) 
+           -> Tree a   @-}
+
+{-@ ignore node @-}
+{-@ node :: (Int -> {tin:Tree a |  0 <= tsize tin}) -> {t:Tree a | 0 <= tsize t} @-}
+node :: (Int -> Tree a) -> Tree a 
+node = Node 
+
+{-@ mapTr :: (a -> a) -> t:Tree a -> {o:Tree a | true} / [tsize t] @-}
+mapTr :: (a -> a) -> Tree a -> Tree a 
+mapTr f (Leaf x) = Leaf $ f x 
+mapTr f (Node n) = mapTr f (Node n) 
diff --git a/tests/neg/FilterAbs.hs b/tests/neg/FilterAbs.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/FilterAbs.hs
@@ -0,0 +1,44 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+
+
+module FilterAbs where
+
+import Prelude hiding (filter)
+
+{-@ filter :: forall <p :: a -> Bool, q :: a -> Bool -> Bool>.
+                  {y::a, flag :: {v:Bool<q y> | v} |- {v:a | v = y} <: a<p>}
+                  (x:a -> Bool<q x>) -> [a] -> [a<p>]
+  @-}
+
+filter f (x:xs)
+  | f x       = x : filter f xs
+  | otherwise = filter f xs
+filter _ []   = []
+
+{-@ isPos :: x:Int -> {v:Bool | v <=> x > 0} @-}
+isPos :: Int -> Bool
+isPos n = n > 0
+
+
+{-@ isNeg :: x:Int -> {v:Bool | v <=> x < 0} @-}
+isNeg :: Int -> Bool
+isNeg n = n < 0
+
+
+-- Now the below *should* work with
+-- p := \v   -> 0 < v
+-- q := \x v -> v <=> 0 < 0
+
+
+{-@ positives :: [Int] -> [{v:Int | v > 0}] @-}
+positives xs = filter isPos xs
+
+{-@ negatives :: [Int] -> [{v:Int | v < 0}] @-}
+negatives xs = filter isNeg xs
+
+{-@ positivesBAD :: [Int] -> [{v:Int | v < 0}] @-}
+positivesBAD xs = filter isPos xs
+
diff --git a/tests/neg/FoldN.hs b/tests/neg/FoldN.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/FoldN.hs
@@ -0,0 +1,17 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--pruneunsorted" @-}
+module FoldN () where
+
+-- Testing "existential-types"
+
+{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+                (i:Int -> a<p i> -> a<p (i+1)>)
+              -> n:{v: Int | v >= 0}
+              -> a <p 0>
+              -> a <p 42>
+  @-}
+
+foldN :: (Int -> a -> a) -> Int -> a -> a
+foldN f n = go 0
+  where go i x | i < n     = go (i+1) (f i x)
+               | otherwise = x
diff --git a/tests/neg/FoldN1.hs b/tests/neg/FoldN1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/FoldN1.hs
@@ -0,0 +1,15 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--pruneunsorted" @-}
+module FoldN1 where
+
+{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+                (i:Int -> a<p i> -> a<p (i+1)>)
+              -> n:{v: Int | v >= 0}
+              -> a <p 0>
+              -> {v : a | 0=1}
+  @-}
+
+foldN :: (Int -> a -> a) -> Int -> a -> a
+foldN f n = go 0
+  where go i x | i < n     = go (i+1) (f i x)
+               | otherwise = x
diff --git a/tests/neg/FunSoundness.hs b/tests/neg/FunSoundness.hs
--- a/tests/neg/FunSoundness.hs
+++ b/tests/neg/FunSoundness.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module FunSoundness where
 
 
diff --git a/tests/neg/FunctionRef.hs b/tests/neg/FunctionRef.hs
--- a/tests/neg/FunctionRef.hs
+++ b/tests/neg/FunctionRef.hs
@@ -1,5 +1,6 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--higherorder"     @-}
-module HigherOrder where
+module FunctionRef where
 
 {-@ measure ackF :: Int -> Int -> Int  @-}
 
diff --git a/tests/neg/GeneralizedTermination.hs b/tests/neg/GeneralizedTermination.hs
--- a/tests/neg/GeneralizedTermination.hs
+++ b/tests/neg/GeneralizedTermination.hs
@@ -1,5 +1,6 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--no-totality" @-}
-module GenTerm () where
+module GeneralizedTermination () where
 
 foo :: Int -> Int -> Int
 {-@ foo :: n:Nat -> m:Nat -> Nat /[n+m] @-}
diff --git a/tests/neg/Grty0.hs b/tests/neg/Grty0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Grty0.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Grty0 () where
+
+{-@ stupid :: Int -> Int @-}
+stupid :: Int -> Int
+stupid x = 0
+
+{-@ myId :: x:a -> {v:a | v = x } @-}
+myId x = x 
+
+{-@ assert single :: a -> {v: [a] | len(v) = 0} @-}
+single x = [x] 
+
+
diff --git a/tests/neg/Grty1.hs b/tests/neg/Grty1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Grty1.hs
@@ -0,0 +1,13 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-totality" @-}
+module Grty1 () where
+
+moo = insert 4 [1, 2, 0]
+
+
+{-@ insert      :: (Ord a) => x:a -> xs: [a]<{\fld v -> (v >= fld)}> -> {v: [a]<{\fld v -> (v >= fld)}> | len(v) = (1 + len(xs)) } @-}
+insert y []                   = [y]
+insert y (x : xs) | y <= x    = y : x : xs 
+                  | otherwise = x : insert y xs
+
+
diff --git a/tests/neg/Grty2.hs b/tests/neg/Grty2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Grty2.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Grty2 () where
+
+moo = insert 4 [1, 2, 3]
+
+{-@ insert      :: (Ord a) => x:a -> xs: [a]<{\fld v -> (v >= fld)}> -> {v: [a]<{\fld v -> (v >= fld)}> | len(v) = (1 + len(xs)) } @-}
+insert y []                            = [y]
+insert y (x : xs) | y > {- <= -} x     = y : x : xs 
+                  | otherwise          = x : insert y xs
+
diff --git a/tests/neg/Grty3.hs b/tests/neg/Grty3.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Grty3.hs
@@ -0,0 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Grty3 () where
+
+
+{-@ choo :: [a] -> {v: Int | v > 0 } @-}
+choo = poo
+
+
+poo :: [a] -> Int 
+poo (x:xs) = poo xs
+poo []     = 0
diff --git a/tests/neg/HasElem.hs b/tests/neg/HasElem.hs
--- a/tests/neg/HasElem.hs
+++ b/tests/neg/HasElem.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module HasElem where
 
 {-@ LIQUID "--no-termination" @-}
diff --git a/tests/neg/Hex00.hs b/tests/neg/Hex00.hs
--- a/tests/neg/Hex00.hs
+++ b/tests/neg/Hex00.hs
@@ -1,4 +1,5 @@
-module Hex where 
+{-@ LIQUID "--expect-any-error" @-}
+module Hex00 where
 
 {-@ foo :: {x:Int | x = 0x7} -> {y:Int | y = 0x6} -> {v:Int | v = 0xF} @-}
 foo :: Int -> Int -> Int 
diff --git a/tests/neg/HigherOrder.hs b/tests/neg/HigherOrder.hs
--- a/tests/neg/HigherOrder.hs
+++ b/tests/neg/HigherOrder.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--higherorder" @-}
 module HigherOrder where
 
diff --git a/tests/neg/HolesTop.hs b/tests/neg/HolesTop.hs
--- a/tests/neg/HolesTop.hs
+++ b/tests/neg/HolesTop.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module HolesTop where
 
 import Language.Haskell.Liquid.Prelude
diff --git a/tests/neg/Inc2.hs b/tests/neg/Inc2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Inc2.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+-- ISSUE #671
+--
+-- | ISSUE would be nice to have error reported at `x-1` and NOT the `inc`
+--   note that the right place gets shown if you comment out the `inc 0 = 1`
+
+module Inc2 where
+
+{-@ inc :: x:Int -> {v:Int | v > x} @-}
+inc :: Int -> Int
+inc 0 = 1
+inc x = x - 1
diff --git a/tests/neg/IntAbsRef.hs b/tests/neg/IntAbsRef.hs
--- a/tests/neg/IntAbsRef.hs
+++ b/tests/neg/IntAbsRef.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 
 module IntAbsRef where
 
diff --git a/tests/neg/LazyWhere.hs b/tests/neg/LazyWhere.hs
--- a/tests/neg/LazyWhere.hs
+++ b/tests/neg/LazyWhere.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module LazyWhere () where
 
 import Language.Haskell.Liquid.Prelude
diff --git a/tests/neg/LazyWhere1.hs b/tests/neg/LazyWhere1.hs
--- a/tests/neg/LazyWhere1.hs
+++ b/tests/neg/LazyWhere1.hs
@@ -1,4 +1,5 @@
-module LazyWhere () where
+{-@ LIQUID "--expect-any-error" @-}
+module LazyWhere1 () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/neg/LetRecStack.hs b/tests/neg/LetRecStack.hs
--- a/tests/neg/LetRecStack.hs
+++ b/tests/neg/LetRecStack.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--eliminate=all" @-}
 -- | This test case is to check that LH properly accounts for the case where GHC Core 
 --   contains stuff like:
@@ -18,7 +19,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module Foo (prop) where
+module LetRecStack (prop) where
 
 --data Peano a = Z a | S (Peano a) | P (Peano a)
 data Peano = Z | S (Peano ) | P (Peano)
diff --git a/tests/neg/List00.hs b/tests/neg/List00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/List00.hs
@@ -0,0 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
+module List00 () where
+
+import Language.Haskell.Liquid.Prelude -- hiding (copyList)
+
+copyList zs = zs
+
+xs    = [1] :: [Int]
+ys    = copyList xs
+jhala = head ys
+prop0 = crash (0 == 1) 
diff --git a/tests/neg/ListConcat.hs b/tests/neg/ListConcat.hs
--- a/tests/neg/ListConcat.hs
+++ b/tests/neg/ListConcat.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--pruneunsorted" @-}
 
-module Foo () where
+module ListConcat () where
 import Data.Set (Set(..)) 
 import Prelude hiding (concat)
 
diff --git a/tests/neg/ListElem.hs b/tests/neg/ListElem.hs
--- a/tests/neg/ListElem.hs
+++ b/tests/neg/ListElem.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module ListElem (listElem) where
 
 import Data.Set
diff --git a/tests/neg/ListKeys.hs b/tests/neg/ListKeys.hs
--- a/tests/neg/ListKeys.hs
+++ b/tests/neg/ListKeys.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--pruneunsorted" @-}
 
-module Foo () where
+module ListKeys () where
 import Data.Set (Set(..)) 
 
 {-@ measure listKeys :: [(k, v)] -> (Set k)
diff --git a/tests/neg/ListMSort.hs b/tests/neg/ListMSort.hs
--- a/tests/neg/ListMSort.hs
+++ b/tests/neg/ListMSort.hs
@@ -1,4 +1,5 @@
-module ListSort () where
+{-@ LIQUID "--expect-any-error" @-}
+module ListMSort () where
 
 import Language.Haskell.Liquid.Prelude
 
@@ -13,7 +14,7 @@
 merge (x:xs) (y:ys)
   | x <= y
   = x:(merge xs (y:ys))
-  | otherwise 
+  | otherwise
   = y:(merge (x:xs) ys)
 
 {-@ mergesort :: (Ord a) => xs:[a] -> [a]<{\fld v -> (v < fld)}>  @-}
@@ -23,10 +24,10 @@
 mergesort xs = merge (mergesort xs1) (mergesort xs2) where (xs1, xs2) = split xs
 
 chk [] = liquidAssertB True
-chk (x1:xs) = case xs of 
+chk (x1:xs) = case xs of
                []     -> liquidAssertB True
                x2:xs2 -> liquidAssertB (x1 <= x2) && chk xs
-																	
+
 rlist = map choose [1 .. 10]
 
 bar = mergesort rlist
diff --git a/tests/neg/ListRange.hs b/tests/neg/ListRange.hs
--- a/tests/neg/ListRange.hs
+++ b/tests/neg/ListRange.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module ListRange () where
 
 import Language.Haskell.Liquid.Prelude
diff --git a/tests/neg/Listne.hs b/tests/neg/Listne.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Listne.hs
@@ -0,0 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Listne where
+
+{-@ type ListNE a = {v:[a] | 0 < len v} @-}
+
+{-@ junkProp :: ListNE Int @-}
+junkProp :: [Int]
+junkProp = []
+
diff --git a/tests/neg/Lit.hs b/tests/neg/Lit.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Lit.hs
@@ -0,0 +1,5 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Lit where
+
+{-@ test :: {v:Int | v == 30} @-}
+test = length "cat"
diff --git a/tests/neg/LocalSpec.hs b/tests/neg/LocalSpec.hs
--- a/tests/neg/LocalSpec.hs
+++ b/tests/neg/LocalSpec.hs
@@ -1,4 +1,5 @@
-module Foo () where
+{-@ LIQUID "--expect-any-error" @-}
+module LocalSpec () where
 
 import Language.Haskell.Liquid.Prelude (choose)
 
diff --git a/tests/neg/Mapreduce.hs b/tests/neg/Mapreduce.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Mapreduce.hs
@@ -0,0 +1,56 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+-- RJ: Issues with TypeClasses? Ord?
+
+module Mapreduce () where
+
+import Language.Haskell.Liquid.Prelude
+import qualified Data.Map as M
+import Data.List (foldl')
+
+----------------------------------------------------------------
+--- Step 1: Map each element into key-value list (concatMap) ---
+----------------------------------------------------------------
+
+expand          :: (a -> [(k,v)]) -> [a] -> [(k, v)]
+expand f []     = []
+expand f (x:xs) = (f x) ++ (expand f xs)
+
+----------------------------------------------------------------
+--- Step 2: Group By Key ---------------------------------------
+----------------------------------------------------------------
+
+group :: (Ord k) => [(k, v)] -> M.Map k [v]
+group = foldl' addKV  M.empty
+  
+addKV m (k, v) = M.insert k vs' m
+  where vs' = v : (M.findWithDefault [] k m)
+
+----------------------------------------------------------------
+--- Step 3: Group By Key ---------------------------------------
+----------------------------------------------------------------
+
+collapse f = M.foldrWithKey reduceKV []
+  where reduceKV k (v:vs) acc = if liquidAssertB False then (k, foldl' f v vs) : acc else acc
+        reduceKV k []     _   = crash False --error $ show (liquidAssertB False)
+
+----------------------------------------------------------------
+--- Putting it All Together ------------------------------------
+----------------------------------------------------------------
+
+mapReduce fmap fred = collapse fred . group . expand fmap 
+
+----------------------------------------------------------------
+--- "Word Count" -----------------------------------------------
+----------------------------------------------------------------
+
+wordCount  = mapReduce fm plus 
+  where fm = \doc -> [ (w,1) | w <- words doc]
+
+main = putStrLn $ show $ wordCount docs
+  where docs = [ "this is the end"
+               , "go to the end"
+               , "the end is the beginning"]
+ 
+
+
diff --git a/tests/neg/Mapreduce_tiny.hs b/tests/neg/Mapreduce_tiny.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Mapreduce_tiny.hs
@@ -0,0 +1,31 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+
+
+module Mapreduce_tiny () where
+
+import Language.Haskell.Liquid.Prelude
+
+
+
+prop1       = map choo [[True]] -- replace [[1]] with [[]] for UNSAT
+choo (x:xs) = liquidAssertB False
+-- choo []     = liquidAssertB False
+
+-- import qualified Data.Map as M
+-- import Data.List (foldl')
+
+--keyvals :: [(Int, Int)]
+--keyvals = [(1, 1), (2, 2), (3, 3)]
+--
+--group :: (Ord k) => [(k, v)] -> M.Map k [v]
+--group = foldl' addKV  M.empty
+--
+--addKV m (k, v) = let boo = liquidAssertB False in M.insert k vs' m
+--  where vs' = v : (M.findWithDefault [] k m)
+--
+--checkNN m = M.foldrWithKey reduceKV False m
+--
+--reduceKV _ _ acc = liquidAssertB False 
+--
+--prop = checkNN (group keyvals)
diff --git a/tests/neg/Maps.hs b/tests/neg/Maps.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Maps.hs
@@ -0,0 +1,35 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Maps where
+
+{-@ prop1 :: x:_ -> y:{_ | y == x} -> TT @-}
+prop1 x y = (z == 10)
+  where
+    m1    = put x 10 emp  
+    m2    = put y 20 m1
+    z     = get x m2
+
+{-@ prop2 :: x:_ -> y:{_ | y == x} -> TT @-}
+prop2 x y = (z == 10)
+  where
+    m1    = put x 10 emp 
+    m2    = put y 20 m1
+    z     = get x m2
+
+-----------------------------------------------------------------------
+
+data Map k v = M
+
+{-@ embed Map as Map_t @-}
+{-@ measure Map_select :: Map k v -> k -> v @-}
+{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
+
+emp :: Map Int Int
+emp = undefined   
+     
+{-@ get :: k:k -> m:Map k v -> {v:v | v = Map_select m k} @-}
+get :: k -> Map k v -> v
+get = undefined 
+
+{-@ put :: k:k -> v:v -> m:Map k v -> {n:Map k v | n = Map_store m k v} @-}
+put :: k -> v -> Map k v -> Map k v
+put = undefined 
diff --git a/tests/neg/Maybe.hs b/tests/neg/Maybe.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Maybe.hs
@@ -0,0 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Maybe where
+
+import Data.Maybe
+
+
+foo :: Maybe a -> a
+foo x = fromJust x
diff --git a/tests/neg/MaybeMonad.hs b/tests/neg/MaybeMonad.hs
--- a/tests/neg/MaybeMonad.hs
+++ b/tests/neg/MaybeMonad.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- TODO-REBARE: STRATA
 module MaybeMonad where
 
diff --git a/tests/neg/Meas0.hs b/tests/neg/Meas0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas0.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Meas0 () where
+
+import Control.Applicative
+import Language.Haskell.Liquid.Prelude
+
+goo x = []
+
+poo (x:_) = True
+poo ([])  = liquidAssertB False
+
+xs = goo (choose 0)
+
+prop1 = liquidAssertB (poo xs)
diff --git a/tests/neg/Meas2.hs b/tests/neg/Meas2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas2.hs
@@ -0,0 +1,20 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Meas2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+goo :: a -> Int
+goo _ = 1
+
+bob :: [a] -> Int
+--bob [] = 0
+--bob (n:ns) = goo ns 
+bob ms = case ms of 
+           []     -> 0
+           (n:ns) -> goo ns 
+
+zs :: [Int]
+zs = [1..100]
+
+prop2 = liquidAssertB (n2 `eq` 0) 
+  where n2 = bob zs
diff --git a/tests/neg/Meas3.hs b/tests/neg/Meas3.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas3.hs
@@ -0,0 +1,25 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Meas3 () where
+
+
+import Language.Haskell.Liquid.Prelude
+
+--mylen []       = 0
+--mylen (_:xs)   = 1 `plus` mylen xs
+
+mylen xs = case xs of 
+             []     -> 0
+             (_:ys) -> 1 `plus` mylen ys
+
+
+zs :: [Int]
+zs = [1..100]
+
+goo :: [dogbert] -> Int
+goo _ = 1
+
+bloo :: [Int] -> Int
+bloo _ = 0
+
+prop1 = liquidAssertB (n1 `eq` 0) 
+  where n1 = mylen zs
diff --git a/tests/neg/Meas5.hs b/tests/neg/Meas5.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas5.hs
@@ -0,0 +1,42 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Meas5 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ include <len.hquals> @-}
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+
+mymap f []     = []
+mymap f (x:xs) = (f x) : (mymap f xs)
+
+myreverse = go []
+  where go acc (x:xs) = go (x:acc) xs
+        go acc []     = acc
+    
+myapp [] ys     = ys
+myapp (x:xs) ys = x:(myapp xs ys)
+
+zs :: [Int]
+zs = [1..100]
+
+zs' :: [Int]
+zs' = [500..1000]
+
+prop2 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ mymap (+ 1) zs 
+
+prop3 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ myreverse zs 
+
+prop4 = liquidAssertB ((n1 + n2) == n3) 
+  where n1 = mylen zs
+        n2 = mylen zs'
+        n3 = mylen $ myapp zs zs' 
+
+prop5 = zipWith (+) zs (0: myreverse zs)
diff --git a/tests/neg/Meas7.hs b/tests/neg/Meas7.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas7.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+module Meas7 () where
+
+-- some tests for the 'expandDefaultCase' trick to case-split 
+-- on the "missing" constructors.
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+
+{-@ foo :: [a] -> {v: Int | v = 0} @-}
+foo :: [a] -> Int
+foo zs = case zs of
+           [] -> 0
+           _  -> mylen zs
+
diff --git a/tests/neg/Meas9.hs b/tests/neg/Meas9.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Meas9.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Meas9 () where
+
+import Data.Set (Set(..))
+
+{-@ myid :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
+myid []     = []
+myid (x:xs) = x : myid xs
+
+{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | listElts(v) = Set_cup (listElts xs) (listElts xs) } @-}
+myapp :: [a] -> [a] -> [a]
+myapp []     ys = ys
+myapp (x:xs) ys = x : myapp xs ys
+
diff --git a/tests/neg/MeasureContains.hs b/tests/neg/MeasureContains.hs
--- a/tests/neg/MeasureContains.hs
+++ b/tests/neg/MeasureContains.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-any-error" @-}
+module MeasureContains where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/neg/MeasureDups.hs b/tests/neg/MeasureDups.hs
--- a/tests/neg/MeasureDups.hs
+++ b/tests/neg/MeasureDups.hs
@@ -1,12 +1,13 @@
-module Measures where
+{-@ LIQUID "--expect-any-error" @-}
+module MeasureDups where
 
-import Data.Set 
+import Data.Set
 
 {-@ LIQUID "--no-termination" @-}
 {-@ measure elements @-}
 {-@ measure dups @-}
 
-data F a = F a |  C a (F a) | E 
+data F a = F a |  C a (F a) | E
 
 dups :: Ord a => F a -> Set a
 dups E        = empty
@@ -30,5 +31,5 @@
 
 {-@ prop :: { v: Bool | v } @-}
 prop = dups s == empty
-  where 
-  	s = C 1 (C 3 (F 1)) :: F Int
+  where
+    s = C 1 (C 3 (F 1)) :: F Int
diff --git a/tests/neg/MergeSort.hs b/tests/neg/MergeSort.hs
--- a/tests/neg/MergeSort.hs
+++ b/tests/neg/MergeSort.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 ------------------------------------------------------------------------------
 -- | An implementation of Merge Sort, where LH verifies:
 --   1. Termination (Totality) 
diff --git a/tests/neg/Monad3.hs b/tests/neg/Monad3.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Monad3.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Monad3 () where
+
+import Language.Haskell.Liquid.Prelude
+
+-- gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x >= 0) (x + 1)
+
+
+-- decrlist n = n : decrlist (n-1)
+
+xs, ys, zs :: [Int]
+xs = [0, -1]
+ys = gpp xs
+zs = gpp ys
diff --git a/tests/neg/Monad4.hs b/tests/neg/Monad4.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Monad4.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Monad4 () where
+
+import Language.Haskell.Liquid.Prelude
+
+-- gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x > 0) (x - 10)
+
+
+incrlist n = n : incrlist (n+1)
+
+xs, ys, zs :: Maybe Int
+xs = Just 9
+ys = gpp xs
+zs = gpp ys
diff --git a/tests/neg/Monad5.hs b/tests/neg/Monad5.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Monad5.hs
@@ -0,0 +1,19 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Monad5 () where
+
+import Language.Haskell.Liquid.Prelude
+
+-- gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x > 0) (x + 1)
+
+myabs :: Int -> Int
+myabs x | x >= 0     = x
+        | otherwise  = 0-x
+
+posM :: Monad m => m Int
+posM = return $ myabs $ choose 0
+
+
+yM :: Monad m => m Int
+yM = gpp posM
diff --git a/tests/neg/Monad6.hs b/tests/neg/Monad6.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Monad6.hs
@@ -0,0 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Monad6 where
+
+import Language.Haskell.Liquid.Prelude 
+
+{-@ gpp :: Monad m => m {v:Int|v>=0} -> m {v:Int|v>0} @-}
+gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x >= 0) (x)
diff --git a/tests/neg/Monad7.hs b/tests/neg/Monad7.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Monad7.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Monad7 () where
+
+import Language.Haskell.Liquid.Prelude 
+
+{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
+{-@ gpp :: (Ord a, Monad m) => [a] -> m (OList a) @-}
+gpp :: (Ord a, Monad m) => [a] -> m [a]
+gpp ls = return $ reverse $ insertSort ls
+
+{-@ insertSort :: (Ord a) => xs:[a] -> OList a @-}
+insertSort            :: (Ord a) => [a] -> [a]
+insertSort []         = []
+insertSort (x:xs)     = insert x (insertSort xs) 
+
+insert y []                   = [y]
+insert y (x : xs) | y <= x    = y : x : xs 
+                  | otherwise = x : insert y xs
+
+
+
+
+
diff --git a/tests/neg/Mr00.hs b/tests/neg/Mr00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Mr00.hs
@@ -0,0 +1,17 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Mr00 () where
+
+import Language.Haskell.Liquid.Prelude 
+import Data.Map hiding (filter, map, foldl)
+
+baz (v:vs) _ = crash False 
+baz []     _ = crash False
+
+mymap = Data.Map.fromList [('a', [1])]
+
+-- Why is this safe
+coll = Data.Map.foldr baz 0 
+prop_safe = coll mymap 
+
+-- Oddly, this is unsafe
+-- prop_unsafe = Data.Map.foldr baz 0 mymap
diff --git a/tests/neg/MultiParamTypeClasses.hs b/tests/neg/MultiParamTypeClasses.hs
--- a/tests/neg/MultiParamTypeClasses.hs
+++ b/tests/neg/MultiParamTypeClasses.hs
@@ -1,5 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
+
+module MultiParamTypeClasses where
 
 class Add a b where
     rAdd :: [a] -> [b] -> [a]
diff --git a/tests/neg/Multi_pred_app_00.hs b/tests/neg/Multi_pred_app_00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Multi_pred_app_00.hs
@@ -0,0 +1,6 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Multi_pred_app_00 () where
+
+{-@ bar :: forall < p :: Int -> Bool, q :: Int -> Bool>. Int<p> -> Int<p, q> @-}
+bar :: Int -> Int
+bar x = x
diff --git a/tests/neg/MultipleInvariants.hs b/tests/neg/MultipleInvariants.hs
--- a/tests/neg/MultipleInvariants.hs
+++ b/tests/neg/MultipleInvariants.hs
@@ -1,4 +1,5 @@
-module Blank where
+{-@ LIQUID "--expect-any-error" @-}
+module MultipleInvariants where
 
 import Data.Word
 import GHC.Ptr
diff --git a/tests/neg/NameResolution.hs b/tests/neg/NameResolution.hs
--- a/tests/neg/NameResolution.hs
+++ b/tests/neg/NameResolution.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-any-error" @-}
+module NameResolution where
 
 import Prelude hiding ((==), (++))
 import Language.Haskell.Liquid.Equational 
diff --git a/tests/neg/NestedRecursion.hs b/tests/neg/NestedRecursion.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/NestedRecursion.hs
@@ -0,0 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
+module NestedRecursion (radicals) where
+
+radicals :: Int -> [a]
+radicals n = [ foo (radicals n) i | i <- [1..]]
+
+foo = undefined
diff --git a/tests/neg/NoExhaustiveGuardsError.hs b/tests/neg/NoExhaustiveGuardsError.hs
--- a/tests/neg/NoExhaustiveGuardsError.hs
+++ b/tests/neg/NoExhaustiveGuardsError.hs
@@ -1,4 +1,5 @@
-module Foo where
+{-@ LIQUID "--expect-any-error" @-}
+module NoExhaustiveGuardsError where
 
 bar :: Int -> Int -> Int
 bar x y | x >  y = 1
diff --git a/tests/neg/NoMethodBindingError.hs b/tests/neg/NoMethodBindingError.hs
--- a/tests/neg/NoMethodBindingError.hs
+++ b/tests/neg/NoMethodBindingError.hs
@@ -1,4 +1,6 @@
-module Foo where
+{-# OPTIONS_GHC -Wno-missing-methods #-}
+{-@ LIQUID "--expect-any-error" @-}
+module NoMethodBindingError where
 
 class Foo a where
   foo :: a -> a
diff --git a/tests/neg/Null.hs b/tests/neg/Null.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Null.hs
@@ -0,0 +1,5 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Null where
+
+foo :: [Int] -> Int
+foo xs = if null xs then head xs else 0
diff --git a/tests/neg/Pair.hs b/tests/neg/Pair.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Pair.hs
@@ -0,0 +1,26 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Pair () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: a -> b -> Bool> = P { pX :: a, pY :: b<p pX> } @-} 
+data Pair a b = P a b
+
+incr x = let p = P x ((x+1)) in p
+chk (P x (y)) = liquidAssertB (x == y)
+prop  = chk $ incr n
+  where n = choose 0
+
+incr2 x =
+  let p1 = (P True (x+1)) in
+  let p2 = P x p1 in
+   p2
+chk2 (P x w) =
+   case w of (P z y) -> liquidAssertB (x == y)
+prop2  = chk2 $ incr2 n
+  where n = choose 0
+
+incr3 x = P x (P True (P 0 (x+1)))
+chk3 (P x (P _(P _ y))) = liquidAssertB (x == y)
+prop3  = chk3 $ incr3 n
+  where n = choose 0
diff --git a/tests/neg/Pair0.hs b/tests/neg/Pair0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Pair0.hs
@@ -0,0 +1,22 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Pair0 () where
+
+import Language.Haskell.Liquid.Prelude 
+
+data Pair a b = P a b
+
+
+incr x = (x, x-1)
+chk (x, y) = liquidAssertB (x <y) 
+prop  = chk $ incr n
+  where n = choose 0
+
+incr2 x = (x, True, x-1)
+chk2 (x, _, y) = liquidAssertB (x <y) 
+prop2  = chk2 $ incr2 n
+  where n = choose 0
+
+incr3 x = (x, (True, (0, x-1)))
+chk3 (x, (_, (_, y))) = liquidAssertB (x <y) 
+prop3  = chk3 $ incr3 n
+  where n = choose 0
diff --git a/tests/neg/PairMeasure.hs b/tests/neg/PairMeasure.hs
--- a/tests/neg/PairMeasure.hs
+++ b/tests/neg/PairMeasure.hs
@@ -1,4 +1,5 @@
-module Foo () where
+{-@ LIQUID "--expect-any-error" @-}
+module PairMeasure () where
 
 {-@ LIQUID "--bscope" @-}
 
diff --git a/tests/neg/Pargs.hs b/tests/neg/Pargs.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Pargs.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Pargs () where
+
+{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+             (i:Int -> a<p i>) -> {v:Int| v=0}
+              -> a <p 1>
+  @-}
+
+foo ::  (Int -> a) -> Int ->  a
+foo f i = f i
diff --git a/tests/neg/Pargs1.hs b/tests/neg/Pargs1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Pargs1.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--pruneunsorted" @-}
+module Pargs1 () where
+
+{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+             (i:Int  -> j : Int-> a<p (i)>) ->
+               ii:Int -> jj:Int
+              -> a <p (ii+jj)>
+  @-}
+
+foo ::  (Int -> Int -> a) -> Int -> Int ->  a
+foo f i j = f i j
diff --git a/tests/neg/Partial.hs b/tests/neg/Partial.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Partial.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Partial () where
+
+{-@ posPlus :: x:{v: Int | v >= 0} -> {v: Int | v >= x} @-}
+posPlus :: Int -> Int
+posPlus x = if (x > 0) 
+              then 2 + (posPlus (x - 1))
+              else 0
+
+goo = posPlus (-3)
+
+{-@ poo :: x:Int -> {v: Int | v >= x } @-}
+poo x = if x > 0 then posPlus x else x
+
diff --git a/tests/neg/Poly0.hs b/tests/neg/Poly0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Poly0.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Poly0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+myid arg     = arg
+
+----------------------------------------------------------
+
+x = choose 0
+
+prop_id1 = let x'  = myabs x in 
+           let x'' = myid x' in 
+           liquidAssertB (x'' `geq` 0)
+
+prop_id2 = liquidAssertB (x'' `geq` 0)
+  where x'  = myabs x 
+        x'' = myid x' 
+
+prop_id3 = liquidAssertB (x' `geq` 20)
+  where x' = myid $ myabs x 
diff --git a/tests/neg/Poly1.hs b/tests/neg/Poly1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Poly1.hs
@@ -0,0 +1,20 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Poly1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+myid2 a b  = a  
+
+----------------------------------------------------------
+
+x =  choose 0
+
+prop_id4 = let x'  = myabs x in 
+           let x'' = myid2 x' [] in 
+           liquidAssertB (x'' `geq` 10)
+
+prop_id5 = liquidAssertB (x'' `geq` 0)
+  where x'  = myabs x 
+        x'' = myid2 x' [] 
diff --git a/tests/neg/Poly2.hs b/tests/neg/Poly2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Poly2.hs
@@ -0,0 +1,17 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Poly2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+----------------------------------------------------------
+
+myid3 x y  = y
+
+x = choose 0
+
+prop_id6 = liquidAssertB (x' `geq` 10)
+  where x' = myid3 [] $ myabs x 
+
+
diff --git a/tests/neg/Poly2_degenerate.hs b/tests/neg/Poly2_degenerate.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Poly2_degenerate.hs
@@ -0,0 +1,15 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Poly2_degenerate () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+----------------------------------------------------------
+
+myid3 x y  = y
+
+prop_id6 = liquidAssertB (x' `geq` 10)
+  where x' = myid3 [] $ myabs n 
+        n  = choose 0
+
diff --git a/tests/neg/Polypred.hs b/tests/neg/Polypred.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Polypred.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Polypred () where
+
+import Language.Haskell.Liquid.Prelude
+
+prop :: Int -> Bool
+prop x = liquidAssertB (x == 0)
+
+foo :: a -> Int
+foo longVarName = choose 20 
+
+-- propUNSAFE = prop (foo "ker")
+propSAFE = prop (foo id)
+
diff --git a/tests/neg/Poslist.hs b/tests/neg/Poslist.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Poslist.hs
@@ -0,0 +1,17 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Poslist () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+absList xs = map myabs xs
+
+prop1 = map (liquidAssertB . (`geq` 0)) $ absList $ map choose [1..]
+
+
+numAbs x   = if x > 0 then x else (x)
+
+numAbsList = map numAbs 
+
+prop2      = map (liquidAssertB . (>= 0)) $ numAbsList $ map choose [1..]
diff --git a/tests/neg/Pred.hs b/tests/neg/Pred.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Pred.hs
@@ -0,0 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Pred () where
+
+{-@ predicate Gt X Y = (X < Y) @-}
+
+{-@ incr :: x:Int -> {v:Int | Gt v x} @-}
+incr :: Int -> Int
+incr x = x + 1
diff --git a/tests/neg/Propability.hs b/tests/neg/Propability.hs
--- a/tests/neg/Propability.hs
+++ b/tests/neg/Propability.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--prune-unsorted" @-}
 
 module Propability where
diff --git a/tests/neg/Propability0.hs b/tests/neg/Propability0.hs
--- a/tests/neg/Propability0.hs
+++ b/tests/neg/Propability0.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 
 {-@ LIQUID "--prune-unsorted" @-}
 
-module Propability where
+module Propability0 where
 
 {-@ type Propability = {v:Double | ((0.0 <= v) && (v <= 1.0)) } @-}
 
diff --git a/tests/neg/Prune0.hs b/tests/neg/Prune0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Prune0.hs
@@ -0,0 +1,53 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Prune0 where
+
+import Prelude hiding (read, length)
+import Control.Monad.Primitive
+import Data.Vector.Generic.Mutable
+
+----------------------------------------------------------------------------
+-- LIQUID Specifications ---------------------------------------------------
+----------------------------------------------------------------------------
+
+-- | Vector Size Measure
+
+{-@ measure vsize :: forall a. a -> Int @-}
+
+-- | Vector Type Aliases
+{-@ type      OkIdx X     = {v:Nat | v < vsize X} @-}
+
+-- | Assumed Types for Vector
+
+{-@ assume unsafeRead  
+      :: (PrimMonad m, MVector v a) 
+      => xorp:(v (PrimState m) a) 
+      -> (OkIdx xorp) 
+      -> m a       
+  @-}
+
+yuck xanadu i = if (i > 0) then unsafeRead xanadu i else undefined
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/neg/QQTySig.hs b/tests/neg/QQTySig.hs
--- a/tests/neg/QQTySig.hs
+++ b/tests/neg/QQTySig.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySig where
 
 import LiquidHaskell
 
diff --git a/tests/neg/QQTySyn1.hs b/tests/neg/QQTySyn1.hs
--- a/tests/neg/QQTySyn1.hs
+++ b/tests/neg/QQTySyn1.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySyn1 where
 
 import LiquidHaskell
 
diff --git a/tests/neg/QQTySyn2.hs b/tests/neg/QQTySyn2.hs
--- a/tests/neg/QQTySyn2.hs
+++ b/tests/neg/QQTySyn2.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySyn2 where
 
 import LiquidHaskell
 
diff --git a/tests/neg/RG.hs b/tests/neg/RG.hs
--- a/tests/neg/RG.hs
+++ b/tests/neg/RG.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module RG where
 
 import Data.IORef as R
diff --git a/tests/neg/Range.hs b/tests/neg/Range.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Range.hs
@@ -0,0 +1,20 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Range () where
+
+import Language.Haskell.Liquid.Prelude
+
+range :: Int -> Int -> [Int]
+range i j  
+  | i `lt` j  = i : (range (i `plus` 1) j)
+  | otherwise = []  
+
+sumTo = foldl plus 0 . range 0
+
+n = choose 0 
+m = choose 1
+
+prop_rng1 = map (liquidAssertB . (10 `leq`)) $ range 0 n
+prop_rng2 = map (liquidAssertB . (n `leq`)) $ range n 100
+prop_rng3 = map (liquidAssertB . (n `leq`)) $ range n m
+prop_rng4 = map (liquidAssertB . (`leq` m)) $ range n m 
+prop_rng5 = liquidAssertB ((sumTo n) `geq` 10)
diff --git a/tests/neg/ReWrite.hs b/tests/neg/ReWrite.hs
--- a/tests/neg/ReWrite.hs
+++ b/tests/neg/ReWrite.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module ReWrite where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/neg/ReWrite2.hs b/tests/neg/ReWrite2.hs
--- a/tests/neg/ReWrite2.hs
+++ b/tests/neg/ReWrite2.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module ReWrite2 where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/neg/ReWrite3.hs b/tests/neg/ReWrite3.hs
--- a/tests/neg/ReWrite3.hs
+++ b/tests/neg/ReWrite3.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module ReWrite3 where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/neg/ReWrite4.hs b/tests/neg/ReWrite4.hs
--- a/tests/neg/ReWrite4.hs
+++ b/tests/neg/ReWrite4.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
+{-@ LIQUID "--expect-any-error" @-}
 module ReWrite4 where
 
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/neg/Rebind.hs b/tests/neg/Rebind.hs
--- a/tests/neg/Rebind.hs
+++ b/tests/neg/Rebind.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE RebindableSyntax #-}
 
-module Rebind () where 
+module Rebind () where
 
 import Prelude hiding ((>>), (>>=), return)
 
diff --git a/tests/neg/RecQSort.hs b/tests/neg/RecQSort.hs
--- a/tests/neg/RecQSort.hs
+++ b/tests/neg/RecQSort.hs
@@ -1,4 +1,5 @@
-module GhcSort () where
+{-@ LIQUID "--expect-any-error" @-}
+module RecQSort () where
 
 {-@ type OList a =  [a]<{\fld v -> (v >= fld)}>  @-}
 
diff --git a/tests/neg/RecSelector.hs b/tests/neg/RecSelector.hs
--- a/tests/neg/RecSelector.hs
+++ b/tests/neg/RecSelector.hs
@@ -1,4 +1,5 @@
-module Invariant where
+{-@ LIQUID "--expect-any-error" @-}
+module RecSelector where
 
 data F a = F {fxx :: a, fy :: a, fzz :: a} | G {fxx :: a}
 
diff --git a/tests/neg/Record0.hs b/tests/neg/Record0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Record0.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Record0 (clone, mk) where
+
+{-@ data LL a = BXYZ { size  :: {v: Int | v > 0 }
+                     , elems :: {v: [a] | (len v) = size }
+                     }
+  @-}
+
+data LL a = BXYZ { size  :: Int
+                 , elems :: [a]
+                 }
+
+{-@ mk :: a -> Int -> LL a @-}
+mk x n = BXYZ n (clone x 0)
+
+{-@ clone :: x:a -> n:Int -> {v:[a]| (len v) = n} @-}
+clone :: a -> Int -> [a]
+clone = undefined 
diff --git a/tests/neg/Revshape.hs b/tests/neg/Revshape.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Revshape.hs
@@ -0,0 +1,35 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-@ LIQUID "--no-termination" @-}
+
+module Revshape () where
+ 
+-- https://gist.github.com/cartazio/6891549
+
+data Shape = Nil | Cons !Int !Shape 
+
+{-@ measure rank @-}
+rank :: Shape -> Int
+rank (Nil)       = 0
+rank (Cons d ds) = 1 + (rank ds)
+
+{-@ type DIM1 = {v:Shape | (rank v) = 1} @-}
+{-@ type DIM2 = {v:Shape | (rank v) = 2} @-}
+
+{-@ oneDim :: DIM1 @-}
+oneDim = 12 `Cons` Nil
+
+{-@ twoDim :: DIM2 @-}
+twoDim = 2 `Cons` (17 `Cons` Nil)
+
+-- clearly an error, is flagged by LiquidHaskell
+{-@ twoDim' :: DIM2 @-}
+twoDim' = 56 `Cons` (2 `Cons` (17 `Cons` Nil))
+
+{-@ reverseShape :: sh:Shape -> {v:Shape | (rank v) = (rank sh)} @-}
+reverseShape shs = go shs Nil 
+    where
+        {-@ go ::  a:Shape -> b:Shape -> {v:Shape | (rank v) = (rank a) + (rank b)} @-}
+        go Nil res            = res   
+        go (Cons ix more) res = go more  (Cons ix res)
+ 
+  
diff --git a/tests/neg/Risers.hs b/tests/neg/Risers.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Risers.hs
@@ -0,0 +1,13 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Risers where
+
+{-@ predicate NonNull X = ((len X) > 0) @-}
+
+{- risers :: (Ord a) => zs:[a] -> {v: [[a]] | ((NonNull zs) => (NonNull v)) } @-} 
+risers []        
+  = []
+risers [x]       
+  = [[x]]
+risers (x:y:etc) 
+  = if x <= y then (x:s):ss else [x]:(s:ss)
+    where (s:ss) = risers [] -- insert partiality (y:etc)
diff --git a/tests/neg/SafePartialFunctions.hs b/tests/neg/SafePartialFunctions.hs
--- a/tests/neg/SafePartialFunctions.hs
+++ b/tests/neg/SafePartialFunctions.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module SafePartialFunctions (gotail, gohead) where
 
 import Prelude hiding (fromJust, tail, head)
diff --git a/tests/neg/Solver.hs b/tests/neg/Solver.hs
--- a/tests/neg/Solver.hs
+++ b/tests/neg/Solver.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--pruneunsorted"  @-}
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "--short-names"    @-}
 {-@ LIQUID "--reflection"     @-}
 {-@ LIQUID "--ple"            @-}
 
-module MultiParams where
+module Solver where
 
 
 import Data.Tuple
@@ -47,19 +48,19 @@
 asgns :: Formula -> [Asgn] -- generates all possible T/F vectors
 asgns = go . vars
   where
-  	go [] = []
-  	go (x:xs) = let ass = go xs in (inject (x, VTrue) ass) ++ (inject (x, VFalse) ass)
+    go [] = []
+    go (x:xs) = let ass = go xs in (inject (x, VTrue) ass) ++ (inject (x, VFalse) ass)
 
-  	inject x xs = map (\y -> x:y) xs
+    inject x xs = map (\y -> x:y) xs
 
 vars :: Formula -> [Var]
 vars = nub . go
   where
-  	go [] = []
-  	go (ls:xs) = map go' ls ++ go xs
+    go [] = []
+    go (ls:xs) = map go' ls ++ go xs
 
-  	go' (Pos x) = x
-  	go' (Neg x) = x
+    go' (Pos x) = x
+    go' (Neg x) = x
 
 -- | Satisfaction
 
diff --git a/tests/neg/Stacks.hs b/tests/neg/Stacks.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Stacks.hs
@@ -0,0 +1,36 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Stacks () where
+
+
+{-@ type DList a = [a]<{\fld v -> (v != fld)}> @-}
+
+{-@ data Stack a = St { focus  :: a    
+                      , up     :: DList {v: a | v != focus}
+                      , down   :: DList {v: a | v != focus}
+                      } 
+  @-}
+
+data Stack a = St { focus  :: !a    
+                  , up     :: ![a] 
+                  , down   :: ![a]
+                  } deriving (Show, Eq)
+
+-- All of the below violate the invariant, get liquid to say so!
+
+{-@ bad0 :: a -> Stack a @-}
+bad0   :: a -> Stack a 
+bad0 x = St x [x] []
+
+
+{-@ bad1 :: a -> Stack a @-}
+bad1   :: a -> Stack a 
+bad1 x = St x []  [x]
+
+{-@ bad2 :: Int -> Stack Int @-}
+bad2 :: Int -> Stack Int
+bad2 x = St 0 [x] [x]
+
+{-@ bad3 :: Int -> Stack Int @-}
+bad3 :: Int -> Stack Int
+bad3 x = St x [1] [1] 
+
diff --git a/tests/neg/State0.hs b/tests/neg/State0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/State0.hs
@@ -0,0 +1,13 @@
+{-@ LIQUID "--expect-any-error" @-}
+module State0 () where
+
+type State = Int
+data ST a = S (State -> (a, State))
+{-@ data ST a <p1 :: State -> Bool,
+               p2 :: State -> Bool> 
+     = S (x::(f:State<p1> -> (a, State<p2>)))
+  @-}
+
+{-@ fresh :: ST <{\v -> v>=0}, {\v -> v>=0}> Int @-}
+fresh :: ST Int
+fresh = S $ \n -> (n, n-1)
diff --git a/tests/neg/State00.hs b/tests/neg/State00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/State00.hs
@@ -0,0 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
+module State00 () where
+
+type State = Int
+data ST a b = S (a -> (a, b)) | F a
+
+{-@ fresh :: ST Int {v:Int|v>=0} @-}
+fresh :: ST Int Int
+fresh = S $ \n -> (n, n+1)
+
+
diff --git a/tests/neg/StateConstraints.hs b/tests/neg/StateConstraints.hs
--- a/tests/neg/StateConstraints.hs
+++ b/tests/neg/StateConstraints.hs
@@ -1,4 +1,5 @@
-module Compose where
+{-@ LIQUID "--expect-any-error" @-}
+module StateConstraints where
 
 data ST s = ST {runState :: s -> s}
 
diff --git a/tests/neg/StateConstraints0.hs b/tests/neg/StateConstraints0.hs
--- a/tests/neg/StateConstraints0.hs
+++ b/tests/neg/StateConstraints0.hs
@@ -1,4 +1,5 @@
-module Compose where
+{-@ LIQUID "--expect-any-error" @-}
+module StateConstraints0 where
 
 import Prelude hiding (Monad(..))
 
diff --git a/tests/neg/StateConstraints00.hs b/tests/neg/StateConstraints00.hs
--- a/tests/neg/StateConstraints00.hs
+++ b/tests/neg/StateConstraints00.hs
@@ -1,4 +1,5 @@
-module Compose where
+{-@ LIQUID "--expect-any-error" @-}
+module StateConstraints00 where
 
 import Prelude hiding (Monad, return )
 
diff --git a/tests/neg/StrictPair0.hs b/tests/neg/StrictPair0.hs
--- a/tests/neg/StrictPair0.hs
+++ b/tests/neg/StrictPair0.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- Compare with tests/neg/StrictPair1.hs
 
-module SPair (poo) where
+module StrictPair0 (poo) where
 
 {-@ measure tsnd @-}
 tsnd :: (a, b) -> b 
diff --git a/tests/neg/StrictPair1.hs b/tests/neg/StrictPair1.hs
--- a/tests/neg/StrictPair1.hs
+++ b/tests/neg/StrictPair1.hs
@@ -1,9 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
 -- From Data.ByteString.Fusion
 
 -- Compare with tests/neg/StrictPair0.hs
 
-module SPair (
-    PairS(..)
+module StrictPair1
+  ( PairS(..)
   , moo
   ) where
 
diff --git a/tests/neg/String00.hs b/tests/neg/String00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/String00.hs
@@ -0,0 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
+module String00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo = "dog"
+
+prop1 = liquidAssertB (0 == 1)
+prop2 = liquidAssertB (1 /= 1)
diff --git a/tests/neg/Strings.hs b/tests/neg/Strings.hs
--- a/tests/neg/Strings.hs
+++ b/tests/neg/Strings.hs
@@ -1,4 +1,5 @@
-module DBC where
+{-@ LIQUID "--expect-any-error" @-}
+module Strings where
 
 import GHC.CString  -- This import interprets Strings as constants!
 
diff --git a/tests/neg/SumPoly.hs b/tests/neg/SumPoly.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/SumPoly.hs
@@ -0,0 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
+module SumPoly where
+
+{-@ sumPoly :: forall <p ::a -> Bool>. (Num a, Ord a) => [a<p>] -> a<p> @-} 
+sumPoly     :: (Num a, Ord a) => [a] -> a
+sumPoly (x:xs) = foldl (+) x xs
+
diff --git a/tests/neg/Sumk.hs b/tests/neg/Sumk.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Sumk.hs
@@ -0,0 +1,17 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Sumk () where
+
+import Language.Haskell.Liquid.Prelude
+
+m   = choose 0
+bot = choose 0
+
+dsum ranjit jhala k =
+  if (ranjit `leq` 0)
+    then k jhala 
+    else dsum (ranjit `minus` 1) (ranjit `plus` jhala) k
+
+prop0 = dsum m bot (\x -> liquidAssertB ((m `plus` bot) `leq` x))
+
+prop1 = liquidAssertB (1 `leq` 0)
+
diff --git a/tests/neg/T1095C.hs b/tests/neg/T1095C.hs
--- a/tests/neg/T1095C.hs
+++ b/tests/neg/T1095C.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--max-case-expand=0" @-}
 {-@ LIQUID "--no-termination" @-}
 
-module Foo where
+module T1095C where
 
 data Foo 
   = A Foo 
diff --git a/tests/neg/T1126.hs b/tests/neg/T1126.hs
--- a/tests/neg/T1126.hs
+++ b/tests/neg/T1126.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE FlexibleInstances #-}
 
-module Instances where
+module T1126 where
 
 class OptEq a where
   (==.) :: a -> a -> a
diff --git a/tests/neg/T1198.3.hs b/tests/neg/T1198.3.hs
deleted file mode 100644
--- a/tests/neg/T1198.3.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Term where
-
-{-@ data Tree [sz] @-}
-data Tree a =  Bin | Node (Tree a) (Tree a)
-
-{-@ measure sz @-}
-sz :: Tree a -> Int
-sz Bin = 0 
-sz (Node t1 t2) = 1 + sz  (Node t1 t2) + sz  t2
diff --git a/tests/neg/T1198_3.hs b/tests/neg/T1198_3.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/T1198_3.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module T1198_3 where
+
+{-@ data Tree [sz] @-}
+data Tree a =  Bin | Node (Tree a) (Tree a)
+
+{-@ measure sz @-}
+sz :: Tree a -> Int
+sz Bin = 0 
+sz (Node t1 t2) = 1 + sz  (Node t1 t2) + sz  t2
diff --git a/tests/neg/T1267.hs b/tests/neg/T1267.hs
--- a/tests/neg/T1267.hs
+++ b/tests/neg/T1267.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--max-case-expand=0" @-}
 
-module NoCaseExpand where
+module T1267 where
 
 data ABC = A | B | C 
 
diff --git a/tests/neg/T1286.hs b/tests/neg/T1286.hs
--- a/tests/neg/T1286.hs
+++ b/tests/neg/T1286.hs
@@ -1,4 +1,5 @@
-module Example where
+{-@ LIQUID "--expect-any-error" @-}
+module T1286 where
 
 {-@ fails :: {v:Bool | v} @-}
 fails =  'a' == 'b'
diff --git a/tests/neg/T1288.hs b/tests/neg/T1288.hs
--- a/tests/neg/T1288.hs
+++ b/tests/neg/T1288.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T1288 where
 
 {-@ measure foo @-}
diff --git a/tests/neg/T1490.hs b/tests/neg/T1490.hs
--- a/tests/neg/T1490.hs
+++ b/tests/neg/T1490.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T1490 where
 
 newtype MyId a = MyId a
diff --git a/tests/neg/T1490A.hs b/tests/neg/T1490A.hs
--- a/tests/neg/T1490A.hs
+++ b/tests/neg/T1490A.hs
@@ -1,4 +1,5 @@
-module Repro2 () where
+{-@ LIQUID "--expect-any-error" @-}
+module T1490A () where
 
 newtype Embed a = Embed a
 
diff --git a/tests/neg/T1498.hs b/tests/neg/T1498.hs
--- a/tests/neg/T1498.hs
+++ b/tests/neg/T1498.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T1498 where
 
 class FromTo a where 
diff --git a/tests/neg/T1498A.hs b/tests/neg/T1498A.hs
--- a/tests/neg/T1498A.hs
+++ b/tests/neg/T1498A.hs
@@ -1,4 +1,5 @@
-module T1498 where
+{-@ LIQUID "--expect-any-error" @-}
+module T1498A where
 
 class FromTo a where 
   from :: a -> Int 
diff --git a/tests/neg/T1546.hs b/tests/neg/T1546.hs
--- a/tests/neg/T1546.hs
+++ b/tests/neg/T1546.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--rankNTypes" @-}
 
diff --git a/tests/neg/T1553.hs b/tests/neg/T1553.hs
--- a/tests/neg/T1553.hs
+++ b/tests/neg/T1553.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 
-module Example  where 
+module T1553 where
 
 negPos :: (a -> ()) -> ()
 {-@ assume negPos :: (a -> {v:() | 0 == 1 }) -> {v:() | 0 == 1 } @-}
diff --git a/tests/neg/T1553A.hs b/tests/neg/T1553A.hs
--- a/tests/neg/T1553A.hs
+++ b/tests/neg/T1553A.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection"     @-}
 {-@ LIQUID "--extensionality" @-}
 
-module Example  where 
+module T1553A where
 
 {-@ assume extensionality :: f:(a -> b) -> g:(a -> b) -> (x:a -> { f x == g x }) -> {f == g} @-}
 extensionality :: (a -> b) -> (a -> b) -> (a -> ()) -> ()
diff --git a/tests/neg/T1555.hs b/tests/neg/T1555.hs
--- a/tests/neg/T1555.hs
+++ b/tests/neg/T1555.hs
@@ -1,8 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--rankNTypes" @-}
 {-# LANGUAGE RankNTypes   #-}
 
-module Theorems where
+module T1555 where
 
 import Language.Haskell.Liquid.Equational 
 
diff --git a/tests/neg/T1577.hs b/tests/neg/T1577.hs
--- a/tests/neg/T1577.hs
+++ b/tests/neg/T1577.hs
@@ -1,8 +1,9 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection"     @-}
 {-@ LIQUID "--extensionality" @-}
 {-@ LIQUID "--ple"            @-}
 
-module T1577 where 
+module T1577 where
 
 -- | 1 . ints
 
diff --git a/tests/neg/T1604.hs b/tests/neg/T1604.hs
--- a/tests/neg/T1604.hs
+++ b/tests/neg/T1604.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple"        @-}
 module T1604 where
diff --git a/tests/neg/T1613.hs b/tests/neg/T1613.hs
--- a/tests/neg/T1613.hs
+++ b/tests/neg/T1613.hs
@@ -1,6 +1,7 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE RankNTypes #-}
 {-@ LIQUID "--reflection" @-}
-module Subclass2 where
+module T1613 where
 
 data MyFunctor f = CMyFunctor {myfmap :: forall a b. (a -> b) -> f a -> f b}
 
diff --git a/tests/neg/T1642A.hs b/tests/neg/T1642A.hs
--- a/tests/neg/T1642A.hs
+++ b/tests/neg/T1642A.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-} 
 
 {-# LANGUAGE RankNTypes     #-}
 {-# LANGUAGE GADTs          #-}
 {-# LANGUAGE KindSignatures #-}
 
-module RefinedEquality where 
+module T1642A where
 
 
 {-@ measure eqT :: a -> a -> Bool @-}
diff --git a/tests/neg/T1657.hs b/tests/neg/T1657.hs
--- a/tests/neg/T1657.hs
+++ b/tests/neg/T1657.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T1657 where
 
 {-@ data I <p :: Int -> Bool> = I _ @-}
diff --git a/tests/neg/T1657A.hs b/tests/neg/T1657A.hs
--- a/tests/neg/T1657A.hs
+++ b/tests/neg/T1657A.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T1657A where
 
 {-@ data I <pigbert :: Int -> Bool> = I Int @-}
diff --git a/tests/neg/T1659.hs b/tests/neg/T1659.hs
--- a/tests/neg/T1659.hs
+++ b/tests/neg/T1659.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 {-# LANGUAGE TypeFamilies, TypeFamilyDependencies #-}
 module T1659 where
diff --git a/tests/neg/T1814.hs b/tests/neg/T1814.hs
--- a/tests/neg/T1814.hs
+++ b/tests/neg/T1814.hs
@@ -1,7 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple"        @-}
 
-module SExec where
+module T1814 where
 
 import qualified Data.Set as S 
 
diff --git a/tests/neg/T1907.hs b/tests/neg/T1907.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/T1907.hs
@@ -0,0 +1,20 @@
+{-@ LIQUID "--expect-any-error" @-}
+
+-- Test for https://github.com/ucsd-progsys/liquidhaskell/issues/1907
+
+module T1907 where
+
+{-@ foldr' :: forall <inv :: [a] -> b -> Bool>.
+              (a -> b -> b) -> b<inv []> -> xs:[a] -> b<inv xs>
+  @-}
+foldr' op b = go
+  where
+    {-@ go :: forall <inv :: [a] -> b -> Bool>.
+              xs:[a] -> b<inv xs>
+      @-} 
+    go []    = b
+    go (h:t) = op h (go t)
+
+
+{-@ mlength :: zs:[a] -> {v:_ | v == 42 * (len zs) } @-}
+mlength = foldr' (\_ n -> n + 1) 0
diff --git a/tests/neg/T602.hs b/tests/neg/T602.hs
--- a/tests/neg/T602.hs
+++ b/tests/neg/T602.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module T602 where
 
 -- UNSOUNDLY SAFE
diff --git a/tests/neg/T743-mini.hs b/tests/neg/T743-mini.hs
deleted file mode 100644
--- a/tests/neg/T743-mini.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Bob (bar) where
-
-{-@ bar :: Nat @-}
-bar :: Int
-bar = 2 - 10
-
-data Foo a = FooCon a
-data Dict = DictCon
-
-
-{-@ mkDict :: Foo Int -> Dict @-}
-mkDict :: Foo Int -> Dict
-mkDict _ = DictCon
-
-dict      = mkDict dictList
-dictList  = readListPrecDefault dict
-
-{-@ readListPrecDefault :: Dict -> Foo Int @-}
-readListPrecDefault :: Dict -> Foo Int
-readListPrecDefault = undefined
diff --git a/tests/neg/T743.hs b/tests/neg/T743.hs
--- a/tests/neg/T743.hs
+++ b/tests/neg/T743.hs
@@ -1,4 +1,5 @@
-module Bob where
+{-@ LIQUID "--expect-any-error" @-}
+module T743 where
 
 {-@ checkNat :: Nat -> Int @-}
 checkNat :: Int -> Int
diff --git a/tests/neg/T743_mini.hs b/tests/neg/T743_mini.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/T743_mini.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--expect-any-error" @-}
+module T743_mini (bar) where
+
+{-@ bar :: Nat @-}
+bar :: Int
+bar = 2 - 10
+
+data Foo a = FooCon a
+data Dict = DictCon
+
+
+{-@ mkDict :: Foo Int -> Dict @-}
+mkDict :: Foo Int -> Dict
+mkDict _ = DictCon
+
+dict      = mkDict dictList
+dictList  = readListPrecDefault dict
+
+{-@ readListPrecDefault :: Dict -> Foo Int @-}
+readListPrecDefault :: Dict -> Foo Int
+readListPrecDefault = undefined
diff --git a/tests/neg/TermReal.hs b/tests/neg/TermReal.hs
--- a/tests/neg/TermReal.hs
+++ b/tests/neg/TermReal.hs
@@ -1,4 +1,5 @@
-module Search where
+{-@ LIQUID "--expect-any-error" @-}
+module TermReal where
 
 {-@ search :: { hi : Int | 0 < hi } -> Int @-}
 search :: Int -> Int
diff --git a/tests/neg/TerminationNum.hs b/tests/neg/TerminationNum.hs
--- a/tests/neg/TerminationNum.hs
+++ b/tests/neg/TerminationNum.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-any-error" @-}
+module TerminationNum where
 
 {-@ fak2 :: (Ord a, Eq a, Num a) => y:{x: a | x >= 0} -> a /[y]@-}
 fak2 :: (Ord a, Eq a, Num a) => a -> a
diff --git a/tests/neg/TerminationNum0.hs b/tests/neg/TerminationNum0.hs
--- a/tests/neg/TerminationNum0.hs
+++ b/tests/neg/TerminationNum0.hs
@@ -1,4 +1,5 @@
-module Fixme where
+{-@ LIQUID "--expect-any-error" @-}
+module TerminationNum0 where
 
 {-@fak2 :: (Ord a, Eq a, Num a) => {x: a | x >= 0} -> a @-}
 fak2 :: (Ord a, Eq a, Num a) => a -> a
diff --git a/tests/neg/Test00.hs b/tests/neg/Test00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test00.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+x :: Int
+x = choose 0
+
+prop_abs = if x > 0 then baz x else False
+
+baz :: Int -> Bool
+baz z = liquidAssertB (z `geq` 100)
diff --git a/tests/neg/Test00a.hs b/tests/neg/Test00a.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test00a.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test00a () where
+
+import Language.Haskell.Liquid.Prelude
+
+x = choose 0
+
+prop_abs = if x > 0 then baz x else False
+
+baz z = liquidAssertB (z >= 10)
diff --git a/tests/neg/Test00b.hs b/tests/neg/Test00b.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test00b.hs
@@ -0,0 +1,15 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test00b () where
+
+import Language.Haskell.Liquid.Prelude
+
+x = choose 0
+
+foo ::  Num a => a -> a
+foo x = 0 - x
+
+prop_abs ::  Bool
+prop_abs = if x > 0 then baz (foo x) else False
+
+baz ::  (Num a, Ord a) => a -> Bool
+baz z = liquidAssertB (z > 0)
diff --git a/tests/neg/Test00c.hs b/tests/neg/Test00c.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test00c.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test00c (ok, inc) where
+
+{-@ ok
+      :: Int -> Nat
+  @-}
+ok :: Int -> Int
+ok x = x + 120
+
+{-@ inc :: Int -> Nat @-}
+inc :: Int -> Int
+inc x = x + 10
diff --git a/tests/neg/Test1.hs b/tests/neg/Test1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test1.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x = if x `gt` 0 then x else 0 `minus` x
+
+n = choose 0
+
+prop_absf = liquidAssertB ((myabs n) `geq` 4)
diff --git a/tests/neg/Test2.hs b/tests/neg/Test2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Test2.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Test2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x = if x `gt` 0 then x else 0 `minus` x
+
+n = choose 0
+
+prop_absf = 
+  let zz = (myabs n) `geq` 4 in
+  liquidAssertB zz
diff --git a/tests/neg/TopLevel.hs b/tests/neg/TopLevel.hs
--- a/tests/neg/TopLevel.hs
+++ b/tests/neg/TopLevel.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module TopLevel where
 
 import Language.Haskell.Liquid.Prelude
diff --git a/tests/neg/TotalHaskell.hs b/tests/neg/TotalHaskell.hs
--- a/tests/neg/TotalHaskell.hs
+++ b/tests/neg/TotalHaskell.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module TotalHaskell where
 
 -- | totalHaskell overrides no-termination
diff --git a/tests/neg/Trans.hs b/tests/neg/Trans.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Trans.hs
@@ -0,0 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Trans () where
+
+{-@ assert compre :: xs:[a] -> {v:[(a,a)] | len(v) = len(xs) } @-}
+compre xs = [(x,x) | x <- xs]
+
+{-@ assert transpose :: n: Int -> [{v:[a] | len(v) = n}] -> {v: [[a]] | len(v) > n} @-}
+transpose               :: Int -> [[a]] -> [[a]]
+transpose 0 _              = []
+transpose n ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (n-1) (xs : [ t | (_:t) <- xss]) 
+-- transpose []             = []
+-- transpose ([]   : xss)   = transpose xss
+
+
diff --git a/tests/neg/Truespec.hs b/tests/neg/Truespec.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Truespec.hs
@@ -0,0 +1,8 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Truespec (foo) where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ foo :: Int -> Int @-}
+foo :: Int -> Int
+foo x = liquidAssert (x > 0) $ x + 1
diff --git a/tests/neg/Tyclass0_unsafe.hs b/tests/neg/Tyclass0_unsafe.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Tyclass0_unsafe.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Tyclass0_unsafe (poop) where
+
+class Zog a where
+  zoom :: a -> Int
+
+-- Assume the relevant behavior for the method.
+{-@ zoom :: (Zog a) => a -> Int @-}
+
+-- Uses the behavior of `zoom`
+{-@ poop :: (Zog a) => a -> Nat @-}
+poop x = zoom x
diff --git a/tests/neg/TypeLitNat.hs b/tests/neg/TypeLitNat.hs
--- a/tests/neg/TypeLitNat.hs
+++ b/tests/neg/TypeLitNat.hs
@@ -1,10 +1,11 @@
+{-@ LIQUID "--expect-any-error" @-}
 {-# LANGUAGE KindSignatures      #-}
 {-# LANGUAGE DataKinds           #-}
 {-# LANGUAGE OverloadedStrings   #-}
 {-# LANGUAGE RankNTypes          #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 
-module DependeTypes where
+module TypeLitNat where
 
 import GHC.TypeLits
 
diff --git a/tests/neg/Variance.hs b/tests/neg/Variance.hs
--- a/tests/neg/Variance.hs
+++ b/tests/neg/Variance.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module Variance where
 
 {-@ data variance Foo invariant bivariant covariant contravariant @-}
diff --git a/tests/neg/Variance1.hs b/tests/neg/Variance1.hs
--- a/tests/neg/Variance1.hs
+++ b/tests/neg/Variance1.hs
@@ -1,3 +1,4 @@
+{-@ LIQUID "--expect-any-error" @-}
 module Variance1 where
 
 import Data.Binary
diff --git a/tests/neg/Vector00.hs b/tests/neg/Vector00.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Vector00.hs
@@ -0,0 +1,13 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Vector00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
+
+xs    = [1,2,3,4] :: [Int]
+vs    = fromList xs
+jhala = vs ! (x + y + z)
+  where x = 2
+        y = 3
+        z = 5
diff --git a/tests/neg/Vector0a.hs b/tests/neg/Vector0a.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Vector0a.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Vector0a () where
+
+import Language.Haskell.Liquid.Prelude
+
+import Data.Vector hiding(map, concat, zipWith, filter, foldl, foldr, (++))
+
+xs  = [1,2,3,4] :: [Int]
+vs  = fromList xs
+
+--prop0 = liquidAssertB (x >= 0)
+--        where x = Prelude.head xs
+--
+--prop1 = liquidAssertB (n > 0)
+--        where n = Prelude.length xs
+--
+--prop2 = liquidAssertB (Data.Vector.length vs > 0)
+--prop3 = liquidAssertB (Data.Vector.length vs > 3)
+
+prop6 = crash (0 == 1) 
+x0    = vs ! 0
diff --git a/tests/neg/Vector1a.hs b/tests/neg/Vector1a.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Vector1a.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Vector1a () where
+
+import Language.Haskell.Liquid.Prelude
+import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
+
+
+-- HA this needs a non-TOP spec due to contravariance...
+foo = (Data.Vector.!) 
+
+for :: Int -> Int -> a -> (Int -> a -> a) -> a
+for lo hi acc f 
+  | lo <= hi   = for (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+dotProd       :: Vector Int -> Vector Int -> Int
+dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
+  where n = Data.Vector.length v1
+
+sumSquare   :: Vector Int -> Int
+sumSquare v = dotProd v v
+
+total = sumSquare $ Data.Vector.fromList [0..100]
diff --git a/tests/neg/Vector2.hs b/tests/neg/Vector2.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Vector2.hs
@@ -0,0 +1,68 @@
+{-@ LIQUID "--expect-any-error" @-}
+module Vector2 () where
+
+import Prelude hiding (length)
+import Data.Vector
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+    
+{-@ predicate Lt X Y      = X < Y                         @-}
+{-@ predicate Ge X Y      = not (Lt X Y)                  @-}
+{-@ predicate InBound I A = ((Ge I 0) && (Lt I (vlen A))) @-}
+
+{-@ unsafeLookup :: vec:Vector a 
+                 -> {v: Int | (0 <= v && v < (vlen vec)) } 
+                 -> a @-}
+unsafeLookup vec i = vec ! i
+
+{-@ unsafeLookup' :: vec:Vector a -> {v: Int | (InBound v vec)} -> a @-}
+unsafeLookup' vec i = vec ! i
+
+safeLookup x i 
+  | 0 <= i && i < length x = Just (x ! i)
+  | otherwise              = Nothing 
+
+{-@ absoluteSum   :: Vector Int -> {v: Int | 0 <= v}  @-}
+absoluteSum       :: Vector Int -> Int 
+absoluteSum vec   = if 0 < n then go 0 0 else 0
+  where
+    go acc i 
+      | i /= n    = go (acc + abz (vec ! i)) (i + 1)
+      | otherwise = acc 
+    n             = length vec
+
+abz n = if 0 <= n then n else (0 - n) 
+
+loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
+loop lo hi base f = go base lo
+  where
+    go acc i     
+      | i /= hi   = go (f i acc) (i + 1)
+      | otherwise = acc
+
+incr x = x + 1
+
+zoo = incr 29
+
+{-@ dotProduct :: x:(Vector Int) 
+               -> y:{v: Vector Int | (vlen x) = (vlen x)} 
+               -> Int 
+  @-}
+dotProduct     :: Vector Int -> Vector Int -> Int
+dotProduct x y 
+  = loop 0 (length x) 0 (\index -> (+ (x ! index) * (y ! index))) 
+  -- = error "dotProduct only on equal-sized vectors!"
+
+
+{-@ type SparseVector a N = [({v: Int | (0 <= v && v <= N)}, a)] @-}
+
+{-@ sparseDotProduct :: (Num a) => x:(Vector a) -> (SparseVector a {(vlen x)}) -> a @-}
+sparseDotProduct x y  = go 0 y
+  where 
+    go sum ((i, v) : y') = go (sum + (x ! i) * v) y' 
+    go sum []            = sum
+
+jhala = vs ! (x + y + z)
+  where x = 2
+        y = 3
+        z = 5
+        vs = fromList [1,2,3,4] 
diff --git a/tests/neg/VerifiedNum.hs b/tests/neg/VerifiedNum.hs
--- a/tests/neg/VerifiedNum.hs
+++ b/tests/neg/VerifiedNum.hs
@@ -1,13 +1,14 @@
+{-@ LIQUID "--expect-any-error" @-}
 module VerifiedNum where
 
 -- Hiding numeric operations, because they get by default translated to SMT equivalent
 import Prelude hiding (Num(..))
 
-import qualified Prelude as Prelude 
+import qualified Prelude as Prelude
 
-class VerifiedNum a where 
-  (+) :: a -> a -> a 
-  (-) :: a -> a -> a 
+class VerifiedNum a where
+  (+) :: a -> a -> a
+  (-) :: a -> a -> a
 
 {-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
 
@@ -17,17 +18,17 @@
 
 
 instance VerifiedNum Int where
-{-@ instance VerifiedNum Int where 
-      + :: x:Int -> y:Int -> OkInt {x + y} 
+{-@ instance VerifiedNum Int where
+      + :: x:Int -> y:Int -> OkInt {x + y}
   @-}
-	x + y = (Prelude.+) x y  
-{-@ instance VerifiedNum Int where 
-      - :: x:Int -> y:Int -> OkInt {x - y} 
+    x + y = (Prelude.+) x y
+{-@ instance VerifiedNum Int where
+      - :: x:Int -> y:Int -> OkInt {x - y}
   @-}
-	x - y = (Prelude.-) x y  
+    x - y = (Prelude.-) x y
 
 
 {-@ good :: {v:Int | v == 10} @-}
-good :: Int 
+good :: Int
 good  = 5 + 5
 
diff --git a/tests/neg/Wrap0.hs b/tests/neg/Wrap0.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Wrap0.hs
@@ -0,0 +1,23 @@
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
+{-@ LIQUID "--expect-any-error" @-}
+module Wrap0 () where
+
+import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
+
+{-@ data Foo a <p :: a -> Bool> = F (f :: a <p>) @-}
+data Foo a = F a
+
+type IntFoo = Foo Int
+
+{-@ assert flibberty :: (Eq a) => a -> Bool @-}
+flibberty x   = prop x (F x)
+prop x (F y)  = liquidAssertB (x == y)
+
+{-@ assert flibInt :: (Num a, Ord a) => a -> Bool @-}
+flibInt x     = prop1 x (F (x + 1))
+prop1 x (F y) = liquidAssertB (x < y)
+
+{-@ assert flibXs :: a -> Bool @-}
+flibXs x     = prop2 (F [x, x, x])
+prop2 (F _ ) = liquidError "no!"
+prop2 (F _ ) = True
diff --git a/tests/neg/Wrap1.hs b/tests/neg/Wrap1.hs
new file mode 100644
--- /dev/null
+++ b/tests/neg/Wrap1.hs
@@ -0,0 +1,33 @@
+{-@ LIQUID "--expect-any-error" @-}
+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
+
+module Wrap1 () where
+
+
+import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
+import Data.Function (on)
+import Data.Ord (comparing)
+
+data WrapType b a = WrapType {getVect :: b, getVal :: a}
+
+instance Eq (WrapType [Double] a) where
+   (==) = (==) `on` getVect
+
+instance Ord (WrapType [Double] a) where
+    compare = comparing getVect
+
+{-@ assert flibXs :: a -> Bool @-}
+flibXs x              = prop1 (WrapType [x, x, x] x)
+prop1 (WrapType [] _) = liquidError "no!"
+prop1 (WrapType _  _) = True
+
+{-@ assert nflibXs :: Int -> a -> Bool @-}
+nflibXs n x           = prop2 n (WrapType nxs x)
+                        where nxs = replicate n x 
+
+prop2 n (WrapType xs _) = liquidAssertB (n > length xs) 
+
+
+
+
+
diff --git a/tests/neg/alias00.hs b/tests/neg/alias00.hs
deleted file mode 100644
--- a/tests/neg/alias00.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Test0 () where
-
-{-@ type NegInt = {v: Int | v <= 0} @-}
-{-@ myabs :: Int -> NegInt @-}
-myabs :: Int -> Int
-myabs x = if (x > 0) then x else (0 - x)
-
-{-@ type NNList a = {v: [a] | len(v) = 0} @-}
-{-@ single :: a -> NNList a @-}
-single x = [x] 
diff --git a/tests/neg/ass0.hs b/tests/neg/ass0.hs
deleted file mode 100644
--- a/tests/neg/ass0.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Ass (testError) where
-
--- import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ assert foo :: x:a -> {v: a | (v != x) } @-}
-foo x = x 
-
-testError :: Int -> Int 
-testError x = bar x 
-
-
-{-@ bar :: Nat -> Nat @-} 
-bar :: Int -> Int 
-bar x = x
diff --git a/tests/neg/bag1.hs b/tests/neg/bag1.hs
deleted file mode 100644
--- a/tests/neg/bag1.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module BagTest where
-
-import qualified Data.Set as S
-import Language.Haskell.Liquid.Bag as B
-
-{-@ zorg :: {v:B.Bag Int | v = B.empty} @-}
-zorg :: B.Bag Int
-zorg = B.empty
-
-{-@ measure elems @-}
-elems :: (Ord a) => [a] -> B.Bag a
-elems []     = B.empty
-elems (x:xs) = B.put x (elems xs)
-
-{-@ prop0 :: x:_ -> TT @-}
-prop0 :: Int -> Bool
-prop0 x = (B.get x b == 3) 
-  where
-    a   = elems [x, x]
-    b   = B.union a a 
diff --git a/tests/neg/concat.hs b/tests/neg/concat.hs
deleted file mode 100644
--- a/tests/neg/concat.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Concat () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo :: [Int]
-foo = [1..10]
-
-concatmap f ls = concat $ map f ls
-
-myconcatmap f []     = []
-myconcatmap f (x:xs) = (f x) ++ (myconcatmap f xs) 
-
-
-chooseList x = [choose x]
-r :: Int
-r = 5
-
-prop x = liquidAssertB (x == r)
-
-propMap  = map prop $ myconcatmap chooseList foo
-propMap1 = map prop $ concatmap   chooseList foo
diff --git a/tests/neg/concat1.hs b/tests/neg/concat1.hs
deleted file mode 100644
--- a/tests/neg/concat1.hs
+++ /dev/null
@@ -1,38 +0,0 @@
-module Concat () where
-
-import Language.Haskell.Liquid.Prelude
-
-------------------------------------------------------------
------------- Longer Version of neg/polypred.hs -------------
-------------------------------------------------------------
-
-foo :: [[Int]]
-foo = [[choose 1], [choose 2]]
-
--- concatmap f ls = concat $ map f ls
-
-myconcat []     = []
-myconcat (x:xs) = x ++ (myconcat xs) 
-
-
-myconcat1 :: a -> [[Int]] -> [Int]
-myconcat1 _ []     = []
-myconcat1 f (x:xs) = x ++ (myconcat1 f xs) 
-
-concat1 f = concat
-myconcat2 f = myconcat
-
-r :: Int
-r = 5
-
-prop x = liquidAssertB (x == r)
-
--- ok 
--- propC0 = map prop $ myconcat foo
--- this is safe
--- propC1 = map prop $ myconcat foo
--- propC2 = map prop $ concat foo
--- propC3 = map prop $ concat1 id foo
-
-propC4 = map prop $ myconcat1 id foo
-
diff --git a/tests/neg/concat2.hs b/tests/neg/concat2.hs
deleted file mode 100644
--- a/tests/neg/concat2.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Concat () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo :: [Int]
-foo = [choose 1, choose 2]
-
--- myconcat1 :: (a -> a) -> [[Int]] -> [Int] 
--- :: a goes to False -> safe
-myconcat1 :: (a -> [(k,v)]) -> [a] -> [(k, v)]
-myconcat1 _ []     = []
-myconcat1 f (x:xs) = (f x) ++ (myconcat1 f xs) 
-
-r :: Int
-r = 5
-
-prop (x, y) = liquidAssertB (x > r)
---  where r = 5
--- this is safe
-propC = map prop $ myconcat1 (\x->[(x, x)]) foo
diff --git a/tests/neg/contra0.hs b/tests/neg/contra0.hs
deleted file mode 100644
--- a/tests/neg/contra0.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-import Data.IORef
-
-
-{-@ data variance IO bivariant @-}
-{-@ data variance IORef bivariant @-}
-
-job :: IO () 
-job = do
-  p <- newIORef (0 :: Int)
-  writeIORef p 10
-  v <- readIORef p
-  liquidAssert (v == 0) $ return ()
diff --git a/tests/neg/coretologic.hs b/tests/neg/coretologic.hs
deleted file mode 100644
--- a/tests/neg/coretologic.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module CoreToLog where
-
-import Data.Set
-
--- ISSUE: can we please allow things like `empty` to also
--- appear in type and alias specifications, not just in
--- measures as in `goo` below?
-
-{-@ type IsEmp a = {v:[a] | listElts v = Data.Set.empty } @-}
-
-{-@ foo :: IsEmp Int @-}
-foo :: [Int]
-foo = []
-
-{-@ bar :: IsEmp Int @-}
-bar :: [Int]
-bar = [1]
-
-{-@ measure goo @-}
-goo        :: (Ord a) => [a] -> Set a
-goo []     = empty
-goo (x:xs) = (singleton x) `union` (goo xs)  
diff --git a/tests/neg/csv.hs b/tests/neg/csv.hs
deleted file mode 100644
--- a/tests/neg/csv.hs
+++ /dev/null
@@ -1,38 +0,0 @@
-module CSV () where
-
--- | Using LiquidHaskell for CSV lists
--- c.f. http://www.reddit.com/r/scala/comments/1nhzi2/using_shapelesss_sized_type_to_eliminate_real/
-
-data CSV = Csv { headers :: [String]
-               , rows    :: [[String]]
-               }
-
-{-@ data CSV = Csv { headers :: [String]
-                   , rows    :: [{v:[String] | (len v) = (len headers)}]
-                   }
-  @-}
-
--- Eeks, we missed the column name.
-
-csvBad1 = Csv ["Date"] 
-              [ ["Mon", "1"]
-              , ["Tue", "2"]
-              , ["Wed", "3"] 
-              ]
-
--- Eeks, we missed a column.
-
-csvBad2 = Csv ["Name", "Age"] 
-              [ ["Alice", "32"]
-              , ["Bob"        ]
-              , ["Cris" , "29"] 
-              ]
-                      
--- All is well! 
-
-csvGood = Csv ["Id", "Name", "Days"]
-              [ ["1", "Jan", "31"]
-              , ["2", "Feb", "28"]
-              , ["3", "Mar", "31"]
-              , ["4", "Apr", "30"] 
-              ]
diff --git a/tests/neg/datacon-eq.hs b/tests/neg/datacon-eq.hs
deleted file mode 100644
--- a/tests/neg/datacon-eq.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Blank (foo) where
-
--- This is a blank file.
-
-data G = A | B
-
-{-@ foo :: Int -> {v:G | v = A} @-}
-foo  :: Int -> G
-foo _ = B
-
-
diff --git a/tests/neg/elim-ex-compose.hs b/tests/neg/elim-ex-compose.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-compose.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module ElimExCompose (prop) where
-
-{-@ prop :: x:Nat -> {v:Int | v = x + 5} @-}
-prop :: Int -> Int
-prop = incr . incr . incr . incr
-
-{-@ incr :: dog:Int -> {v:Int | v == dog + 1} @-}
-incr :: Int -> Int
-incr cat = cat + 1
diff --git a/tests/neg/elim-ex-let.hs b/tests/neg/elim-ex-let.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-let.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExLet (prop) where
-
-import LiquidHaskell
-
-[lq| type Nat = {v:Int | 0 <= v} |]
-
-[lq| prop :: a -> Nat |]
-prop _ = let x _ = let y = 0 
-                   in
-                     y - 3
-         in 
-           x () + 2
diff --git a/tests/neg/elim-ex-list.hs b/tests/neg/elim-ex-list.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-list.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExList (prop) where
-
-import LiquidHaskell
-import Prelude hiding (head)
-
---------------------------------------------------------------------------
-[lq| prop :: a -> Even |]
-prop _ = (head ys) - 1
-  where 
-    ys = Cons 1 (Cons 2 (Cons 5 Nil))
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-head :: List a -> a 
-head (Cons x _) = x
-
diff --git a/tests/neg/elim-ex-map-1.hs b/tests/neg/elim-ex-map-1.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-map-1.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop xs = map (+ 2) (map (+ 1) xs)
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/elim-ex-map-2.hs b/tests/neg/elim-ex-map-2.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-map-2.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop = map (+ 2) . map (+ 1)
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/elim-ex-map-3.hs b/tests/neg/elim-ex-map-3.hs
deleted file mode 100644
--- a/tests/neg/elim-ex-map-3.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop = map ((+ 0) . (+ 1))
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/neg/elim000.hs b/tests/neg/elim000.hs
deleted file mode 100644
--- a/tests/neg/elim000.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Poslist () where
-
-{-@ prop2 :: Int -> Nat @-}
-prop2 :: Int -> Int
-prop2 x = numAbsList x
-
-numAbsList = glap numAbs
-
-{-@ glap :: (a -> b) -> a -> b @-}
-glap :: (a -> b) -> a -> b
-glap = undefined
-
--- Adding the below signature makes it flag an error...
--- numAbs :: Int -> Int
-numAbs x = if x > 0 then x else x
diff --git a/tests/neg/errmsg.hs b/tests/neg/errmsg.hs
deleted file mode 100644
--- a/tests/neg/errmsg.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-{-@ LIQUID "--short-names" @-}
-
-module Goo where
-
-import Data.Set
-
-{- the "error message" is garbled thanks to all the ill-formatted
-   "Eq [Contravariant]" stuff. Can we remove it, or at least NOT show
-   it when running in --short-names mode. -}
-
-{-@ foo :: (Eq a) => x:a -> xs:[a] -> {v:Bool | v <=> (Data.Set.member x (Data.Set.fromList xs))} @-}
-foo          :: (Eq a) => a -> [a] -> Bool
-foo x (y:ys) = x == y || elem x ys
-foo _ []     = False
-
-{-@ measure elements @-}
-elements  []    = empty
-elements (x:xs) = singleton x `union` elements xs
-
-{- append :: xs:_ -> ys:_ -> {v:_ | elements v = union (elements xs) (elements ys) }@-}
-append :: [a] -> [a] -> [a]
-append = undefined 
-
diff --git a/tests/neg/errorloc.hs b/tests/neg/errorloc.hs
deleted file mode 100644
--- a/tests/neg/errorloc.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ zoo :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
-zoo   :: Int -> Int -> Int 
-zoo x y = liquidAssert (x /= 0) $ x + y 
-
-
-foo = zoo (-1) (-2)
-
diff --git a/tests/neg/ex0-unsafe.hs b/tests/neg/ex0-unsafe.hs
deleted file mode 100644
--- a/tests/neg/ex0-unsafe.hs
+++ /dev/null
@@ -1,28 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Ex () where
-
--- Testing "existential-types"
-
-{-@ foldN :: forall a <p :: x0000:Int -> x1111:a -> Bool>. 
-                (i:Int -> a<p i> -> a<p (i+1)>)
-              -> n:{v: Int | v >= 0}
-              -> a <p 0>
-              -> a <p n>
-  @-}
-
-foldN :: (Int -> a -> a) -> Int -> a -> a
-foldN f n = go 0
-  where go i x | i < n     = go (i+1) (f i x)
-               | otherwise = x
-
-
-fooBar :: (Int -> a -> a) -> Int -> a -> a
-fooBar f n = go 0
-  where go i x | i < n     = go (i+1) (f i x)
-               | otherwise = x
-
-
-{-@ count :: m: {v: Int | v > 0 } -> {v: Int | v = 44 } @-}
-count :: Int -> Int
-count m = foldN (\_ n -> n + 1) m 0
--- count m = fooBar (\_ n -> n + 1) m 0
diff --git a/tests/neg/ex1-unsafe.hs b/tests/neg/ex1-unsafe.hs
deleted file mode 100644
--- a/tests/neg/ex1-unsafe.hs
+++ /dev/null
@@ -1,65 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-
--- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
-
-module Ex () where
-
--------------------------------------------------------------------------
--- | Data types ---------------------------------------------------------
--------------------------------------------------------------------------
-
-data Vec a = Nil | Cons a (Vec a)
-
--- | We can encode the notion of length as an inductive measure @llen@
-
-{-@ measure llen     :: forall a. Vec a -> Int
-      llen (Nil)       = 0
-      llen (Cons x xs) = 1 + llen(xs)
-  @-}
-
-
--- | As a warmup, lets check that a /real/ length function indeed computes
--- the length of the list.
-
-{-@ sizeOf :: xs:Vec a -> {v: Int | v = llen(xs)} @-}
-sizeOf             :: Vec a -> Int
-sizeOf Nil         = 0
-sizeOf (Cons _ xs) = 1 + sizeOf xs
-
--------------------------------------------------------------------------
--- | Higher-order fold --------------------------------------------------
--------------------------------------------------------------------------
-
--- | Time to roll up the sleeves. Here's a a higher-order @foldr@ function
--- for our `Vec` type. Note that the `op` argument takes an extra /ghost/
--- parameter that will let us properly describe the type of `efoldr`
-
-{-@ efoldr :: forall a b <p :: x0:Vec a -> x1:b -> Bool>. 
-                (xs:Vec a -> x:a -> b <p xs> -> b <p (Ex.Cons x xs)>)
-              -> b <p Ex.Nil>
-              -> ys: Vec a
-              -> b <p ys>
-  @-}
-efoldr :: (Vec a -> a -> b -> b) -> b -> Vec a -> b
-efoldr op b Nil         = b
-efoldr op b (Cons x xs) = op xs x (efoldr op b xs)
-
--------------------------------------------------------------------------
--- | Clients of `efold` -------------------------------------------------
--------------------------------------------------------------------------
-
--- | Finally, lets write a few /client/ functions that use `efoldr` to
--- operate on the `Vec`s.
-
--- | First: Computing the length using `efoldr`
-{-@ size :: xs:Vec a -> {v: Int | v = llen(xs)} @-}
-size :: Vec a -> Int
-size = efoldr (\_ _ n -> n + 1) 0
-
-{-@ suc :: x:Int -> {v: Int | v = x + 1} @-}
-suc :: Int -> Int
-suc x = x + 1
-
--- | Second: Appending two lists using `efoldr`
-{-@ app  :: xs: Vec a -> ys: Vec a -> {v: Vec a | llen(v) = 1 + llen(xs) + llen(ys) } @-}
-app xs ys = efoldr (\_ z zs -> Cons z zs) ys xs
diff --git a/tests/neg/filterAbs.hs b/tests/neg/filterAbs.hs
deleted file mode 100644
--- a/tests/neg/filterAbs.hs
+++ /dev/null
@@ -1,43 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-
-
-
-module Filter where
-
-import Prelude hiding (filter)
-
-{-@ filter :: forall <p :: a -> Bool, q :: a -> Bool -> Bool>.
-                  {y::a, flag :: {v:Bool<q y> | v} |- {v:a | v = y} <: a<p>}
-                  (x:a -> Bool<q x>) -> [a] -> [a<p>]
-  @-}
-
-filter f (x:xs)
-  | f x       = x : filter f xs
-  | otherwise = filter f xs
-filter _ []   = []
-
-{-@ isPos :: x:Int -> {v:Bool | v <=> x > 0} @-}
-isPos :: Int -> Bool
-isPos n = n > 0
-
-
-{-@ isNeg :: x:Int -> {v:Bool | v <=> x < 0} @-}
-isNeg :: Int -> Bool
-isNeg n = n < 0
-
-
--- Now the below *should* work with
--- p := \v   -> 0 < v
--- q := \x v -> v <=> 0 < 0
-
-
-{-@ positives :: [Int] -> [{v:Int | v > 0}] @-}
-positives xs = filter isPos xs
-
-{-@ negatives :: [Int] -> [{v:Int | v < 0}] @-}
-negatives xs = filter isNeg xs
-
-{-@ positivesBAD :: [Int] -> [{v:Int | v < 0}] @-}
-positivesBAD xs = filter isPos xs
-
diff --git a/tests/neg/foldN.hs b/tests/neg/foldN.hs
deleted file mode 100644
--- a/tests/neg/foldN.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Ex () where
-
--- Testing "existential-types"
-
-{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-                (i:Int -> a<p i> -> a<p (i+1)>)
-              -> n:{v: Int | v >= 0}
-              -> a <p 0>
-              -> a <p 42>
-  @-}
-
-foldN :: (Int -> a -> a) -> Int -> a -> a
-foldN f n = go 0
-  where go i x | i < n     = go (i+1) (f i x)
-               | otherwise = x
diff --git a/tests/neg/foldN1.hs b/tests/neg/foldN1.hs
deleted file mode 100644
--- a/tests/neg/foldN1.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Toy  where
-
-{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-                (i:Int -> a<p i> -> a<p (i+1)>)
-              -> n:{v: Int | v >= 0}
-              -> a <p 0>
-              -> {v : a | 0=1}
-  @-}
-
-foldN :: (Int -> a -> a) -> Int -> a -> a
-foldN f n = go 0
-  where go i x | i < n     = go (i+1) (f i x)
-               | otherwise = x
diff --git a/tests/neg/grty0.hs b/tests/neg/grty0.hs
deleted file mode 100644
--- a/tests/neg/grty0.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test () where
-
-{-@ stupid :: Int -> Int @-}
-stupid :: Int -> Int
-stupid x = 0
-
-{-@ myId :: x:a -> {v:a | v = x } @-}
-myId x = x 
-
-{-@ assert single :: a -> {v: [a] | len(v) = 0} @-}
-single x = [x] 
-
-
diff --git a/tests/neg/grty1.hs b/tests/neg/grty1.hs
deleted file mode 100644
--- a/tests/neg/grty1.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-module Foo () where
-
-moo = insert 4 [1, 2, 0]
-
-
-{-@ insert      :: (Ord a) => x:a -> xs: [a]<{\fld v -> (v >= fld)}> -> {v: [a]<{\fld v -> (v >= fld)}> | len(v) = (1 + len(xs)) } @-}
-insert y []                   = [y]
-insert y (x : xs) | y <= x    = y : x : xs 
-                  | otherwise = x : insert y xs
-
-
diff --git a/tests/neg/grty2.hs b/tests/neg/grty2.hs
deleted file mode 100644
--- a/tests/neg/grty2.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Foo () where
-
-moo = insert 4 [1, 2, 3]
-
-{-@ insert      :: (Ord a) => x:a -> xs: [a]<{\fld v -> (v >= fld)}> -> {v: [a]<{\fld v -> (v >= fld)}> | len(v) = (1 + len(xs)) } @-}
-insert y []                            = [y]
-insert y (x : xs) | y > {- <= -} x     = y : x : xs 
-                  | otherwise          = x : insert y xs
-
diff --git a/tests/neg/grty3.hs b/tests/neg/grty3.hs
deleted file mode 100644
--- a/tests/neg/grty3.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Foo () where
-
-
-{-@ choo :: [a] -> {v: Int | v > 0 } @-}
-choo = poo
-
-
-poo :: [a] -> Int 
-poo (x:xs) = poo xs
-poo []     = 0
diff --git a/tests/neg/inc2.hs b/tests/neg/inc2.hs
deleted file mode 100644
--- a/tests/neg/inc2.hs
+++ /dev/null
@@ -1,11 +0,0 @@
--- ISSUE #671
---
--- | ISSUE would be nice to have error reported at `x-1` and NOT the `inc`
---   note that the right place gets shown if you comment out the `inc 0 = 1`
-
-module Inc where
-
-{-@ inc :: x:Int -> {v:Int | v > x} @-}
-inc :: Int -> Int
-inc 0 = 1
-inc x = x - 1
diff --git a/tests/neg/list00.hs b/tests/neg/list00.hs
deleted file mode 100644
--- a/tests/neg/list00.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Vec0 () where
-
-import Language.Haskell.Liquid.Prelude -- hiding (copyList)
-
-copyList zs = zs
-
-xs    = [1] :: [Int]
-ys    = copyList xs
-jhala = head ys
-prop0 = crash (0 == 1) 
diff --git a/tests/neg/listne.hs b/tests/neg/listne.hs
deleted file mode 100644
--- a/tests/neg/listne.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module ListNe where
-
-{-@ type ListNE a = {v:[a] | 0 < len v} @-}
-
-{-@ junkProp :: ListNE Int @-}
-junkProp :: [Int]
-junkProp = []
-
diff --git a/tests/neg/lit.hs b/tests/neg/lit.hs
deleted file mode 100644
--- a/tests/neg/lit.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Lit where
-
-{-@ test :: {v:Int | v == 30} @-}
-test = length "cat"
diff --git a/tests/neg/mapreduce-tiny.hs b/tests/neg/mapreduce-tiny.hs
deleted file mode 100644
--- a/tests/neg/mapreduce-tiny.hs
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-
-
-prop1       = map choo [[True]] -- replace [[1]] with [[]] for UNSAT
-choo (x:xs) = liquidAssertB False
--- choo []     = liquidAssertB False
-
--- import qualified Data.Map as M
--- import Data.List (foldl')
-
---keyvals :: [(Int, Int)]
---keyvals = [(1, 1), (2, 2), (3, 3)]
---
---group :: (Ord k) => [(k, v)] -> M.Map k [v]
---group = foldl' addKV  M.empty
---
---addKV m (k, v) = let boo = liquidAssertB False in M.insert k vs' m
---  where vs' = v : (M.findWithDefault [] k m)
---
---checkNN m = M.foldrWithKey reduceKV False m
---
---reduceKV _ _ acc = liquidAssertB False 
---
---prop = checkNN (group keyvals)
diff --git a/tests/neg/mapreduce.hs b/tests/neg/mapreduce.hs
deleted file mode 100644
--- a/tests/neg/mapreduce.hs
+++ /dev/null
@@ -1,55 +0,0 @@
-
--- RJ: Issues with TypeClasses? Ord?
-
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-import qualified Data.Map as M
-import Data.List (foldl')
-
-----------------------------------------------------------------
---- Step 1: Map each element into key-value list (concatMap) ---
-----------------------------------------------------------------
-
-expand          :: (a -> [(k,v)]) -> [a] -> [(k, v)]
-expand f []     = []
-expand f (x:xs) = (f x) ++ (expand f xs)
-
-----------------------------------------------------------------
---- Step 2: Group By Key ---------------------------------------
-----------------------------------------------------------------
-
-group :: (Ord k) => [(k, v)] -> M.Map k [v]
-group = foldl' addKV  M.empty
-  
-addKV m (k, v) = M.insert k vs' m
-  where vs' = v : (M.findWithDefault [] k m)
-
-----------------------------------------------------------------
---- Step 3: Group By Key ---------------------------------------
-----------------------------------------------------------------
-
-collapse f = M.foldrWithKey reduceKV []
-  where reduceKV k (v:vs) acc = if liquidAssertB False then (k, foldl' f v vs) : acc else acc
-        reduceKV k []     _   = crash False --error $ show (liquidAssertB False)
-
-----------------------------------------------------------------
---- Putting it All Together ------------------------------------
-----------------------------------------------------------------
-
-mapReduce fmap fred = collapse fred . group . expand fmap 
-
-----------------------------------------------------------------
---- "Word Count" -----------------------------------------------
-----------------------------------------------------------------
-
-wordCount  = mapReduce fm plus 
-  where fm = \doc -> [ (w,1) | w <- words doc]
-
-main = putStrLn $ show $ wordCount docs
-  where docs = [ "this is the end"
-               , "go to the end"
-               , "the end is the beginning"]
- 
-
-
diff --git a/tests/neg/maps.hs b/tests/neg/maps.hs
deleted file mode 100644
--- a/tests/neg/maps.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-module Maps where
-
-{-@ prop1 :: x:_ -> y:{_ | y == x} -> TT @-}
-prop1 x y = (z == 10)
-  where
-    m1    = put x 10 emp  
-    m2    = put y 20 m1
-    z     = get x m2
-
-{-@ prop2 :: x:_ -> y:{_ | y == x} -> TT @-}
-prop2 x y = (z == 10)
-  where
-    m1    = put x 10 emp 
-    m2    = put y 20 m1
-    z     = get x m2
-
------------------------------------------------------------------------
-
-data Map k v = M
-
-{-@ embed Map as Map_t @-}
-{-@ measure Map_select :: Map k v -> k -> v @-}
-{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
-
-emp :: Map Int Int
-emp = undefined   
-     
-{-@ get :: k:k -> m:Map k v -> {v:v | v = Map_select m k} @-}
-get :: k -> Map k v -> v
-get = undefined 
-
-{-@ put :: k:k -> v:v -> m:Map k v -> {n:Map k v | n = Map_store m k v} @-}
-put :: k -> v -> Map k v -> Map k v
-put = undefined 
diff --git a/tests/neg/maybe.hs b/tests/neg/maybe.hs
deleted file mode 100644
--- a/tests/neg/maybe.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Foo where
-
-import Data.Maybe
-
-
-foo :: Maybe a -> a
-foo x = fromJust x
diff --git a/tests/neg/meas0.hs b/tests/neg/meas0.hs
deleted file mode 100644
--- a/tests/neg/meas0.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Range () where
-
-import Control.Applicative
-import Language.Haskell.Liquid.Prelude
-
-goo x = []
-
-poo (x:_) = True
-poo ([])  = liquidAssertB False
-
-xs = goo (choose 0)
-
-prop1 = liquidAssertB (poo xs)
diff --git a/tests/neg/meas2.hs b/tests/neg/meas2.hs
deleted file mode 100644
--- a/tests/neg/meas2.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-goo :: a -> Int
-goo _ = 1
-
-bob :: [a] -> Int
---bob [] = 0
---bob (n:ns) = goo ns 
-bob ms = case ms of 
-           []     -> 0
-           (n:ns) -> goo ns 
-
-zs :: [Int]
-zs = [1..100]
-
-prop2 = liquidAssertB (n2 `eq` 0) 
-  where n2 = bob zs
diff --git a/tests/neg/meas3.hs b/tests/neg/meas3.hs
deleted file mode 100644
--- a/tests/neg/meas3.hs
+++ /dev/null
@@ -1,24 +0,0 @@
-module Meas () where
-
-
-import Language.Haskell.Liquid.Prelude
-
---mylen []       = 0
---mylen (_:xs)   = 1 `plus` mylen xs
-
-mylen xs = case xs of 
-             []     -> 0
-             (_:ys) -> 1 `plus` mylen ys
-
-
-zs :: [Int]
-zs = [1..100]
-
-goo :: [dogbert] -> Int
-goo _ = 1
-
-bloo :: [Int] -> Int
-bloo _ = 0
-
-prop1 = liquidAssertB (n1 `eq` 0) 
-  where n1 = mylen zs
diff --git a/tests/neg/meas5.hs b/tests/neg/meas5.hs
deleted file mode 100644
--- a/tests/neg/meas5.hs
+++ /dev/null
@@ -1,41 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ include <len.hquals> @-}
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-
-mymap f []     = []
-mymap f (x:xs) = (f x) : (mymap f xs)
-
-myreverse = go []
-  where go acc (x:xs) = go (x:acc) xs
-        go acc []     = acc
-    
-myapp [] ys     = ys
-myapp (x:xs) ys = x:(myapp xs ys)
-
-zs :: [Int]
-zs = [1..100]
-
-zs' :: [Int]
-zs' = [500..1000]
-
-prop2 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ mymap (+ 1) zs 
-
-prop3 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ myreverse zs 
-
-prop4 = liquidAssertB ((n1 + n2) == n3) 
-  where n1 = mylen zs
-        n2 = mylen zs'
-        n3 = mylen $ myapp zs zs' 
-
-prop5 = zipWith (+) zs (0: myreverse zs)
diff --git a/tests/neg/meas7.hs b/tests/neg/meas7.hs
deleted file mode 100644
--- a/tests/neg/meas7.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-
-module Meas () where
-
--- some tests for the 'expandDefaultCase' trick to case-split 
--- on the "missing" constructors.
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-
-{-@ foo :: [a] -> {v: Int | v = 0} @-}
-foo :: [a] -> Int
-foo zs = case zs of
-           [] -> 0
-           _  -> mylen zs
-
diff --git a/tests/neg/meas9.hs b/tests/neg/meas9.hs
deleted file mode 100644
--- a/tests/neg/meas9.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Meas () where
-
-import Data.Set (Set(..))
-
-{-@ myid :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
-myid []     = []
-myid (x:xs) = x : myid xs
-
-{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | listElts(v) = Set_cup (listElts xs) (listElts xs) } @-}
-myapp :: [a] -> [a] -> [a]
-myapp []     ys = ys
-myapp (x:xs) ys = x : myapp xs ys
-
diff --git a/tests/neg/monad3.hs b/tests/neg/monad3.hs
deleted file mode 100644
--- a/tests/neg/monad3.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude
-
--- gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x >= 0) (x + 1)
-
-
--- decrlist n = n : decrlist (n-1)
-
-xs, ys, zs :: [Int]
-xs = [0, -1]
-ys = gpp xs
-zs = gpp ys
diff --git a/tests/neg/monad4.hs b/tests/neg/monad4.hs
deleted file mode 100644
--- a/tests/neg/monad4.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude
-
--- gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x > 0) (x - 10)
-
-
-incrlist n = n : incrlist (n+1)
-
-xs, ys, zs :: Maybe Int
-xs = Just 9
-ys = gpp xs
-zs = gpp ys
diff --git a/tests/neg/monad5.hs b/tests/neg/monad5.hs
deleted file mode 100644
--- a/tests/neg/monad5.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude
-
--- gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x > 0) (x + 1)
-
-myabs :: Int -> Int
-myabs x | x >= 0     = x
-        | otherwise  = 0-x
-
-posM :: Monad m => m Int
-posM = return $ myabs $ choose 0
-
-
-yM :: Monad m => m Int
-yM = gpp posM
diff --git a/tests/neg/monad6.hs b/tests/neg/monad6.hs
deleted file mode 100644
--- a/tests/neg/monad6.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Foo  where
-
-import Language.Haskell.Liquid.Prelude 
-
-{-@ gpp :: Monad m => m {v:Int|v>=0} -> m {v:Int|v>0} @-}
-gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x >= 0) (x)
diff --git a/tests/neg/monad7.hs b/tests/neg/monad7.hs
deleted file mode 100644
--- a/tests/neg/monad7.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude 
-
-{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
-{-@ gpp :: (Ord a, Monad m) => [a] -> m (OList a) @-}
-gpp :: (Ord a, Monad m) => [a] -> m [a]
-gpp ls = return $ reverse $ insertSort ls
-
-{-@ insertSort :: (Ord a) => xs:[a] -> OList a @-}
-insertSort            :: (Ord a) => [a] -> [a]
-insertSort []         = []
-insertSort (x:xs)     = insert x (insertSort xs) 
-
-insert y []                   = [y]
-insert y (x : xs) | y <= x    = y : x : xs 
-                  | otherwise = x : insert y xs
-
-
-
-
-
diff --git a/tests/neg/mr00.hs b/tests/neg/mr00.hs
deleted file mode 100644
--- a/tests/neg/mr00.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module MapReduce () where
-
-import Language.Haskell.Liquid.Prelude 
-import Data.Map hiding (filter, map, foldl)
-
-baz (v:vs) _ = crash False 
-baz []     _ = crash False
-
-mymap = Data.Map.fromList [('a', [1])]
-
--- Why is this safe
-coll = Data.Map.foldr baz 0 
-prop_safe = coll mymap 
-
--- Oddly, this is unsafe
--- prop_unsafe = Data.Map.foldr baz 0 mymap
diff --git a/tests/neg/multi-pred-app-00.hs b/tests/neg/multi-pred-app-00.hs
deleted file mode 100644
--- a/tests/neg/multi-pred-app-00.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module Blank () where
-
-{-@ bar :: forall < p :: Int -> Bool, q :: Int -> Bool>. Int<p> -> Int<p, q> @-}
-bar :: Int -> Int
-bar x = x
diff --git a/tests/neg/nestedRecursion.hs b/tests/neg/nestedRecursion.hs
deleted file mode 100644
--- a/tests/neg/nestedRecursion.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Map (radicals) where
-
-radicals :: Int -> [a]
-radicals n = [ foo (radicals n) i | i <- [1..]]
-
-foo = undefined
diff --git a/tests/neg/null.hs b/tests/neg/null.hs
deleted file mode 100644
--- a/tests/neg/null.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Foo where
-
-foo :: [Int] -> Int
-foo xs = if null xs then head xs else 0
diff --git a/tests/neg/pair.hs b/tests/neg/pair.hs
deleted file mode 100644
--- a/tests/neg/pair.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-module Pair () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: a -> b -> Bool> = P { pX :: a, pY :: b<p pX> } @-} 
-data Pair a b = P a b
-
-incr x = let p = P x ((x+1)) in p
-chk (P x (y)) = liquidAssertB (x == y)
-prop  = chk $ incr n
-  where n = choose 0
-
-incr2 x =
-  let p1 = (P True (x+1)) in
-  let p2 = P x p1 in
-   p2
-chk2 (P x w) =
-   case w of (P z y) -> liquidAssertB (x == y)
-prop2  = chk2 $ incr2 n
-  where n = choose 0
-
-incr3 x = P x (P True (P 0 (x+1)))
-chk3 (P x (P _(P _ y))) = liquidAssertB (x == y)
-prop3  = chk3 $ incr3 n
-  where n = choose 0
diff --git a/tests/neg/pair0.hs b/tests/neg/pair0.hs
deleted file mode 100644
--- a/tests/neg/pair0.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Pair () where 
-
-import Language.Haskell.Liquid.Prelude 
-
-data Pair a b = P a b
-
-
-incr x = (x, x-1)
-chk (x, y) = liquidAssertB (x <y) 
-prop  = chk $ incr n
-  where n = choose 0
-
-incr2 x = (x, True, x-1)
-chk2 (x, _, y) = liquidAssertB (x <y) 
-prop2  = chk2 $ incr2 n
-  where n = choose 0
-
-incr3 x = (x, (True, (0, x-1)))
-chk3 (x, (_, (_, y))) = liquidAssertB (x <y) 
-prop3  = chk3 $ incr3 n
-  where n = choose 0
diff --git a/tests/neg/pargs.hs b/tests/neg/pargs.hs
deleted file mode 100644
--- a/tests/neg/pargs.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Foo () where
-
-{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-             (i:Int -> a<p i>) -> {v:Int| v=0}
-              -> a <p 1>
-  @-}
-
-foo ::  (Int -> a) -> Int ->  a
-foo f i = f i
diff --git a/tests/neg/pargs1.hs b/tests/neg/pargs1.hs
deleted file mode 100644
--- a/tests/neg/pargs1.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Foo () where
-
-{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-             (i:Int  -> j : Int-> a<p (i)>) ->
-               ii:Int -> jj:Int
-              -> a <p (ii+jj)>
-  @-}
-
-foo ::  (Int -> Int -> a) -> Int -> Int ->  a
-foo f i j = f i j
diff --git a/tests/neg/partial.hs b/tests/neg/partial.hs
deleted file mode 100644
--- a/tests/neg/partial.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test () where
-
-{-@ posPlus :: x:{v: Int | v >= 0} -> {v: Int | v >= x} @-}
-posPlus :: Int -> Int
-posPlus x = if (x > 0) 
-              then 2 + (posPlus (x - 1))
-              else 0
-
-goo = posPlus (-3)
-
-{-@ poo :: x:Int -> {v: Int | v >= x } @-}
-poo x = if x > 0 then posPlus x else x
-
diff --git a/tests/neg/poly0.hs b/tests/neg/poly0.hs
deleted file mode 100644
--- a/tests/neg/poly0.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-myid arg     = arg
-
-----------------------------------------------------------
-
-x = choose 0
-
-prop_id1 = let x'  = myabs x in 
-           let x'' = myid x' in 
-           liquidAssertB (x'' `geq` 0)
-
-prop_id2 = liquidAssertB (x'' `geq` 0)
-  where x'  = myabs x 
-        x'' = myid x' 
-
-prop_id3 = liquidAssertB (x' `geq` 20)
-  where x' = myid $ myabs x 
diff --git a/tests/neg/poly1.hs b/tests/neg/poly1.hs
deleted file mode 100644
--- a/tests/neg/poly1.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-myid2 a b  = a  
-
-----------------------------------------------------------
-
-x =  choose 0
-
-prop_id4 = let x'  = myabs x in 
-           let x'' = myid2 x' [] in 
-           liquidAssertB (x'' `geq` 10)
-
-prop_id5 = liquidAssertB (x'' `geq` 0)
-  where x'  = myabs x 
-        x'' = myid2 x' [] 
diff --git a/tests/neg/poly2-degenerate.hs b/tests/neg/poly2-degenerate.hs
deleted file mode 100644
--- a/tests/neg/poly2-degenerate.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-----------------------------------------------------------
-
-myid3 x y  = y
-
-prop_id6 = liquidAssertB (x' `geq` 10)
-  where x' = myid3 [] $ myabs n 
-        n  = choose 0
-
diff --git a/tests/neg/poly2.hs b/tests/neg/poly2.hs
deleted file mode 100644
--- a/tests/neg/poly2.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-----------------------------------------------------------
-
-myid3 x y  = y
-
-x = choose 0
-
-prop_id6 = liquidAssertB (x' `geq` 10)
-  where x' = myid3 [] $ myabs x 
-
-
diff --git a/tests/neg/polypred.hs b/tests/neg/polypred.hs
deleted file mode 100644
--- a/tests/neg/polypred.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Concat () where
-
-import Language.Haskell.Liquid.Prelude
-
-prop :: Int -> Bool
-prop x = liquidAssertB (x == 0)
-
-foo :: a -> Int
-foo longVarName = choose 20 
-
--- propUNSAFE = prop (foo "ker")
-propSAFE = prop (foo id)
-
diff --git a/tests/neg/poslist.hs b/tests/neg/poslist.hs
deleted file mode 100644
--- a/tests/neg/poslist.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Poslist () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-absList xs = map myabs xs
-
-prop1 = map (liquidAssertB . (`geq` 0)) $ absList $ map choose [1..]
-
-
-numAbs x   = if x > 0 then x else (x)
-
-numAbsList = map numAbs 
-
-prop2      = map (liquidAssertB . (>= 0)) $ numAbsList $ map choose [1..]
diff --git a/tests/neg/pred.hs b/tests/neg/pred.hs
deleted file mode 100644
--- a/tests/neg/pred.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Foo () where
-
-{-@ predicate Gt X Y = (X < Y) @-}
-
-{-@ incr :: x:Int -> {v:Int | Gt v x} @-}
-incr :: Int -> Int
-incr x = x + 1
diff --git a/tests/neg/prune0.hs b/tests/neg/prune0.hs
deleted file mode 100644
--- a/tests/neg/prune0.hs
+++ /dev/null
@@ -1,52 +0,0 @@
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-
-module Prune where
-
-import Prelude hiding (read, length)
-import Control.Monad.Primitive
-import Data.Vector.Generic.Mutable
-
-----------------------------------------------------------------------------
--- LIQUID Specifications ---------------------------------------------------
-----------------------------------------------------------------------------
-
--- | Vector Size Measure
-
-{-@ measure vsize :: forall a. a -> Int @-}
-
--- | Vector Type Aliases
-{-@ type      OkIdx X     = {v:Nat | v < vsize X} @-}
-
--- | Assumed Types for Vector
-
-{-@ assume unsafeRead  
-      :: (PrimMonad m, MVector v a) 
-      => xorp:(v (PrimState m) a) 
-      -> (OkIdx xorp) 
-      -> m a       
-  @-}
-
-yuck xanadu i = if (i > 0) then unsafeRead xanadu i else undefined
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/neg/range.hs b/tests/neg/range.hs
deleted file mode 100644
--- a/tests/neg/range.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Range () where
-
-import Language.Haskell.Liquid.Prelude
-
-range :: Int -> Int -> [Int]
-range i j  
-  | i `lt` j  = i : (range (i `plus` 1) j)
-  | otherwise = []  
-
-sumTo = foldl plus 0 . range 0
-
-n = choose 0 
-m = choose 1
-
-prop_rng1 = map (liquidAssertB . (10 `leq`)) $ range 0 n
-prop_rng2 = map (liquidAssertB . (n `leq`)) $ range n 100
-prop_rng3 = map (liquidAssertB . (n `leq`)) $ range n m
-prop_rng4 = map (liquidAssertB . (`leq` m)) $ range n m 
-prop_rng5 = liquidAssertB ((sumTo n) `geq` 10)
diff --git a/tests/neg/record0.hs b/tests/neg/record0.hs
deleted file mode 100644
--- a/tests/neg/record0.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Rec0 (clone, mk) where
-
-{-@ data LL a = BXYZ { size  :: {v: Int | v > 0 }
-                     , elems :: {v: [a] | (len v) = size }
-                     }
-  @-}
-
-data LL a = BXYZ { size  :: Int
-                 , elems :: [a]
-                 }
-
-{-@ mk :: a -> Int -> LL a @-}
-mk x n = BXYZ n (clone x 0)
-
-{-@ clone :: x:a -> n:Int -> {v:[a]| (len v) = n} @-}
-clone :: a -> Int -> [a]
-clone = undefined 
diff --git a/tests/neg/revshape.hs b/tests/neg/revshape.hs
deleted file mode 100644
--- a/tests/neg/revshape.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-module Shapes () where
- 
--- https://gist.github.com/cartazio/6891549
-
-data Shape = Nil | Cons !Int !Shape 
-
-{-@ measure rank @-}
-rank :: Shape -> Int
-rank (Nil)       = 0
-rank (Cons d ds) = 1 + (rank ds)
-
-{-@ type DIM1 = {v:Shape | (rank v) = 1} @-}
-{-@ type DIM2 = {v:Shape | (rank v) = 2} @-}
-
-{-@ oneDim :: DIM1 @-}
-oneDim = 12 `Cons` Nil
-
-{-@ twoDim :: DIM2 @-}
-twoDim = 2 `Cons` (17 `Cons` Nil)
-
--- clearly an error, is flagged by LiquidHaskell
-{-@ twoDim' :: DIM2 @-}
-twoDim' = 56 `Cons` (2 `Cons` (17 `Cons` Nil))
-
-{-@ reverseShape :: sh:Shape -> {v:Shape | (rank v) = (rank sh)} @-}
-reverseShape shs = go shs Nil 
-    where
-        {-@ go ::  a:Shape -> b:Shape -> {v:Shape | (rank v) = (rank a) + (rank b)} @-}
-        go Nil res            = res   
-        go (Cons ix more) res = go more  (Cons ix res)
- 
-  
diff --git a/tests/neg/risers.hs b/tests/neg/risers.hs
deleted file mode 100644
--- a/tests/neg/risers.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Risers  where
-
-{-@ predicate NonNull X = ((len X) > 0) @-}
-
-{- risers :: (Ord a) => zs:[a] -> {v: [[a]] | ((NonNull zs) => (NonNull v)) } @-} 
-risers []        
-  = []
-risers [x]       
-  = [[x]]
-risers (x:y:etc) 
-  = if x <= y then (x:s):ss else [x]:(s:ss)
-    where (s:ss) = risers [] -- insert partiality (y:etc)
diff --git a/tests/neg/stacks.hs b/tests/neg/stacks.hs
deleted file mode 100644
--- a/tests/neg/stacks.hs
+++ /dev/null
@@ -1,35 +0,0 @@
-module Stacks () where
-
-
-{-@ type DList a = [a]<{\fld v -> (v != fld)}> @-}
-
-{-@ data Stack a = St { focus  :: a    
-                      , up     :: DList {v: a | v != focus}
-                      , down   :: DList {v: a | v != focus}
-                      } 
-  @-}
-
-data Stack a = St { focus  :: !a    
-                  , up     :: ![a] 
-                  , down   :: ![a]
-                  } deriving (Show, Eq)
-
--- All of the below violate the invariant, get liquid to say so!
-
-{-@ bad0 :: a -> Stack a @-}
-bad0   :: a -> Stack a 
-bad0 x = St x [x] []
-
-
-{-@ bad1 :: a -> Stack a @-}
-bad1   :: a -> Stack a 
-bad1 x = St x []  [x]
-
-{-@ bad2 :: Int -> Stack Int @-}
-bad2 :: Int -> Stack Int
-bad2 x = St 0 [x] [x]
-
-{-@ bad3 :: Int -> Stack Int @-}
-bad3 :: Int -> Stack Int
-bad3 x = St x [1] [1] 
-
diff --git a/tests/neg/state0.hs b/tests/neg/state0.hs
deleted file mode 100644
--- a/tests/neg/state0.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module StateMonad () where
-
-type State = Int
-data ST a = S (State -> (a, State))
-{-@ data ST a <p1 :: State -> Bool,
-               p2 :: State -> Bool> 
-     = S (x::(f:State<p1> -> (a, State<p2>)))
-  @-}
-
-{-@ fresh :: ST <{\v -> v>=0}, {\v -> v>=0}> Int @-}
-fresh :: ST Int
-fresh = S $ \n -> (n, n-1)
diff --git a/tests/neg/state00.hs b/tests/neg/state00.hs
deleted file mode 100644
--- a/tests/neg/state00.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module StateMonad () where
-
-type State = Int
-data ST a b = S (a -> (a, b)) | F a
-
-{-@ fresh :: ST Int {v:Int|v>=0} @-}
-fresh :: ST Int Int
-fresh = S $ \n -> (n, n+1)
-
-
diff --git a/tests/neg/string00.hs b/tests/neg/string00.hs
deleted file mode 100644
--- a/tests/neg/string00.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Str0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo = "dog"
-
-prop1 = liquidAssertB (0 == 1)	
-prop2 = liquidAssertB (1 /= 1)
diff --git a/tests/neg/sumPoly.hs b/tests/neg/sumPoly.hs
deleted file mode 100644
--- a/tests/neg/sumPoly.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Toy  where
-
-{-@ sumPoly :: forall <p ::a -> Bool>. (Num a, Ord a) => [a<p>] -> a<p> @-} 
-sumPoly     :: (Num a, Ord a) => [a] -> a
-sumPoly (x:xs) = foldl (+) x xs
-
diff --git a/tests/neg/sumk.hs b/tests/neg/sumk.hs
deleted file mode 100644
--- a/tests/neg/sumk.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Sumk () where
-
-import Language.Haskell.Liquid.Prelude
-
-m   = choose 0
-bot = choose 0
-
-dsum ranjit jhala k =
-  if (ranjit `leq` 0)
-    then k jhala 
-    else dsum (ranjit `minus` 1) (ranjit `plus` jhala) k
-
-prop0 = dsum m bot (\x -> liquidAssertB ((m `plus` bot) `leq` x))
-
-prop1 = liquidAssertB (1 `leq` 0)
-
diff --git a/tests/neg/test00.hs b/tests/neg/test00.hs
deleted file mode 100644
--- a/tests/neg/test00.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x :: Int
-x = choose 0
-
-prop_abs = if x > 0 then baz x else False
-
-baz :: Int -> Bool
-baz z = liquidAssertB (z `geq` 100)
diff --git a/tests/neg/test00a.hs b/tests/neg/test00a.hs
deleted file mode 100644
--- a/tests/neg/test00a.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x = choose 0
-
-prop_abs = if x > 0 then baz x else False
-
-baz z = liquidAssertB (z >= 10)
diff --git a/tests/neg/test00b.hs b/tests/neg/test00b.hs
deleted file mode 100644
--- a/tests/neg/test00b.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x = choose 0
-
-foo ::  Num a => a -> a
-foo x = 0 - x
-
-prop_abs ::  Bool
-prop_abs = if x > 0 then baz (foo x) else False
-
-baz ::  (Num a, Ord a) => a -> Bool
-baz z = liquidAssertB (z > 0)
diff --git a/tests/neg/test00c.hs b/tests/neg/test00c.hs
deleted file mode 100644
--- a/tests/neg/test00c.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test (ok, inc) where
-
-{-@ ok
-      :: Int -> Nat
-  @-}
-ok :: Int -> Int
-ok x = x + 120
-
-{-@ inc :: Int -> Nat @-}
-inc :: Int -> Int
-inc x = x + 10
diff --git a/tests/neg/test1.hs b/tests/neg/test1.hs
deleted file mode 100644
--- a/tests/neg/test1.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Test1 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x = if x `gt` 0 then x else 0 `minus` x
-
-n = choose 0
-
-prop_absf = liquidAssertB ((myabs n) `geq` 4)
diff --git a/tests/neg/test2.hs b/tests/neg/test2.hs
deleted file mode 100644
--- a/tests/neg/test2.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test1 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x = if x `gt` 0 then x else 0 `minus` x
-
-n = choose 0
-
-prop_absf = 
-  let zz = (myabs n) `geq` 4 in
-  liquidAssertB zz
diff --git a/tests/neg/trans.hs b/tests/neg/trans.hs
deleted file mode 100644
--- a/tests/neg/trans.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Tx () where
-
-{-@ assert compre :: xs:[a] -> {v:[(a,a)] | len(v) = len(xs) } @-}
-compre xs = [(x,x) | x <- xs]
-
-{-@ assert transpose :: n: Int -> [{v:[a] | len(v) = n}] -> {v: [[a]] | len(v) > n} @-}
-transpose               :: Int -> [[a]] -> [[a]]
-transpose 0 _              = []
-transpose n ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (n-1) (xs : [ t | (_:t) <- xss]) 
--- transpose []             = []
--- transpose ([]   : xss)   = transpose xss
-
-
diff --git a/tests/neg/truespec.hs b/tests/neg/truespec.hs
deleted file mode 100644
--- a/tests/neg/truespec.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module TrueSpec (foo) where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ foo :: Int -> Int @-}
-foo :: Int -> Int
-foo x = liquidAssert (x > 0) $ x + 1
diff --git a/tests/neg/tyclass0-unsafe.hs b/tests/neg/tyclass0-unsafe.hs
deleted file mode 100644
--- a/tests/neg/tyclass0-unsafe.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Goo (poop) where
-
-class Zog a where
-  zoom :: a -> Int
-
--- Assume the relevant behavior for the method.
-{-@ zoom :: (Zog a) => a -> Int @-}
-
--- Uses the behavior of `zoom`
-{-@ poop :: (Zog a) => a -> Nat @-}
-poop x = zoom x
diff --git a/tests/neg/vector00.hs b/tests/neg/vector00.hs
deleted file mode 100644
--- a/tests/neg/vector00.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Vec0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
-
-xs    = [1,2,3,4] :: [Int]
-vs    = fromList xs
-jhala = vs ! (x + y + z)
-  where x = 2
-        y = 3
-        z = 5
diff --git a/tests/neg/vector0a.hs b/tests/neg/vector0a.hs
deleted file mode 100644
--- a/tests/neg/vector0a.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Vec0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-import Data.Vector hiding(map, concat, zipWith, filter, foldl, foldr, (++))
-
-xs  = [1,2,3,4] :: [Int]
-vs  = fromList xs
-
---prop0 = liquidAssertB (x >= 0)
---        where x = Prelude.head xs
---
---prop1 = liquidAssertB (n > 0)
---        where n = Prelude.length xs
---
---prop2 = liquidAssertB (Data.Vector.length vs > 0)
---prop3 = liquidAssertB (Data.Vector.length vs > 3)
-
-prop6 = crash (0 == 1) 
-x0    = vs ! 0
diff --git a/tests/neg/vector1a.hs b/tests/neg/vector1a.hs
deleted file mode 100644
--- a/tests/neg/vector1a.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module Vec1 () where
-
-import Language.Haskell.Liquid.Prelude
-import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
-
-
--- HA this needs a non-TOP spec due to contravariance...
-foo = (Data.Vector.!) 
-
-for :: Int -> Int -> a -> (Int -> a -> a) -> a
-for lo hi acc f 
-  | lo <= hi   = for (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-dotProd       :: Vector Int -> Vector Int -> Int
-dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
-  where n = Data.Vector.length v1
-
-sumSquare   :: Vector Int -> Int
-sumSquare v = dotProd v v
-
-total = sumSquare $ Data.Vector.fromList [0..100]
diff --git a/tests/neg/vector2.hs b/tests/neg/vector2.hs
deleted file mode 100644
--- a/tests/neg/vector2.hs
+++ /dev/null
@@ -1,67 +0,0 @@
-module Vec0 () where
-
-import Prelude hiding (length)
-import Data.Vector
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-    
-{-@ predicate Lt X Y      = X < Y                         @-}
-{-@ predicate Ge X Y      = not (Lt X Y)                  @-}
-{-@ predicate InBound I A = ((Ge I 0) && (Lt I (vlen A))) @-}
-
-{-@ unsafeLookup :: vec:Vector a 
-                 -> {v: Int | (0 <= v && v < (vlen vec)) } 
-                 -> a @-}
-unsafeLookup vec i = vec ! i
-
-{-@ unsafeLookup' :: vec:Vector a -> {v: Int | (InBound v vec)} -> a @-}
-unsafeLookup' vec i = vec ! i
-
-safeLookup x i 
-  | 0 <= i && i < length x = Just (x ! i)
-  | otherwise              = Nothing 
-
-{-@ absoluteSum   :: Vector Int -> {v: Int | 0 <= v}  @-}
-absoluteSum       :: Vector Int -> Int 
-absoluteSum vec   = if 0 < n then go 0 0 else 0
-  where
-    go acc i 
-      | i /= n    = go (acc + abz (vec ! i)) (i + 1)
-      | otherwise = acc 
-    n             = length vec
-
-abz n = if 0 <= n then n else (0 - n) 
-
-loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
-loop lo hi base f = go base lo
-  where
-    go acc i     
-      | i /= hi   = go (f i acc) (i + 1)
-      | otherwise = acc
-
-incr x = x + 1
-
-zoo = incr 29
-
-{-@ dotProduct :: x:(Vector Int) 
-               -> y:{v: Vector Int | (vlen x) = (vlen x)} 
-               -> Int 
-  @-}
-dotProduct     :: Vector Int -> Vector Int -> Int
-dotProduct x y 
-  = loop 0 (length x) 0 (\index -> (+ (x ! index) * (y ! index))) 
-  -- = error "dotProduct only on equal-sized vectors!"
-
-
-{-@ type SparseVector a N = [({v: Int | (0 <= v && v <= N)}, a)] @-}
-
-{-@ sparseDotProduct :: (Num a) => x:(Vector a) -> (SparseVector a {(vlen x)}) -> a @-}
-sparseDotProduct x y  = go 0 y
-  where 
-    go sum ((i, v) : y') = go (sum + (x ! i) * v) y' 
-    go sum []            = sum
-
-jhala = vs ! (x + y + z)
-  where x = 2
-        y = 3
-        z = 5
-        vs = fromList [1,2,3,4] 
diff --git a/tests/neg/wrap0.hs b/tests/neg/wrap0.hs
deleted file mode 100644
--- a/tests/neg/wrap0.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Wrap0 () where
-
-import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
-
-{-@ data Foo a <p :: a -> Bool> = F (f :: a <p>) @-}
-data Foo a = F a
-
-type IntFoo = Foo Int
-
-{-@ assert flibberty :: (Eq a) => a -> Bool @-}
-flibberty x   = prop x (F x)
-prop x (F y)  = liquidAssertB (x == y)
-
-{-@ assert flibInt :: (Num a, Ord a) => a -> Bool @-}
-flibInt x     = prop1 x (F (x + 1))
-prop1 x (F y) = liquidAssertB (x < y) 
-
-{-@ assert flibXs :: a -> Bool @-}
-flibXs x     = prop2 (F [x, x, x])
-prop2 (F _ ) = liquidError "no!"
-prop2 (F _ ) = True
diff --git a/tests/neg/wrap1.hs b/tests/neg/wrap1.hs
deleted file mode 100644
--- a/tests/neg/wrap1.hs
+++ /dev/null
@@ -1,32 +0,0 @@
-{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
-
-module Wrap0 () where
-
-
-import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
-import Data.Function (on)
-import Data.Ord (comparing)
-
-data WrapType b a = WrapType {getVect :: b, getVal :: a}
-
-instance Eq (WrapType [Double] a) where
-   (==) = (==) `on` getVect
-
-instance Ord (WrapType [Double] a) where
-    compare = comparing getVect
-
-{-@ assert flibXs :: a -> Bool @-}
-flibXs x              = prop1 (WrapType [x, x, x] x)
-prop1 (WrapType [] _) = liquidError "no!"
-prop1 (WrapType _  _) = True
-
-{-@ assert nflibXs :: Int -> a -> Bool @-}
-nflibXs n x           = prop2 n (WrapType nxs x)
-                        where nxs = replicate n x 
-
-prop2 n (WrapType xs _) = liquidAssertB (n > length xs) 
-
-
-
-
-
diff --git a/tests/pos/AVLRJ.hs b/tests/pos/AVLRJ.hs
--- a/tests/pos/AVLRJ.hs
+++ b/tests/pos/AVLRJ.hs
@@ -2,7 +2,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module AVL (Tree, empty, singleton, insert, ht, bFac, balanced) where
+module AVLRJ (Tree, empty, singleton, insert, ht, bFac, balanced) where
 
 -- Basic functions
 data Tree a = Nil | Tree { tKey :: a, tLeft ::Tree a, tRight :: Tree a} deriving Show
diff --git a/tests/pos/Absref_crash.hs b/tests/pos/Absref_crash.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Absref_crash.hs
@@ -0,0 +1,9 @@
+module Absref_crash where
+
+data L a = C (L a)
+
+{-@ data L a <p :: L a -> Bool> = C { xs :: L<p> a } @-}
+
+{-@ lazy foo @-}
+foo :: b -> L a
+foo x = C $ foo x
diff --git a/tests/pos/Absref_crash0.hs b/tests/pos/Absref_crash0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Absref_crash0.hs
@@ -0,0 +1,36 @@
+{-@ LIQUID "--short-names"    @-}
+{-@ LIQUID "--no-warnings"    @-}
+{-@ LIQUID "--no-termination" @-}
+
+
+module Absref_crash0 (insertSort) where
+
+data List a = N | C a (List a)
+
+infixr 9 `C`
+
+{-@ ifoldr :: forall a b <p :: List a -> b -> Bool>. 
+                 (xs:_ -> x:_ -> b<p xs> -> b<p(C x xs)>) 
+               -> b<p N> 
+               -> ys:List a
+               -> b<p ys>                            @-}
+ifoldr :: (List a -> a -> b -> b) -> b -> List a -> b
+ifoldr = undefined
+
+{-@ data List a <p :: a -> a -> Bool> 
+     = N | C {x :: a, xs :: List<p> a<p x>} @-}
+
+{-@ type IncrList a = List <{\x y -> x <= y}> a @-} 
+
+{-@ insert :: a -> IncrList a -> IncrList a @-}
+insert :: a -> List a -> List a
+insert = undefined
+
+{-@ insertSort      :: xs:List a -> {v:IncrList a | true } @-}
+insertSort :: List a -> List a
+insertSort = undefined
+
+
+
+nil :: List a 
+nil = N
diff --git a/tests/pos/Adt0.hs b/tests/pos/Adt0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Adt0.hs
@@ -0,0 +1,10 @@
+module Adt0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+data Pair a = P a Int | D a Bool
+
+
+goo z = P z z
+
+baz = goo 10
diff --git a/tests/pos/AdtList0.hs b/tests/pos/AdtList0.hs
--- a/tests/pos/AdtList0.hs
+++ b/tests/pos/AdtList0.hs
@@ -1,7 +1,7 @@
 
 {-@ LIQUID "--exact-data-cons" @-}
 
-module AdtList where 
+module AdtList0 where
 
 data LL a = Emp | Cons a (LL a) 
 
diff --git a/tests/pos/AdtList1.hs b/tests/pos/AdtList1.hs
--- a/tests/pos/AdtList1.hs
+++ b/tests/pos/AdtList1.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--exact-data-cons" @-}
 
-module AdtList where 
+module AdtList1 where
 
 data LL a = Emp | Cons a (LL a) 
 
diff --git a/tests/pos/AdtList2.hs b/tests/pos/AdtList2.hs
--- a/tests/pos/AdtList2.hs
+++ b/tests/pos/AdtList2.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple"        @-}
 
-module AdtList where 
+module AdtList2 where
 
 data LL a = Emp | Cons a (LL a) 
 
diff --git a/tests/pos/AdtList3.hs b/tests/pos/AdtList3.hs
--- a/tests/pos/AdtList3.hs
+++ b/tests/pos/AdtList3.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--exact-data-cons" @-}
 
-module AdtList where 
+module AdtList3 where
 
 data LL a = Emp | Cons a (LL a) 
 
diff --git a/tests/pos/AdtList4.hs b/tests/pos/AdtList4.hs
--- a/tests/pos/AdtList4.hs
+++ b/tests/pos/AdtList4.hs
@@ -4,7 +4,7 @@
 
 {-@ LIQUID "--exact-data-cons" @-}
 
-module AdtList where 
+module AdtList4 where
 
 data LL a = Emp | Cons a (LL a) 
 
diff --git a/tests/pos/AdtList5.hs b/tests/pos/AdtList5.hs
--- a/tests/pos/AdtList5.hs
+++ b/tests/pos/AdtList5.hs
@@ -4,7 +4,7 @@
 
 {-@ LIQUID "--exact-data-cons" @-}
 
-module AdtList where
+module AdtList5 where
 
 data Zing = ZZ (Int -> ())
 
diff --git a/tests/pos/AdtPeano0.hs b/tests/pos/AdtPeano0.hs
--- a/tests/pos/AdtPeano0.hs
+++ b/tests/pos/AdtPeano0.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exact-data-con" @-}
 {-@ LIQUID "--higherorder"    @-}
 
-module Peano where
+module AdtPeano0 where
 
 -- | The code currently works if we add the below, but thats icky.
 --   First, lets get this file to work _without_ the below.
diff --git a/tests/pos/AdtPeano1.hs b/tests/pos/AdtPeano1.hs
--- a/tests/pos/AdtPeano1.hs
+++ b/tests/pos/AdtPeano1.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exact-data-con"                      @-}
 {-@ LIQUID "--higherorder"                         @-}
 
-module Peano where
+module AdtPeano1 where
 
 data Influx = Silly { goo :: Int }
 
diff --git a/tests/pos/Alias00.hs b/tests/pos/Alias00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Alias00.hs
@@ -0,0 +1,12 @@
+module Alias00 () where
+
+{-@ type PosInt = {v: Int | v >= 0} @-}
+
+{-@ assert myabs :: Int -> PosInt @-}
+myabs   :: Int -> Int
+myabs x = if (x > 0) then x else (0 - x)
+
+{-@ type NNList a = {v: [a] | len v > 0} @-}
+
+{-@ assert single :: a -> NNList a @-}
+single x = [x] 
diff --git a/tests/pos/Alias01.hs b/tests/pos/Alias01.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Alias01.hs
@@ -0,0 +1,14 @@
+module Alias01 () where
+
+{-@ type GeNum a N = {v: a | N <= v} @-}
+
+{-@ type PosInt = GeNum Int {0} @-}
+
+{-@ myabs :: Int -> PosInt @-}
+myabs :: Int -> Int
+myabs x = if (x > 0) then x else (0 - x)
+
+{-@ incr :: x:Int -> GeNum Int {x} @-}
+incr :: Int -> Int
+incr x = x + 1
+
diff --git a/tests/pos/Alphaconvert_List.hs b/tests/pos/Alphaconvert_List.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Alphaconvert_List.hs
@@ -0,0 +1,140 @@
+{-@ LIQUID "--pruneunsorted" @-}
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+{-@ LIQUID "--fullcheck"      @-}
+{-@ LIQUID "--maxparams=3"    @-}
+
+-- | An example from "A Relational Framework for Higher-Order Shape Analysis",
+--   by Gowtham Kaki Suresh Jagannathan, ICFP 2014.
+
+module Alphaconvert_List (subst, alpha, isAbs, maxs) where
+
+import Prelude hiding ((++), elem)
+import qualified Data.Set as S
+import Language.Haskell.Liquid.Prelude
+
+alpha  :: [Bndr] -> Expr -> Expr
+subst  :: Expr -> Bndr -> Expr -> Expr
+lemma1 :: Int -> [Int] -> Bool
+fresh  :: [Bndr] -> Bndr
+free   :: Expr -> [Bndr]
+
+---------------------------------------------------------------------
+-- | Datatype Definition --------------------------------------------
+---------------------------------------------------------------------
+
+type Bndr
+  = Int
+
+data Expr
+  = Var Bndr
+  | Abs Bndr Expr
+  | App Expr Expr
+
+{-@ measure fv @-}
+fv :: Expr -> S.Set Bndr
+fv (Var x)   = S.singleton x
+fv (Abs x e) = S.difference (fv e) (S.singleton x)
+fv (App e a) = S.union (fv e) (fv a)
+
+{-@ measure isAbs  @-}
+isAbs :: Expr -> Bool
+isAbs (Abs v e)  = True
+isAbs (Var v)    = False
+isAbs (App e a)  = False
+
+{-@ predicate AddV E E2 X E1   = fv E = Set_cup (Set_dif (fv E2) (Set_sng X)) (fv E1) @-}
+{-@ predicate EqV E1 E2        = fv E1 = fv E2                                        @-}
+{-@ predicate Occ X E          = Set_mem X (fv E)                                     @-}
+{-@ predicate Subst E E1 X E2  = if (Occ X E2) then (AddV E E2 X E1) else (EqV E E2)  @-}
+
+----------------------------------------------------------------------------
+-- | Part 5: Capture Avoiding Substitution ---------------------------------
+----------------------------------------------------------------------------
+{-@ subst :: e1:Expr -> x:Bndr -> e2:Expr -> {e:Expr | Subst e e1 x e2} @-}
+----------------------------------------------------------------------------
+
+subst e1 x e2@(Var y)
+  | x == y                = e1
+  | otherwise             = e2
+
+subst e1 x (App ea eb)    = App ea' eb'
+  where
+    ea'                   = subst e1 x ea
+    eb'                   = subst e1 x eb
+
+subst e1 x e2@(Abs y e)
+  | x == y                = e2
+  | y `elem` xs           = subst e1 x (alpha xs e2)
+  | otherwise             = Abs y      (subst e1 x e)
+     where
+      xs                  = free e1
+
+----------------------------------------------------------------------------
+-- | Part 4: Alpha Conversion ----------------------------------------------
+----------------------------------------------------------------------------
+{-@ alpha :: ys:[Bndr] -> e:{Expr | isAbs e} -> {v:Expr | EqV v e} @-}
+----------------------------------------------------------------------------
+alpha ys (Abs x e) = Abs x' (subst (Var x') x e)
+  where
+    xs             = free e
+    x'             = fresh (x : ys ++ xs)
+
+alpha _  _         = liquidError "never"
+
+
+----------------------------------------------------------------------------
+-- | Part 3: Fresh Variables -----------------------------------------------
+----------------------------------------------------------------------------
+{-@ fresh :: xs:[Bndr] -> {v:Bndr | NotElem v xs} @-}
+----------------------------------------------------------------------------
+fresh bs = liquidAssert (lemma1 n bs) n
+  where
+    n    = 1 + maxs bs
+
+{-@ measure maxs @-}
+maxs   :: [Int] -> Int
+maxs ([])   = 0
+maxs (x:xs) = if (x > maxs xs) then x else (maxs xs)
+
+{-@ lemma1 :: x:Int -> xs:{[Int] | x > maxs xs} -> {v:Bool | v && NotElem x xs} @-}
+lemma1 _ []     = True
+lemma1 x (_:ys) = lemma1 x ys
+
+
+----------------------------------------------------------------------------
+-- | Part 2: Free Variables ------------------------------------------------
+----------------------------------------------------------------------------
+
+----------------------------------------------------------------------------
+{-@ free         :: e:Expr -> {v:[Bndr] | elts v = fv e} @-}
+----------------------------------------------------------------------------
+free (Var x)     = [x]
+free (App e e')  = free e ++ free e'
+free (Abs x e)   = free e \\ x
+
+
+----------------------------------------------------------------------------
+-- | Part I: Sets with Lists -----------------------------------------------
+----------------------------------------------------------------------------
+
+{-@ predicate IsCup X Y Z  = elts X = Set_cup (elts Y) (elts Z)    @-}
+{-@ predicate IsDel X Y Z  = elts X = Set_dif (elts Y) (Set_sng Z) @-}
+{-@ predicate Elem  X Ys   = Set_mem X (elts Ys)                   @-}
+{-@ predicate NotElem X Ys = not (Elem X Ys)                       @-}
+
+{-@ (++)      :: xs:[a] -> ys:[a] -> {v:[a] | IsCup v xs ys}  @-}
+[]     ++ ys  = ys
+(x:xs) ++ ys  = x : (xs ++ ys)
+
+{-@ (\\)      :: (Eq a) => xs:[a] -> y:a -> {v:[a] | IsDel v xs y} @-}
+xs   \\ y     = [x | x <- xs, x /= y]
+
+{-@ elem      :: (Eq a) => x:a -> ys:[a] -> {v:Bool | v <=> Elem x ys} @-}
+elem x []     = False
+elem x (y:ys) = x == y || elem x ys
+
+{-@ measure elts @-}
+elts :: (Ord a) => [a] -> S.Set a
+elts []     = S.empty
+elts (x:xs) = S.union (S.singleton x) (elts xs)
diff --git a/tests/pos/Alphaconvert_Set.hs b/tests/pos/Alphaconvert_Set.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Alphaconvert_Set.hs
@@ -0,0 +1,101 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+{-@ LIQUID "--fullcheck"      @-}
+{-@ LIQUID "--maxparams=3"    @-}
+
+module Alphaconvert_Set (isAbs, subst) where
+
+import qualified Data.Set as S
+
+import Language.Haskell.Liquid.Prelude
+
+freshS  :: S.Set Bndr -> Bndr
+alpha   :: S.Set Bndr -> Expr -> Expr
+subst   :: Expr -> Bndr -> Expr -> Expr
+free    :: Expr -> S.Set Bndr
+
+
+---------------------------------------------------------------------
+-- | Datatype Definition --------------------------------------------
+---------------------------------------------------------------------
+
+type Bndr
+  = Int
+
+data Expr
+  = Var Bndr
+  | Abs Bndr Expr
+  | App Expr Expr
+
+{-@ measure fv @-}
+fv :: Expr -> S.Set Bndr
+fv (Var x)   = S.singleton x
+fv (Abs x e) = S.difference (fv e) (S.singleton x)
+fv (App e a) = S.union (fv e) (fv a)
+
+{-@ measure isAbs @-}
+isAbs (Var v)    = False
+isAbs (Abs v e)  = True
+isAbs (App e a)  = False
+
+{-@ predicate Elem  X Ys       = Set_mem X Ys               @-}
+{-@ predicate NotElem X Ys     = not (Elem X Ys)            @-}
+{-@ predicate AddV E E2 X E1   = fv E = Set_cup (Set_dif (fv E2) (Set_sng X)) (fv E1) @-}
+{-@ predicate EqV E1 E2        = fv E1 = fv E2                                        @-}
+{-@ predicate Occ X E          = Set_mem X (fv E)                                     @-}
+{-@ predicate Subst E E1 X E2  = if (Occ X E2) then (AddV E E2 X E1) else (EqV E E2)  @-}
+
+----------------------------------------------------------------------------
+-- | Part 5: Capture Avoiding Substitution ---------------------------------
+----------------------------------------------------------------------------
+{-@ subst :: e1:Expr -> x:Bndr -> e2:Expr -> {e:Expr | Subst e e1 x e2} @-}
+----------------------------------------------------------------------------
+
+subst e' x e@(Var y)
+  | x == y                = e'
+  | otherwise             = e
+
+subst e' x (App ea eb)    = App ea' eb'
+  where
+    ea'                   = subst e' x ea
+    eb'                   = subst e' x eb
+
+subst e1 x e2@(Abs y e)
+  | x == y                = e2
+  | y `S.member` xs       = subst e1 x (alpha xs e2)
+  | otherwise             = Abs y (subst e1 x e)
+    where
+      xs                  = free e1
+
+----------------------------------------------------------------------------
+-- | Part 4: Alpha Conversion ----------------------------------------------
+----------------------------------------------------------------------------
+{-@ alpha :: ys:(S.Set Bndr) -> e:{Expr | isAbs e} -> {v:Expr | EqV v e} @-}
+----------------------------------------------------------------------------
+alpha ys (Abs x e) = Abs x' (subst (Var x') x e)
+  where
+    xs             = free e
+    x'             = freshS zs
+    zs             = S.insert x (S.union ys xs)
+
+alpha _  _         = liquidError "never"
+
+
+----------------------------------------------------------------------------
+-- | Part 3: Fresh Variables -----------------------------------------------
+----------------------------------------------------------------------------
+{-@ freshS :: xs:(S.Set Bndr) -> {v:Bndr | NotElem v xs} @-}
+----------------------------------------------------------------------------
+freshS xs = undefined
+
+
+----------------------------------------------------------------------------
+-- | Part 2: Free Variables ------------------------------------------------
+----------------------------------------------------------------------------
+
+----------------------------------------------------------------------------
+{-@ free         :: e:Expr -> {v : S.Set Bndr | v = fv e} @-}
+----------------------------------------------------------------------------
+free (Var x)     = S.singleton x
+free (App e e')  = S.union  (free e) (free e')
+free (Abs x e)   = S.delete x (free e)
diff --git a/tests/pos/AmortizedQueue.hs b/tests/pos/AmortizedQueue.hs
--- a/tests/pos/AmortizedQueue.hs
+++ b/tests/pos/AmortizedQueue.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "--maxparams=3"    @-}
 
-module LazyQueue where
+module AmortizedQueue where
 
 -- Source: Okasaki, JFP 1995
 -- http://www.westpoint.edu/eecs/SiteAssets/SitePages/Faculty%20Publication%20Documents/Okasaki/jfp95queue.pdf
diff --git a/tests/pos/Anfbug.hs b/tests/pos/Anfbug.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Anfbug.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--no-termination" @-}
+
+module Anfbug (x,y) where
+
+import Control.Exception (assert)
+
+-- TransformRec BUG: this causes a temporary to get hoisted out of scope
+getTails' :: Int -> [[a]] -> [[a]]
+getTails' n xss = assert (n > 0) [t | (_:t) <- xss]
+
+x = getTails' 1 []
+
+-- HACK give hints for internal variables....
+{- decrease ds_d258 3 @-}
+{- decrease ds_d25g 3 @-}
+
+-- TransformRec BUG: this causes some weird unused variable error (occurrence of DEAD ID)?
+getTails'' :: Int -> [[a]] -> [[a]]
+getTails'' n xss = [t | (_:t) <- xss]
+
+y = getTails'' 1 []
diff --git a/tests/pos/Anftest.hs b/tests/pos/Anftest.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Anftest.hs
@@ -0,0 +1,29 @@
+module Anftest () where
+
+-- xs :: [Int]
+-- xs = let x0 = 0
+--          x1 = 1
+--          x2 = 2
+--          x3 = 3
+--          x4 = 4
+--          x5 = 5
+--          x6 = 6
+--          x7 = 7
+--          x8 = 8
+--          x9 = 9
+--      in [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9]
+
+xs :: [Int]
+xs = let x0 = 0
+         x1 = 1
+     in [x0, x1]
+
+ys :: [Int]
+ys = [y0, y1]
+     where y0 = 0
+           y1 = 1
+
+{-@ incr :: x: Int -> {v: Int | v > x} @-}
+incr :: Int -> Int
+incr y = y + length xs 
+  
diff --git a/tests/pos/Anish1.hs b/tests/pos/Anish1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Anish1.hs
@@ -0,0 +1,13 @@
+module Anish1 () where
+
+inc :: Int -> Int
+inc xoooo = xoooo + 1
+
+test1 :: Int -> Int
+test1 nine = let b = 0 <= nine in
+          if b then
+            let a = inc nine
+            in
+               div nine a
+          else
+            1
diff --git a/tests/pos/AssumedRecursive.hs b/tests/pos/AssumedRecursive.hs
--- a/tests/pos/AssumedRecursive.hs
+++ b/tests/pos/AssumedRecursive.hs
@@ -1,5 +1,6 @@
-module Foo where
+module AssumedRecursive where
 
+{-@ lazy foo @-}
 {-@ assume foo :: a -> a @-}
 foo :: a -> a
 foo f = foo f
diff --git a/tests/pos/AutoTerm.hs b/tests/pos/AutoTerm.hs
--- a/tests/pos/AutoTerm.hs
+++ b/tests/pos/AutoTerm.hs
@@ -1,4 +1,4 @@
-module Isort where
+module AutoTerm where
 
 data SortedList a =
      Mt
diff --git a/tests/pos/AutoTerm1.hs b/tests/pos/AutoTerm1.hs
--- a/tests/pos/AutoTerm1.hs
+++ b/tests/pos/AutoTerm1.hs
@@ -1,4 +1,4 @@
-module Isort where
+module AutoTerm1 where
 
 data F = F | C Int F  
 
diff --git a/tests/pos/BST000.hs b/tests/pos/BST000.hs
--- a/tests/pos/BST000.hs
+++ b/tests/pos/BST000.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--no-totality" @-}
-module BST where
+module BST000 where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/Bag1.hs b/tests/pos/Bag1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Bag1.hs
@@ -0,0 +1,20 @@
+module Bag1 where
+
+import qualified Data.Set as S
+import Language.Haskell.Liquid.Bag as B
+
+{-@ zorg :: {v:B.Bag Int | v = B.empty} @-}
+zorg :: B.Bag Int
+zorg = B.empty
+
+{-@ measure elems @-}
+elems :: (Ord a) => [a] -> B.Bag a
+elems []     = B.empty
+elems (x:xs) = B.put x (elems xs)
+
+{-@ prop0 :: x:_ -> TT @-}
+prop0 :: Int -> Bool
+prop0 x = (B.get x b == 4) 
+  where
+    a   = elems [x, x]
+    b   = B.union a a 
diff --git a/tests/pos/BangPatterns.hs b/tests/pos/BangPatterns.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/BangPatterns.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE BangPatterns #-}
+module BangPatterns where
+
+import Data.IORef
+
+import Language.Haskell.Liquid.Prelude
+
+foo :: IORef a -> IORef a
+{-@ foo :: x:IORef a -> {v:IORef a |  v = x} @-}
+foo !x = x
diff --git a/tests/pos/BinarySearchOverflow.hs b/tests/pos/BinarySearchOverflow.hs
--- a/tests/pos/BinarySearchOverflow.hs
+++ b/tests/pos/BinarySearchOverflow.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--no-termination" @-}
 
-module BinarySearch where
+module BinarySearchOverflow where
 
 import Prelude hiding (Num(..))
 import CheckedNum 
diff --git a/tests/pos/Bool0.hs b/tests/pos/Bool0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Bool0.hs
@@ -0,0 +1,16 @@
+module Bool0 where
+
+{-@ myhead :: {v:[a] | nonEmpty v} -> a @-}
+myhead (x:_) = x
+
+{-@ measure nonEmpty @-}   
+nonEmpty :: [a] -> Bool
+nonEmpty (x:xs) = True 
+nonEmpty []     = False
+
+
+
+
+
+
+
diff --git a/tests/pos/Bool1.hs b/tests/pos/Bool1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Bool1.hs
@@ -0,0 +1,5 @@
+module Bool1 where
+
+{-@ baz :: x:Bool -> {v:Bool | v == x} @-}
+baz :: Bool -> Bool 
+baz x = x 
diff --git a/tests/pos/Bool2.hs b/tests/pos/Bool2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Bool2.hs
@@ -0,0 +1,9 @@
+module Bool2 where
+
+
+{-@ gerb :: (Ord a) => x:a -> {v:a | x <= v } -> {v:a | x <= v} @-}
+gerb :: (Ord a) => a -> a -> a 
+gerb x y = y 
+
+ 
+moo = gerb False False 
diff --git a/tests/pos/Bounds1.hs b/tests/pos/Bounds1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Bounds1.hs
@@ -0,0 +1,14 @@
+module Bounds1 where
+
+{-
+Interesting example as subtyping of bounds is instantiated
+with function types!
+-}
+
+zipWith :: (b -> Char -> a) 
+        -> b -> b -> a
+zipWith f =  (bar . f)
+
+bar :: (Char -> c) -> a -> c
+bar = undefined
+
diff --git a/tests/pos/Case_lambda_join.hs b/tests/pos/Case_lambda_join.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Case_lambda_join.hs
@@ -0,0 +1,27 @@
+{-@ LIQUID "--no-totality" @-}
+{-@ LIQUID "--no-termination"   @-}
+
+module Case_lambda_join where
+
+import Language.Haskell.Liquid.Prelude
+import Data.Set (Set (..))
+
+data RBTree a = Leaf | Node Color a !(RBTree a) !(RBTree a)
+data Color    = B | R deriving (Eq)
+
+{-@ rbalBAD, rbalOK :: k:_ -> l:_ -> r:_ -> {v:_ | Join v k l r} @-}
+rbalBAD x l r = case r of
+  Node R y b (Node R z c d) -> unsafeError "ASD" -- Node R y (Node B x l b) (Node B z c d)
+  Node R z (Node R y b c) d -> Node R y (Node B x l b) (Node B z c d)
+
+rbalOK x l r = case r of
+  -- Node R y b (Node R z c d) -> Node R y (Node B x l b) (Node B z c d)
+  Node R z (Node R y b c) d -> Node R y (Node B x l b) (Node B z c d)
+
+{-@ measure elems :: RBTree a -> (Set a)
+      elems Leaf         = (Set_empty 0)
+      elems (Node c k l r) = (Set_cup (Set_sng k) (Set_cup (elems l) (elems r))) 
+  @-}
+
+{-@ predicate Union V L R  = elems V = Set_cup (elems L) (elems R)                       @-}
+{-@ predicate Join V X L R = elems V = Set_cup (Set_sng X) (Set_cup (elems L) (elems R)) @-}
diff --git a/tests/pos/CasesToLogic.hs b/tests/pos/CasesToLogic.hs
--- a/tests/pos/CasesToLogic.hs
+++ b/tests/pos/CasesToLogic.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exact-data-cons"     @-}
 {-@ LIQUID "--higherorder"        @-}
 
-module StringIndexing where
+module CasesToLogic where
 
 import Prelude hiding (mappend)
 
diff --git a/tests/pos/Cat.hs b/tests/pos/Cat.hs
--- a/tests/pos/Cat.hs
+++ b/tests/pos/Cat.hs
@@ -1,3 +1,4 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-}
 {-@ LIQUID "--no-totality" @-}
 
 {-# LANGUAGE GADTs #-}
@@ -8,9 +9,9 @@
 import Prelude hiding ((.), id)
 
 
-{- 
+{-
 class Category cat where
-  id :: cat a a 
+  id :: cat a a
   (.) :: cat b c -> cat a b -> cat a c
 -}
 
diff --git a/tests/pos/CharLiterals.hs b/tests/pos/CharLiterals.hs
--- a/tests/pos/CharLiterals.hs
+++ b/tests/pos/CharLiterals.hs
@@ -1,5 +1,5 @@
 -- see #1286 
-module Example where
+module CharLiterals where
 
 {-@ fails :: {v:Bool | v} @-}
 fails =  'a' == 'a'
diff --git a/tests/pos/CheckedNum.hs b/tests/pos/CheckedNum.hs
--- a/tests/pos/CheckedNum.hs
+++ b/tests/pos/CheckedNum.hs
@@ -3,22 +3,22 @@
 -- Hiding numeric operations, because they get by default translated to SMT equivalent
 import Prelude hiding (Num(..))
 
-import qualified Prelude as Prelude 
+import qualified Prelude as Prelude
 
-class CheckedNum a where 
-  (+) :: a -> a -> a 
-  (-) :: a -> a -> a 
+class CheckedNum a where
+  (+) :: a -> a -> a
+  (-) :: a -> a -> a
 
 {-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
 
 instance CheckedNum Int where
-{-@ instance CheckedNum Int where 
-      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;  
-      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y} 
+{-@ instance CheckedNum Int where
+      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;
+      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y}
   @-}
-	x - y = (Prelude.-) x y  
+    x - y = (Prelude.-) x y
 
-	x + y = (Prelude.+) x y  
+    x + y = (Prelude.+) x y
 
 
 
diff --git a/tests/pos/CheckedNumLib.hs b/tests/pos/CheckedNumLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/CheckedNumLib.hs
@@ -0,0 +1,24 @@
+module CheckedNumLib where
+
+-- Hiding numeric operations, because they get by default translated to SMT equivalent
+import Prelude hiding (Num(..))
+
+import qualified Prelude as Prelude 
+
+class CheckedNum a where 
+  (+) :: a -> a -> a 
+  (-) :: a -> a -> a 
+
+{-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
+
+instance CheckedNum Int where
+{-@ instance CheckedNum Int where 
+      - :: x:Int -> y:{v:Int | BoundInt (x - v)} -> {v: Int | v == x - y} ;  
+      + :: x:Int -> y:{v:Int | BoundInt (x + v)} -> {v: Int | v == x + y} 
+  @-}
+	x - y = (Prelude.-) x y  
+
+	x + y = (Prelude.+) x y  
+
+
+
diff --git a/tests/pos/Class2.hs b/tests/pos/Class2.hs
--- a/tests/pos/Class2.hs
+++ b/tests/pos/Class2.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE ScopedTypeVariables #-}
 {-@ LIQUID "--no-termination" @-}
-module Class () where
+module Class2 () where
 
 import Language.Haskell.Liquid.Prelude
 import Prelude hiding (sum, length, (!!), Functor(..))
diff --git a/tests/pos/ClassReg.hs b/tests/pos/ClassReg.hs
--- a/tests/pos/ClassReg.hs
+++ b/tests/pos/ClassReg.hs
@@ -1,6 +1,7 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-}
 {-@ LIQUID "--no-totality" @-}
 
-module Compose where
+module ClassReg where
 
 
 data ST s a = ST {runState :: s -> (a,s)}
diff --git a/tests/pos/ClojurVector.hs b/tests/pos/ClojurVector.hs
--- a/tests/pos/ClojurVector.hs
+++ b/tests/pos/ClojurVector.hs
@@ -5,7 +5,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module PVec (height, arrayFor) where
+module ClojurVector (height, arrayFor) where
 
 import qualified Language.Haskell.Liquid.Prelude as Gas
 import qualified Data.Vector as V
diff --git a/tests/pos/Cmptag0.hs b/tests/pos/Cmptag0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Cmptag0.hs
@@ -0,0 +1,13 @@
+module Cmptag0 () where
+
+{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
+
+{-@ foo :: (Ord a) => z:a -> OList a -> [{v:a | z <= v}] @-}
+foo y xs = bar y xs
+
+bar :: (Ord a) => a -> [a] -> [a]
+bar y []     = []
+bar y z@(x:xs) = case compare y x of 
+                   EQ -> xs
+                   GT -> bar y xs
+                   LT -> x:xs
diff --git a/tests/pos/Coercion.hs b/tests/pos/Coercion.hs
--- a/tests/pos/Coercion.hs
+++ b/tests/pos/Coercion.hs
@@ -1,7 +1,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module Encoding where
+module Coercion where
 
 data F a = F a
 data BS = BS (F Int)
diff --git a/tests/pos/Comma.hs b/tests/pos/Comma.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Comma.hs
@@ -0,0 +1,10 @@
+module Comma where
+
+{-@ measure mysnd @-}
+mysnd :: (a, b) -> b
+mysnd (_, y) = y
+
+{-@ foo :: x:Int -> {v:Int | v == x} @-}
+foo :: Int -> Int 
+foo x = mysnd (x, x)
+
diff --git a/tests/pos/CommentedOut.hs b/tests/pos/CommentedOut.hs
--- a/tests/pos/CommentedOut.hs
+++ b/tests/pos/CommentedOut.hs
@@ -1,4 +1,4 @@
-module Nats where 
+module CommentedOut where
 
 {- {-@ nats :: [Nat] @-} -}
 nats :: [Int]
diff --git a/tests/pos/Compare.hs b/tests/pos/Compare.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Compare.hs
@@ -0,0 +1,13 @@
+module Compare () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo x y
+ = case compare x y of 
+    EQ -> liquidAssertB (x == y)
+    LT -> liquidAssertB (x < y)
+    GT -> liquidAssertB (x > y)
+
+prop = foo n m 
+  where n = choose 0
+        m = choose 1
diff --git a/tests/pos/Compare1.hs b/tests/pos/Compare1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Compare1.hs
@@ -0,0 +1,12 @@
+module Compare1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo x y
+ | compare x y == EQ = liquidAssertB (x == y)
+ | compare x y == LT = liquidAssertB (x < y)
+ | compare x y == GT = liquidAssertB (x >  y)
+
+prop = foo n m 
+  where n = choose 0
+        m = choose 1
diff --git a/tests/pos/Compare2.hs b/tests/pos/Compare2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Compare2.hs
@@ -0,0 +1,11 @@
+module Compare2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo x y
+ | compare x y == EQ = liquidAssertB (x == y)
+ | otherwise         = liquidAssertB (True)
+
+prop = foo n m 
+  where n = choose 0
+        m = choose 1
diff --git a/tests/pos/CompareConstraints.hs b/tests/pos/CompareConstraints.hs
--- a/tests/pos/CompareConstraints.hs
+++ b/tests/pos/CompareConstraints.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--no-totality" @-}
-module Foo where
+module CompareConstraints where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/Comprehension.hs b/tests/pos/Comprehension.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Comprehension.hs
@@ -0,0 +1,7 @@
+module Comprehension where
+
+{-@ foo :: n:Int -> [{v:Nat | v <= n}] @-}
+foo :: Int -> [Int]
+foo n = [0 .. n]
+
+{-@ assume GHC.Enum.enumFromTo :: (Enum a) => lo:a -> hi:a -> [{v:a | lo <= v && v <= hi}] @-}
diff --git a/tests/pos/ComprehensionTerm.hs b/tests/pos/ComprehensionTerm.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ComprehensionTerm.hs
@@ -0,0 +1,27 @@
+{-@ LIQUID "--no-termination" @-}
+module ComprehensionTerm (quickSort, foo, qsort) where
+
+-- This is a blank file.
+
+{- foo :: xs:[Int] -> {v:[Int] | (len v) = (len xs)} @-}
+foo :: [Int] -> [Int]
+foo []     = []
+foo (x:xs) = (x+1) : foo [y | y <- xs] 
+
+{- qsort :: (Ord a) => xs:[a] -> {v:[a] | (len v) <= (len xs)} @-}
+qsort []     = []
+qsort (x:xs) = x : qsort [y | y <- xs, y < x]
+
+{-@ quickSort    :: (Ord a) => [a] -> SList a @-}
+quickSort []       = []
+quickSort xs@(x:_) = append x lts gts 
+  where 
+    lts          = quickSort [y | y <- xs, y < x]
+    gts          = quickSort [z | z <- xs, z >= x]
+
+{- append :: k:a -> SList {v:a | v<k} -> SList {v:a | v >= k} -> SList a @-}
+append k []     ys  = k : ys
+append k (x:xs) ys  = x : append k xs ys
+
+{-@ type SList a = [a]<{\x v -> (v >= x)}> @-}
+
diff --git a/tests/pos/Constraints.hs b/tests/pos/Constraints.hs
--- a/tests/pos/Constraints.hs
+++ b/tests/pos/Constraints.hs
@@ -1,4 +1,4 @@
-module Compose where
+module Constraints where
 
 {-@ 
 cmp :: forall < pref :: b -> Bool, postf :: b -> c -> Bool
diff --git a/tests/pos/ConstraintsAppend.hs b/tests/pos/ConstraintsAppend.hs
--- a/tests/pos/ConstraintsAppend.hs
+++ b/tests/pos/ConstraintsAppend.hs
@@ -1,4 +1,4 @@
-module ListSort () where
+module ConstraintsAppend () where
 
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/pos/Coretologic.hs b/tests/pos/Coretologic.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Coretologic.hs
@@ -0,0 +1,18 @@
+module Coretologic where
+
+import Data.Set
+
+-- ISSUE: can we please allow things like `empty` to also
+-- appear in type and alias specifications, not just in
+-- measures as in `goo` below?
+
+{-@ type IsEmp a = {v:[a] | Data.Set.fromList v = Data.Set.empty } @-}
+
+{-@ foo :: IsEmp Int @-}
+foo :: [Int]
+foo = []
+
+{-@ measure goo @-}
+goo        :: (Ord a) => [a] -> Set a
+goo []     = empty
+goo (x:xs) = (singleton x) `union` (goo xs)
diff --git a/tests/pos/CountMonad.hs b/tests/pos/CountMonad.hs
--- a/tests/pos/CountMonad.hs
+++ b/tests/pos/CountMonad.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--no-pattern-inline" @-}
 
-module Count () where
+module CountMonad () where
 
 {-@ measure count :: Count a -> Int @-}
 
@@ -8,7 +8,7 @@
 data Count a = Count a
 
 instance Functor Count where
-	fmap = undefined
+    fmap = undefined
 instance Applicative Count where
   pure  = undefined
   (<*>) = undefined
diff --git a/tests/pos/Csgordon_issue_296.hs b/tests/pos/Csgordon_issue_296.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Csgordon_issue_296.hs
@@ -0,0 +1,6 @@
+module Csgordon_issue_296 where
+
+{-@ measure fwd_extends :: IO () -> IO () -> Bool @-}
+{-@ assume fwd_extends_refl :: m:IO () -> {v:Bool | (fwd_extends m m)} @-}
+fwd_extends_refl :: IO () -> Bool
+fwd_extends_refl = undefined
diff --git a/tests/pos/Cut00.hs b/tests/pos/Cut00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Cut00.hs
@@ -0,0 +1,18 @@
+module Cut00 (foo0) where
+
+{-@ foo0 :: Nat -> Nat @-}
+
+foo0 x = 1 + foo1 x
+foo1 x = 1 + foo2 x
+foo2 x = 1 + foo3 x
+foo3 x = 1 + foo4 x
+foo4 x = 1 + foo5 x
+foo5 x = 1 + foo  x
+
+foo :: Int -> Int
+foo x = 1 + x
+
+bar :: Int -> Int
+bar y = y + 10
+
+-- foo x = 1 + foo (x - 1)
diff --git a/tests/pos/DB00.hs b/tests/pos/DB00.hs
--- a/tests/pos/DB00.hs
+++ b/tests/pos/DB00.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "totality" @-}
 
-module DataBase (values) where
+module DB00 (values) where
 
 {-@ values :: forall <rr2 :: key -> val -> Bool>.
       k:key -> [Dict <rr2> key val]  -> [val<rr2 k>] @-}
diff --git a/tests/pos/Data2.hs b/tests/pos/Data2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Data2.hs
@@ -0,0 +1,25 @@
+module Data2 (prop_rng1, llen) where
+
+import Control.Applicative
+import Language.Haskell.Liquid.Prelude
+
+data LL a = N | C { headC :: a, tailC :: (LL a) }
+{-@ data LL [llen] a = N | C { headC :: a, tailC :: (LL a) } @-}
+
+{-@ measure llen @-}
+llen :: LL a -> Int 
+{-@ llen :: LL a -> Nat @-}
+llen N = 0 
+llen (C _ xs) = 1 + llen xs 
+
+--instance Functor LL where
+--  fmap f N                = N
+--  fmap f (C jhala jhalas) = C (f jhala) (fmap f jhalas)
+
+lmap f N = N
+lmap f (C jhala jhalas) = C (f jhala) (lmap f jhalas)
+
+range :: Int -> Int -> LL Int
+range i j = C i N
+
+prop_rng1 n   = (liquidAssertB . (0 <=)) `lmap` range 0 n
diff --git a/tests/pos/DataConQuals.hs b/tests/pos/DataConQuals.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/DataConQuals.hs
@@ -0,0 +1,27 @@
+module DataConQuals () where
+
+data G = G { gx :: Int, gy :: Int }
+
+
+-- | We should scrape qualifiers from data definitions; why doesn't it happen
+--   "automatically" from the data-con-function signature anyway?
+
+{-@ data G = G { gx :: Int, gy :: {v:Int | v = gx + 5} } @-}
+
+poo :: Int -> Int
+poo n = n + 5
+
+-- | `goo` fails because `poo` doesn't have the type `n -> n + 5` because no qual...
+
+{-@ goo :: {v:Int | v = 105} @-}
+goo :: Int
+goo = poo 100
+
+-- | But `goo` succeeds if we add `chump` into the mix, because
+--   it picks up the qualifers.
+
+{- chump :: z:Int -> {v:Int | v = z + 5} @-}
+chump   :: Int -> Int
+chump z = z + 5
+
+         
diff --git a/tests/pos/Datacon0.hs b/tests/pos/Datacon0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Datacon0.hs
@@ -0,0 +1,29 @@
+module Datacon0 (llen) where
+
+import Language.Haskell.Liquid.Prelude
+
+data Foo a = F a a a 
+
+data LL a = N | C a (LL a)
+
+{-@ data LL [llen] @-} 
+
+
+{-@ measure llen @-}
+llen :: LL a -> Int 
+{-@ llen :: LL a -> Nat @-}
+llen N = 0 
+llen (C _ xs) = 1 + llen xs 
+
+lmap f N = N
+lmap f (C x xs) = C (f x) (lmap f xs)
+
+range :: Int -> Int -> LL Int
+range i j = C i N
+
+n = choose 0
+
+prop_rng1 = (liquidAssertB . (0 <=)) `lmap` range 0 n
+
+--poo :: LL Int
+poo = C (1 :: Int) 
diff --git a/tests/pos/Datacon1.hs b/tests/pos/Datacon1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Datacon1.hs
@@ -0,0 +1,7 @@
+module Datacon1 () where
+
+data Foo a = F a a a 
+
+z :: Foo Int
+z = F 1 2 3 
+
diff --git a/tests/pos/Datacon_inv.hs b/tests/pos/Datacon_inv.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Datacon_inv.hs
@@ -0,0 +1,8 @@
+module Datacon_inv where
+
+data T =  A | B
+
+{-@ invariant {v:T | (v = A || v = B)} @-}
+
+thisIsA = A
+thisIsB = B
diff --git a/tests/pos/Deepmeas0.hs b/tests/pos/Deepmeas0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Deepmeas0.hs
@@ -0,0 +1,29 @@
+{-@ LIQUID "--pruneunsorted" @-}
+module Deepmeas0 () where
+
+import Language.Haskell.Liquid.Prelude (liquidError)
+import Data.Set
+
+{-@ measure getfst :: (a, b) -> a
+      getfst (x, y) = x
+  @-}
+
+{-@ measure keys :: [(k, v)] -> (Set k) 
+      keys []   = {v | Set_emp v }
+      keys (x:xs) = {v | (v = (Set_cup (Set_sng (getfst x)) (keys xs))) }
+  @-}
+
+{-@ getKeys :: kvs:[(a, b)] -> {v:[a] | ((keys kvs) = (listElts v))} @-}
+getKeys []           = [] 
+getKeys ((x,_) : xs) = x : getKeys xs
+
+{-@ klookup :: forall k v. (Eq k) => k:k -> {v: [(k, v)] | (Set_mem k (keys v))} -> v @-}
+
+klookup k ((k',v):kvs)
+  | k == k'          = v
+  | otherwise        = klookup k kvs
+klookup _ []         = liquidError "Never!"
+
+
+
+
diff --git a/tests/pos/DepTriples.hs b/tests/pos/DepTriples.hs
--- a/tests/pos/DepTriples.hs
+++ b/tests/pos/DepTriples.hs
@@ -1,6 +1,4 @@
-module DependentTriples  where
-
-{-@ LIQUID "--savequery" @-}
+module DepTriples where
 
 {-@ type INCR3 = (Int, Int, Int)<{\a b -> a < b}, {\b a c -> b < c }>@-}
 
diff --git a/tests/pos/DependentPairs.hs b/tests/pos/DependentPairs.hs
--- a/tests/pos/DependentPairs.hs
+++ b/tests/pos/DependentPairs.hs
@@ -1,4 +1,4 @@
-module DPairs where
+module DependentPairs where
 
 
 {-@ incrPair :: Int -> (x::Int, {v:Int | x <= v}) @-}
diff --git a/tests/pos/DependentPairsFun.hs b/tests/pos/DependentPairsFun.hs
--- a/tests/pos/DependentPairsFun.hs
+++ b/tests/pos/DependentPairsFun.hs
@@ -1,4 +1,4 @@
-module DPairs where
+module DependentPairsFun where
 
 
 {-@ ex :: (y::Int, () -> {v:() | 0 < y } )
diff --git a/tests/pos/Deptup.hs b/tests/pos/Deptup.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Deptup.hs
@@ -0,0 +1,30 @@
+module Deptup () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
+data Pair a b = P a b
+
+
+{-- TODO: mkP :: forall a b <p :: a -> b -> Bool>. x: a -> y: b<p x> -> Pair <p> a b  --}
+
+mkP :: a -> a -> Pair a a
+mkP x y = P x y
+
+incr x = x + 1
+
+baz x  = mkP x (incr x)
+
+chk (P x y) = liquidAssertB (x < y)
+
+prop = chk $ baz n
+  where n = choose 100
+
+
+bazList  xs = map baz xs
+
+n           = choose 0
+
+xs          = [0,1,2,3,4]
+
+prop_baz    = map chk $ bazList xs
diff --git a/tests/pos/Deptup1.hs b/tests/pos/Deptup1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Deptup1.hs
@@ -0,0 +1,19 @@
+module Deptup1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
+data Pair a b = P a b
+
+incr        :: Int -> Int
+incr x      = x + 1
+
+baz x       = P x (incr x)
+
+bazList xs  = map baz xs
+
+n           = choose 0
+xs          = [0..n]
+
+chk (P x y) = liquidAssertB (x < y)
+prop_baz    = map chk $ bazList xs
diff --git a/tests/pos/Deptup3.hs b/tests/pos/Deptup3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Deptup3.hs
@@ -0,0 +1,19 @@
+module Deptup3 () where
+
+import Language.Haskell.Liquid.Prelude
+
+data Pair a b = P a b
+
+incr :: Int -> Int
+incr x = x + 1
+
+baz    :: Int -> Pair Int Int
+baz x  = P x (incr x)
+
+n :: Int
+n           = choose 0
+
+prop_baz    = chk (baz n)
+
+chk :: Pair Int Int -> Bool
+chk (P x y) = liquidAssertB (x <= y)
diff --git a/tests/pos/DeptupW.hs b/tests/pos/DeptupW.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/DeptupW.hs
@@ -0,0 +1,21 @@
+module DeptupW () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
+data Pair a b = P a b
+
+{-@ mkP :: forall a <q :: y0:a -> y1:a -> Bool>. x: a -> y: a<q x> -> Pair <q> a a @-}
+mkP :: a -> a -> Pair a a
+mkP x y = P x y
+
+incr :: Int -> Int
+incr x = x + 1
+
+baz x = mkP x (incr x)
+
+chk :: Pair Int Int -> Bool
+chk (P x y) = liquidAssertB (x < y)
+
+prop = chk $ baz n
+  where n = choose 100
diff --git a/tests/pos/Div000.hs b/tests/pos/Div000.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Div000.hs
@@ -0,0 +1,11 @@
+module Div000 (bar) where
+
+{-@ mydiv :: Int -> {v:Int | v /= 0} -> Int @-}
+mydiv :: Int -> Int -> Int
+mydiv = undefined
+
+foo :: Int -> Int
+foo _ = 12
+
+bar :: Int -> Int
+bar m = mydiv m z where z = foo m
diff --git a/tests/pos/Dropwhile.hs b/tests/pos/Dropwhile.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Dropwhile.hs
@@ -0,0 +1,82 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--no-totality"    @-}
+
+module Dropwhile where
+
+import Language.Haskell.Liquid.Prelude
+import Prelude hiding (head, dropWhile, (.), filter)
+
+--main :: IO ()
+foo =  
+  if head (dropWhile ((/=) 3) (1:::2:::3:::Emp)) == 3
+     then ()
+     else liquidError "Not going to happen"
+
+-------------------------------------------------------------------------------
+-- | The `head` function returns a value that satisfies the abstract refinement
+-------------------------------------------------------------------------------
+
+{-@ head ::  forall <p :: a -> Bool>. List <p> a -> a<p> @-}
+head (x ::: _) = x
+
+-------------------------------------------------------------------------------
+-- | A List 
+-------------------------------------------------------------------------------
+
+data List a = Emp | (:::) { hd :: a
+                          , tl :: List a }
+infixr 5 :::
+
+-------------------------------------------------------------------------------
+-- | A list whose head satisfies an abstract refinement `p`
+-------------------------------------------------------------------------------
+
+-- in the below, `hd :: a<p>` means the "head" is a value of type `a` that
+-- additionally, satisfies `p hd`.
+
+{-@ data List a <p :: a -> Bool> = Emp
+                                 | (:::) { hd :: a<p>
+                                         , tl :: List a }
+  @-}
+
+-- | e.g. a list whose head equals `3`
+
+{-@ type OneList = List <{\v -> v == 3}> Int @-}
+
+{-@ one :: OneList @-}
+one :: List Int
+one = 3 ::: 2 ::: 1 ::: Emp
+
+-------------------------------------------------------------------------------
+-- | dropWhile some predicate `f` is not satisfied
+-------------------------------------------------------------------------------
+
+{-@ dropWhile :: forall <p :: a -> Bool, w :: a -> Bool -> Bool>.
+                   {y::a, b::{v:Bool<w y> | not v} |- {v:a | v == y} <: a<p>}
+                   (x:a -> Bool<w x>) -> List a -> List <p> a
+  @-}
+dropWhile :: (a -> Bool) -> List a -> List a
+dropWhile f (x:::xs)
+  | not (f x)    = x ::: xs
+  | otherwise    = dropWhile f xs
+dropWhile f Emp  = Emp
+
+-- | This `witness` bound relates the predicate used in dropWhile
+
+{-@ bound witness @-}
+witness :: Eq a => (a -> Bool) -> (a -> Bool -> Bool) -> a -> Bool -> a -> Bool
+witness p w = \ y b v -> (not b) ==> w y b ==> (v == y) ==> p v
+
+-------------------------------------------------------------------------------
+-- | Drop elements until you hit a `3`
+-------------------------------------------------------------------------------
+
+{-@ dropUntilOne' :: List Int -> OneList @-}
+dropUntilOne' :: List Int -> List Int
+dropUntilOne' = dropWhile (/= 3)
+
+-- | Currently needed for the qual; should be made redundant by `--eliminate`
+
+{-@ eqOne :: x:Int -> {v:Bool | v <=> x /= 3} @-}
+eqOne :: Int -> Bool
+eqOne x = x /= 3
diff --git a/tests/pos/Duplicate_bind.hs b/tests/pos/Duplicate_bind.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Duplicate_bind.hs
@@ -0,0 +1,6 @@
+module Duplicate_bind where
+
+import Language.Haskell.Liquid.Prelude
+
+insert key value [] = [(key, value)]
+insert _ _ _        = unsafeError ""
diff --git a/tests/pos/Elements.hs b/tests/pos/Elements.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elements.hs
@@ -0,0 +1,67 @@
+{-@ LIQUID "--pruneunsorted" @-}
+module Elements where
+
+import Prelude hiding (elem)
+
+import Data.Set (Set (..))
+
+{-@ append  :: xs:_ -> ys:_ -> {v:_ | UnElts v xs ys} @-}
+append [] ys     = ys
+append (x:xs) ys = x : append xs ys
+
+
+{-@ reverse :: xs:_ -> {v:_ | EqElts v xs} @-}
+reverse xs           = revAcc xs []
+  where
+   revAcc []     acc = acc
+   revAcc (x:xs) acc = revAcc xs (x:acc)
+
+
+
+{-@ nub :: (Eq a) => xs:_ -> {v:_ | nodups v && EqElts v xs} @-}
+nub xs             = go xs []
+  where
+    go (x:xs) l
+      | x `elem` l = go xs l
+      | otherwise  = go xs (x:l)
+    go [] l        = l
+
+
+{-@ elem :: (Eq a) => x:_ -> ys:_ -> {v:Bool | v <=> Set_mem x (elems ys)} @-}
+elem x []     = False
+elem x (y:ys) = x == y || elem x ys
+
+
+
+{-@ find :: (Eq a) => key:_ -> {map:_ | ValidKey key map} -> b @-}
+find key ((k,v):kvs)
+  | key == k  = v
+  | otherwise = find key kvs
+find _ []     = die "Lookup failed!"
+
+
+{-@ die :: {v:String | false} -> b @-}
+die x = error x
+
+----------------------------------------------------------------------------
+----------------------------------------------------------------------------
+----------------------------------------------------------------------------
+
+{-@ predicate ValidKey K M    = Set_mem K (keys M)                       @-}
+{-@ predicate EqElts Xs Ys    = elems Xs = elems Ys                      @-}
+{-@ predicate UnElts Xs Ys Zs = elems Xs = Set_cup (elems Ys) (elems Zs) @-}
+
+{-@ measure keys  :: [(a, b)] -> (Set a)
+      keys []     = (Set_empty 0)
+      keys (kv:kvs) = (Set_cup (Set_sng (fst kv)) (keys kvs))
+  @-}
+
+{-@ measure elems :: [a] -> (Set a)
+      elems []    = (Set_empty 0)
+      elems (x:xs)  = (Set_cup (Set_sng x) (elems xs))
+  @-}
+
+{-@ measure nodups :: [a] -> Bool
+      nodups []   = true
+      nodups (x:xs) = (not (Set_mem x (elems xs)) && nodups xs)
+  @-}
diff --git a/tests/pos/Elems.hs b/tests/pos/Elems.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elems.hs
@@ -0,0 +1,13 @@
+module Elems where
+
+import qualified Data.Set as S
+
+data T a = T a
+
+{-@ measure elems @-}
+elems       :: T a -> S.Set a
+elems (T a) = S.singleton a
+
+{-@ member :: x:a -> t:T a -> {v:Bool | v <=> S.member x (elems t)} @-}
+member :: a -> T a -> Bool
+member = undefined
diff --git a/tests/pos/Elim00.hs b/tests/pos/Elim00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim00.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--no-totality" @-}
+{-@ LIQUID "--short-names"  @-}
+
+module Elim00 where
+
+data Pair a b = PP a b | Emp
+
+data Foo = Foo { xx :: Int, yy :: Int }
+
+{-@ data Foo = Foo {xx :: Int, yy :: {v:Int | xx < v} }  @-}
+
+foo :: Foo -> Foo
+foo (Foo xig yog) = Foo wink cow
+  where
+    PP wink cow   = PP xig yog
+
diff --git a/tests/pos/Elim01.hs b/tests/pos/Elim01.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim01.hs
@@ -0,0 +1,11 @@
+module Elim01 (bar) where
+
+{-@ bar :: n:{Int | n > 0} -> {v:Int | v = n + 4 } @-}
+bar :: Int -> Int 
+bar n0 = let 
+            n1 = if (n0 == 0) then 0 else 1 + n0
+            n2 = if (n1 == 0) then 0 else 1 + n1
+            n3 = if (n2 == 0) then 0 else 1 + n2
+            n4 = if (n3 == 0) then 0 else 1 + n3
+         in 
+            n4
diff --git a/tests/pos/Elim_ex_compose.hs b/tests/pos/Elim_ex_compose.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_compose.hs
@@ -0,0 +1,11 @@
+-- TAG: absref 
+
+module Elim_ex_compose (prop) where
+
+{-@ prop :: x:Nat -> {v:Int | v = x + 5} @-}
+prop :: Int -> Int
+prop = incr . incr . incr . incr . incr
+
+{-@ incr :: dog:Int -> {v:Int | v == dog + 1} @-}
+incr :: Int -> Int
+incr cat = cat + 1
diff --git a/tests/pos/Elim_ex_let.hs b/tests/pos/Elim_ex_let.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_let.hs
@@ -0,0 +1,15 @@
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_let (prop) where
+
+import LiquidHaskell
+
+[lq| type MyNat = {v:Int | 0 <= v} |]
+
+[lq| prop :: a -> MyNat |]
+prop _ = let x _ = let y = 0 
+                   in
+                     y - 1
+         in 
+           x () + 2
diff --git a/tests/pos/Elim_ex_list.hs b/tests/pos/Elim_ex_list.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_list.hs
@@ -0,0 +1,23 @@
+{-@ LIQUID "--no-totality" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_list (prop) where
+
+import LiquidHaskell
+import Prelude hiding (head)
+
+--------------------------------------------------------------------------
+[lq| prop :: a -> Even |]
+prop _ = (head ys) - 1
+  where 
+    ys = Cons 1 (Cons 3 (Cons 5 Nil))
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+head :: List a -> a 
+head (Cons x _) = x
+
diff --git a/tests/pos/Elim_ex_map_1.hs b/tests/pos/Elim_ex_map_1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_map_1.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_1 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop xs = map (+ 1) (map (+ 1) xs)
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/Elim_ex_map_2.hs b/tests/pos/Elim_ex_map_2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_map_2.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_2 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop = map (+ 1) . map (+ 1)
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/Elim_ex_map_3.hs b/tests/pos/Elim_ex_map_3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Elim_ex_map_3.hs
@@ -0,0 +1,21 @@
+{-@ LIQUID "--no-termination" @-}
+
+{-# LANGUAGE QuasiQuotes #-}
+
+module Elim_ex_map_3 (prop) where
+
+import LiquidHaskell
+
+import Prelude hiding (map)
+
+--------------------------------------------------------------------------
+[lq| prop :: List Even -> List Even |]
+prop = map ((+ 1) . (+ 1))
+--------------------------------------------------------------------------
+
+[lq| type Even = {v:Int | v mod 2 == 0 } |]
+
+data List a = Nil | Cons a (List a)
+
+map f Nil         = Nil
+map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/Eq_poly_measure.hs b/tests/pos/Eq_poly_measure.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Eq_poly_measure.hs
@@ -0,0 +1,14 @@
+module Eq_poly_measure () where
+
+import Language.Haskell.Liquid.Prelude 
+
+{-@ data Thing a = P (unThing :: a) @-} 
+data Thing a = P a
+
+property :: Bool
+property = chk t1 
+  where 
+  chk (P x) = liquidAssertB x 
+
+  t1 :: Thing Bool 
+  t1 = P True 
diff --git a/tests/pos/Eqelems.hs b/tests/pos/Eqelems.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Eqelems.hs
@@ -0,0 +1,14 @@
+module Eqelems where
+
+import qualified Data.Set as S
+
+data T a = T a
+
+{-@ measure elems @-}
+elems       :: T a -> S.Set a
+elems (T a) = S.singleton a
+
+{-@ inline eqelems @-}
+eqelems :: Eq a => T a -> T a -> Bool
+eqelems s t = (elems s) == (elems t)
+         
diff --git a/tests/pos/EvalQuery.hs b/tests/pos/EvalQuery.hs
--- a/tests/pos/EvalQuery.hs
+++ b/tests/pos/EvalQuery.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--no-termination"  @-}
 {-@ LIQUID "--ple" @-}
 
-module Query where
+module EvalQuery where
 
 import Prelude hiding (filter, all)
 
diff --git a/tests/pos/Even.hs b/tests/pos/Even.hs
--- a/tests/pos/Even.hs
+++ b/tests/pos/Even.hs
@@ -1,4 +1,4 @@
-module Even where 
+module Even where
 
 {-@ type Even = {v:Int | v mod 2 = 0} @-}
 
diff --git a/tests/pos/Even0.hs b/tests/pos/Even0.hs
--- a/tests/pos/Even0.hs
+++ b/tests/pos/Even0.hs
@@ -1,4 +1,4 @@
-module Even () where
+module Even0 () where
 
 {-@ isEven :: n:Nat -> Bool / [n, 0]@-}
 {-@ isOdd  :: m:Nat -> Bool / [m, 1] @-}
diff --git a/tests/pos/Ex0.hs b/tests/pos/Ex0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ex0.hs
@@ -0,0 +1,41 @@
+{-@ LIQUID "--pruneunsorted" @-}
+{-@ LIQUID "--no-termination" @-}
+
+module Ex0 where
+
+-- Testing "existential-types"
+
+{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+                (i:Int -> a<p i> -> a<p (i+1)>) 
+              -> n:{v: Int | v >= 0}
+              -> a <p 0> 
+              -> a <p n>
+  @-}
+
+foldN :: (Int -> a -> a) -> Int -> a -> a
+foldN f n = go 0 
+  where 
+    go i x 
+      | i < n     = go (i+1) (f i x)
+      | otherwise = x
+
+{-@ goo :: forall a <pig :: x0:Int -> x1:a -> Bool>. 
+                (i:Int -> a<pig i> -> a<pig (i+1)>) 
+              -> i:{v: Int | 0 <= v}
+              -> n:{v: Int | i <= v}
+              -> a <pig i> 
+              -> a <pig n>
+  @-}
+
+goo :: (Int -> a -> a) -> Int -> Int -> a -> a
+goo f i n x 
+  | i < n     = goo f (i+1) n (f i x) 
+  | otherwise = x
+
+
+
+
+{-@ count :: m: {v: Int | v > 0 } -> {v: Int | v = m} @-}
+count :: Int -> Int
+count m = foldN (\_ n -> n + 1) m 0
+
diff --git a/tests/pos/Ex01.hs b/tests/pos/Ex01.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ex01.hs
@@ -0,0 +1,20 @@
+
+-- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
+
+module Ex01 () where
+
+
+-------------------------------------------------------------------------
+-- | Data types ---------------------------------------------------------
+-------------------------------------------------------------------------
+
+data Vec a = Nil 
+
+{-@ efoldr :: forall b a <p :: x0:Vec a -> x1:b -> Bool>. 
+              b <p Ex01.Nil>
+              -> ys: Vec a
+              -> b <p ys>
+  @-}
+efoldr :: b -> Vec a -> b
+efoldr b Nil         = b
+
diff --git a/tests/pos/Ex1.hs b/tests/pos/Ex1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ex1.hs
@@ -0,0 +1,64 @@
+{-@ LIQUID "--pruneunsorted" @-}
+
+-- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
+
+module Ex1 (llen) where
+
+-------------------------------------------------------------------------
+-- | Data types ---------------------------------------------------------
+-------------------------------------------------------------------------
+
+data Vec a = Nil | Cons a (Vec a)
+
+{-@ data Vec [llen] a = Nil | Cons { vx::a, vxs :: Vec a } @-}
+
+-- | We can encode the notion of length as an inductive measure @llen@
+
+{-@ measure llen @-}
+llen :: Vec a -> Int
+llen (Nil)       = 0
+llen (Cons x xs) = 1 + llen xs
+
+
+-- | As a warmup, lets check that a /real/ length function indeed computes
+-- the length of the list.
+
+{-@ sizeOf :: xs:Vec a -> {v: Int | v = llen xs} @-}
+sizeOf             :: Vec a -> Int
+sizeOf Nil         = 0
+sizeOf (Cons _ xs) = 1 + sizeOf xs
+
+-------------------------------------------------------------------------
+-- | Higher-order fold --------------------------------------------------
+-------------------------------------------------------------------------
+
+-- | Time to roll up the sleeves. Here's a a higher-order @foldr@ function
+-- for our `Vec` type. Note that the `op` argument takes an extra /ghost/
+-- parameter that will let us properly describe the type of `efoldr`
+
+{-@ efoldr :: forall a b <p :: x0:Vec a -> x1:b -> Bool>.
+                (xs:Vec a -> x:a -> b <p xs> -> b <p (Ex1.Cons x xs)>)
+              -> b <p Ex1.Nil>
+              -> ys: Vec a
+              -> b <p ys>
+  @-}
+efoldr :: (Vec a -> a -> b -> b) -> b -> Vec a -> b
+efoldr op b Nil         = b
+efoldr op b (Cons x xs) = op xs x (efoldr op b xs)
+
+-------------------------------------------------------------------------
+-- | Clients of `efold` -------------------------------------------------
+-------------------------------------------------------------------------
+
+-- | Finally, lets write a few /client/ functions that use `efoldr` to
+-- operate on the `Vec`s.
+
+-- | First: Computing the length using `efoldr`
+{-@ size :: xs:Vec a -> {v: Int | v = llen xs} @-}
+size :: Vec a -> Int
+size = efoldr (\_ _ n -> n + 1) 0
+
+-- | Second: Appending two lists using `efoldr`
+{-@ app  :: xs: Vec Int -> ys: Vec Int -> {v: Vec Int | llen v = llen xs + llen ys } @-}
+app :: Vec Int -> Vec Int -> Vec Int
+app xs ys = efoldr (\_ z zs -> Cons z zs) ys xs
diff --git a/tests/pos/ExactGADT.hs b/tests/pos/ExactGADT.hs
--- a/tests/pos/ExactGADT.hs
+++ b/tests/pos/ExactGADT.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE  GADTs #-}
 
-module Query where
+module ExactGADT where
 
 {-@ data Field typ where
         FldX :: Field Int
diff --git a/tests/pos/ExactGADT0.hs b/tests/pos/ExactGADT0.hs
--- a/tests/pos/ExactGADT0.hs
+++ b/tests/pos/ExactGADT0.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--exact-data-con" @-}
 
 
-module Zong where
+module ExactGADT0 where
 
 data Value a where
   VInt  :: Int  -> Value Int
diff --git a/tests/pos/ExactGADT1.hs b/tests/pos/ExactGADT1.hs
--- a/tests/pos/ExactGADT1.hs
+++ b/tests/pos/ExactGADT1.hs
@@ -2,7 +2,7 @@
 
 {-# LANGUAGE  GADTs #-}
 
-module Query where
+module ExactGADT1 where
 
 data Field typ where
   FldX :: Field Int
diff --git a/tests/pos/ExactGADT2.hs b/tests/pos/ExactGADT2.hs
--- a/tests/pos/ExactGADT2.hs
+++ b/tests/pos/ExactGADT2.hs
@@ -2,7 +2,7 @@
 
 {-# LANGUAGE  GADTs #-}
 
-module Query where
+module ExactGADT2 where
 
 {-@ data Field typ where
         FldX :: Field Int
diff --git a/tests/pos/Exp0.hs b/tests/pos/Exp0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Exp0.hs
@@ -0,0 +1,16 @@
+
+-- small test for playing around with exports.
+
+module Exp0 (f) where
+
+import Language.Haskell.Liquid.Prelude
+
+data Goo = G Int
+
+{-@ data Goo = G (x :: {v:Int | v > 0}) @-}
+
+{-@ f :: Goo -> Goo @-} 
+f (G n) 
+  | n > 0     = G (n +  1)
+  | otherwise = liquidError "ad"
+
diff --git a/tests/pos/Extype.hs b/tests/pos/Extype.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Extype.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses #-}
+module Extype where
+
+class Show (layout a) => LayoutClass layout a where
+
+data Layout a = forall l. Layout (l a)
+
+
+readsLayout :: Layout a -> String -> Layout a
+readsLayout (Layout l) s = Layout (asTypeOf undefined l)
+
+type Size = Int
+data Step s a = S s a
+
+data Stream a =
+    forall s. Stream
+    (s -> Step s a)             -- stepper function
+    !s                          -- current state
+    !Size                       -- size hint
+
+
+foo :: Stream a -> Size
+foo (Stream _ _ s) = s
+
+
+stream = Stream (\_ -> S 1 True) 0 0
diff --git a/tests/pos/FFI.hs b/tests/pos/FFI.hs
--- a/tests/pos/FFI.hs
+++ b/tests/pos/FFI.hs
@@ -1,5 +1,5 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
-module Main where
+module FFI where
 
 import Foreign.C.Types
 
diff --git a/tests/pos/Fail.hs b/tests/pos/Fail.hs
--- a/tests/pos/Fail.hs
+++ b/tests/pos/Fail.hs
@@ -1,4 +1,4 @@
-module Fail where 
+module Fail where
 
 {-@ fail incr @-}
 {-@ incr :: x:Int -> {v:Int |  x < v } @-}
diff --git a/tests/pos/FailName.hs b/tests/pos/FailName.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/FailName.hs
@@ -0,0 +1,10 @@
+module FailName where
+
+bar = fail
+  where fail = foo
+        foo = 3 -- undefined
+
+
+bar1 = fail ()
+  where fail = foo
+        foo = undefined
diff --git a/tests/pos/FancyMutualTerm.hs b/tests/pos/FancyMutualTerm.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/FancyMutualTerm.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE GADTs #-}
+module FancyMutualTerm where 
+
+import Language.Haskell.Liquid.This
+
+{-@ measure tsize :: Tree a -> Nat @-}
+{-@ data size (Tree a) tsize @-}
+
+data Tree a where 
+    Leaf :: a -> Tree a 
+    Node :: (Int -> (Tree a)) -> Tree a 
+
+{-@ data Tree a where 
+      Leaf :: a -> {t:Tree a  | tsize t == 0 } 
+      Node :: f:(Int -> Tree a) -> Tree a  @-}
+
+
+{-@ mapTr :: (a -> a) -> t:Tree a -> Tree a / [tsize t, 2] @-}
+mapTr :: (a -> a) -> Tree a -> Tree a 
+mapTr f (Leaf x) = Leaf (f x) 
+mapTr f d@(Node n) = Node (mapTr2 d f n)
+
+
+{-@ mapTr2 :: t:Tree a -> (a -> a) -> (Int -> {tt:Tree a | tsize tt < tsize t }) -> Int -> Tree a / [tsize t, 1] @-} 
+mapTr2 :: Tree a -> (a -> a) -> (Int -> Tree a) -> Int -> Tree a  
+mapTr2 _ f n x = mapTr f (n x)
+
+
diff --git a/tests/pos/FancyTerm.hs b/tests/pos/FancyTerm.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/FancyTerm.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE GADTs #-}
+module FancyTerm where 
+
+
+data Tree a where 
+    Leaf :: a -> Tree a 
+    Node :: (Int -> (Tree a)) -> Tree a 
+
+{-@ measure tsize :: Tree a -> Nat @-}
+{-@ data size (Tree a) tsize @-}
+
+{-@ data Tree a where 
+      Leaf :: a -> {t:Tree a  | tsize t == 0 } 
+      Node :: f:(Int -> Tree a) -> Tree a   @-}
+
+{-@ mapTr :: (a -> a) -> t:Tree a -> o:Tree a / [tsize t] @-}
+mapTr :: (a -> a) -> Tree a -> Tree a 
+mapTr f (Leaf x) = Leaf $ f x 
+mapTr f (Node n) = Node (\x -> mapTr f (n x)) 
+
+
+
+-- With Nat invariant 
+{-@ measure itsize :: ITree a -> Nat @-}
+{-@ data size (ITree a) itsize @-}
+
+data ITree a where 
+    ILeaf :: a -> ITree a 
+    INode :: (Int -> ITree a) -> ITree a 
+
+{-@ data ITree a where 
+      ILeaf :: a -> {t:ITree a  | itsize t == 0 } 
+      INode :: f:(Int -> ITree a) 
+            -> ITree a  @-}
+
+{-@ imapTr :: (a -> a) -> t:ITree a -> o:ITree a / [itsize t] @-}
+imapTr :: (a -> a) -> ITree a -> ITree a 
+imapTr f (ILeaf x) = ILeaf $ f x 
+imapTr f (INode n) = INode (\x -> imapTr f (n x)) 
diff --git a/tests/pos/Fib0.hs b/tests/pos/Fib0.hs
--- a/tests/pos/Fib0.hs
+++ b/tests/pos/Fib0.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--higherorder"                         @-}
 {-@ LIQUID "--ple" @-}
 
-module Fib0 where 
+module Fib0 where
 
 {-@ reflect fibExp @-}
 {-@ fibExp :: Nat -> Nat @-}
diff --git a/tests/pos/FibEq.hs b/tests/pos/FibEq.hs
--- a/tests/pos/FibEq.hs
+++ b/tests/pos/FibEq.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--higherorder"                         @-}
 {-@ LIQUID "--ple" @-}
 
-module FibEq where 
+module FibEq where
 
 fibInv  :: Int -> Int -> () 
 fibLin  :: Int -> Int 
diff --git a/tests/pos/FilterAbs.hs b/tests/pos/FilterAbs.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/FilterAbs.hs
@@ -0,0 +1,45 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+
+
+module FilterAbs where
+
+import Prelude hiding (filter)
+
+{-@ filter :: forall <p :: a -> Bool, q :: a -> Bool -> Bool>.
+                  {y::a, flag::{v:Bool<q y> | v} |- {v:a | v = y} <: a<p>}
+                  (x:a -> Bool<q x>) -> [a] -> [a<p>]
+  @-}
+
+filter :: (a -> Bool) -> [a] -> [a]
+filter f (x:xs)
+  | f x       = x : filter f xs
+  | otherwise = filter f xs
+filter _ []   = []
+
+{-@ isPos :: x:Int -> {v:Bool | v <=> x > 0} @-}
+isPos :: Int -> Bool
+isPos n = n > 0
+
+
+{-@ isNeg :: x:Int -> {v:Bool | v <=> x < 0} @-}
+isNeg :: Int -> Bool
+isNeg n = n < 0
+
+
+-- | `positives` works by instantiating:
+-- p := \v   -> 0 < v
+-- q := \x v -> v <=> 0 < x  (NV ??)
+
+
+{-@ positives :: [Int] -> [{v:Int | v > 0}] @-}
+positives xs = filter isPos xs
+
+
+-- | `negatives` works by instantiating:
+-- p := \v   -> 0 > v
+-- q := \x v -> v <=> x < 0
+
+{-@ negatives :: [Int] -> [{v:Int | v < 0}] @-}
+negatives xs = filter isNeg xs
diff --git a/tests/pos/FingerTree.hs b/tests/pos/FingerTree.hs
--- a/tests/pos/FingerTree.hs
+++ b/tests/pos/FingerTree.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection"     @-}
 {-@ LIQUID "--ple"            @-}
 
-module FingerTree where 
+module FingerTree where
 
 import Language.Haskell.Liquid.ProofCombinators 
 
diff --git a/tests/pos/FoldN.hs b/tests/pos/FoldN.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/FoldN.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--pruneunsorted" @-}
+{-@ LIQUID "--no-termination" @-}
+
+module FoldN () where
+
+-- Testing "existential-types"
+
+{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+                (i:Int -> a<p i> -> a<p (i+1)>) 
+              -> n:{v: Int | v >= 0}
+              -> a <p 0> 
+              -> a <p n>
+  @-}
+
+foldN :: (Int -> a -> a) -> Int -> a -> a
+foldN f n = go 0 
+  where go i x | i < n     = go (i+1) (f i x)
+               | otherwise = x
diff --git a/tests/pos/Foldl.hs b/tests/pos/Foldl.hs
--- a/tests/pos/Foldl.hs
+++ b/tests/pos/Foldl.hs
@@ -1,4 +1,4 @@
-module Fold where
+module Foldl where
 
 {-@ LIQUID "--no-termination" @-}
 import Prelude hiding (foldr)
diff --git a/tests/pos/Foldr.hs b/tests/pos/Foldr.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Foldr.hs
@@ -0,0 +1,10 @@
+module Foldr where
+
+import Language.Haskell.Liquid.Prelude
+import Data.List (foldl')
+
+foo ::  a -> b -> c -> d
+foo = \_ _ _ -> unsafeError "False" 
+
+bar ::  p -> [(q, r)] -> p
+bar = foldr (\(k, v) -> foo k v)
diff --git a/tests/pos/For.hs b/tests/pos/For.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/For.hs
@@ -0,0 +1,32 @@
+module For (prop, prop2, even_, minifac) where
+
+{-@ LIQUID "--no-termination-check" @-}
+
+import Language.Haskell.Liquid.Prelude
+
+even_ arg = if arg == 0 then True else odd_ (arg - 1)
+
+odd_  arg = if arg == 0 then False else even_ (arg - 1)
+
+mmax x y 
+  | x < y     = y
+  | otherwise = x
+
+minifac foobar 
+  | foobar > 1 =  minifac (foobar - 1)
+  | otherwise  =  1
+
+for lo hi acc f 
+  | lo < hi   = for (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+sumRange i j = for i j 0 (+)
+
+prop = liquidAssertB (m >= 0)
+  where m = sumRange 0 k
+        k = choose 0
+
+prop2 = liquidAssertB (z >= x && z >= y)
+  where x = choose 0
+        y = choose 1
+        z = mmax x y
diff --git a/tests/pos/Forloop.hs b/tests/pos/Forloop.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Forloop.hs
@@ -0,0 +1,23 @@
+module Forloop () where
+
+{-@ LIQUID "--no-termination" @-}
+import Language.Haskell.Liquid.Prelude
+
+mmax x y 
+  | x < y     = y
+  | otherwise = x
+
+for lo hi acc f 
+  | lo < hi   = for (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+sumRange i j = for i j 0 (+)
+
+prop = liquidAssertB (m >= 0)
+  where m = sumRange 0 k
+        k = choose 0
+
+prop2 = liquidAssertB (z >= x && z >= y)
+  where x = choose 0
+        y = choose 1
+        z = mmax x y
diff --git a/tests/pos/Fractional.hs b/tests/pos/Fractional.hs
--- a/tests/pos/Fractional.hs
+++ b/tests/pos/Fractional.hs
@@ -1,4 +1,4 @@
-module Fixme where
+module Fractional where
 
 
 {-@ foo :: Fractional a => {v:a | v >= 1.0} @-}
diff --git a/tests/pos/FractionalInstance.hs b/tests/pos/FractionalInstance.hs
--- a/tests/pos/FractionalInstance.hs
+++ b/tests/pos/FractionalInstance.hs
@@ -1,6 +1,7 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-}
 {-@ LIQUID "--no-totality" @-}
 
-module Fractional where
+module FractionalInstance where
 
 data Frac a
 
diff --git a/tests/pos/GadtEval.hs b/tests/pos/GadtEval.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/GadtEval.hs
@@ -0,0 +1,91 @@
+
+module GadtEval () where
+
+import Language.Haskell.Liquid.Prelude (liquidError)
+
+-- "Classic" GADT 
+-- 
+-- data Expr a where
+--   I :: Int -> Expr Int
+--   B :: Bool -> Expr Bool
+--   Eq :: Expr a -> Expr a -> Expr Bool
+--   Pl :: Expr Int -> Expr Int -> Expr Int
+-- 
+-- eval :: Expr a -> a
+-- eval (I i)      = i
+-- eval (B b)      = b
+-- eval (Eq e1 e2) = (eval e1) == (eval e2)
+-- eval (Pl e1 e2) = (eval e1) + (eval e2)
+
+data Ty   = TInt 
+          | TBool
+
+data Expr = I     Int
+          | B     Bool
+          | Equal Expr Expr
+          | Plus  Expr Expr
+          deriving (Eq, Show)
+
+
+{-@ check          :: e:ValidExpr  -> {v:Ty | (v = (eType e))} @-}
+check (I _)        = TInt
+check (B _)        = TBool
+check (Plus e1 e2) = TInt
+check (Equal _ _)  = TBool
+
+{-@ lazy eval @-}
+
+{-@ eval           :: e:ValidExpr  -> {v:ValidExpr | ((isValue v) && (((eType e) = (eType v))))} @-}
+eval e@(I _)       = e
+eval e@(B _)       = e
+eval (Plus e1 e2)  = (eval e1) `plus` (eval e2)
+eval (Equal e1 e2) = (eval e1) `equal` (eval e2)
+
+plus (I i) (I j)   = I (i + j)
+plus _       _     = liquidError "don't worry, its impossible" 
+
+equal (I i) (I j)  = B (i == j)
+equal (B x) (B y)  = B (x == y)
+equal _       _    = liquidError "don't worry, its impossible" 
+
+-- | The next two are silly, for scraping quals. Yuck. Should scrape from measure-DEFS etc.
+
+{-@ toInt :: IntExpr -> Int @-}
+toInt (I i) = i
+toInt _     = liquidError "impossible"
+
+{-@ toBool :: BoolExpr -> Bool @-}
+toBool (B b) = b
+toBool _     = liquidError "impossible"
+
+
+{-@ predicate IsTInt X   = ((eType X) = TInt)  @-}
+{-@ predicate IsTBool X  = ((eType X) = TBool) @-}
+
+
+{-@ type ValidExpr     = {v: Expr | (isValid v)}                @-}
+{-@ type IntExpr       = {v: Expr | ((isValue v) && (IsTInt  v))} @-}
+{-@ type BoolExpr      = {v: Expr | ((isValue v) && (IsTBool v))} @-}
+
+
+{-@ measure isValue       :: Expr -> Bool
+      isValue (I i)         = true
+      isValue (B b)         = true
+      isValue (Equal e1 e2) = false 
+      isValue (Plus e1 e2)  = false
+  @-}  
+
+{-@ measure eType       :: Expr -> Ty 
+      eType (I i)         = TInt  
+      eType (Plus  e1 e2) = TInt 
+      eType (B b)         = TBool 
+      eType (Equal e1 e2) = TBool 
+  @-}
+
+{-@ measure isValid       :: Expr -> Bool
+      isValid (I i)         = true
+      isValid (B b)         = true
+      isValid (Equal e1 e2) = (((eType e1) = (eType e2)) && (isValid e1) && (isValid e2))
+      isValid (Plus e1 e2)  = ((IsTInt e1) && (IsTInt e2) && (isValid e1) && (isValid e2))
+  @-}
+
diff --git a/tests/pos/GeneralizedTermination.hs b/tests/pos/GeneralizedTermination.hs
--- a/tests/pos/GeneralizedTermination.hs
+++ b/tests/pos/GeneralizedTermination.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--no-totality" @-}
-module GenTerm (llen) where
+module GeneralizedTermination (llen) where
 
 import Prelude hiding (reverse)
 
diff --git a/tests/pos/GhcSort1.hs b/tests/pos/GhcSort1.hs
--- a/tests/pos/GhcSort1.hs
+++ b/tests/pos/GhcSort1.hs
@@ -1,10 +1,11 @@
+{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
 {-# Language ScopedTypeVariables   #-}
 {-# Language PartialTypeSignatures #-}
 
 -- TODO: Fix resolve so we can remove this/add termination metrics
 {-@ LIQUID "--no-termination" @-}
 
-module ListSort () where
+module GhcSort1 () where
 
 import Language.Haskell.Liquid.Prelude 
 
diff --git a/tests/pos/GhcSort2.hs b/tests/pos/GhcSort2.hs
--- a/tests/pos/GhcSort2.hs
+++ b/tests/pos/GhcSort2.hs
@@ -1,4 +1,4 @@
-module GhcSort () where
+module GhcSort2 () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/GhcSort3.T.hs b/tests/pos/GhcSort3.T.hs
deleted file mode 100644
--- a/tests/pos/GhcSort3.T.hs
+++ /dev/null
@@ -1,41 +0,0 @@
-module GhcSort () where
-
-{-@ type OList a =  [a]<{\fld v -> (v >= fld)}>  @-}
-
-{-@ assert sort3 :: (Ord a) => w:a -> [{v:a|v<=w}] -> OList a @-}
-sort3 :: (Ord a) => a -> [a] -> [a]
-sort3 w ls = qsort w ls [] (length ls) 0
-
-{-@ decrease qsort 5 6 @-}
-{-@ decrease rqsort 5 6 @-}
-{-@ decrease qpart 8 9 @-}
-{-@ decrease rqpart 8 9 @-}
-qsort :: (Ord a) =>  a -> [a] -> [a] -> Int -> Int -> [a]
-{-@ qsort, rqsort :: (Ord a) =>  w:a -> xs:[{v:a|v<=w}] -> OList {v:a|v>=w} -> {v:Int | v = (len xs) } -> {v:Int | v = 0 } -> OList a @-}
-qsort _ []     r _ _ = r
-qsort _ [x]    r _ _ = x:r
-qsort w (x:xs) r _ _ = qpart w x xs [] [] r (length xs) (length xs + 1)
-
-{-@ qpart, rqpart :: (Ord a) => w:a -> x:{v:a|v<=w} -> xs:[{v:a|v <= w}] -> lt:[{v:a|((v<=x) && (v<=w))}] -> ge:[{v:a|((v >= x) && (v<=w))}] -> rs:(OList {v:a|v >= w}) -> {v:Int | v = ((len xs) + (len lt) + (len ge))} -> {v:Int|v = (len xs) + 1} -> OList a @-}
-qpart :: (Ord a) => a -> a -> [a] -> [a] -> [a] -> [a] -> Int -> Int -> [a]
-qpart w x [] rlt rge r _ _ =
-    rqsort x rlt (x:rqsort w rge r (length rge) 0) (length rlt) 0
-qpart w x (y:ys) rlt rge r d1 d2 =
-    case compare x y of
-        GT -> qpart w x ys (y:rlt) rge r d1 (d2 - 1)
-        _  -> qpart w x ys rlt (y:rge) r d1 (d2 - 1)
-
-{- rqsort :: (Ord a) =>  w:a -> xs:[{v:a|v<=w}] -> OList {v:a|v>=w} -> {v:Int | v = (len xs) } -> {v:Int | v = 0 } -> OList a @-}
-rqsort :: (Ord a) => a -> [a] -> [a] -> Int -> Int -> [a]
-rqsort _ []     r _ _ = r
-rqsort _ [x]    r _ _ = x:r
-rqsort w (x:xs) r _ _ = rqpart w x xs [] [] r (length xs) (length xs + 1)
-
-rqpart :: (Ord a) => a -> a -> [a] -> [a] -> [a] -> [a] -> Int -> Int -> [a]
-rqpart w x [] rle rgt r _ _ =
-    qsort x rle (x:qsort w rgt r (length rgt) 0) (length rle) 0 
-rqpart w x (y:ys) rle rgt r d1 d2 =
-    case compare y x of
-        GT -> rqpart w x ys rle (y:rgt) r d1 (d2-1)
-        _  -> rqpart w x ys (y:rle) rgt r d1 (d2-1)
-
diff --git a/tests/pos/GhcSort3.hs b/tests/pos/GhcSort3.hs
--- a/tests/pos/GhcSort3.hs
+++ b/tests/pos/GhcSort3.hs
@@ -1,4 +1,4 @@
-module GhcSort () where
+module GhcSort3 () where
 
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/pos/GhcSort3_T.hs b/tests/pos/GhcSort3_T.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/GhcSort3_T.hs
@@ -0,0 +1,41 @@
+module GhcSort3_T () where
+
+{-@ type OList a =  [a]<{\fld v -> (v >= fld)}>  @-}
+
+{-@ assert sort3 :: (Ord a) => w:a -> [{v:a|v<=w}] -> OList a @-}
+sort3 :: (Ord a) => a -> [a] -> [a]
+sort3 w ls = qsort w ls [] (length ls) 0
+
+{-@ decrease qsort 5 6 @-}
+{-@ decrease rqsort 5 6 @-}
+{-@ decrease qpart 8 9 @-}
+{-@ decrease rqpart 8 9 @-}
+qsort :: (Ord a) =>  a -> [a] -> [a] -> Int -> Int -> [a]
+{-@ qsort, rqsort :: (Ord a) =>  w:a -> xs:[{v:a|v<=w}] -> OList {v:a|v>=w} -> {v:Int | v = (len xs) } -> {v:Int | v = 0 } -> OList a @-}
+qsort _ []     r _ _ = r
+qsort _ [x]    r _ _ = x:r
+qsort w (x:xs) r _ _ = qpart w x xs [] [] r (length xs) (length xs + 1)
+
+{-@ qpart, rqpart :: (Ord a) => w:a -> x:{v:a|v<=w} -> xs:[{v:a|v <= w}] -> lt:[{v:a|((v<=x) && (v<=w))}] -> ge:[{v:a|((v >= x) && (v<=w))}] -> rs:(OList {v:a|v >= w}) -> {v:Int | v = ((len xs) + (len lt) + (len ge))} -> {v:Int|v = (len xs) + 1} -> OList a @-}
+qpart :: (Ord a) => a -> a -> [a] -> [a] -> [a] -> [a] -> Int -> Int -> [a]
+qpart w x [] rlt rge r _ _ =
+    rqsort x rlt (x:rqsort w rge r (length rge) 0) (length rlt) 0
+qpart w x (y:ys) rlt rge r d1 d2 =
+    case compare x y of
+        GT -> qpart w x ys (y:rlt) rge r d1 (d2 - 1)
+        _  -> qpart w x ys rlt (y:rge) r d1 (d2 - 1)
+
+{- rqsort :: (Ord a) =>  w:a -> xs:[{v:a|v<=w}] -> OList {v:a|v>=w} -> {v:Int | v = (len xs) } -> {v:Int | v = 0 } -> OList a @-}
+rqsort :: (Ord a) => a -> [a] -> [a] -> Int -> Int -> [a]
+rqsort _ []     r _ _ = r
+rqsort _ [x]    r _ _ = x:r
+rqsort w (x:xs) r _ _ = rqpart w x xs [] [] r (length xs) (length xs + 1)
+
+rqpart :: (Ord a) => a -> a -> [a] -> [a] -> [a] -> [a] -> Int -> Int -> [a]
+rqpart w x [] rle rgt r _ _ =
+    qsort x rle (x:qsort w rgt r (length rgt) 0) (length rle) 0 
+rqpart w x (y:ys) rle rgt r d1 d2 =
+    case compare y x of
+        GT -> rqpart w x ys rle (y:rgt) r d1 (d2-1)
+        _  -> rqpart w x ys (y:rle) rgt r d1 (d2-1)
+
diff --git a/tests/pos/Gimme.hs b/tests/pos/Gimme.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Gimme.hs
@@ -0,0 +1,15 @@
+module Gimme () where
+
+import Language.Haskell.Liquid.Prelude
+
+{- qualif Gimme(v:[a], n:int, acc:[a]): (len v == n + 1 + len acc) -}
+
+{-@ gimme :: xs:[a] -> n:Int -> acc:[a] -> {v:[a] | len v = n + 1 + len acc} @-}
+gimme :: [a] -> Int -> [a] -> [a]
+gimme xs (-1) acc  = acc
+gimme (x:xs) n acc = gimme xs (n-1) (x : acc)
+gimme _ _ _        = unsafeError "gimme"
+
+{-@ boober :: n:Int -> Int -> {v:[Int] | (len v) = n} @-}
+boober :: Int -> Int -> [Int]
+boober n y = gimme [y..] (n-1) []
diff --git a/tests/pos/Go.hs b/tests/pos/Go.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Go.hs
@@ -0,0 +1,20 @@
+module Go (poop) where
+
+{-@ invariant {v:Int | v >= 0} @-}
+
+{-@ qualif Sum(v:Int, x: Int, y: Int): v = x + y @-}
+
+{-@ invariant {v:Int | v >= 0} @-}
+
+{-@ foo  :: x:Int -> {v:Int | v = x} @-}
+foo x    = go x 0
+  where 
+    go     :: Int -> Int -> Int 
+    go 0 m = m
+    go n m = go (n-1) (m+1)
+
+
+poop x = foo x 
+
+
+
diff --git a/tests/pos/Go_ugly_type.hs b/tests/pos/Go_ugly_type.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Go_ugly_type.hs
@@ -0,0 +1,13 @@
+module Go_ugly_type where
+
+{- decrease go 2 @-}
+
+{-@ rev :: xs:[a] -> {v: [a] | len v = len xs} @-}
+rev = go [] 
+  where 
+    {-@ go :: acc:_ -> xs:_ -> {v:_ | len v = len acc + len xs} @-}
+    go acc []     = acc
+    go acc (x:xs) = go (x:acc) xs
+
+main :: IO ()
+main = pure ()
diff --git a/tests/pos/GoodHMeas.hs b/tests/pos/GoodHMeas.hs
--- a/tests/pos/GoodHMeas.hs
+++ b/tests/pos/GoodHMeas.hs
@@ -1,3 +1,5 @@
+module GoodHMeas where
+
 {-@ LIQUID "--prune-unsorted" @-}
 
 {-@ measure foo @-}
diff --git a/tests/pos/Grty0.hs b/tests/pos/Grty0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Grty0.hs
@@ -0,0 +1,13 @@
+module Grty0 () where
+
+{-@ stupid :: Int -> Int @-}
+stupid :: Int -> Int
+stupid x = 0
+
+{-@ myId :: x:a -> {v:a | v = x } @-}
+myId x = x 
+
+{-@ assert single :: a -> {v: [a] | len(v) > 0} @-}
+single x = [x] 
+
+
diff --git a/tests/pos/Grty1.hs b/tests/pos/Grty1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Grty1.hs
@@ -0,0 +1,12 @@
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
+module Grty1 () where
+import Language.Haskell.Liquid.Prelude 
+
+{-@ sz :: {v:[a]|((len v) = 1)} -> a @-}
+-- sz (x:xs) = sz xs
+sz [x]    = x
+
+{-@ poo :: [a] -> a @-}
+poo (x:xs) = poo xs
+poo [x]    = x
+poo _      = unsafeError "poo"
diff --git a/tests/pos/Grty2.hs b/tests/pos/Grty2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Grty2.hs
@@ -0,0 +1,7 @@
+module Grty2 () where
+
+{-@ foo :: {vv:[{v:[a]|((len v) = 1)}]|((len vv)= 1)} -> [[a]] @-}
+foo [[x]] = [[x]]
+
+
+
diff --git a/tests/pos/Grty3.hs b/tests/pos/Grty3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Grty3.hs
@@ -0,0 +1,7 @@
+module Grty3 () where
+
+{-@ bar :: (a, {v:[b]|((len v) = 1)}) -> b @-}
+bar (_, [x]) = x
+
+
+
diff --git a/tests/pos/GuardedNegative.hs b/tests/pos/GuardedNegative.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/GuardedNegative.hs
@@ -0,0 +1,29 @@
+{-@ LIQUID "--no-positivity-check" @-}
+{-@ LIQUID "--reflection" @-}
+{-@ LIQUID "--ple"        @-}
+
+{-# LANGUAGE GADTs #-}
+module GuardedNegative where
+
+data GuardedNegative where  
+      NatInduction  :: (Int -> Bool) -> GuardedNegative -> (Int -> GuardedNegative -> GuardedNegative) -> Int -> GuardedNegative
+      FromSMT       :: Bool -> GuardedNegative
+
+{-@ data GuardedNegative where 
+      NatInduction :: p:(Nat -> Bool)
+                   -> Prop {p 0} 
+                   -> (n:Nat -> Prop {p (n-1)} -> Prop {p n})      
+                   -> n:Nat -> Prop {p n} 
+      FromSMT :: b:{Bool | b} -> Prop {b} 
+  @-}
+
+{-@ type Prop E = { p:GuardedNegative | E } @-}
+
+trivialUse :: Int -> GuardedNegative 
+{-@ trivialUse :: n:Nat -> {v:_ | 0 <= n} @-}
+trivialUse = NatInduction p (FromSMT (0 <= 0)) (\n _ -> FromSMT (0 <= n))
+
+{-@ reflect p @-}
+{-@ p :: Int -> Bool @-}
+p :: Int -> Bool
+p i = 0 <= i 
diff --git a/tests/pos/HaskellMeasure.hs b/tests/pos/HaskellMeasure.hs
--- a/tests/pos/HaskellMeasure.hs
+++ b/tests/pos/HaskellMeasure.hs
@@ -1,4 +1,4 @@
-module Measures where
+module HaskellMeasure where
 
 {-@ measure lllen @-}
 llen :: [a] -> Int
@@ -7,7 +7,7 @@
 
 {-@ llen, llllen :: xs:[a] -> {v:Int| (lllen xs) = v} @-}
 
-lllen :: [a] -> Int	
+lllen :: [a] -> Int
 lllen [] = 0
 lllen (x:xs) = 1 + lllen xs
 
diff --git a/tests/pos/HedgeUnion.hs b/tests/pos/HedgeUnion.hs
--- a/tests/pos/HedgeUnion.hs
+++ b/tests/pos/HedgeUnion.hs
@@ -1,4 +1,5 @@
-module Map where
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
+module HedgeUnion where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/Hello.hs b/tests/pos/Hello.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Hello.hs
@@ -0,0 +1,12 @@
+module Hello () where
+
+{-@ abz :: (Num a, Ord a) => x:a -> {v: a | v >= x} @-}
+abz x   = if (x > 0) then x else (0 - x)  
+
+{-@ incr :: (Num a) => x:a -> {v: a | v > x}        @-}
+incr x  = x + 1 
+
+{-@ decr :: (Num a) => x:a -> {v: a | v < x}        @-}
+decr x  = x - 1 
+
+
diff --git a/tests/pos/Hex00.hs b/tests/pos/Hex00.hs
--- a/tests/pos/Hex00.hs
+++ b/tests/pos/Hex00.hs
@@ -1,4 +1,4 @@
-module Hex where 
+module Hex00 where
 
 foo :: Int -> Int -> Int 
 foo x y = x + y
diff --git a/tests/pos/HigherOrderRecFun.hs b/tests/pos/HigherOrderRecFun.hs
--- a/tests/pos/HigherOrderRecFun.hs
+++ b/tests/pos/HigherOrderRecFun.hs
@@ -1,4 +1,4 @@
-module HOF () where
+module HigherOrderRecFun () where
 
 foo :: [a] -> (b -> c) -> (b -> c)
 foo []     f = f
diff --git a/tests/pos/Hole_app.hs b/tests/pos/Hole_app.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Hole_app.hs
@@ -0,0 +1,12 @@
+module Hole_app where
+
+{-@ type Vec a N = {v:[a] | len v = N } @-}
+
+{-@ ok :: Vec Int 3 @-}
+ok = [1,2,3] :: [Int]
+
+{-@ ok' :: Vec _ 3 @-}  -- would be nice to support the hole in the application..
+ok'     = [1,2,3]
+
+
+
diff --git a/tests/pos/Hole_fun.hs b/tests/pos/Hole_fun.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Hole_fun.hs
@@ -0,0 +1,10 @@
+module Hole_fun (test) where
+
+inc :: Int -> Int 
+inc x = x + 1
+
+{-@ app :: _ -> Nat -> Nat @-} 
+app :: (Int -> Int) -> Int -> Int
+app f x = f x
+
+test = app inc 7
diff --git a/tests/pos/Holes-Slicing.hs b/tests/pos/Holes-Slicing.hs
deleted file mode 100644
--- a/tests/pos/Holes-Slicing.hs
+++ /dev/null
@@ -1,21 +0,0 @@
--- TODO-REBARE: What the hell is noslice? 
-{- LIQUID "--noslice"     @-}
-
-module Foo () where
-
-
-{-@ measure isFoo :: A -> B -> Bool @-}
-{-@ isFooF :: a:A -> b:B -> {v:Bool | v <=> isFoo a b} @-}
-isFooF :: A -> B -> Bool
-isFooF a b = undefined
-
-{-@ prop1 :: u:A -> p:B -> {v : Int | isFoo u p <=> (v < 2) } @-}
-prop1 :: A -> B -> Int
-prop1 = undefined
-
-{-@ foo :: A -> B -> _ @-}
-foo :: A -> B -> Int
-foo a b = if isFooF a b then 0 else 2 
-
-data A
-data B
diff --git a/tests/pos/Holes_Slicing.hs b/tests/pos/Holes_Slicing.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Holes_Slicing.hs
@@ -0,0 +1,21 @@
+-- TODO-REBARE: What the hell is noslice? 
+{- LIQUID "--noslice"     @-}
+
+module Holes_Slicing () where
+
+
+{-@ measure isFoo :: A -> B -> Bool @-}
+{-@ isFooF :: a:A -> b:B -> {v:Bool | v <=> isFoo a b} @-}
+isFooF :: A -> B -> Bool
+isFooF a b = undefined
+
+{-@ prop1 :: u:A -> p:B -> {v : Int | isFoo u p <=> (v < 2) } @-}
+prop1 :: A -> B -> Int
+prop1 = undefined
+
+{-@ foo :: A -> B -> _ @-}
+foo :: A -> B -> Int
+foo a b = if isFooF a b then 0 else 2 
+
+data A
+data B
diff --git a/tests/pos/IdNat.hs b/tests/pos/IdNat.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/IdNat.hs
@@ -0,0 +1,5 @@
+module IdNat where
+
+{-@ nat :: Nat @-}
+nat :: Int
+nat = id 0 -- (id (id (id (id 0))))
diff --git a/tests/pos/IdNat0.hs b/tests/pos/IdNat0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/IdNat0.hs
@@ -0,0 +1,8 @@
+module IdNat0 where
+
+{-@ nat :: Nat @-}
+nat :: Int
+nat = idd 0 
+
+idd :: a -> a
+idd = undefined 
diff --git a/tests/pos/Ignores.hs b/tests/pos/Ignores.hs
--- a/tests/pos/Ignores.hs
+++ b/tests/pos/Ignores.hs
@@ -1,4 +1,4 @@
-module Ignores where 
+module Ignores where
 
 {-@ ignore inc @-}
 {-@ inc :: Nat -> Nat @-}
diff --git a/tests/pos/Imp0.hs b/tests/pos/Imp0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Imp0.hs
@@ -0,0 +1,20 @@
+module Imp0 () where
+
+import Language.Haskell.Liquid.Prelude
+import Foreign.Storable
+
+-- ERROR goes away if we:
+-- import Language.Haskell.Liquid.Foreign
+
+-- We shouldn't have to do so since, 
+--   include/Foreign/Storable.Spec
+-- has the line:
+--   import Language.Haskell.Liquid.Foreign
+
+-- HYPOTHESIS: the import in the spec file above ONLY
+--             imports other .spec files... and hence 
+--             ignores include/Language/Haskell/Liquid/Foreign.hs 
+
+{-@ inc :: x:Nat -> {v:Nat | v > x} @-}
+inc :: Int -> Int
+inc x = x + 1
diff --git a/tests/pos/Implies.hs b/tests/pos/Implies.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Implies.hs
@@ -0,0 +1,5 @@
+module Implies where
+
+{-@ inline implies @-}
+implies p q = (not p) || q
+
diff --git a/tests/pos/Infix.hs b/tests/pos/Infix.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Infix.hs
@@ -0,0 +1,18 @@
+module Infix () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ (!) :: zogbert:{v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
+(!) :: Int -> Int -> Int
+x ! y = x + y
+
+
+{-@ (!!) :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
+(!!)   :: Int -> Int -> Int 
+x !! y = liquidAssert (x /= 0) $ x + y 
+
+{-@ zoo :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
+zoo   :: Int -> Int -> Int 
+zoo x y = liquidAssert (x /= 0) $ x + y 
+
+
diff --git a/tests/pos/Inline.hs b/tests/pos/Inline.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Inline.hs
@@ -0,0 +1,39 @@
+{-@ LIQUID "--no-totality" @-}
+module Inline where
+
+{-@ inline eqq @-}
+eqq :: Ord a => a -> a -> Bool
+eqq x y = x > y
+
+{-@ eqqtest :: Eq a => x:a -> y:a -> {v:Bool | v <=> (eqq x y) } @-}
+eqqtest :: Ord a => a -> a -> Bool
+eqqtest x y = x > y
+
+{-@ inline mymax @-}
+mymax :: Ord a => a -> a -> a
+mymax x y = if x >= y then x else y
+
+{-@ inline mymin @-}
+mymin :: Ord a => a -> a -> a
+mymin x y = mymax y x
+
+{-@ measure foo @-}
+foo :: Ord a => D a -> a
+foo (D x y) = mymax x y
+foo (F x)   = x
+
+{-@ measure bar @-}
+bar :: Ord a => D a -> a
+bar (D x y) = mymax x y
+
+{-@ measure bar2 @-}
+bar2 :: Ord a => D a -> a
+bar2 (D x y) = mymin y x
+
+foooo = D
+
+data D a = D a a | F a
+
+{-@ mymax3, mymax :: x:a -> y:a -> {v:a | v = mymax x y} @-}
+mymax3 :: Ord a => a -> a -> a
+mymax3 x y = if x >= y then x else y
diff --git a/tests/pos/Inline1.hs b/tests/pos/Inline1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Inline1.hs
@@ -0,0 +1,16 @@
+module Inline1 where
+
+data Zoo a = Z { elts :: [a], sz :: Int }
+
+-- | this is not ok (unbound symbol `boo`)
+{-@ data Zoo a = Z { elts :: [a], sz :: {v: Int | isBoo v elts} } @-}
+
+{-@ inline isBoo @-}
+isBoo :: Int -> [a] -> Bool
+isBoo v e = v == boo e
+
+{-@ type Moo a = {v:Zoo a | sz v = boo (elts v)} @-}
+
+{-@ inline boo @-}
+boo    :: [a] -> Int
+boo xs = 0
diff --git a/tests/pos/Invlhs.hs b/tests/pos/Invlhs.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Invlhs.hs
@@ -0,0 +1,19 @@
+module Invlhs where
+
+data Bob = B {foo :: Int}
+{-@ data Bob = B {foo :: Int} @-}
+
+{-@ foo :: x:Bob -> {v:Int | v = foo x} @-}
+
+{-@ invariant {v:Bob | foo v == 10} @-}
+
+mk :: a -> Bob
+mk = undefined
+
+{-@ propFAIL :: {v:_ | foo v = 10} @-}
+propFAIL = mk ()
+
+{-@ propOK :: {v:_ | foo v = 10} @-}
+propOK = let z = mk () in z 
+
+
diff --git a/tests/pos/Ite.hs b/tests/pos/Ite.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ite.hs
@@ -0,0 +1,6 @@
+module Ite () where
+
+{-@ assert myabs :: x:Int -> {v: Int | if x > 0 then v = x else v + x = 0 } @-}
+myabs :: Int -> Int
+myabs x | x > 0     = x
+        | otherwise = (0 - x)
diff --git a/tests/pos/Ite1.hs b/tests/pos/Ite1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ite1.hs
@@ -0,0 +1,6 @@
+module Ite1 () where
+
+{-@ assert myabs :: x:Int -> {v: Int | v = (if x > 0 then x else (0 - x)) } @-}
+myabs :: Int -> Int
+myabs x | x > 0     = x
+        | otherwise = (0 - x)
diff --git a/tests/pos/Jeff.hs b/tests/pos/Jeff.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Jeff.hs
@@ -0,0 +1,261 @@
+{-
+
+This code implements a Monoid for string matching; i.e. a data
+structure, MatchIdxs, which has the result of a string match function
+plus a little extra information for monoidally combining things
+together; the purpose of course is to parallelize string matching
+computations. This is the original version I wrote which uses type
+level strings to guarantee that only computations done with the same
+target string are combinable.
+
+The invariants I'd like to prove are in the comments on the MatchIdxs
+constructors. I'd be interested in a way to do it directly with this
+code (though it seems that would require extending LH), or doing it in
+a version of this code where the constructors have an extra argument
+with the value of the target-- however that formulation seems to raise
+issues about forcing those values to be the same.
+
+I have a version of the code lying around which tries this approach,
+but I couldn't get it to work. I chose to send this version first so
+you have the chance to see where I started; I could send you my version
+with the explicit terms if you like.
+
+If this goes well, then there are a couple of further things to think
+about:
+
+  1) I have another Monoid construction for actual splitting, but
+     I don't think LH can handle the invariants as they require an
+     isInfixOf operation; but I could be wrong about what LH can do.
+
+  2) It would be interesting to think about whether one can encode
+     correctness, rather than just some invariants. By correctness
+     I mean both that the monoid laws are satisfied, and that there
+     is a homomorphic-like property to the effect of:
+
+     match (x <> y) == match x <> match y
+
+Let me know if you have any questions about the code, or need more
+comments/explanation.
+-}
+
+
+{- LIQUID "--diff" @-}
+{-@ LIQUID "--scrape-used-imports" @-}
+{-@ LIQUID "--short-names" @-}
+
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Jeff where
+
+import qualified Data.ByteString as BS
+-- RJ import qualified Data.ByteString.Search as BS
+import Data.Char
+-- RJ import Data.List.Split(chunksOf)
+
+import Data.Monoid
+import Data.Proxy
+import Debug.Trace
+import GHC.TypeLits
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+import Prelude hiding (head, min, max)
+
+junk = BS.head
+
+
+traceMsg msg x = trace (msg ++ show x) x
+
+{-@ chunksBS :: Int -> b:BS.ByteString -> [BS.ByteString] / [(bLength b)] @-}
+chunksBS n' xs | BS.null xs = []
+               | otherwise = x : chunksBS n xs'
+    where (x,xs') = BS.splitAt  (liquidAssert (n > 0) n) xs
+          n       = max 1 n'
+
+bsToString :: BS.ByteString -> String
+bsToString = map (chr . fromIntegral) . BS.unpack
+
+stringToBS :: String -> BS.ByteString
+stringToBS = BS.pack . map (fromIntegral . ord)
+
+-- | get the (proxied and existentially boxed) type level Symbol for a bytestring
+someSymbolValBS :: BS.ByteString -> SomeSymbol
+someSymbolValBS = someSymbolVal . bsToString
+
+-- | get the bytestring corresponding to a type level Symbol
+mkTarg :: forall t . KnownSymbol t => Proxy t -> BS.ByteString
+mkTarg = stringToBS . symbolVal
+
+
+-- | Naive specification of string matching (from Bird)
+{-@ indicesSpec :: t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
+-- indicesSpec targ = map ((BS.length targ -) . BS.length) . filter (targ `BS.isSuffixOf`) . BS.inits
+indicesSpec targ s = [ BS.length s' - BS.length targ | s' <- BS.inits s
+                                                     , targ `BS.isSuffixOf` s' ]
+
+indicesSpec :: BS.ByteString -> BS.ByteString -> [Int]
+
+
+
+-- | Datatype to name string matching algorithms; will use it's lifted
+-- version put choice in type.
+data Alg = BM  -- ^ Boyer-Moore from stringsearch package
+         | Spec  -- ^ Naive spec
+
+{-@ indices :: Alg -> t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
+indices BM   = assumeIndices -- RJ BS.indices
+indices Spec = indicesSpec
+
+
+-- | Monoid
+--
+-- 'MatchIdxs alg targ' denotes the result of running string matching
+-- algorithm 'alg' search for target 'targ' in some input. In addition
+-- to the match indices, information needed to combine this result
+-- with similar results on input to the left and right are also
+-- included.
+--
+-- We'd like to prove that the invariants in the comments hold (|x|
+-- denotes the length of x).
+data MatchIdxs
+    = Small { targ :: BS.ByteString
+            , bs   :: BS.ByteString
+            }
+    | MatchIdxs { targ    :: BS.ByteString
+                , input   :: Int
+                , left    :: BS.ByteString
+                , matches :: [Int]
+                , right   :: BS.ByteString
+                }
+  deriving (Eq, Show)
+
+{-@ data MatchIdxs
+      = Small { targ    :: ByteStringNE
+              , bs      :: {b:BS.ByteString | bLength b < bLength targ}
+              }
+
+      | MatchIdxs
+              { targ    :: ByteStringNE
+              , input   :: {i  : Int | i >= bLength targ}
+              , left    :: {l  : BS.ByteString | bLength l == bLength targ - 1}
+              , matches :: [{v : Int | v <= input - bLength targ}]
+              , right   :: {r  : BS.ByteString | bLength r == bLength targ - 1}
+              }
+  @-}
+
+
+matchIdxsIs :: MatchIdxs -> [Int]
+matchIdxsIs (Small _ _) = []
+matchIdxsIs (MatchIdxs _ _ _ is _) = is
+
+-- | create a 'MatchIdxs'
+{-@ myIndices :: Alg -> t:ByteStringNE -> BS.ByteString -> MatchIdxsT t @-}
+myIndices alg t bs
+  | BS.length bs > fringeLen = let right1 = BS.drop (BS.length bs - fringeLen) bs in
+                                MatchIdxs t (BS.length bs) left is right1
+  | otherwise = Small t bs
+  where
+    is        = indices alg t bs
+    fringeLen = BS.length t - 1
+    left      = BS.take fringeLen bs
+    -- right1    = BS.drop (BS.length bs - fringeLen) bs
+
+-- ISSUE: get contextual output with --diff
+-- ISSUE: why does lazyvar right1 not work? it drops the output type on right1!
+
+{- lazyvar right1 -}
+
+{-@ type OkPos Targ Str = {v:Nat | v <= bLength Str - bLength Targ} @-}
+{-@ type ByteStringNE   = {v:BS.ByteString | bLength v > 0 }   @-}
+{-@ type ByteStringN N  = {v:BS.ByteString | bLength v == N}   @-}
+{-@ type MatchIdxsT T   = {v:MatchIdxs | targ v == T}          @-}
+
+{-@ assume BS.isSuffixOf :: targ:_ -> s:_ -> {v:_ | v => (bLength targ <= bLength s) } @-}
+{-@ assume BS.length  :: b:BS.ByteString -> {v:Nat | v == bLength b}  @-}
+{-@ assume BS.empty   :: {v:BS.ByteString | bLength v == 0}    @-}
+{-@ assume BS.take    :: n:Nat -> b:BS.ByteString -> ByteStringN {min n (bLength b)} @-}
+{-@ assume BS.drop    :: n:Nat -> b:{BS.ByteString | n <= bLength b} -> ByteStringN {bLength b - n} @-}
+{-@ assume BS.inits   :: b:BS.ByteString -> [{v:BS.ByteString | bLength v <= bLength b}] @-}
+{-@ assume BS.append  :: b1:BS.ByteString -> b2:BS.ByteString -> ByteStringN {bLength b1 + bLength b2} @-}
+{-@ assume BS.null    :: b:BS.ByteString -> {v:Bool | v <=> (bLength b == 0)} @-}
+{-@ assume BS.splitAt :: n:Nat -> b:BS.ByteString -> (ByteStringN {min n (bLength b)}, ByteStringN {max 0 (bLength b - n)}) @-}
+{-@ assume BS.head    :: BS.ByteString -> _ @-}
+
+{-@ measure target @-}
+target :: MatchIdxs -> BS.ByteString
+target (Small t _)           = t
+target (MatchIdxs t _ _ _ _) = t
+
+{-@ inline min @-}
+min :: Int -> Int -> Int
+min x y = if x <= y then x else y
+
+{-@ inline max @-}
+max :: Int -> Int -> Int
+max x y = if x <= y then y else x
+
+-- RJ instance (KnownSymbol t, StringMatch alg) => Monoid (MatchIdxs alg t) where
+{-@ mmempty :: t:ByteStringNE -> MatchIdxsT t @-}
+mmempty t = Small t BS.empty
+
+{-@ mmconcat :: (Foldable t) => Alg -> tg:ByteStringNE -> t (MatchIdxsT tg) -> (MatchIdxsT tg) @-}
+mmconcat alg t = foldr (mmappend alg t) (mmempty t)
+
+{-@ qualif BB(v:Int, n:Int, d:Int, b:BS.ByteString): v <= (n + d) - bLength b @-}
+
+{-@ mmappend :: Alg -> t:ByteStringNE -> MatchIdxsT t -> MatchIdxsT t -> MatchIdxsT t @-}
+mmappend alg t mx my =
+  let fringeLen = BS.length t - 1
+      idxFun    = indices alg t
+  in
+  case (mx, my) of
+    (Small tx x, Small _ y) -> myIndices alg tx (x <> y)
+    (Small tx x, MatchIdxs _ yLen ly iy rt) -> MatchIdxs tx xyLen lt is rt
+       where
+         xyLen = xLen + yLen
+         xLen  = BS.length x
+         xly   = BS.append x ly
+         lt    = BS.take fringeLen xly
+         is    = idxFun xly ++ map (+ xLen) iy
+    (MatchIdxs tx xLen lt ix rx, Small ty y) -> MatchIdxs tx xyLen lt (ix ++ is) rt
+       where
+         xyLen = xLen + yLen
+         yLen  = BS.length y
+         is    = map (+ (xLen - fringeLen)) (idxFun rxy)
+         rt    = BS.drop (BS.length rxy - fringeLen) rxy
+         rxy   = BS.append rx y
+    (MatchIdxs tx xLen lt ix rx, MatchIdxs ty yLen ly iy rt) -> MatchIdxs tx xyLen lt (ix ++ is) rt
+       where
+         xyLen = xLen + yLen
+         is    = ixy ++ map (+ xLen) iy
+         ixy   = map (+ (xLen - fringeLen)) $ idxFun (BS.append rx ly)
+
+-- | Example applications
+--
+-- The bufLen and chunkSz arguments are there to exercise the monoid,
+-- though they also foreshadow a parallel implementation.
+{-@ indicesBS' :: Alg -> Int -> Int -> ByteStringNE -> BS.ByteString -> [Int] @-}
+indicesBS' alg bufLen chunkSz t bs =
+  let si = mmconcat alg t . map (mmconcat alg t) . chunksOf bufLen . map (myIndices alg t) $ chunksBS chunkSz bs in
+  matchIdxsIs si
+
+{-@ indicesBS, indicesNaive :: Int -> Int -> ByteStringNE -> BS.ByteString -> [Int] @-}
+indicesBS    = indicesBS' BM   -- RJ (Proxy :: Proxy BM)
+indicesNaive = indicesBS' Spec -- RJ (Proxy :: Proxy Spec)
+
+{-@ isInfixOfBS :: Int -> Int -> ByteStringNE -> BS.ByteString -> Bool @-}
+isInfixOfBS bufLen chunkSz t = not . null . indicesBS bufLen chunkSz t
+
+------------------------------------------------------------------------------------------
+{-@ invariant {v:BS.ByteString | 0 <= bLength v } @-}
+{-@ measure bLength :: BS.ByteString -> Int @-}
+{-@ type LNat N = {v:Nat | v < N} @-}
+
+chunksOf :: Int -> [a] -> [[a]]
+chunksOf =  undefined
+
+{-@ assumeIndices :: t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
+assumeIndices :: BS.ByteString -> BS.ByteString -> [Int]
+assumeIndices = undefined
diff --git a/tests/pos/Keys.hs b/tests/pos/Keys.hs
--- a/tests/pos/Keys.hs
+++ b/tests/pos/Keys.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--prune-unsorted" @-}
 
-module Eval where
+module Keys where
 
 
 import qualified Data.Set as S
diff --git a/tests/pos/Kmp.hs b/tests/pos/Kmp.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Kmp.hs
@@ -0,0 +1,95 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+module Kmp (search) where
+
+import Language.Haskell.Liquid.Prelude (liquidError)
+
+search pat str = kmpSearch (ofList pat) (ofList str) 
+
+-------------------------------------------------------------
+-- | Do the Search ------------------------------------------
+-------------------------------------------------------------
+
+kmpSearch p@(A m _) s@(A n _) = go 0 0 
+  where
+    t              = kmpTable p
+    go i j
+      | j >= m     = i - m
+      | i >= n     = (-1)
+      | s!i == p!j = go (i+1) (j+1)
+      | j == 0     = go (i+1) j
+      | otherwise  = go i     (t!j) 
+
+
+-------------------------------------------------------------
+-- | Make Table ---------------------------------------------
+-------------------------------------------------------------
+
+{-@ kmpTable :: (Eq a) => p:Arr a -> {v:DArr Nat | alen v = alen p} @-}
+kmpTable p@(A m _) = go 1 0 t
+  where
+    t              = new m (\_ -> 0)
+    go i j t
+      | i >= m - 1 = t
+
+      | p!i == p!j = let i' = i + 1
+                         j' = j + 1
+                         t' = wipe $ set t i' j'
+                     in go i' j' t'           
+    
+      | (j == 0)   = let i' = i + 1
+                         t' = wipe $ set t i' 0
+                     in go i' j t'
+                             
+      | otherwise  = let j' = t ! j
+                     in go i j' t 
+
+{-@ wipe :: a:DArr Nat -> {v:DArr Nat | alen v = alen a} @-}
+wipe :: Arr Int -> Arr Int
+wipe = undefined
+
+
+{-@ type DArr a = Arr<{\k v -> v <= k}> a @-}
+{-@ type Upto N = {v:Nat | v < N} @-} 
+
+-------------------------------------------------------------
+-- | An Array type ------------------------------------------
+-------------------------------------------------------------
+
+data Arr a = A { alen :: Int
+               , aval :: Int -> a
+               }
+
+{-@ data Arr a <rng :: Int -> a -> Bool>
+      = A { alen :: Nat 
+          , aval :: i:Upto alen -> a<rng i>
+          }
+  @-}
+
+
+{-@ new :: forall <p :: Int -> a -> Bool>.
+             n:Nat -> (i:Upto n -> a<p i>) -> {v: Arr<p> a | alen v = n}
+  @-}
+new n v = A { alen = n
+            , aval = \i -> if (0 <= i && i < n)
+                             then v i
+                             else liquidError "Out of Bounds!"
+            }
+
+{-@ (!) :: forall <p :: Int -> a -> Bool>.
+             a:Arr<p> a -> i:Upto (alen a) -> a<p i>
+  @-}
+
+(A _ f) ! i = f i
+  
+{-@ set :: forall <p :: Int -> a -> Bool>.
+             a:Arr<p> a -> i:Upto (alen a) -> a<p i> -> {v:Arr<p> a | alen v = alen a}
+  @-}
+set a@(A _ f) i v = a { aval = \j -> if (i == j) then v else f j }
+
+
+{-@ ofList :: xs:[a] -> {v:Arr a | alen v = len xs} @-} 
+ofList :: [a] -> Arr a
+ofList = undefined
+
diff --git a/tests/pos/KmpIO.hs b/tests/pos/KmpIO.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/KmpIO.hs
@@ -0,0 +1,139 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+module KmpIO (search) where
+
+import Language.Haskell.Liquid.Prelude (liquidError)
+import Data.IORef
+import Control.Applicative ((<$>))
+import qualified Data.Map as M
+
+{-@ type Upto N = {v:Nat | v < N} @-}
+
+---------------------------------------------------------------------------
+{-@ search :: String -> str:String -> Maybe (Upto (len str)) @-}
+---------------------------------------------------------------------------
+search :: String -> String -> Maybe Int
+search pat str = kmpSearch (ofList pat) (ofList str)
+
+
+-------------------------------------------------------------
+-- | Do the Search ------------------------------------------
+-------------------------------------------------------------
+
+{-@ kmpSearch :: (Eq a) => p:Arr a -> s:Arr a -> Maybe (Upto (alen s)) @-}
+kmpSearch p@(A m _) s@(A n _) = go 0 0
+  where
+    t              = kmpTable p
+    go i j
+      | i >= n     = Nothing
+      | j >= m     = Just (i - m)
+      | s!i == p!j = go (i+1) (j+1)
+      | j == 0     = go (i+1) j
+      | otherwise  = go i     (t!j)
+
+
+-------------------------------------------------------------
+-- | Make Table ---------------------------------------------
+-------------------------------------------------------------
+
+kmpTable p@(A m _) = go t 1 0
+  where
+    t              = new m (\_ -> 0)
+    go t i j
+      | i >= m - 1 = t
+
+      | p!i == p!j = let i' = i + 1
+                         j' = j + 1
+                         t' = set t i' j'
+                     in go t' i' j'
+
+      | (j == 0)   = let i' = i + 1
+                         t' = set t i' 0
+                     in go t' i' j
+
+      | otherwise  = let j' = t ! j
+                     in go t i j'
+
+
+-------------------------------------------------------------
+-- | A Pure Array -------------------------------------------
+-------------------------------------------------------------
+
+data Arr a   = A { alen :: Int
+                 , aval :: Int -> a
+                 }
+
+{-@ data Arr a <p :: Int -> a -> Bool>
+             = A { alen :: Nat
+                 , aval :: i:Upto alen -> a<p i>
+                 }
+  @-}
+
+
+{-@ new :: forall <p :: Int -> a -> Bool>.
+             n:Nat -> (i:Upto n -> a<p i>) -> {v: Arr<p> a | alen v = n}
+  @-}
+new n v = A { alen = n
+            , aval = \i -> if (0 <= i && i < n)
+                             then v i
+                             else liquidError "Out of Bounds!"
+            }
+
+{-@ (!) :: forall <p :: Int -> a -> Bool>.
+             a:Arr<p> a -> i:Upto (alen a) -> a<p i>
+  @-}
+
+(A _ f) ! i = f i
+
+{-@ set :: forall <p :: Int -> a -> Bool>.
+             a:Arr<p> a -> i:Upto (alen a) -> a<p i> -> {v:Arr<p> a | alen v = alen a}
+  @-}
+set a@(A _ f) i v = a { aval = \j -> if (i == j) then v else f j }
+
+
+{-@ ofList :: xs:[a] -> {v:Arr a | alen v = len xs} @-}
+ofList xs = new n f
+  where
+    n     = length xs
+    m     = M.fromList $ zip [0..] xs
+    f i   = (M.!) m i
+
+{-@ map :: (a -> b) -> a:Arr a -> {v:Arr b | alen v = alen a} @-}
+map f a@(A n z) = A n (f . z)
+
+
+
+-------------------------------------------------------------
+-- | An Imperative Array ------------------------------------
+-------------------------------------------------------------
+
+data IOArr a = IOA { size :: Int
+                   , pntr :: IORef (Arr a)
+                   }
+
+{-@ data IOArr a <p :: Int -> a -> Bool>
+      = IOA { size :: Nat
+            , pntr :: IORef ({v:Arr<p> a | alen v = size})
+            }
+  @-}
+
+{-@ newIO :: forall <p :: Int -> a -> Bool>.
+               n:Nat -> (i:Upto n -> a<p i>) -> IO ({v: IOArr<p> a | size v = n})
+  @-}
+newIO n f = IOA n <$> newIORef (new n f)
+
+{-@ getIO :: forall <p :: Int -> a -> Bool>.
+              a:IOArr<p> a -> i:Upto (size a) -> IO (a<p i>)
+  @-}
+getIO a@(IOA sz p) i
+  = do arr   <- readIORef p
+       return $ (arr ! i)
+
+{-@ setIO :: forall <p :: Int -> a -> Bool>.
+              a:IOArr<p> a -> i:Upto (size a) -> a<p i> -> IO ()
+  @-}
+setIO a@(IOA sz p) i v
+  = do arr     <- readIORef p
+       let arr' = set arr i v
+       writeIORef p arr'
diff --git a/tests/pos/KmpVec.hs b/tests/pos/KmpVec.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/KmpVec.hs
@@ -0,0 +1,63 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--short-names"    @-}
+
+module KmpVec (search) where
+
+import Language.Haskell.Liquid.Prelude (liquidError)
+import Data.Vector
+import Data.Vector.Mutable (write)
+import Prelude hiding (length, replicate)
+
+{-@ type Idx X = {v:Nat | v < vlen X} @-}
+
+
+search pat str = kmpSearch (fromList pat) (fromList str) 
+
+-------------------------------------------------------------
+-- | Do the Search ------------------------------------------
+-------------------------------------------------------------
+
+kmpSearch p s      = go 0 0 
+  where
+    t              = kmpTable p
+    m              = length p
+    n              = length s
+    go i j
+      | j >= m     = i - m
+      | i >= n     = (-1)
+      | s!i == p!j = go (i+1) (j+1)
+      | j == 0     = go (i+1) j
+      | otherwise  = go i     (t!j) 
+
+
+-------------------------------------------------------------
+-- | Make Table ---------------------------------------------
+-------------------------------------------------------------
+
+{-@ kmpTable :: (Eq a) => p:Vector a -> {v:Vector Nat | vlen v = vlen p} @-}
+kmpTable p         = go 1 0 t
+  where
+    m              = length p
+    t              = replicate m 0 
+    go i j t
+      | i >= m - 1 = t
+
+      | p!i == p!j = let i' = i + 1
+                         j' = j + 1
+                         t' = set t i' j'
+                     in go i' j' t'           
+    
+      | (j == 0)   = let i' = i + 1
+                         t' = set t i' 0
+                     in go i' j t'
+                             
+      | otherwise  = let j' = t ! j
+                     in go i j' t 
+
+
+{-@ type Upto N = {v:Nat | v < N} @-} 
+
+{-@ set :: a:Vector a -> i:Idx a -> a -> {v:Vector a | vlen v = vlen a} @-}
+set :: Vector a -> Int -> a -> Vector a
+set = undefined
+
diff --git a/tests/pos/LNot.hs b/tests/pos/LNot.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/LNot.hs
@@ -0,0 +1,30 @@
+{-@ LIQUID "--reflection" @-}
+{-@ LIQUID "--ple"        @-}
+module LNot where 
+import Prelude  hiding (any, all, filter, nub, foldr, flip)
+
+
+
+{-@  lemma_all_ex_not :: f:(a->Bool) -> ls:[a] -> { (bnot (any f ls)) == all (bnot . f) ls} @-}
+lemma_all_ex_not :: (a->Bool) -> [a] -> ()
+lemma_all_ex_not f [] = ()
+lemma_all_ex_not f (x:xs) 
+  | f x = lemma_all_ex_not f xs 
+lemma_all_ex_not f (x:xs) 
+  | (bnot . f) x = lemma_all_ex_not f xs 
+
+{-@ reflect any @-}
+any :: (a -> Bool) -> [a] -> Bool 
+any _ []     = False 
+any p (x:xs) = if p x then True else any p xs
+
+{-@ reflect all @-}
+all :: (a -> Bool) -> [a] -> Bool 
+all _ []     = True 
+all p (x:xs) = if p x then all p xs else False 
+
+{-@ reflect bnot @-}
+{-@ bnot :: x:Bool -> {v:Bool | v = not x} @-} 
+bnot :: Bool -> Bool 
+bnot True  = False 
+bnot False = True  
diff --git a/tests/pos/LambdaEvalSuperTiny.hs b/tests/pos/LambdaEvalSuperTiny.hs
--- a/tests/pos/LambdaEvalSuperTiny.hs
+++ b/tests/pos/LambdaEvalSuperTiny.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "--no-totality" @-}
 
-module LambdaEvalMini () where
+module LambdaEvalSuperTiny () where
 import Language.Haskell.Liquid.Prelude 
 
 ---------------------------------------------------------------------
diff --git a/tests/pos/LambdaEvalTiny.hs b/tests/pos/LambdaEvalTiny.hs
--- a/tests/pos/LambdaEvalTiny.hs
+++ b/tests/pos/LambdaEvalTiny.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "--no-totality" @-}
 
-module LambdaEvalMini () where
+module LambdaEvalTiny () where
 import Language.Haskell.Liquid.Prelude 
 
 ---------------------------------------------------------------------
diff --git a/tests/pos/LazyWhere1.hs b/tests/pos/LazyWhere1.hs
--- a/tests/pos/LazyWhere1.hs
+++ b/tests/pos/LazyWhere1.hs
@@ -1,4 +1,4 @@
-module LazyWhere () where
+module LazyWhere1 () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/Lets.hs b/tests/pos/Lets.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Lets.hs
@@ -0,0 +1,14 @@
+module Lets () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo :: Int -> (Int, Int)
+foo z = (z, z + 1)
+
+baz :: Int -> (Int, Int)
+baz z = let (i, j) = foo z 
+        in (i, j + 1)
+
+{-@ prop :: Int -> Bool @-}
+prop x = let (a, b) = baz x in
+         liquidAssertB (a < b)
diff --git a/tests/pos/Lex.hs b/tests/pos/Lex.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Lex.hs
@@ -0,0 +1,10 @@
+-- TAG: termination
+
+module Lex (foo) where
+
+bar = foo [1, 2, 3] [2, 3, 4]
+
+{- decrease foo 1 2 @-}
+foo xs    (y:ys) = foo xs ys
+foo (x:xs) ys    = foo xs ys
+foo xs     ys    = xs
diff --git a/tests/pos/ListAnf.hs b/tests/pos/ListAnf.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListAnf.hs
@@ -0,0 +1,90 @@
+module ListAnf (llen) where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@  
+data List [llen] a <p :: x0:a -> x1:a -> Bool>  
+  = Nil 
+  | Cons (h :: a) (t :: List <p> (a <p h>))
+@-}
+
+{-@ measure llen @-}
+llen :: List a -> Int 
+{-@ llen :: List a -> Nat @-} 
+llen Nil = 0 
+llen (Cons _ xs) = 1 + llen xs 
+
+data List a 
+   = Nil 
+   | Cons a (List a)
+
+checkSort Nil                        = True
+checkSort (_ `Cons` Nil)             = True
+checkSort (x1 `Cons` (x2 `Cons` xs)) = liquidAssertB (x1 <= x2) && checkSort (x2 `Cons` xs)
+
+z3 :: List Integer 
+z3    = 3 `Cons` (6 `Cons` Nil)
+prop3 = checkSort z3
+
+-- The below works because it is properly ANF-ed
+-- The above fails because the "3" is not hoisted out into its own binding.
+
+--three :: Integer
+--three = 3
+--
+--six :: Integer
+--six = 6
+--
+--z2 :: List Integer 
+--z2    = three `Cons` (six `Cons` Nil) 
+--prop2 = checkSort z2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/pos/ListConcat.hs b/tests/pos/ListConcat.hs
--- a/tests/pos/ListConcat.hs
+++ b/tests/pos/ListConcat.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--pruneunsorted" @-}
 {-@ LIQUID "--no-termination" @-}
 
-module Foo () where
+module ListConcat () where
 import Data.Set (Set(..)) 
 import Prelude hiding (concat)
 
diff --git a/tests/pos/ListISort-bag.hs b/tests/pos/ListISort-bag.hs
deleted file mode 100644
--- a/tests/pos/ListISort-bag.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module ListSort where
-
-import qualified Language.Haskell.Liquid.Bag as B
-
-{-@ type OList a = [a]<{\fld v -> v >= fld}> @-}
-
-{-@ insertSort    :: (Ord a) => xs:[a] -> {v : OList a | bag v = bag xs} @-}
-insertSort        :: (Ord a) => [a] -> [a]
-insertSort []     = []
-insertSort (x:xs) = insert x (insertSort xs)
-
-{-@ insert      :: (Ord a) => x:a -> xs: OList a -> {v: OList a | bag v = B.put x (bag xs) } @-}
-insert y []     = [y]
-insert y (x:xs)
-  | y <= x    	= y : x : xs
-  | otherwise 	= x : insert y xs
-
-{-@ measure bag @-}
-bag :: (Ord a) => [a] -> B.Bag a
-bag []     = B.empty
-bag (x:xs) = B.put x (bag xs)
diff --git a/tests/pos/ListISort-perm.hs b/tests/pos/ListISort-perm.hs
deleted file mode 100644
--- a/tests/pos/ListISort-perm.hs
+++ /dev/null
@@ -1,97 +0,0 @@
-{-# LANGUAGE GADTs            #-}
-{-@ LIQUID "--exact-data-con" @-}
-{-@ LIQUID "--higherorder"    @-}
-
-module ListSort where
-
-import Language.Haskell.Liquid.ProofCombinators
-
-
--- FULL SIGS: don't work right now, thanks to https://github.com/ucsd-progsys/liquidhaskell/issues/1205
-{-type OList a = List <{\fld v -> v >= fld}> a @-}
-{- insertSort :: (Ord a) => xs:List a -> (res :: OList a, {v:_ | prop v = Perm xs res})          @-}
-{- insert     :: (Ord a) => x:a -> xs:OList a -> (res :: OList a, {v:_ | prop v = Ins x xs res}) @-}
-
-{-@ insertSort :: (Ord a) => xs:List a -> (res :: List a, {v:_ | prop v = (Perm xs res)})         @-}
-insertSort        :: (Ord a) => List a -> (List a, Perm a)
-insertSort Nil         = (Nil, NilPerm)
-insertSort (Cons x xs) = (xys, ConsPerm x xs ys xys x_ys_xys xs_ys)
-  where
-    (ys,  xs_ys)       = insertSort xs
-    (xys, x_ys_xys)    = insert x ys
-
-{-@ insert     :: (Ord a) => x:a -> xs:List a -> (res :: List a, {v:_ | prop v = (Ins x xs res)}) @-}
-insert    :: (Ord a) => a -> List a -> (List a, Ins a)
-insert y (Cons x xs)
-  | y <= x    = (Cons y (Cons x xs), Here y (Cons x xs) )
-  | otherwise = (Cons x yxs        , There y x xs yxs pf)
-  where
-    (yxs, pf) = insert y xs
-insert y Nil  = (Cons y Nil, Here y Nil)
-
--- | Lists ---------------------------------------------------------------------
-
-data List a
-  = Nil
-  | Cons { lHd :: a, lTl :: List a }
-
-{-@ data List [llen] a <p :: x0:a -> x1:a -> Bool>
-      = Nil
-      | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
-  @-}
-
--- | List Membership -----------------------------------------------------------
-
-data InsP a where
-  Ins :: a -> List a -> List a -> InsP a
-
-data Ins a where
-  Here  :: a -> List a -> Ins a
-  There :: a -> a -> List a -> List a -> Ins a -> Ins a
-
-{-@ data Ins [insNat] a where
-        Here  :: m:a -> ms:List a
-              -> Prop (Ins m ms (Cons m ms))
-
-        There :: m:a -> n:a -> ns:List a -> mns:List a
-              -> Prop (Ins m ns mns)
-              -> Prop (Ins m (Cons n ns) (Cons n mns))
-  @-}
-
--- | Permutations --------------------------------------------------------------
-
-data PermP a where
-  Perm :: List a -> List a -> PermP a
-
-data Perm a where
-  NilPerm  :: Perm a
-  ConsPerm :: a -> List a -> List a -> List a -> Ins a -> Perm a -> Perm a
-
-{-@ data Perm [permNat] a where
-        NilPerm  :: Prop (Perm Nil Nil)
-        ConsPerm :: m:a -> ms:List a -> ns:List a -> mns:List a
-                 -> Prop (Ins m ns mns)
-                 -> Prop (Perm ms ns)
-                 -> Prop (Perm (Cons m ms) mns)
-  @-}
-
-
--- | BOILERPLATE ---------------------------------------------------------------
-
-{-@ measure permNat @-}
-{-@ permNat :: Perm a -> Nat @-}
-permNat :: Perm a -> Int
-permNat (NilPerm)              = 0
-permNat (ConsPerm _ _ _ _ _ t) = 1 + permNat t
-
-{-@ measure insNat @-}
-{-@ insNat :: Ins a -> Nat @-}
-insNat :: Ins a -> Int
-insNat (Here _ _)        = 0
-insNat (There _ _ _ _ t) = 1 + insNat t
-
-{-@ measure llen          @-}
-{-@ llen :: List a -> Nat @-}
-llen :: List a -> Int
-llen Nil        = 0
-llen (Cons h t) = 1 + llen t
diff --git a/tests/pos/ListISort_bag.hs b/tests/pos/ListISort_bag.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListISort_bag.hs
@@ -0,0 +1,21 @@
+module ListISort_bag where
+
+import qualified Language.Haskell.Liquid.Bag as B
+
+{-@ type OList a = [a]<{\fld v -> v >= fld}> @-}
+
+{-@ insertSort    :: (Ord a) => xs:[a] -> {v : OList a | bag v = bag xs} @-}
+insertSort        :: (Ord a) => [a] -> [a]
+insertSort []     = []
+insertSort (x:xs) = insert x (insertSort xs)
+
+{-@ insert      :: (Ord a) => x:a -> xs: OList a -> {v: OList a | bag v = B.put x (bag xs) } @-}
+insert y []     = [y]
+insert y (x:xs)
+  | y <= x    = y : x : xs
+  | otherwise = x : insert y xs
+
+{-@ measure bag @-}
+bag :: (Ord a) => [a] -> B.Bag a
+bag []     = B.empty
+bag (x:xs) = B.put x (bag xs)
diff --git a/tests/pos/ListISort_perm.hs b/tests/pos/ListISort_perm.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListISort_perm.hs
@@ -0,0 +1,97 @@
+{-# LANGUAGE GADTs            #-}
+{-@ LIQUID "--exact-data-con" @-}
+{-@ LIQUID "--higherorder"    @-}
+
+module ListISort_perm where
+
+import Language.Haskell.Liquid.ProofCombinators
+
+
+-- FULL SIGS: don't work right now, thanks to https://github.com/ucsd-progsys/liquidhaskell/issues/1205
+{-type OList a = List <{\fld v -> v >= fld}> a @-}
+{- insertSort :: (Ord a) => xs:List a -> (res :: OList a, {v:_ | prop v = Perm xs res})          @-}
+{- insert     :: (Ord a) => x:a -> xs:OList a -> (res :: OList a, {v:_ | prop v = Ins x xs res}) @-}
+
+{-@ insertSort :: (Ord a) => xs:List a -> (res :: List a, {v:_ | prop v = (Perm xs res)})         @-}
+insertSort        :: (Ord a) => List a -> (List a, Perm a)
+insertSort Nil         = (Nil, NilPerm)
+insertSort (Cons x xs) = (xys, ConsPerm x xs ys xys x_ys_xys xs_ys)
+  where
+    (ys,  xs_ys)       = insertSort xs
+    (xys, x_ys_xys)    = insert x ys
+
+{-@ insert     :: (Ord a) => x:a -> xs:List a -> (res :: List a, {v:_ | prop v = (Ins x xs res)}) @-}
+insert    :: (Ord a) => a -> List a -> (List a, Ins a)
+insert y (Cons x xs)
+  | y <= x    = (Cons y (Cons x xs), Here y (Cons x xs) )
+  | otherwise = (Cons x yxs        , There y x xs yxs pf)
+  where
+    (yxs, pf) = insert y xs
+insert y Nil  = (Cons y Nil, Here y Nil)
+
+-- | Lists ---------------------------------------------------------------------
+
+data List a
+  = Nil
+  | Cons { lHd :: a, lTl :: List a }
+
+{-@ data List [llen] a <p :: x0:a -> x1:a -> Bool>
+      = Nil
+      | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
+  @-}
+
+-- | List Membership -----------------------------------------------------------
+
+data InsP a where
+  Ins :: a -> List a -> List a -> InsP a
+
+data Ins a where
+  Here  :: a -> List a -> Ins a
+  There :: a -> a -> List a -> List a -> Ins a -> Ins a
+
+{-@ data Ins [insNat] a where
+        Here  :: m:a -> ms:List a
+              -> Prop (Ins m ms (Cons m ms))
+
+        There :: m:a -> n:a -> ns:List a -> mns:List a
+              -> Prop (Ins m ns mns)
+              -> Prop (Ins m (Cons n ns) (Cons n mns))
+  @-}
+
+-- | Permutations --------------------------------------------------------------
+
+data PermP a where
+  Perm :: List a -> List a -> PermP a
+
+data Perm a where
+  NilPerm  :: Perm a
+  ConsPerm :: a -> List a -> List a -> List a -> Ins a -> Perm a -> Perm a
+
+{-@ data Perm [permNat] a where
+        NilPerm  :: Prop (Perm Nil Nil)
+        ConsPerm :: m:a -> ms:List a -> ns:List a -> mns:List a
+                 -> Prop (Ins m ns mns)
+                 -> Prop (Perm ms ns)
+                 -> Prop (Perm (Cons m ms) mns)
+  @-}
+
+
+-- | BOILERPLATE ---------------------------------------------------------------
+
+{-@ measure permNat @-}
+{-@ permNat :: Perm a -> Nat @-}
+permNat :: Perm a -> Int
+permNat (NilPerm)              = 0
+permNat (ConsPerm _ _ _ _ _ t) = 1 + permNat t
+
+{-@ measure insNat @-}
+{-@ insNat :: Ins a -> Nat @-}
+insNat :: Ins a -> Int
+insNat (Here _ _)        = 0
+insNat (There _ _ _ _ t) = 1 + insNat t
+
+{-@ measure llen          @-}
+{-@ llen :: List a -> Nat @-}
+llen :: List a -> Int
+llen Nil        = 0
+llen (Cons h t) = 1 + llen t
diff --git a/tests/pos/ListKeys.hs b/tests/pos/ListKeys.hs
--- a/tests/pos/ListKeys.hs
+++ b/tests/pos/ListKeys.hs
@@ -1,6 +1,6 @@
 {- LIQUID "--pruneunsorted" @-}
 
-module Foo () where
+module ListKeys () where
 import Data.Set (Set(..), empty, union, singleton) 
 
 {-@  measure listKeys @-}
diff --git a/tests/pos/ListLen-LType.hs b/tests/pos/ListLen-LType.hs
deleted file mode 100644
--- a/tests/pos/ListLen-LType.hs
+++ /dev/null
@@ -1,54 +0,0 @@
-module ListLen (llen) where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@  
-data List [llen] a <p :: x0:a -> x1:a -> Bool>  
-  = Nil 
-  | Cons (h :: a) (t :: List <p> (a <p h>))
-@-}
-
-{-@ measure llen @-}
-llen :: (List a) -> Int
-{-@ llen :: List a -> Nat @-}
-llen Nil         = 0
-llen (Cons x xs) = 1 + (llen xs)
-
-data List a = Nil | Cons a (List a)
-
-make2d :: a -> Int -> Int -> List ([a])
-make2d x n m = cloneL (clone x n) m
-
-{-@ invariant {v:Int | v >= 0} @-}
-
-clone :: a -> Int -> [a]
-clone x n
-  | n == 0
-  = []
-  | otherwise 
-  = x : (clone x (n-1))
-
-cloneL :: a -> Int -> List a
-cloneL x n
-  | n == 0
-  = Nil
-  | otherwise 
-  = Cons x  (cloneL x (n-1))
-
--- check [] = [liquidAssertB True]
--- check (xs:xss) = let n = length xs in map (\xs' -> liquidAssertB (length xs' == n)) xss
-
-chk :: List [a] -> Bool
-chk Nil = liquidAssertB True
-chk (Cons xs xss) =
-  case xss of 
-   (Cons xs1 xss1) -> let n = length xs in liquidAssertB (length xs1 == n) && chk xss
-   Nil -> liquidAssertB True
-
-fooL  = Cons [1, 1, 3] (Cons [2, 2, 5] Nil)
-fooL1 = make2d 0 n m
-  where n = choose 0
-        m = choose 1
-
-propL = chk fooL1
-prop  = chk fooL
diff --git a/tests/pos/ListLen.hs b/tests/pos/ListLen.hs
--- a/tests/pos/ListLen.hs
+++ b/tests/pos/ListLen.hs
@@ -1,4 +1,4 @@
-module ListClone () where
+module ListLen () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/ListLen_LType.hs b/tests/pos/ListLen_LType.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListLen_LType.hs
@@ -0,0 +1,54 @@
+module ListLen_LType (llen) where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@  
+data List [llen] a <p :: x0:a -> x1:a -> Bool>  
+  = Nil 
+  | Cons (h :: a) (t :: List <p> (a <p h>))
+@-}
+
+{-@ measure llen @-}
+llen :: (List a) -> Int
+{-@ llen :: List a -> Nat @-}
+llen Nil         = 0
+llen (Cons x xs) = 1 + (llen xs)
+
+data List a = Nil | Cons a (List a)
+
+make2d :: a -> Int -> Int -> List ([a])
+make2d x n m = cloneL (clone x n) m
+
+{-@ invariant {v:Int | v >= 0} @-}
+
+clone :: a -> Int -> [a]
+clone x n
+  | n == 0
+  = []
+  | otherwise 
+  = x : (clone x (n-1))
+
+cloneL :: a -> Int -> List a
+cloneL x n
+  | n == 0
+  = Nil
+  | otherwise 
+  = Cons x  (cloneL x (n-1))
+
+-- check [] = [liquidAssertB True]
+-- check (xs:xss) = let n = length xs in map (\xs' -> liquidAssertB (length xs' == n)) xss
+
+chk :: List [a] -> Bool
+chk Nil = liquidAssertB True
+chk (Cons xs xss) =
+  case xss of 
+   (Cons xs1 xss1) -> let n = length xs in liquidAssertB (length xs1 == n) && chk xss
+   Nil -> liquidAssertB True
+
+fooL  = Cons [1, 1, 3] (Cons [2, 2, 5] Nil)
+fooL1 = make2d 0 n m
+  where n = choose 0
+        m = choose 1
+
+propL = chk fooL1
+prop  = chk fooL
diff --git a/tests/pos/ListMSort-LType.hs b/tests/pos/ListMSort-LType.hs
deleted file mode 100644
--- a/tests/pos/ListMSort-LType.hs
+++ /dev/null
@@ -1,60 +0,0 @@
-module ListRange () where
-{-@ LIQUID "--no-termination" @-}
-
-import Language.Haskell.Liquid.Prelude
-
-{-@  
-data List a <p :: x0:a -> x1:a -> Bool>  
-  = Nil 
-  | Cons (h :: a) (t :: List <p> (a <p h>))
-@-}
-data List a = Nil | Cons a (List a)
-
-
--- This is needed to conclude that 
--- xs = Nil /\ xs = Cons _ _ <=> false
-
-{-@ measure llen @-}
-llen :: (List a) -> Int
-llen Nil       = 0
-llen (Cons x xs) = 1 + llen xs
-
-{-@ invariant {v:List a | (llen v) >= 0} @-}
-
-split :: List a -> (List a, List a)
-split (Cons x (Cons y zs)) = (Cons x xs, Cons y ys) where (xs, ys) = split zs
-split xs                   = (xs, Nil)
-
-
-{-@ lazy merge @-}
-merge :: Ord a => List a -> List a -> List a
-merge xs Nil = xs
-merge Nil ys = ys
-merge (Cons x xs) (Cons y ys)
-  | x <= y
-  = Cons x (merge xs (Cons y ys))
-  | otherwise 
-  = Cons y (merge (Cons x xs) ys)
-
-mergesort :: Ord a => List a -> List a
-mergesort Nil = Nil
-mergesort (Cons x Nil) = Cons x Nil
-mergesort xs = merge (mergesort xs1) (mergesort xs2) where (xs1, xs2) = split xs
-
-chk y = 
-  case y of 
-   Nil -> True
-   Cons x1 xs -> case xs of 
-                  Nil -> True
-                  Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs2
-																	
-bar = mergesort $ mkList [1 .. 100]
-
-barI :: List Int
-barI = Cons 1 $ Cons 2 $ Cons 3 Nil
-
-mkList :: Ord a => [a] -> List a
-mkList = foldr Cons Nil
-
-prop0 = chk bar
-prop1 = chk barI
diff --git a/tests/pos/ListMSort.hs b/tests/pos/ListMSort.hs
--- a/tests/pos/ListMSort.hs
+++ b/tests/pos/ListMSort.hs
@@ -1,4 +1,4 @@
-module ListSort () where
+module ListMSort () where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/ListMSort_LType.hs b/tests/pos/ListMSort_LType.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListMSort_LType.hs
@@ -0,0 +1,60 @@
+module ListMSort_LType () where
+{-@ LIQUID "--no-termination" @-}
+
+import Language.Haskell.Liquid.Prelude
+
+{-@
+data List a <p :: x0:a -> x1:a -> Bool>
+  = Nil
+  | Cons (h :: a) (t :: List <p> (a <p h>))
+@-}
+data List a = Nil | Cons a (List a)
+
+
+-- This is needed to conclude that
+-- xs = Nil /\ xs = Cons _ _ <=> false
+
+{-@ measure llen @-}
+llen :: (List a) -> Int
+llen Nil       = 0
+llen (Cons x xs) = 1 + llen xs
+
+{-@ invariant {v:List a | (llen v) >= 0} @-}
+
+split :: List a -> (List a, List a)
+split (Cons x (Cons y zs)) = (Cons x xs, Cons y ys) where (xs, ys) = split zs
+split xs                   = (xs, Nil)
+
+
+{-@ lazy merge @-}
+merge :: Ord a => List a -> List a -> List a
+merge xs Nil = xs
+merge Nil ys = ys
+merge (Cons x xs) (Cons y ys)
+  | x <= y
+  = Cons x (merge xs (Cons y ys))
+  | otherwise
+  = Cons y (merge (Cons x xs) ys)
+
+mergesort :: Ord a => List a -> List a
+mergesort Nil = Nil
+mergesort (Cons x Nil) = Cons x Nil
+mergesort xs = merge (mergesort xs1) (mergesort xs2) where (xs1, xs2) = split xs
+
+chk y =
+  case y of
+   Nil -> True
+   Cons x1 xs -> case xs of
+                  Nil -> True
+                  Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs2
+
+bar = mergesort $ mkList [1 .. 100]
+
+barI :: List Int
+barI = Cons 1 $ Cons 2 $ Cons 3 Nil
+
+mkList :: Ord a => [a] -> List a
+mkList = foldr Cons Nil
+
+prop0 = chk bar
+prop1 = chk barI
diff --git a/tests/pos/ListQSort-LType.hs b/tests/pos/ListQSort-LType.hs
deleted file mode 100644
--- a/tests/pos/ListQSort-LType.hs
+++ /dev/null
@@ -1,54 +0,0 @@
-module ListRange (llen) where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@
-data List [llen] a <p :: x0:a -> x1:a -> Bool>
-  = Nil
-  | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
-@-}
-
-{-@ measure llen @-}
-llen :: (List a) -> Int
-{-@ llen :: List a -> Nat @-}
-llen Nil         = 0
-llen (Cons x xs) = 1 + (llen xs)
-
-
-{-@ qualif ZLLen(v:ListRange.List a) : (llen(v) >= 0)@-}
-
-{-@ qualif CmpLLen(v:ListRange.List a, a:ListRange.List b) : (llen v <= llen a) @-}
-
-data List a = Nil | Cons a (List a)
-
-append k Nil         ys = Cons k ys
-append k (Cons x xs) ys = Cons x (append k xs ys)
-
-takeL x Nil         = Nil
-takeL x (Cons y ys) = if (y<x) then Cons y (takeL x ys) else takeL x ys
-
-{-@ takeGE :: Ord a
-           => x:a
-           -> xs:List a
-           -> {v: (List {v:a | v >= x}) | ((llen v) <= (llen xs))}  @-}
-takeGE x Nil         = Nil
-takeGE x (Cons y ys) = if (y>=x) then Cons y (takeGE x ys) else takeGE x ys
-
-quicksort Nil = Nil
-quicksort (Cons x xs) = append x xsle xsge
-  where xsle = quicksort (takeL x xs)
-        xsge = quicksort (takeGE x xs)
-
-chk y =
-  case y of
-   Nil -> True
-   Cons x1 xs -> case xs of
-                 Nil -> True
-                 Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs
-
-bar = quicksort $ mkList [1 .. 100]
-
-mkList :: Ord a => [a] -> List a
-mkList = foldr Cons Nil
-
-prop0 = chk bar
diff --git a/tests/pos/ListQSort_LType.hs b/tests/pos/ListQSort_LType.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListQSort_LType.hs
@@ -0,0 +1,54 @@
+module ListQSort_LType (llen) where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@
+data List [llen] a <p :: x0:a -> x1:a -> Bool>
+  = Nil
+  | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
+@-}
+
+{-@ measure llen @-}
+llen :: (List a) -> Int
+{-@ llen :: List a -> Nat @-}
+llen Nil         = 0
+llen (Cons x xs) = 1 + (llen xs)
+
+
+{-@ qualif ZLLen(v:ListRange.List a) : (llen(v) >= 0)@-}
+
+{-@ qualif CmpLLen(v:ListRange.List a, a:ListRange.List b) : (llen v <= llen a) @-}
+
+data List a = Nil | Cons a (List a)
+
+append k Nil         ys = Cons k ys
+append k (Cons x xs) ys = Cons x (append k xs ys)
+
+takeL x Nil         = Nil
+takeL x (Cons y ys) = if (y<x) then Cons y (takeL x ys) else takeL x ys
+
+{-@ takeGE :: Ord a
+           => x:a
+           -> xs:List a
+           -> {v: (List {v:a | v >= x}) | ((llen v) <= (llen xs))}  @-}
+takeGE x Nil         = Nil
+takeGE x (Cons y ys) = if (y>=x) then Cons y (takeGE x ys) else takeGE x ys
+
+quicksort Nil = Nil
+quicksort (Cons x xs) = append x xsle xsge
+  where xsle = quicksort (takeL x xs)
+        xsge = quicksort (takeGE x xs)
+
+chk y =
+  case y of
+   Nil -> True
+   Cons x1 xs -> case xs of
+                 Nil -> True
+                 Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs
+
+bar = quicksort $ mkList [1 .. 100]
+
+mkList :: Ord a => [a] -> List a
+mkList = foldr Cons Nil
+
+prop0 = chk bar
diff --git a/tests/pos/ListRange-LType.hs b/tests/pos/ListRange-LType.hs
deleted file mode 100644
--- a/tests/pos/ListRange-LType.hs
+++ /dev/null
@@ -1,38 +0,0 @@
-module ListRange () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ LIQUID "--no-termination" @-}
-
-{-@
-data List a <p :: x0:a -> x1:a -> Bool>
-  = Nil
-  | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
-@-}
-
-{-@ measure llen @-}
-llen  :: List a -> Int
-llen Nil       = 0
-llen (Cons x xs) = 1 + (llen xs)
-
-{-@ invariant {v:(List a) | ((llen v) >= 0)} @-}
-
-data List a = Nil | Cons a (List a)
-
-{-
-low, high :: Int
-low  = 0
-high = 10
--}
-
-range l h =
-  if l <= h then Cons l (range (l+1) h) else Nil
-
-chk y =
-  case y of
-   Nil -> True
-   Cons x1 xs -> case xs of
-                 Nil -> True
-                 Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs2
-
-prop3 = chk $ range 1 100
diff --git a/tests/pos/ListRange.hs b/tests/pos/ListRange.hs
--- a/tests/pos/ListRange.hs
+++ b/tests/pos/ListRange.hs
@@ -1,4 +1,4 @@
-module ListSort () where
+module ListRange () where
 
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/pos/ListRange_LType.hs b/tests/pos/ListRange_LType.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListRange_LType.hs
@@ -0,0 +1,38 @@
+module ListRange_LType () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ LIQUID "--no-termination" @-}
+
+{-@
+data List a <p :: x0:a -> x1:a -> Bool>
+  = Nil
+  | Cons { lHd :: a, lTl :: List <p> (a <p lHd>) }
+@-}
+
+{-@ measure llen @-}
+llen  :: List a -> Int
+llen Nil       = 0
+llen (Cons x xs) = 1 + (llen xs)
+
+{-@ invariant {v:(List a) | ((llen v) >= 0)} @-}
+
+data List a = Nil | Cons a (List a)
+
+{-
+low, high :: Int
+low  = 0
+high = 10
+-}
+
+range l h =
+  if l <= h then Cons l (range (l+1) h) else Nil
+
+chk y =
+  case y of
+   Nil -> True
+   Cons x1 xs -> case xs of
+                 Nil -> True
+                 Cons x2 xs2 -> liquidAssertB (x1 <= x2) && chk xs2
+
+prop3 = chk $ range 1 100
diff --git a/tests/pos/ListReverse-LType.hs b/tests/pos/ListReverse-LType.hs
deleted file mode 100644
--- a/tests/pos/ListReverse-LType.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Reverse (x, llen) where
-
-import Language.Haskell.Liquid.Prelude        
-import Prelude hiding (reverse)
-data L a = N | C a (L a)
-
-{-@ data L [llen] @-}
-
-{-@ measure llen @-}
-llen :: (L a) -> Int
-{-@ llen :: L a -> Nat @-}
-llen N        = 0
-llen (C x xs) = 1 + (llen xs)
-
-{-@ invariant {v: L a | (llen v) >= 0} @-}
-reverse N xs = xs
-reverse (C y ys) xs = reverse ys (C y xs)
-
-x = reverse (C 1 (C 2 N))
diff --git a/tests/pos/ListReverse_LType.hs b/tests/pos/ListReverse_LType.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListReverse_LType.hs
@@ -0,0 +1,19 @@
+module ListReverse_LType (x, llen) where
+
+import Language.Haskell.Liquid.Prelude        
+import Prelude hiding (reverse)
+data L a = N | C a (L a)
+
+{-@ data L [llen] @-}
+
+{-@ measure llen @-}
+llen :: (L a) -> Int
+{-@ llen :: L a -> Nat @-}
+llen N        = 0
+llen (C x xs) = 1 + (llen xs)
+
+{-@ invariant {v: L a | (llen v) >= 0} @-}
+reverse N xs = xs
+reverse (C y ys) xs = reverse ys (C y xs)
+
+x = reverse (C 1 (C 2 N))
diff --git a/tests/pos/ListSet.hs b/tests/pos/ListSet.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListSet.hs
@@ -0,0 +1,56 @@
+module ListSet () where
+
+-------------------------------------------------------------------------
+-- | Encoding Sets of Values With Liquid Types --------------------------
+-------------------------------------------------------------------------
+
+-- TODO: make this self-enclosed
+
+import Data.Set (Set(..))  
+
+-- | To start with, lets check that the `listElts` measure is sensible
+
+{-@ myid0 :: xs:[a] -> {v:[a]| (len v) = (len xs)} @-}
+myid0 []     = []
+myid0 (x:xs) = x : myid0 xs
+
+
+{-@ myid :: xs:[a] -> {v:[a]| (listElts v) = (listElts xs)} @-}
+myid []     = []
+myid (x:xs) = x : myid xs
+
+-- | The reverse function should also return the same set of values.
+-- Note that the reverse uses the tail-recursive helper @go@. 
+-- Mouse over and see what type is inferred for it!
+
+{-@ decrease go 2 @-}
+{-@ myrev :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
+myrev :: [a] -> [a]
+myrev = go [] 
+  where 
+    go acc []     = acc
+    go acc (y:ys) = go (y:acc) ys
+
+-- | Next, here's good old List-append, but now with a specification about
+-- the sets of values in the input and output.
+
+{-@ myapp :: xs:[a] 
+          -> ys:[a] 
+          -> {v:[a] | listElts v = Set_cup (listElts xs) (listElts ys) } @-}
+myapp :: [a] -> [a] -> [a]
+myapp []     ys = ys
+myapp (x:xs) ys = x : myapp xs ys
+
+-- | Finally, to round off this little demo, here's @filter@, which returns a subset.
+
+{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a] | Set_sub (listElts v) (listElts xs) } @-}
+myfilter :: (a -> Bool) -> [a] -> [a]
+myfilter f []     = []
+myfilter f (x:xs) = if f x 
+                      then x : myfilter f xs 
+                      else myfilter f xs
+
+
+
+
+
diff --git a/tests/pos/ListSetDemo.hs b/tests/pos/ListSetDemo.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ListSetDemo.hs
@@ -0,0 +1,55 @@
+module ListSetDemo () where
+
+-------------------------------------------------------------------------
+-- | Encoding Sets of Values With Liquid Types --------------------------
+-------------------------------------------------------------------------
+
+-- First, lets import the `Set` type from @Data.Set@
+
+import qualified Data.Set as S 
+
+-- Next, lets write a measure for the set of elements in a list.
+
+{-@ measure elts @-}
+elts :: (Ord a) => [a] -> S.Set a 
+elts []     = S.empty
+elts (x:xs) = S.union (S.singleton x) (elts xs)
+
+-- OK, now we can write some specifications!
+
+-- | To start with, lets check that the `elts` measure is sensible
+
+{-@ myid :: xs:[a] -> {v:[a]| (elts v) = (elts xs)} @-}
+myid []     = []
+myid (x:xs) = x : myid xs
+
+-- | The reverse function should also return the same set of values.
+-- Note that the reverse uses the tail-recursive helper @go@. 
+-- Mouse over and see what type is inferred for it!
+
+{-@ decrease go 2 @-}
+{-@ myrev :: xs:[a] -> {v:[a]| (elts v) = (elts xs)} @-}
+myrev = go [] 
+  where 
+    go acc []     = acc
+    go acc (y:ys) = go (y:acc) ys
+
+-- | Next, here's good old List-append, but now with a specification about
+-- the sets of values in the input and output.
+
+{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | (elts v) = (Set_cup (elts xs) (elts ys))} @-}
+myapp []     ys = ys
+myapp (x:xs) ys = x : myapp xs ys
+
+-- | Finally, to round off this little demo, here's @filter@, which returns a subset.
+
+{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a]| Set_sub (elts v) (elts xs) } @-}
+myfilter f []     = []
+myfilter f (x:xs) 
+  | f x           = x : myfilter f xs 
+  | otherwise     = myfilter f xs
+
+
+
+
+
diff --git a/tests/pos/Listqual.hs b/tests/pos/Listqual.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Listqual.hs
@@ -0,0 +1,10 @@
+module Listqual (boo) where
+
+{-@ qualif BadAppend(v:[a], xs:[a], ys:[a]): len v = len xs + len ys @-}
+
+append [] ys     = ys
+append (x:xs) ys = x : append xs ys
+
+{-@ boo :: {v:[Int] | len v = 2} @-}
+boo :: [Int]
+boo = append [1] [2]
diff --git a/tests/pos/Lit.hs b/tests/pos/Lit.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Lit.hs
@@ -0,0 +1,4 @@
+module Lit where
+
+{-@ test :: {v:Int | v == 3} @-}
+test = length "cat"
diff --git a/tests/pos/Lit00.hs b/tests/pos/Lit00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Lit00.hs
@@ -0,0 +1,19 @@
+module Lit00 where
+
+import Language.Haskell.Liquid.Prelude 
+
+poo :: () 
+poo = liquidAssert (zero /= one) ()
+
+data Peano = Z | O deriving (Eq)
+
+bob :: String 
+bob = "I am a cat"
+
+{-@ axiomatize one @-}
+one :: Peano 
+one = O 
+
+{-@ axiomatize zero @-}
+zero :: Peano
+zero = Z
diff --git a/tests/pos/Lit02.hs b/tests/pos/Lit02.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Lit02.hs
@@ -0,0 +1,19 @@
+module Lit02 where
+
+import Data.Set as S 
+
+{-@ predicate ValidMovieScheme V =
+	  ((listElts V == Set_cup (Set_sng "year")
+	  	                      (Set_cup (Set_sng "star")
+	  	                      (Set_cup (Set_sng "director")
+	  	                               (Set_sng "title"))))) @-}
+
+{-@ foo :: xs:[String] -> {ys: [String] | Set_sub (listElts xs) (listElts ys)} -> Int @-}
+foo :: [String] -> [String] -> Int 
+foo = undefined
+
+{-@ assume things :: {v:[String] | ValidMovieScheme v} @-}
+things :: [String] 
+things = undefined 
+
+bar = foo ["director"] things 
diff --git a/tests/pos/LogicCurry1.hs b/tests/pos/LogicCurry1.hs
--- a/tests/pos/LogicCurry1.hs
+++ b/tests/pos/LogicCurry1.hs
@@ -1,3 +1,5 @@
+module LogicCurry1 where
+
 {-@ LIQUID "--higherorder"     @-}
 {-@ LIQUID "--maxparams=5"     @-}
 
diff --git a/tests/pos/Malformed0.hs b/tests/pos/Malformed0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Malformed0.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+-- TODO: Fix resolve so we can remove this/add termination metrics
+{-@ LIQUID "--no-termination" @-}
+
+module Malformed0 () where
+
+{-@ decrease go 3 4 5 @-}
+{-@ decrease perms 4 5 6 @-}
+
+{-@ foo :: xs:[a] -> ys:[a] -> {v:Int| v = (len xs)- (len ys)} -> Int @-}
+foo :: [a] -> [a] -> Int -> Int
+foo = undefined
+
+permutations         :: [a] -> [[a]]
+permutations xs     =  go xs xs (length xs) (length xs) 1
+  where
+    go xs0 xs (d2 :: Int) d1 (d3::Int) = xs : perms xs0 xs [] d2 d1 0
+    perms _ []     _  _ _ _ = []
+    perms xs0 (t:ts) is (d2 :: Int) (d1::Int) (d3 :: Int) = (perms ts xs0 (t:is) d2 (length ts) d3) ++ (go xs0 is (length xs0 - length is) d1 1)
+
+-- permutations         :: [a] -> [[a]]
+-- permutations xs     =  go xs xs (length xs) (0::Int) 1
+--   where
+--     go xs0 xs d1 (d2::Int) (d3::Int) = xs : perms xs0 xs [] d1 0 0
+--     perms _ []     _  _ _ _ = []
+--     perms xs0 (t:ts) is (d1::Int) (d2 :: Int) (d3 :: Int) = (perms ts xs0 (t:is) (length ts) 0 d3) ++ (go xs0 is (length is) 0 1)
+-- 
+-- 
diff --git a/tests/pos/Map0.hs b/tests/pos/Map0.hs
--- a/tests/pos/Map0.hs
+++ b/tests/pos/Map0.hs
@@ -1,4 +1,4 @@
-module Map (mllen) where
+module Map0 (mllen) where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/Map2.hs b/tests/pos/Map2.hs
--- a/tests/pos/Map2.hs
+++ b/tests/pos/Map2.hs
@@ -1,4 +1,4 @@
-module Map (singleton, insert, delete, mllen) where
+module Map2 (singleton, insert, delete, mllen) where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/MapReduceVerified.hs b/tests/pos/MapReduceVerified.hs
--- a/tests/pos/MapReduceVerified.hs
+++ b/tests/pos/MapReduceVerified.hs
@@ -6,7 +6,7 @@
 {-@ LIQUID "--reflection" @-}
 
 
-module MapReduce where 
+module MapReduceVerified where
 
 import Prelude hiding (mconcat, map, split, take, drop, sum)
 import Language.Haskell.Liquid.ProofCombinators 
@@ -83,7 +83,7 @@
   === reduce op (f N) (f is `C` N)
   === op (f is) (reduce op (f N) N)
   === op (f is) (f N)
-	? left_id is
+    ? left_id is
   === f is  
   *** QED 
 
diff --git a/tests/pos/MapTvCrash.hs b/tests/pos/MapTvCrash.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/MapTvCrash.hs
@@ -0,0 +1,7 @@
+module MapTvCrash (foo) where
+
+import Foreign.ForeignPtr
+
+{-@ foo :: FinalizerPtr a -> a @-}
+foo :: FinalizerPtr a -> a
+foo = undefined
diff --git a/tests/pos/Mapreduce_bare.hs b/tests/pos/Mapreduce_bare.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Mapreduce_bare.hs
@@ -0,0 +1,71 @@
+module Mapreduce_bare () where
+
+import Language.Haskell.Liquid.Prelude
+import Data.List (foldl')
+
+----------------------------------------------------------------
+--- Step 1: Map each element into key-value list (concatMap) ---
+----------------------------------------------------------------
+
+expand          :: (a -> [(k,v)]) -> [a] -> [(k, v)]
+expand f []     = []
+expand f (x:xs) = (f x) ++ (expand f xs)
+
+----------------------------------------------------------------
+--- Step 2: Group By Key ---------------------------------------
+----------------------------------------------------------------
+
+group ::[(Int, v)] -> [(Int, [v])]
+group = foldl' addKV [] 
+  
+addKV m (k, v) = insert k vs' m
+  where vs' = v : (findWithDefault [] k m)
+
+insert key value [] 
+  = [(key, value)]
+insert key value ((k,_):kvs)
+  | k == key
+  = (key, value):kvs
+insert key value (kv:kvs)
+  = kv : insert key value kvs  
+
+findWithDefault r _ ([]) 
+  = r
+findWithDefault r k ((key,value):_) 
+  | k `eq` key 
+  = value
+findWithDefault r k (_:kvs) 
+  = findWithDefault r k kvs 
+
+----------------------------------------------------------------
+--- Step 3: Group By Key ---------------------------------------
+----------------------------------------------------------------
+
+collapse f = foldrWithKey reduceKV []
+  where reduceKV k (v:vs) acc = (k, foldl' f v vs) : acc
+        reduceKV k []     _   = crash False -- error $ show (liquidAssertB False)
+
+foldrWithKey f = foldr (\(k, v) acc -> f k v acc) 
+
+----------------------------------------------------------------
+--- Putting it All Together ------------------------------------
+----------------------------------------------------------------
+
+mapReduce fmap fred xs = collapse fred $ group $ expand fmap xs
+
+----------------------------------------------------------------
+--- "Word Count" -----------------------------------------------
+----------------------------------------------------------------
+
+wordCount  = mapReduce fm plus 
+  where fm = \doc -> [ (length w, 1) | w <- words doc]
+
+mytest = 
+  let docs = [ "this is the end"
+             , "go to the end"
+             , "the end is the beginning"]
+  in putStrLn $ isZero {- show -} $ wordCount docs
+ 
+isZero [_]  = "Positive" 
+isZero _    = "Negative"
+
diff --git a/tests/pos/Maps.hs b/tests/pos/Maps.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maps.hs
@@ -0,0 +1,41 @@
+module Maps where
+
+
+{-@ prop0 :: x:_ -> y:{_ | y == x} -> TT @-}
+prop0 x y = (a == b)
+  where
+    a     = get x emp  
+    b     = get y emp 
+
+{-@ prop1 :: x:_ -> y:{_ | y /= x} -> TT @-}
+prop1 x y = (z == 10)
+  where
+    m1    = put x 10 emp  
+    m2    = put y 20 m1
+    z     = get x m2
+
+{-@ prop2 :: x:_ -> y:{_ | y == x} -> TT @-}
+prop2 x y = (z == 20)
+  where
+    m1    = put x 10 emp 
+    m2    = put y 20 m1
+    z     = get x m2
+
+-----------------------------------------------------------------------
+
+data Map k v = M
+
+{-@ embed Map as Map_t @-}
+{-@ measure Map_select :: Map k v -> k -> v @-}
+{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
+
+emp :: Map Int Int
+emp = undefined   
+     
+{-@ get :: k:k -> m:Map k v -> {v:v | v = Map_select m k} @-}
+get :: k -> Map k v -> v
+get = undefined 
+
+{-@ put :: k:k -> v:v -> m:Map k v -> {n:Map k v | n = Map_store m k v} @-}
+put :: k -> v -> Map k v -> Map k v
+put = undefined 
diff --git a/tests/pos/Maps1.hs b/tests/pos/Maps1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maps1.hs
@@ -0,0 +1,36 @@
+module Maps1 where
+
+import Prelude hiding (lookup)
+import Data.Map
+
+{-@ prop0   :: _ -> x:_ -> y:{_ | y == x} -> TT @-}
+prop0       :: Map Int Int -> Int -> Int -> Bool
+prop0 m x y = (a == b)
+  where
+    a       = m ! x
+    b       = m ! y
+
+{-@ prop1   :: _ -> x:_ -> y:{_ | y /= x} -> TT @-}
+prop1       :: Map Int Int -> Int -> Int -> Bool
+prop1 m x y = (z == 10)
+  where
+    m1      = insert x 10 m
+    m2      = insert y 20 m1
+    z       = m2 ! x
+
+{-@ prop2   :: _ -> x:_ -> y:{_ | y == x} -> TT @-}
+prop2 m x y = (z == 20)
+  where
+    m1      = insert x 10 m
+    m2      = insert y 20 m1
+    z       = m2 ! x
+
+-----------------------------------------------------------------------
+
+{-@ embed Map as Map_t @-}
+{-@ measure Map_select :: Map k v -> k -> v @-}
+{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
+{-@ assume (!)         :: (Ord k) => m:Map k v -> k:k -> {v:v | v = Map_select m k} @-}
+{-@ assume insert      :: (Ord k) => key:k -> value:v -> m:Map k v -> {n:Map k v | n = Map_store m key value} @-}
+
+-----------------------------------------------------------------------
diff --git a/tests/pos/MaskError.hs b/tests/pos/MaskError.hs
--- a/tests/pos/MaskError.hs
+++ b/tests/pos/MaskError.hs
@@ -1,4 +1,4 @@
-module MaskError where 
+module MaskError where
 
 {-@ assume error :: String -> a @-}
 
diff --git a/tests/pos/Maybe.hs b/tests/pos/Maybe.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe.hs
@@ -0,0 +1,32 @@
+module Maybe () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
+
+{-@ filterGt :: (Ord a) => x:Maybe a -> OList a -> OList {v:a | (( isJust x ) => (fromJust x <= v)) } @-}
+
+filterGt ::  Ord a => Maybe a -> [a] -> [a]
+filterGt Nothing  xs = xs
+filterGt (Just x) xs = foo x xs
+  
+foo y xs = foo' y xs
+
+foo' :: (Ord a) => a -> [a] -> [a]
+foo' y []     = []
+foo' y (x:xs) 
+ = case compare y x of 
+     GT -> foo' y xs 
+     LT -> x:xs 
+     EQ -> xs 
+
+{-@ bar :: (Ord a) => z:a -> OList a -> OList {v:a | z <= v} @-}
+bar y xs = bar' y xs
+
+bar' y []     = []
+bar' y (x:xs) 
+  | y > x    = bar' y xs 
+  | y < x    = x:xs 
+  | y == x   = xs 
+
+
diff --git a/tests/pos/Maybe0.hs b/tests/pos/Maybe0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe0.hs
@@ -0,0 +1,13 @@
+module Maybe0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ foo :: x:Maybe a -> {v:a | ((isJust(x)) => (fromJust(x) = v)) } @-}
+foo :: Maybe a -> a 
+foo (Just x)  = x 
+foo (Nothing) = unsafeError "foo"
+
+{-@ bar :: x:Maybe a -> {v:Bool | v <=> isJust x } @-}
+bar (Just x)  = True 
+bar (Nothing) = False
+
diff --git a/tests/pos/Maybe000.hs b/tests/pos/Maybe000.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe000.hs
@@ -0,0 +1,48 @@
+module Maybe000 () where
+-- TODO: get this working with the ! annots.
+
+import Language.Haskell.Liquid.Prelude
+-- remove the ! and it is safe...
+data MaybeS a = NothingS | JustS !a
+-- (SAFE) data MaybeS a = NothingS | JustS a
+
+{-@ measure isJustS :: forall a. MaybeS a -> Bool 
+      isJustS (JustS x)  = true
+      isJustS (NothingS) = false
+  @-}
+
+{-@ measure fromJustS :: forall a. MaybeS a -> a
+      fromJustS (JustS x) = x 
+  @-}
+
+gloop = poop True
+
+{-@ poop :: z:a -> {v: MaybeS a | fromJustS(v) = z} @-}
+poop z = JustS z
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/pos/Maybe1.hs b/tests/pos/Maybe1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe1.hs
@@ -0,0 +1,27 @@
+{-@ LIQUID "--no-totality" @-}
+
+module Maybe1 (isJustS, fromJustS) where
+
+data MaybeS a = NothingS | JustS !a
+
+{-@ measure isJustS @-}
+isJustS :: MaybeS a -> Bool
+isJustS (JustS x)  = True
+isJustS (NothingS) = False
+
+{-@ measure fromJustS @-}
+fromJustS :: MaybeS a -> a
+fromJustS (JustS x) = x
+
+{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
+
+{-@ filterGt :: (Ord a) => x:MaybeS a -> OList a -> OList {v:a | isJustS x => fromJustS x <= v } @-}
+
+filterGt ::  Ord a => MaybeS a -> [a] -> [a]
+filterGt NothingS  xs = xs
+filterGt (JustS x) xs = foo' x xs
+  where foo' y []     = []
+        foo' y (x:xs) = case compare y x of
+                          GT -> foo' y xs
+                          LT -> x:xs
+                          EQ -> xs
diff --git a/tests/pos/Maybe2.hs b/tests/pos/Maybe2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe2.hs
@@ -0,0 +1,70 @@
+module Maybe2 (Map(..), isRoot, filterLt, filterGt, mlen) where
+
+data Map k a  = Bin Size k a (Map k a) (Map k a)
+              | Tip
+
+type Size     = Int
+
+data MaybeS a = NothingS | JustS !a
+
+{-@ 
+  data Map [mlen] k a <l :: root:k -> k -> Bool, r :: root:k -> k -> Bool>
+       = Bin (sz    :: Size) 
+             (key   :: k) 
+             (value :: a) 
+             (left  :: Map <l, r> (k <l key>) a) 
+             (right :: Map <l, r> (k <r key>) a) 
+       | Tip 
+  @-}
+
+{-@ measure mlen @-}
+mlen :: Map k a -> Int 
+{-@ mlen :: Map k a -> Nat @-}
+mlen Tip = 0 
+mlen (Bin _ _ _ l r) = 1 + mlen l + mlen r  
+
+{-@ measure isJustS @-}
+isJustS :: MaybeS a -> Bool 
+isJustS (JustS x)  = True
+isJustS (NothingS) = False
+
+{-@ measure fromJustS :: forall a. MaybeS a -> a 
+      fromJustS (JustS x) = x 
+  @-}
+
+{-@ type OMap k a = Map <{\root v -> v < root}, {\root v -> v > root}> k a @-}
+
+{-@ measure isBin @-} 
+isBin :: Map k a -> Bool
+isBin (Bin sz kx x l r) = True
+isBin Tip             = False
+
+{-@ isRoot :: t:Map k a -> {v: Bool | v <=> isBin t} @-}
+isRoot (Bin _ _ _ _ _) = True
+isRoot (Tip)           = False
+
+{-@ filterGt :: (Ord k) => x:MaybeS k -> OMap k v -> OMap {v:k | ((isJustS(x)) => (v > fromJustS(x))) } v @-}
+filterGt :: Ord k => MaybeS k -> Map k v -> Map k v
+filterGt NothingS t = t
+filterGt (JustS b) t = filterGt' b t
+  
+filterGt' _   Tip = Tip
+filterGt' b' (Bin _ kx x l r) =
+          case compare b' kx of LT -> join kx x (filterGt' b' l) r
+                                EQ -> r
+                                GT -> filterGt' b' r
+
+{-@ filterLt :: (Ord k) => x:MaybeS k -> OMap k v -> OMap {v:k | ((isJustS(x)) => (v < fromJustS(x))) } v @-}
+filterLt :: Ord k => MaybeS k -> Map k v -> Map k v
+filterLt NothingS t = t
+filterLt (JustS b) t = filterLt' b t
+  
+filterLt' _   Tip = Tip
+filterLt' b' (Bin _ kx x l r) =
+  case compare kx b' of LT -> join kx x l (filterLt' b' r)
+                        EQ -> l
+                        GT -> filterLt' b' l
+
+{-@ join :: kcut:k -> a -> OMap {v:k | v < kcut} a -> OMap {v:k| v > kcut} a -> OMap k a @-}
+join :: k -> a -> Map k a -> Map k a -> Map k a
+join kx x l r = Bin 1 kx x l r 
diff --git a/tests/pos/Maybe3.hs b/tests/pos/Maybe3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe3.hs
@@ -0,0 +1,20 @@
+module Maybe3 () where
+
+
+{-@ foo :: lo0 : Maybe a
+        -> lo  : {v: Maybe {v: a | isJust lo0 && v = fromJust lo0 } | v = lo0 }  
+        -> hi0 : Maybe a
+        -> hi  : {v: Maybe {v: a | isJust hi0 && v = fromJust hi0 } 
+                   | (((isJust lo && isJust v) => (fromJust v >= fromJust lo)) && (v = hi0)) }   
+        -> Bool @-}
+foo :: Maybe a -> Maybe a -> Maybe a -> Maybe a -> Bool
+foo lo0 lo hi0 hi = bar (id hi) (id lo)
+
+{-@ bar :: hi: Maybe a 
+        -> lo:Maybe {v: a | ((isJust hi) => (v <= fromJust hi)) }  
+        -> Bool @-}
+bar :: Maybe a -> Maybe a -> Bool
+bar hi lo = True
+
+
+
diff --git a/tests/pos/Maybe4.hs b/tests/pos/Maybe4.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe4.hs
@@ -0,0 +1,17 @@
+module Maybe4 () where
+
+{-@ LIQUID "--bscope" @-}
+
+{-@ goo   :: lo:{v0a: Maybe {v:a | ((isJust v0a) && (v = (fromJust v0a)))} | true } 
+          -> hi:{v0b: Maybe {v:a | ((isJust v0b) && (v = (fromJust v0b)))} | (((isJust(lo) && isJust(v0b)) => (fromJust(v0b) >= fromJust(lo)))) }   
+          -> Bool 
+  @-}
+goo       :: Maybe a -> Maybe a -> Bool
+goo lo hi = bar (id hi) (id lo)
+
+{-@ bar :: hi: Maybe a -> lo:Maybe {v: a | ((isJust(hi)) => (v <= fromJust(hi)))} -> Bool @-}
+bar :: Maybe a -> Maybe a -> Bool
+bar hi lo = True
+
+
+
diff --git a/tests/pos/Maybe5.hs b/tests/pos/Maybe5.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Maybe5.hs
@@ -0,0 +1,8 @@
+module Maybe5 where
+
+import Data.Maybe
+
+
+{-@ foo :: {x:_ | isJust x} -> a @-}
+foo :: Maybe a -> a
+foo x = fromJust x
diff --git a/tests/pos/Meas0.hs b/tests/pos/Meas0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas0.hs
@@ -0,0 +1,15 @@
+module Meas0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+goo x = let z = [x] in z
+
+z0 _  = True
+z1 _  = False
+
+poo (x:_) = 0 == 0 
+poo ([])  = liquidAssertB False
+
+xs = goo (choose 0)
+
+prop1 = liquidAssertB (poo xs)
diff --git a/tests/pos/Meas00.hs b/tests/pos/Meas00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas00.hs
@@ -0,0 +1,18 @@
+{-@ LIQUID "--no-totality" @-}
+
+module Meas00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+xs :: [Int]
+xs = [1]
+
+poo [] = liquidAssertB False
+
+prop1  = liquidAssertB (poo xs)
+
+{- qualif PosLen(v:[a]): (len v) > 0 @-}
+
+{- zooper :: {v:[a] | (len v) > 0} -> a -}
+zooper :: [a] -> a
+zooper = undefined
diff --git a/tests/pos/Meas00a.hs b/tests/pos/Meas00a.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas00a.hs
@@ -0,0 +1,5 @@
+module Meas00a () where
+
+import Language.Haskell.Liquid.Prelude
+
+prop0 = liquidAssertB True 
diff --git a/tests/pos/Meas0a.hs b/tests/pos/Meas0a.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas0a.hs
@@ -0,0 +1,16 @@
+module Meas0a () where
+
+import Language.Haskell.Liquid.Prelude
+
+goo x = let z = [x] in z
+
+z0 _  = True
+z1 _  = False
+
+poo (x:_) = True 
+poo ([])  = liquidAssertB False 
+
+xs = goo (choose 0)
+
+prop0 = liquidAssertB True 
+prop1 = liquidAssertB (poo xs)
diff --git a/tests/pos/Meas1.hs b/tests/pos/Meas1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas1.hs
@@ -0,0 +1,14 @@
+module Meas1 () where
+
+import Control.Applicative
+import Language.Haskell.Liquid.Prelude
+
+goo x = [x]
+
+xs = goo (choose 0)
+
+nullity :: [a] -> Int
+nullity []    = 0
+nullity (x:_) = 1
+
+prop2 = liquidAssertB (1 == nullity xs) 
diff --git a/tests/pos/Meas10.hs b/tests/pos/Meas10.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas10.hs
@@ -0,0 +1,22 @@
+module Meas10 where
+
+import qualified Data.Set as S 
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ myrev :: xs:[a] -> {v:[a] | listElts v = listElts xs} @-}
+myrev :: [a] -> [a]
+myrev xs = go [] xs 
+   where 
+      go acc []     = acc
+      go acc (y:ys) = go (y:acc) ys
+
+-- WHY DOES THIS JUST NOT GET ANY MEANINGFUL TYPE?
+{-@ goo :: xs:[a] -> ys:[a] -> {v:[a] | listElts v = S.union (listElts xs) (listElts ys) } @-}
+goo :: [a] -> [a] -> [a]
+goo acc []     = acc
+goo acc (y:ys) = unsafeError "foo" -- goRev (y:acc) ys
+
+{-@ emptySet :: a -> {v:[b] | listElts v == S.empty } @-}
+emptySet :: a -> [b]
+emptySet x = []
diff --git a/tests/pos/Meas11.hs b/tests/pos/Meas11.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas11.hs
@@ -0,0 +1,11 @@
+module Meas11 () where
+
+import Data.Set (Set(..))
+
+{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a] | Set_sub (listElts v) (listElts xs) } @-}
+myfilter :: (a -> Bool) -> [a] -> [a]
+myfilter f []     = []
+myfilter f (x:xs) = if f x 
+                      then x : myfilter f xs 
+                      else myfilter f xs
+
diff --git a/tests/pos/Meas2.hs b/tests/pos/Meas2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas2.hs
@@ -0,0 +1,14 @@
+module Meas2 (n) where
+
+import Language.Haskell.Liquid.Prelude
+
+mylen :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+
+zs :: [Int]
+zs = [1..100]
+
+n  = mylen zs
+
diff --git a/tests/pos/Meas4.hs b/tests/pos/Meas4.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas4.hs
@@ -0,0 +1,17 @@
+module Meas4 () where
+
+import Language.Haskell.Liquid.Prelude
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+mymap f []     = []
+mymap f (x:xs) = (f x) : (mymap f xs)
+
+zs :: [Int]
+zs = [1..100]
+
+prop2 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ mymap (`plus` 1) zs 
diff --git a/tests/pos/Meas5.hs b/tests/pos/Meas5.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas5.hs
@@ -0,0 +1,47 @@
+module Meas5 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ include <len.hquals> @-}
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+
+mymap f []     = []
+mymap f (x:xs) = (f x) : (mymap f xs)
+
+
+{-@ myreverse :: xs:_ -> {v:_ | len v = len xs} @-} 
+myreverse = go []
+  where 
+    {-@ go :: acc:_ -> xs:_ -> {v:_ | len v = len acc + len xs} @-}
+    go acc (x:xs) = go (x:acc) xs
+    go acc []     = acc
+    
+{-@ myapp :: xs:_ -> ys:_ -> {v:_ | len v = len xs + len ys} @-}
+myapp [] ys     = ys
+myapp (x:xs) ys = x:(myapp xs ys)
+
+zs :: [Int]
+zs = [1..100]
+
+zs' :: [Int]
+zs' = [500..1000]
+
+prop2 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ mymap (+ 1) zs 
+
+prop3 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ myreverse zs 
+
+prop4 = liquidAssertB ((n1 + n2) == n3) 
+  where n1 = mylen zs
+        n2 = mylen zs'
+        n3 = mylen $ myapp zs zs' 
+
+prop5 = liquidAssertB (length zs'' == length zs) 
+        where zs'' = safeZipWith (+) zs (myreverse zs)
diff --git a/tests/pos/Meas6.hs b/tests/pos/Meas6.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas6.hs
@@ -0,0 +1,16 @@
+module Meas6 () where
+
+import Language.Haskell.Liquid.Prelude
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+mymap f []     = []
+mymap f (x:xs) = (f x) : (mymap f xs)
+
+zs = [1..100]
+
+prop2 = liquidAssertB (n1 == n2) 
+  where n1 = mylen zs
+        n2 = mylen $ mymap (+ 1) zs 
diff --git a/tests/pos/Meas7.hs b/tests/pos/Meas7.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas7.hs
@@ -0,0 +1,25 @@
+
+module Meas7 () where
+
+-- some tests for the 'expandDefaultCase' trick to case-split 
+-- on the "missing" constructors.
+
+
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+
+{-@ foo :: [a] -> {v: Int | v = 0} @-}
+foo :: [a] -> Int
+foo zs = case zs of
+           (x:xs) -> 0
+           _      -> mylen zs
+
+
+{-@ bar :: [a] -> {v: Int | v > 0} @-}
+bar :: [a] -> Int
+bar zs = case zs of
+           [] -> 1
+           _  -> mylen zs
+
diff --git a/tests/pos/Meas8.hs b/tests/pos/Meas8.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas8.hs
@@ -0,0 +1,23 @@
+module Meas8 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ include <len.hquals> @-}
+
+{-@ measure rlen :: [a] -> Int 
+      rlen []   = {v | v = 0}
+      rlen (y:ys) = {v | v = (1 + rlen(ys))}
+  @-}
+
+{-@ foo :: a -> {v:[b] | rlen(v) = 0} @-}
+foo x = []
+
+{-@ mylen :: xs:[a] -> {v:Int | v = rlen(xs)} @-}
+mylen          :: [a] -> Int
+mylen []       = 0
+mylen (_:xs)   = 1 + mylen xs
+
+{-@ mymap :: (a -> b) -> xs:[a] -> {v:[b] | rlen(v) = rlen(xs)} @-}
+mymap f []     = []
+mymap f (x:xs) = (f x) : (mymap f xs)
+
diff --git a/tests/pos/Meas9.hs b/tests/pos/Meas9.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Meas9.hs
@@ -0,0 +1,20 @@
+module Meas9 () where
+
+import Data.Set (Set(..))
+
+{-@ myid :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
+myid []     = []
+myid (x:xs) = x : myid xs
+
+{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | listElts v = Set_cup (listElts xs) (listElts ys)} @-}
+myapp :: [a] -> [a] -> [a]
+myapp []     ys = ys
+myapp (x:xs) ys = x : myapp xs ys
+
+{-@ myrev :: xs:[a] -> {v:[a]| listElts v = listElts xs} @-}
+myrev :: [a] -> [a]
+myrev = go [] 
+  where 
+    go acc []     = acc
+    go acc (y:ys) = go (y:acc) ys
+
diff --git a/tests/pos/MeasureContains.hs b/tests/pos/MeasureContains.hs
--- a/tests/pos/MeasureContains.hs
+++ b/tests/pos/MeasureContains.hs
@@ -1,4 +1,4 @@
-module Fixme where
+module MeasureContains where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/MeasureDups.hs b/tests/pos/MeasureDups.hs
--- a/tests/pos/MeasureDups.hs
+++ b/tests/pos/MeasureDups.hs
@@ -1,4 +1,4 @@
-module Measures where
+module MeasureDups where
 
 import Data.Set 
 
diff --git a/tests/pos/MeasureSets.hs b/tests/pos/MeasureSets.hs
--- a/tests/pos/MeasureSets.hs
+++ b/tests/pos/MeasureSets.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--pruneunsorted" @-}
 
-module Measures where
+module MeasureSets where
 
 import Data.Set 
 
diff --git a/tests/pos/Measures1.hs b/tests/pos/Measures1.hs
--- a/tests/pos/Measures1.hs
+++ b/tests/pos/Measures1.hs
@@ -1,4 +1,4 @@
-module Measures where
+module Measures1 where
 
 {-@ data Wrapper a <p :: a -> Bool, r :: a -> a -> Bool > 
       = Wrap (rgref_ref :: a<p>) @-}
diff --git a/tests/pos/MergeSort-bag.hs b/tests/pos/MergeSort-bag.hs
deleted file mode 100644
--- a/tests/pos/MergeSort-bag.hs
+++ /dev/null
@@ -1,58 +0,0 @@
-------------------------------------------------------------------------------
--- | An implementation of Merge Sort, where LH verifies
---   * termination, and that
---   * the output is an ordered permutation of the input.
-------------------------------------------------------------------------------
-
-module MergeSort (bag, sort) where
-
-import qualified Language.Haskell.Liquid.Bag as B
-
-{-@ measure bag @-}
-bag :: (Ord a) => [a] -> B.Bag a
-bag []     = B.empty
-bag (x:xs) = B.put x (bag xs)
-
-{-@ type OList a    = [a]<{\fld v -> (v >= fld)}>       @-}
-{-@ type OListN a N = {v:OList a | len v == N}          @-}
-{-@ type OListBag a B = {v:OList a | bag v == B} @-}
-
---------------------------------------------------------------------------------
--- | The top level `sort` function. Proved:
---    *  ordered, and
---    *  same multi-set as the input.
---------------------------------------------------------------------------------
-{-@ sort :: (Ord a) => xs:[a] -> OListBag a (bag xs) @-}
-sort :: Ord a => [a] -> [a]
-sort []   = []
-sort [x]  = [x]
-sort xs   = merge (sort xs1) (sort xs2)
-  where
-    (xs1, xs2) = split xs
-
---------------------------------------------------------------------------------
--- | The `split` function breaks its list into two `Halves`:
---------------------------------------------------------------------------------
-{-@ split :: xs:[a] -> Halves a xs @-}
-split :: [a] -> ([a], [a])
-split (x:(y:zs)) = (x:xs, y:ys) where (xs, ys) = split zs
-split xs         = (xs, [])
-
-
--- | A type describing two `Halves` of a list `Xs`
-{-@ type Halves a Xs = {v: (Half a Xs, Half a Xs) | len (fst v) + len (snd v) = len Xs && B.union (bag (fst v)) (bag (snd v)) == bag Xs}
-  @-}
-
--- | Each `Half` is empty or smaller than the input:
-{-@ type Half a Xs  = {v:[a] | (len v > 1) => (len v < len Xs)} @-}
-
---------------------------------------------------------------------------------
--- | Finally, the `merge` function combines two ordered lists.
---------------------------------------------------------------------------------
-{-@ merge :: Ord a => xs:OList a -> ys:OList a -> OListBag a (B.union (bag xs) (bag ys)) / [(len xs + len ys)] @-}
-merge :: Ord a => [a] -> [a] ->  [a]
-merge xs []         = xs
-merge [] ys         = ys
-merge (x:xs) (y:ys)
-  | x <= y          = x : merge xs (y:ys)
-  | otherwise       = y : merge (x:xs) ys
diff --git a/tests/pos/MergeSort_bag.hs b/tests/pos/MergeSort_bag.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/MergeSort_bag.hs
@@ -0,0 +1,58 @@
+------------------------------------------------------------------------------
+-- | An implementation of Merge Sort, where LH verifies
+--   * termination, and that
+--   * the output is an ordered permutation of the input.
+------------------------------------------------------------------------------
+
+module MergeSort_bag (bag, sort) where
+
+import qualified Language.Haskell.Liquid.Bag as B
+
+{-@ measure bag @-}
+bag :: (Ord a) => [a] -> B.Bag a
+bag []     = B.empty
+bag (x:xs) = B.put x (bag xs)
+
+{-@ type OList a    = [a]<{\fld v -> (v >= fld)}>       @-}
+{-@ type OListN a N = {v:OList a | len v == N}          @-}
+{-@ type OListBag a B = {v:OList a | bag v == B} @-}
+
+--------------------------------------------------------------------------------
+-- | The top level `sort` function. Proved:
+--    *  ordered, and
+--    *  same multi-set as the input.
+--------------------------------------------------------------------------------
+{-@ sort :: (Ord a) => xs:[a] -> OListBag a (bag xs) @-}
+sort :: Ord a => [a] -> [a]
+sort []   = []
+sort [x]  = [x]
+sort xs   = merge (sort xs1) (sort xs2)
+  where
+    (xs1, xs2) = split xs
+
+--------------------------------------------------------------------------------
+-- | The `split` function breaks its list into two `Halves`:
+--------------------------------------------------------------------------------
+{-@ split :: xs:[a] -> Halves a xs @-}
+split :: [a] -> ([a], [a])
+split (x:(y:zs)) = (x:xs, y:ys) where (xs, ys) = split zs
+split xs         = (xs, [])
+
+
+-- | A type describing two `Halves` of a list `Xs`
+{-@ type Halves a Xs = {v: (Half a Xs, Half a Xs) | len (fst v) + len (snd v) = len Xs && B.union (bag (fst v)) (bag (snd v)) == bag Xs}
+  @-}
+
+-- | Each `Half` is empty or smaller than the input:
+{-@ type Half a Xs  = {v:[a] | (len v > 1) => (len v < len Xs)} @-}
+
+--------------------------------------------------------------------------------
+-- | Finally, the `merge` function combines two ordered lists.
+--------------------------------------------------------------------------------
+{-@ merge :: Ord a => xs:OList a -> ys:OList a -> OListBag a (B.union (bag xs) (bag ys)) / [(len xs + len ys)] @-}
+merge :: Ord a => [a] -> [a] ->  [a]
+merge xs []         = xs
+merge [] ys         = ys
+merge (x:xs) (y:ys)
+  | x <= y          = x : merge xs (y:ys)
+  | otherwise       = y : merge (x:xs) ys
diff --git a/tests/pos/ModTest.hs b/tests/pos/ModTest.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ModTest.hs
@@ -0,0 +1,10 @@
+module ModTest () where
+
+import Language.Haskell.Liquid.Prelude (isEven)
+
+{-@ takeEvens :: [Int] -> [{v: Int | v mod 2 = 0}] @-}
+takeEvens :: [Int] -> [Int]
+takeEvens []     = []
+takeEvens (x:xs) = if isEven x
+                     then x : takeEvens xs 
+                     else takeEvens xs 
diff --git a/tests/pos/Monad2.hs b/tests/pos/Monad2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Monad2.hs
@@ -0,0 +1,8 @@
+module Monad2 () where
+
+goo c = return c
+
+foo = 
+  do x <- Just 1
+     y <- goo 3
+     return $ x + y 
diff --git a/tests/pos/Monad5.hs b/tests/pos/Monad5.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Monad5.hs
@@ -0,0 +1,28 @@
+module Monad5 () where
+
+import Language.Haskell.Liquid.Prelude
+
+-- gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x >= 0) (x + 1)
+
+gpp' z n = do x <- z n
+              return $ liquidAssert (x >= 0) (x + 1)
+
+
+myabs :: Int -> Int
+myabs x | x >= 0     = x
+        | otherwise  = 0-x
+
+myabsM :: Monad m => Int -> m Int
+myabsM x | x >= 0     = return $ x
+         | otherwise  = return $ 0-x
+
+
+posM :: Monad m => m Int
+posM = return $ myabs $ choose 0
+
+
+xM, yM :: Monad m => m Int
+yM = gpp posM
+xM = gpp' myabsM $ choose 0
diff --git a/tests/pos/Monad6.hs b/tests/pos/Monad6.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Monad6.hs
@@ -0,0 +1,12 @@
+module Monad6 () where
+
+import Language.Haskell.Liquid.Prelude 
+
+{-@ gpp :: Monad m => m {v:Int|v>=0} -> m {v:Int|v>=0} @-}
+gpp :: Monad m => m Int -> m Int
+gpp z = do x <- z
+           return $ liquidAssert (x >= 0) (x + 1)
+
+
+xM :: [Int]
+xM = gpp [0]
diff --git a/tests/pos/Multi_pred_app_00.hs b/tests/pos/Multi_pred_app_00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Multi_pred_app_00.hs
@@ -0,0 +1,6 @@
+module Multi_pred_app_00 () where
+
+{-@ foo :: forall < p :: Int -> Bool
+                  , q :: Int -> Bool >. Int<p,q> -> Int<p> @-}
+foo :: Int -> Int
+foo x = x
diff --git a/tests/pos/Mutrec.hs b/tests/pos/Mutrec.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Mutrec.hs
@@ -0,0 +1,14 @@
+module Mutrec () where
+
+{-@ isEven :: n:Nat -> Bool / [n, 0] @-}
+isEven :: Int -> Bool
+isEven 0 = True
+isEven n = isOdd (n-1)
+
+{-@ isOdd :: n:Nat -> Bool / [n, 1] @-}
+isOdd :: Int -> Bool
+isOdd  n = not $ isEven n
+
+
+{- decrease isEven 1 2 -}
+{- decrease isOdd 1 2  -}
diff --git a/tests/pos/MutuallyDependentADT.hs b/tests/pos/MutuallyDependentADT.hs
--- a/tests/pos/MutuallyDependentADT.hs
+++ b/tests/pos/MutuallyDependentADT.hs
@@ -1,3 +1,5 @@
+module MutuallyDependentADT where
+
 {-@ LIQUID "--exactdc"  @-}
 
 data Pred l 
diff --git a/tests/pos/Nats.hs b/tests/pos/Nats.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Nats.hs
@@ -0,0 +1,5 @@
+module Nats where
+
+{-@ nats :: [Nat] @-}
+nats :: [Int]
+nats = [1,2,3,4,5,6,7,8,9,10]
diff --git a/tests/pos/Niki.hs b/tests/pos/Niki.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Niki.hs
@@ -0,0 +1,11 @@
+module Niki () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P (x :: a) (y :: b<p x>) @-} 
+data Pair a b = P a b
+
+bar = P (0::Int) (1::Int)
+foo = chk bar
+
+chk (P x1 y1) = liquidAssertB (x1 <= y1)
diff --git a/tests/pos/Niki1.hs b/tests/pos/Niki1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Niki1.hs
@@ -0,0 +1,23 @@
+module Niki1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P (px :: a) (py :: b<p px>) @-} 
+data Pair a b = P a b
+
+incr :: Int -> Int
+incr x = x + 1
+
+baz :: Int -> Pair Int Int
+baz x = P x (incr x)
+
+prop :: Bool
+prop = chk (baz n)
+  where n = choose 100
+{-
+foo = baz n
+ where n = choose 10
+-}
+chk :: Pair Int Int -> Bool
+chk (P x y) = liquidAssertB (x < y)
+
diff --git a/tests/pos/NoExhaustiveGuardsError.hs b/tests/pos/NoExhaustiveGuardsError.hs
--- a/tests/pos/NoExhaustiveGuardsError.hs
+++ b/tests/pos/NoExhaustiveGuardsError.hs
@@ -1,4 +1,4 @@
-module Foo where
+module NoExhaustiveGuardsError where
 
 {-@ LIQUID "--no-totality" @-}
 bar :: Int -> Int -> Int
diff --git a/tests/pos/NoPositivityCheck.hs b/tests/pos/NoPositivityCheck.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/NoPositivityCheck.hs
@@ -0,0 +1,10 @@
+{-@ LIQUID "--no-positivity-check" @-}
+
+module NoPositivityCheck where
+
+data Bad1 a = No11 (Bad1 a -> Int) | No12 (Bad1 a) 
+data Bad2 a = No2 (Int -> Bad2 a -> Int)
+data Bad3 a = No3 (Bad3 Int -> Int)
+
+data BadRec1 a = NoRec1 (BadRec2 a -> Int)
+data BadRec2 a = NoRec2 (BadRec1 a)
diff --git a/tests/pos/Null.hs b/tests/pos/Null.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Null.hs
@@ -0,0 +1,4 @@
+module Null where
+
+foo :: [a] -> [a]
+foo xs = if null xs then [] else tail xs
diff --git a/tests/pos/Pair.hs b/tests/pos/Pair.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pair.hs
@@ -0,0 +1,25 @@
+module Pair () where
+
+import Language.Haskell.Liquid.Prelude 
+
+{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P { px :: a, py :: b<p px> } @-} 
+data Pair a b = P a b
+
+incr x = let p = P x ((x+1)) in p
+chk (P x (y)) = liquidAssertB (x<y) 
+prop  = chk $ incr n
+  where n = choose 0
+
+incr2 x = 
+  let p1 = (P True (x+1)) in 
+  let p2 = P x p1 in 
+   p2
+chk2 (P x w) = 
+   case w of (P z y) -> liquidAssertB (x<y) 
+prop2  = chk2 $ incr2 n
+  where n = choose 0
+
+incr3 x = P x (P True (P 0 (x+1)))
+chk3 (P x (P _(P _ y))) = liquidAssertB (x<y) 
+prop3  = chk3 $ incr3 n
+  where n = choose 0
diff --git a/tests/pos/Pair0.hs b/tests/pos/Pair0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pair0.hs
@@ -0,0 +1,22 @@
+module Pair0 () where
+
+{-@ LIQUID "--no-termination" @-}
+import Language.Haskell.Liquid.Prelude 
+
+data Pair a b = P a b
+
+
+incr x = (x, x+1)
+chk (x, y) = liquidAssertB (x <y) 
+prop  = chk $ incr n
+  where n = choose 0
+
+incr2 x = (x, True, x+1)
+chk2 (x, _, y) = liquidAssertB (x <y) 
+prop2  = chk2 $ incr2 n
+  where n = choose 0
+
+incr3 x = (x, (True, (0, x+1)))
+chk3 (x, (_, (_, y))) = liquidAssertB (x <y) 
+prop3  = chk3 $ incr3 n
+  where n = choose 0
diff --git a/tests/pos/Pair00.hs b/tests/pos/Pair00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pair00.hs
@@ -0,0 +1,25 @@
+module Pair00 () where
+
+{-@ LIQUID "--no-termination" @-}
+
+import Language.Haskell.Liquid.Prelude
+
+incr z = (x, [x + 1])
+  where
+    x  = choose z
+chk (x, [y]) = liquidAssertB (x < y)
+prop  = chk $ incr n
+  where
+    n = choose 0
+
+incr2 pig = (True, 9, pig, 'o', pig + 1)
+
+chk2 (_, _, cow, _,  dog) = liquidAssertB (cow < dog)
+
+prop2  = chk2 $ incr2 mouse
+  where mouse = choose 0
+
+incr3 x = (x, ( (0, x+1)))
+chk3 (x, ((_, y))) = liquidAssertB (x < y)
+prop3  = chk3 (incr3 n)
+ where n = choose 0
diff --git a/tests/pos/PairMeasure.hs b/tests/pos/PairMeasure.hs
--- a/tests/pos/PairMeasure.hs
+++ b/tests/pos/PairMeasure.hs
@@ -1,7 +1,7 @@
 -- TAG: absref
 -- TAG: measure
 
-module Foo () where
+module PairMeasure () where
 {-@ LIQUID "--bscope" @-}
 
 {-@ measure getfst @-}
diff --git a/tests/pos/PairMeasure0.hs b/tests/pos/PairMeasure0.hs
--- a/tests/pos/PairMeasure0.hs
+++ b/tests/pos/PairMeasure0.hs
@@ -1,4 +1,4 @@
-module Foo () where
+module PairMeasure0 () where
 
 {-@ LIQUID "--bscope" @-}
 
diff --git a/tests/pos/Pargs.hs b/tests/pos/Pargs.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pargs.hs
@@ -0,0 +1,10 @@
+module Pargs () where
+
+{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+             (i:Int -> a<p i>) -> {v:Int| v=0}
+              -> a <p 0>
+  @-}
+
+foo ::  (Int -> a) -> Int ->  a
+foo f i = f i
+
diff --git a/tests/pos/Pargs1.hs b/tests/pos/Pargs1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pargs1.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--pruneunsorted" @-}
+module Pargs1 () where
+
+{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
+             (i:Int  -> j : Int-> a<p (i+j)>) -> 
+               ii:Int -> jj:Int
+              -> a <p (ii+jj)>
+  @-}
+
+foo ::  (Int -> Int -> a) -> Int -> Int ->  a
+foo f i j = f i j
+
diff --git a/tests/pos/Partial_tycon.hs b/tests/pos/Partial_tycon.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Partial_tycon.hs
@@ -0,0 +1,8 @@
+module Partial_tycon () where
+
+data Id a = Id a
+
+data Foo m a = Foo (m a)
+
+foo :: Foo Id a
+foo = undefined
diff --git a/tests/pos/Partialmeasure.hs b/tests/pos/Partialmeasure.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Partialmeasure.hs
@@ -0,0 +1,28 @@
+{-@ LIQUID "--no-totality" @-}
+
+module Partialmeasure where
+
+-- Note: `partialmeasureOld.hs` works fine 
+
+{-@ cons :: x:a -> _ -> {v:[a] | hd v = x} @-}
+cons x xs = x : xs
+
+{-@ test :: {v:_ | hd v = 0} @-}
+test :: [Int]
+test =  cons 0 [1,2,3,4]
+
+{-@ measure hd @-}
+hd       :: [a] -> a
+hd (x:_) = x
+
+
+-- Instead of rejecting, can we just default to "un-refined" constructors?
+
+-- Strengthened constructors
+--   data [a] where
+--     []  :: [a]    -- as before
+--     (:) :: x:a -> xs:[a] -> {v:[a] | hd v = x}
+
+
+
+
diff --git a/tests/pos/Permutation.hs b/tests/pos/Permutation.hs
--- a/tests/pos/Permutation.hs
+++ b/tests/pos/Permutation.hs
@@ -1,3 +1,8 @@
+-- | This module contains a termination proof of Data.List.permutations.
+--
+-- See tests/ple/pos/Permutations.hs for a proof of the laziness
+-- requirement.
+--
 module Permutation () where
 
 {-@ permutations :: ts:[a] -> [[a]] / [(len ts), 1, 0] @-}
@@ -12,5 +17,4 @@
             interleave' _ []     r = (ts, r)
             interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r
                                      in  (y:us, f (t:y:us) : zs)
-
 
diff --git a/tests/pos/PersistentVector.hs b/tests/pos/PersistentVector.hs
--- a/tests/pos/PersistentVector.hs
+++ b/tests/pos/PersistentVector.hs
@@ -5,7 +5,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module PVec (arrayFor, height) where
+module PersistentVector (arrayFor, height) where
 
 import Data.Bits
 
diff --git a/tests/pos/Ple1.hs b/tests/pos/Ple1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Ple1.hs
@@ -0,0 +1,52 @@
+{-@ LIQUID "--reflection" @-} 
+
+module Ple1 where
+
+import Prelude hiding ((++))
+import Language.Haskell.Liquid.ProofCombinators
+
+assocThm :: (Eq a) => [a] -> [a] -> [a] -> Bool
+assocProof :: [a] -> [a] -> [a] -> Proof
+
+{-@ infix ++ @-}
+
+{-@ reflect ++ @-}
+(++) :: [a] -> [a] -> [a]
+[]     ++ ys = ys
+(x:xs) ++ ys = x : (xs ++ ys)
+
+{-@ inline assocThm @-}
+assocThm xs ys zs = (xs ++ ys) ++ zs == xs ++ (ys ++ zs)
+
+{-@ assocProof :: xs:[a] -> ys:[a] -> zs:[a] -> { assocThm xs ys zs } @-}
+assocProof []     ys zs
+  =   ([] ++ ys) ++ zs
+  === [] ++ (ys ++ zs)
+  *** QED
+
+assocProof (x:xs) ys zs
+  =   ((x:xs) ++ ys) ++ zs
+  === (x : (xs ++ ys)) ++ zs
+  === x : ((xs ++ ys) ++ zs)
+    ? assocProof xs ys zs
+  === x : (xs ++ (ys ++ zs)) 
+  === (x:xs) ++ (ys ++ zs)
+  ***  QED
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+---
diff --git a/tests/pos/PointDist.hs b/tests/pos/PointDist.hs
--- a/tests/pos/PointDist.hs
+++ b/tests/pos/PointDist.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--short-names"    @-}
 
-module Point where
+module PointDist where
 
 -- | Non-negative numbers:
 
diff --git a/tests/pos/Poly0.hs b/tests/pos/Poly0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly0.hs
@@ -0,0 +1,21 @@
+module Poly0 () where
+
+import Language.Haskell.Liquid.Prelude
+myabs x    = if x > 0 then x else 0 - x
+
+myid arg   = arg
+
+----------------------------------------------------------
+
+x = choose 0
+
+prop_id1 = let x'  = myabs x in 
+           let x'' = myid x' in 
+           liquidAssertB (x'' >= 0)
+
+prop_id2 = liquidAssertB (x'' >= 0)
+  where x'  = myabs x 
+        x'' = myid x' 
+
+prop_id3 = liquidAssertB (x' >= 0)
+  where x' = myid $ myabs x
diff --git a/tests/pos/Poly1.hs b/tests/pos/Poly1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly1.hs
@@ -0,0 +1,19 @@
+module Poly1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x > 0 then x else (0 - x)
+
+myid2 a b  = a  
+
+----------------------------------------------------------
+
+x =  choose 0
+
+prop_id4 = let x'  = myabs x in 
+           let x'' = myid2 x' [] in 
+           liquidAssertB (x'' >= 0) 
+
+prop_id5 = liquidAssertB (x'' >= 0)
+  where x'  = myabs x 
+        x'' = myid2 x' [] 
diff --git a/tests/pos/Poly2.hs b/tests/pos/Poly2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly2.hs
@@ -0,0 +1,14 @@
+module Poly2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+----------------------------------------------------------
+
+myid3 x y  = y
+
+x = choose 0 
+
+prop_id6 = liquidAssertB (x' `geq` 0)
+  where x' = myid3 [] $ myabs x 
diff --git a/tests/pos/Poly2_degenerate.hs b/tests/pos/Poly2_degenerate.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly2_degenerate.hs
@@ -0,0 +1,14 @@
+module Poly2_degenerate (prop_id6) where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+----------------------------------------------------------
+
+myid3 x y  = y
+
+prop_id6 x = liquidAssertB (x' `geq` 0)
+  where x' = myid3 [] $ myabs x 
+
+
diff --git a/tests/pos/Poly3.hs b/tests/pos/Poly3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly3.hs
@@ -0,0 +1,11 @@
+module Poly3 (goo) where
+
+expand          :: (a -> [b]) -> [a] -> [b]
+expand f []     = []
+expand f (x:xs) = (f x) ++ (expand f xs)
+
+baz :: a -> [Int]
+baz _ = [0]
+
+goo = expand baz
+
diff --git a/tests/pos/Poly3a.hs b/tests/pos/Poly3a.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly3a.hs
@@ -0,0 +1,10 @@
+module Poly3a (goo) where
+
+expand f []     = []
+expand f (x:xs) = (f x) ++ (expand f xs)
+
+baz :: a -> [Int]
+baz _ = [0]
+
+goo = expand baz
+
diff --git a/tests/pos/Poly4.hs b/tests/pos/Poly4.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poly4.hs
@@ -0,0 +1,9 @@
+module Poly4 () where
+
+import Language.Haskell.Liquid.Prelude
+
+x     = choose 0
+
+baz y = y
+
+prop  = liquidAssertB (baz True)
diff --git a/tests/pos/Polyfun.hs b/tests/pos/Polyfun.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Polyfun.hs
@@ -0,0 +1,9 @@
+module Polyfun () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo :: a -> [Int]
+foo f = [0]
+
+prop  = all (\z -> liquidAssertB (z >= 0)) zs
+          where zs = foo id 
diff --git a/tests/pos/Polyqual.hs b/tests/pos/Polyqual.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Polyqual.hs
@@ -0,0 +1,27 @@
+module Polyqual (nearestCenter) where
+
+import Data.List (minimumBy)
+
+data WrapType b a = WrapType {getVect :: b, getVal :: a}
+
+{-@ type List a N     = {v : [a] | (len v) = N} @-}
+{-@ type Point N      = List Double N           @-}
+{-@ type GenPoint a N = WrapType (Point N) a    @-}
+
+
+{-@ nearestCenter :: n:Int -> (GenPoint a n) -> [(Point n)] -> (Point n) @-} 
+nearestCenter     :: Int -> WrapType [Double] a -> [[Double]] -> [Double] 
+nearestCenter n x = minKey . map (\c -> (c, distance c (getVect x)))
+
+minKey  :: (Ord v) => [(k, v)] -> k
+minKey  = fst . minimumBy (\x y -> compare (snd x) (snd y)) 
+
+{- distance :: a:[Double] -> {v:[Double] | (len v) = (len a)} -> Double -}
+distance     :: [Double] -> [Double] -> Double 
+distance a b = sqrt . sum $ safeZipWith (\v1 v2 -> (v1 - v2) ^ 2) a b
+
+{-@ safeZipWith :: (a -> b -> c) -> xs:[a] -> (List b (len xs)) -> (List c (len xs)) @-}
+safeZipWith f (a:as) (b:bs) = f a b : safeZipWith f as bs
+safeZipWith _ [] []         = []
+
+
diff --git a/tests/pos/PositivityCheck.hs b/tests/pos/PositivityCheck.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/PositivityCheck.hs
@@ -0,0 +1,8 @@
+module PositivityCheck where
+
+data Good1 a = Nil | Cons a (Good1 a)
+data Good2 a = Yes ((Good2 a -> Int) -> Int)
+
+data GoodRec1 a = YesRec1 (GoodRec2 a -> Int)
+data GoodRec2 a = YesRec2 (GoodRec1 a -> Int)
+
diff --git a/tests/pos/Poslist.hs b/tests/pos/Poslist.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poslist.hs
@@ -0,0 +1,16 @@
+module Poslist () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+
+absList xs = map myabs xs
+
+prop1 = map (liquidAssertB . (`geq` 0)) $ absList $ map choose [1..]
+
+
+numAbs x   = if x > 0 then x else (0 - x)
+
+numAbsList = map numAbs 
+
+prop2      = map (liquidAssertB . (>= 0)) $ numAbsList $ map choose [1..]
diff --git a/tests/pos/Poslist_dc.hs b/tests/pos/Poslist_dc.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Poslist_dc.hs
@@ -0,0 +1,12 @@
+module Poslist_dc () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x    = if x `gt` 0 then x else 0 `minus` x
+----------------------------------------------------------
+
+checkPos [] = True
+checkPos (z:zs) = liquidAssertB (z `geq` 0) &&  (checkPos zs)
+
+xs   = [-100..100]
+prop = checkPos $ map myabs xs
diff --git a/tests/pos/Pragma0.hs b/tests/pos/Pragma0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pragma0.hs
@@ -0,0 +1,8 @@
+{-@ LIQUID "--notermination" @-}
+
+module Pragma0 where
+
+
+-- an obviously non-terminating function
+zoo   :: Int -> Int
+zoo x = zoo x
diff --git a/tests/pos/Pred.hs b/tests/pos/Pred.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Pred.hs
@@ -0,0 +1,9 @@
+module Pred () where
+
+{-@ predicate Lt X Y = X < Y        @-}
+{-@ predicate Ge X Y = not (Lt X Y) @-}
+{-@ predicate Pos X  = X > 0        @-}
+
+{-@ incr :: x:{v:Int | (Pos v)} -> { v:Int | ((Pos v) && (Ge v x))} @-}
+incr :: Int -> Int
+incr x = x + 1
diff --git a/tests/pos/PrimInt0.hs b/tests/pos/PrimInt0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/PrimInt0.hs
@@ -0,0 +1,48 @@
+{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE CPP,  MagicHash #-}
+{-# OPTIONS_HADDOCK hide #-}
+
+module PrimInt0 (ptake, mtake, ztake, itake) where
+
+import Data.Maybe
+import GHC.Base
+
+{-@ ztake  :: n: {v: Int# | 0 <= v} -> {v: Int | v = n } @-}
+ztake :: Int# -> Int
+ztake 0# = 0
+ztake n# = 1 + ztake (n# -# 1#)
+
+{-@ itake  :: n: {v: Int | 0 <= v} -> {v: Int | v = n } @-}
+itake :: Int -> Int
+itake 0 = 0
+itake n = 1 + itake (n - 1)
+
+{-@ ptake  :: n: {v: GHC.Prim.Int# | 0 <= v} -> {v:[a] | ((len v) >= n)} -> {v:[a] | (len(v) = n)} @-}
+ptake :: Int# -> [a] -> [a]
+ptake 0# _      = []
+ptake n# (x:xs) = x : ptake (n# -# 1#) xs
+
+{-@ mtake  :: n: {v: Int | 0 <= v} -> {v:[a]|((len v) >= n)} -> {v:[a] | (len(v) = n)} @-}
+mtake          :: Int -> [a] -> [a]
+mtake 0 _      = []
+mtake n (x:xs) = x : mtake (n - 1) xs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/pos/Product.hs b/tests/pos/Product.hs
--- a/tests/pos/Product.hs
+++ b/tests/pos/Product.hs
@@ -1,4 +1,4 @@
-module Vectors where
+module Product where
 
 import Prelude hiding (sum, product, zipWith)
 
diff --git a/tests/pos/Profcrasher.hs b/tests/pos/Profcrasher.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Profcrasher.hs
@@ -0,0 +1,6 @@
+module Profcrasher () where
+
+import Language.Haskell.Liquid.Prelude
+
+x :: Int
+x = 4
diff --git a/tests/pos/Propability.hs b/tests/pos/Propability.hs
--- a/tests/pos/Propability.hs
+++ b/tests/pos/Propability.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--prune-unsorted" @-}
 
-module Boolability where
+module Propability where
 
 {-@ type Boolability = {v:Double | ((0.0 <= v) && (v <= 1.0)) } @-}
 
diff --git a/tests/pos/Propmeasure.hs b/tests/pos/Propmeasure.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Propmeasure.hs
@@ -0,0 +1,59 @@
+{-# LANGUAGE EmptyDataDecls #-}
+
+module Propmeasure where
+
+import Prelude hiding (length)
+
+{-@ myhead :: {v:[a] | nonEmpty v} -> a @-}
+myhead (x:_) = x
+
+{-@ measure nonEmpty @-}   
+nonEmpty (x:xs) = True 
+nonEmpty []     = False
+
+{-@ measure length @-}   
+length :: [a] -> Int
+length (x:xs) = 1 + length xs 
+length []     = 0
+
+
+{-@ measure lenEqFive @-}   
+lenEqFive (x:xs) = length xs == 4
+lenEqFive []     = False
+
+{-@ measure lenNEqFive @-}   
+lenNEqFive (x:xs) = not (length xs == 4)
+lenNEqFive []     = True
+
+
+{-@ measure lenGEFour @-}   
+lenGEFour (x:xs) = length xs >= 3
+lenGEFour []     = False
+
+
+{-@ len3 :: {v:[Int] | (not (lenEqFive v))} @-}
+len3 :: [Int]
+len3 = [1, 2, 3]
+
+
+{-@ len5 :: {v:[Int] | (lenEqFive v) && (lenGEFour v) } @-}
+len5 :: [Int]
+len5 = [1, 2, 3, 4, 5]
+
+{-@ measure length @-}
+
+{-@ foo  :: x:[a] -> {v: Bool | v <=> (nonEmpty x) } @-}
+foo  :: [a] -> Bool
+foo x = nonEmpty x
+
+
+cons = (:)
+nil  = []
+
+
+
+
+
+
+
+
diff --git a/tests/pos/Propmeasure1.hs b/tests/pos/Propmeasure1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Propmeasure1.hs
@@ -0,0 +1,11 @@
+module Propmeasure1 where
+
+nil  = []
+
+
+
+
+
+
+
+
diff --git a/tests/pos/QQTySig.hs b/tests/pos/QQTySig.hs
--- a/tests/pos/QQTySig.hs
+++ b/tests/pos/QQTySig.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySig where
 
 import LiquidHaskell
 
diff --git a/tests/pos/QQTySigTyVars.hs b/tests/pos/QQTySigTyVars.hs
--- a/tests/pos/QQTySigTyVars.hs
+++ b/tests/pos/QQTySigTyVars.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySigTyVars where
 
 import LiquidHaskell
 
diff --git a/tests/pos/QQTySyn.hs b/tests/pos/QQTySyn.hs
--- a/tests/pos/QQTySyn.hs
+++ b/tests/pos/QQTySyn.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE QuasiQuotes #-}
 
-module Nats where
+module QQTySyn where
 
 import LiquidHaskell
 
diff --git a/tests/pos/QualTest.hs b/tests/pos/QualTest.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/QualTest.hs
@@ -0,0 +1,14 @@
+module QualTest () where
+
+-- this test demonstrates the inclusion of qualifiers in source files
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ qualif Plus100(v:Int, a:Int): (v = a + 100) @-}
+ 
+incr :: Int -> Int
+incr x = x + 100
+
+prop = liquidAssert (y == 100) y
+  where 
+    y  = incr 0 
diff --git a/tests/pos/RBTree-col-height.hs b/tests/pos/RBTree-col-height.hs
deleted file mode 100644
--- a/tests/pos/RBTree-col-height.hs
+++ /dev/null
@@ -1,208 +0,0 @@
-
-{-@ LIQUID "--no-termination"   @-}
-
-module RedBlackTree where
-
-import Language.Haskell.Liquid.Prelude
-
-data RBTree a = Leaf 
-              | Node Color a !(RBTree a) !(RBTree a)
-              deriving (Show)
-
-data Color = B -- ^ Black
-           | R -- ^ Red
-           deriving (Eq,Show)
-
----------------------------------------------------------------------------
--- | Add an element -------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
-add x s = makeBlack (ins x s)
-
-{-@ ins :: (Ord a) => a -> t:RBT a -> {v: ARBTN a {(bh t)} | ((IsB t) => (isRB v))} @-}
-ins kx Leaf             = Node R kx Leaf Leaf
-ins kx s@(Node B x l r) = case compare kx x of
-                            LT -> let t = lbal x (ins kx l) r in t 
-                            GT -> let t = rbal x l (ins kx r) in t 
-                            EQ -> s
-ins kx s@(Node R x l r) = case compare kx x of
-                            LT -> Node R x (ins kx l) r
-                            GT -> Node R x l (ins kx r)
-                            EQ -> s
-
----------------------------------------------------------------------------
--- | Delete an element ----------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
-remove x t = makeBlack (del x t)
-
-{-@ predicate HDel T V = (bh V) = (if (isB T) then (bh T) - 1 else (bh T)) @-}
-
-{-@ del              :: (Ord a) => a -> t:RBT a -> {v:ARBT a | ((HDel t v) && ((isB t) || (isRB v)))} @-}
-del x Leaf           = Leaf
-del x (Node _ y a b) = case compare x y of
-   EQ -> append y a b 
-   LT -> case a of
-           Leaf         -> Node R y Leaf b
-           Node B _ _ _ -> lbalS y (del x a) b
-           _            -> let t = Node R y (del x a) b in t 
-   GT -> case b of
-           Leaf         -> Node R y a Leaf 
-           Node B _ _ _ -> rbalS y a (del x b)
-           _            -> Node R y a (del x b)
-
-{-@ append :: y:a -> l:RBT a -> r:RBTN a {(bh l)} -> (ARBT2 a l r) @-}
-append :: a -> RBTree a -> RBTree a -> RBTree a
-
-append _ Leaf r                               
-  = r
-
-append _ l Leaf                               
-  = l
-
-append piv (Node R lx ll lr) (Node R rx rl rr)  
-  = case append piv lr rl of 
-     Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
-     lrl              -> Node R lx ll (Node R rx lrl rr)
-
-append piv (Node B lx ll lr) (Node B rx rl rr)  
-  = case append piv lr rl of 
-      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
-      lrl              -> lbalS lx ll (Node B rx lrl rr)
-
-append piv l@(Node B _ _ _) (Node R rx rl rr)   
-  = Node R rx (append piv l rl) rr
-
-append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
-  = Node R lx ll (append piv lr r)
-
----------------------------------------------------------------------------
--- | Delete Minimum Element -----------------------------------------------
----------------------------------------------------------------------------
-
-{-@ deleteMin            :: RBT a -> RBT a @-}
-deleteMin (Leaf)         = Leaf
-deleteMin (Node _ x l r) = makeBlack t
-  where 
-    (_, t)               = deleteMin' x l r
-
-
-{-@ deleteMin'                   :: k:a -> l:RBT a -> r:RBTN a {(bh l)} -> (a, ARBT2 a l r) @-}
-deleteMin' k Leaf r              = (k, r)
-deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
-deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
-
----------------------------------------------------------------------------
--- | Rotations ------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ lbalS  :: k:a -> l:ARBT a -> r:RBTN a {1 + (bh l)} -> {v: ARBTN a {1 + (bh l)} | ((IsB r) => (isRB v))} @-}
-lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
-lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
-lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
-lbalS k l r                           = liquidError "nein" -- Node R l k r
-
-{-@ rbalS  :: k:a -> l:RBT a -> r:ARBTN a {(bh l) - 1} -> {v: ARBTN a {(bh l)} | ((IsB l) => (isRB v))} @-}
-rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
-rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
-rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
-rbalS k l r                           = liquidError "nein" -- Node R l k r
-
-{-@ lbal  :: k:a -> l:ARBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
-lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k l r                            = Node B k l r
-
-{-@ rbal  :: k:a -> l:RBT a -> ARBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
-rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
-rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
-rbal x l r                            = Node B x l r
-
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ type BlackRBT a = {v: RBT a | ((IsB v) && (bh v) > 0)} @-}
-
-{-@ makeRed :: l:BlackRBT a -> ARBTN a {(bh l) - 1} @-}
-makeRed (Node _ x l r) = Node R x l r
-makeRed Leaf           = liquidError "nein" 
-
-{-@ makeBlack :: ARBT a -> RBT a @-}
-makeBlack Leaf           = Leaf
-makeBlack (Node _ x l r) = Node B x l r
-
----------------------------------------------------------------------------
--- | Specifications -------------------------------------------------------
----------------------------------------------------------------------------
-
--- | Red-Black Trees
-
-{-@ type RBT a    = {v: RBTree a | ((isRB v) && (isBH v)) } @-}
-
-{-@ type RBTN a N = {v: (RBT a) | (bh v) = N }              @-}
-
-{-@ measure isRB        :: RBTree a -> Bool
-      isRB Leaf         = true
-      isRB (Node c x l r) = ((isRB l) && (isRB r) && ((c == R) => ((IsB l) && (IsB r))))
-  @-}
-
--- | Almost Red-Black Trees
-
-{-@ type ARBT a    = {v: RBTree a | ((isARB v) && (isBH v))} @-}
-
-{-@ type ARBTN a N = {v: ARBT a   | (bh v) = N }             @-}
-
-{-@ measure isARB        :: (RBTree a) -> Bool
-      isARB Leaf         = true 
-      isARB (Node c x l r) = ((isRB l) && (isRB r))
-  @-}
-
--- | Conditionally Red-Black Tree
-
-{-@ type ARBT2 a L R = {v:ARBTN a {(bh L)} | (((IsB L) && (IsB R)) => (isRB v))} @-}
-
--- | Color of a tree
-
-{-@ measure col         :: RBTree a -> Color
-      col (Node c x l r)  = c
-      col Leaf          = B
-  @-}
-
-{-@ measure isB        :: RBTree a -> Bool
-      isB Leaf         = false
-      isB (Node c x l r) = c == B 
-  @-}
-
-{-@ predicate IsB T = not ((col T) == R) @-}
-
--- | Black Height
-
-{-@ measure isBH        :: RBTree a -> Bool
-      isBH Leaf         = true
-      isBH (Node c x l r) = ((isBH l) && (isBH r) && (bh l) = (bh r))
-  @-}
-
-{-@ measure bh        :: RBTree a -> Int
-      bh Leaf         = 0
-      bh (Node c x l r) = (bh l) + (if (c == R) then 0 else 1) 
-  @-}
-
--------------------------------------------------------------------------------
--- Auxiliary Invariants -------------------------------------------------------
--------------------------------------------------------------------------------
-
-{-@ predicate Invs V = ((Inv1 V) && (Inv2 V) && (Inv3 V))   @-}
-{-@ predicate Inv1 V = (((isARB V) && (IsB V)) => (isRB V)) @-}
-{-@ predicate Inv2 V = ((isRB V) => (isARB V))              @-}
-{-@ predicate Inv3 V = 0 <= (bh V)                          @-}
-
-{-@ invariant {v: Color | (v = R || v = B)}                 @-}
-
-{-@ invariant {v: RBTree a | (Invs v)}                      @-}
-
-{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
-inv Leaf           = Leaf
-inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree-color.hs b/tests/pos/RBTree-color.hs
deleted file mode 100644
--- a/tests/pos/RBTree-color.hs
+++ /dev/null
@@ -1,191 +0,0 @@
-{-@ LIQUID "--no-termination"   @-}
-
-module RedBlackTree where
-
-import Language.Haskell.Liquid.Prelude
-
-data RBTree a = Leaf 
-              | Node Color a !(RBTree a) !(RBTree a)
-              deriving (Show)
-
-data Color = B -- ^ Black
-           | R -- ^ Red
-           deriving (Eq,Show)
-
----------------------------------------------------------------------------
--- | Add an element -------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
-add x s = makeBlack (ins x s)
-
-{-@ ins :: (Ord a) => a -> t:RBT a -> {v: ARBT a | ((notR t) => (isRB v))} @-}
-ins kx Leaf             = Node R kx Leaf Leaf
-ins kx s@(Node B x l r) = case compare kx x of
-                            LT -> let t = lbal x (ins kx l) r in t 
-                            GT -> let t = rbal x l (ins kx r) in t 
-                            EQ -> s
-ins kx s@(Node R x l r) = case compare kx x of
-                            LT -> Node R x (ins kx l) r
-                            GT -> Node R x l (ins kx r)
-                            EQ -> s
-
----------------------------------------------------------------------------
--- | Delete an element ----------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
-remove x t = makeBlack (del x t)
-
-{-@ del              :: (Ord a) => a -> t:RBT a -> {v:ARBT a | ((isB t) || (isRB v))} @-}
-del x Leaf           = Leaf
-del x (Node _ y a b) = case compare x y of
-   EQ -> append y a b 
-   LT -> case a of
-           Leaf         -> Node R y Leaf b
-           Node B _ _ _ -> lbalS y (del x a) b
-           _            -> let t = Node R y (del x a) b in t 
-   GT -> case b of
-           Leaf         -> Node R y a Leaf 
-           Node B _ _ _ -> rbalS y a (del x b)
-           _            -> Node R y a (del x b)
-
-{-@ append :: y:a -> l:RBT a -> r:RBT a -> (ARBT2 a l r) @-}
-
-append :: a -> RBTree a -> RBTree a -> RBTree a
-
-append _ Leaf r 
-  = r
-
-append _ l Leaf 
-  = l
-
-append piv (Node R lx ll lr) (Node R rx rl rr)  
-  = case append piv lr rl of 
-      Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
-      lrl              -> Node R lx ll (Node R rx lrl rr)
-
-append piv (Node B lx ll lr) (Node B rx rl rr)  
-  = case append piv lr rl of 
-      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
-      lrl              -> lbalS lx ll (Node B rx lrl rr)
-
-append piv l@(Node B _ _ _) (Node R rx rl rr)   
-  = Node R rx (append piv l rl) rr
-
-append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
-  = Node R lx ll (append piv lr r)
-
----------------------------------------------------------------------------
--- | Delete Minimum Element -----------------------------------------------
----------------------------------------------------------------------------
-
-{-@ deleteMin :: RBT a -> RBT a @-}
-deleteMin (Leaf)         = Leaf
-deleteMin (Node _ x l r) = makeBlack t
-  where 
-    (_, t)               = deleteMin' x l r
-
-
-{-@ deleteMin' :: k:a -> l:RBT a -> r:RBT a -> (a, ARBT2 a l r) @-}
-deleteMin' k Leaf r              = (k, r)
-deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
-deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
-
----------------------------------------------------------------------------
--- | Rotations ------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ lbalS                             :: k:a -> l:ARBT a -> r:RBT a -> {v: ARBT a | ((notR r) => (isRB v))} @-}
-lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
-lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
-lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
-lbalS k l r                           = unsafeError "nein"
-
-{-@ rbalS                             :: k:a -> l:RBT a -> r:ARBT a -> {v: ARBT a | ((notR l) => (isRB v))} @-}
-rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
-rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
-rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
-rbalS k l r                           = unsafeError "nein" 
-
-{-@ lbal                              :: k:a -> l:ARBT a -> RBT a -> RBT a @-}
-lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k l r                            = Node B k l r
-
-{-@ rbal                              :: k:a -> l:RBT a -> ARBT a -> RBT a  @-}
-rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
-rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
-rbal x l r                            = Node B x l r
-
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ type BlackRBT a = {v: RBT a | (notR v)} @-}
-
-{-@ makeRed :: l:BlackRBT a -> ARBT a @-}
-makeRed (Node B x l r) = Node R x l r
-makeRed _              = unsafeError "nein" 
-
-{-@ makeBlack :: ARBT a -> RBT a @-}
-makeBlack Leaf           = Leaf
-makeBlack (Node _ x l r) = Node B x l r
-
----------------------------------------------------------------------------
--- | Specifications -------------------------------------------------------
----------------------------------------------------------------------------
-
--- | Red-Black Trees
-
-{-@ type RBT a    = {v: RBTree a | (isRB v)} @-}
-
-{-@ measure isRB @-}
-isRB :: RBTree a -> Bool
-isRB Leaf           = True
-isRB (Node c x l r) = (isRB l) && (isRB r) && ((c /= R) || ((notR l) && (notR r)))
-
--- | Almost Red-Black Trees
-
-{-@ type ARBT a    = {v: RBTree a | (isARB v) } @-}
-
-{-@ measure isARB @-} 
-isARB :: RBTree a -> Bool
-isARB Leaf         = True 
-isARB (Node c x l r) = isRB l && isRB r
-
--- | Conditionally Red-Black Tree
-
-{-@ type ARBT2 a L R = {v:ARBT a | (((notR L) && (notR R)) => (isRB v))} @-}
-
--- | Color of a tree
-
-{-@ measure col @-}
-col :: RBTree a -> Color
-col (Node c x l r) = c
-col Leaf           = B
-
-{-@ measure isB @-} 
-isB :: RBTree a -> Bool
-isB Leaf           = False
-isB (Node c x l r) = (c == B) 
-
-{-@ inline notR @-}
-notR :: RBTree a -> Bool
-notR t = not ((col t) == R)
-
-------------------------------------------------------------------
--- | Auxiliary Invariants ----------------------------------------
-------------------------------------------------------------------
-
-{-@ predicate Invs V = ((Inv1 V) && (Inv2 V))               @-}
-{-@ predicate Inv1 V = (((isARB V) && (notR V)) => (isRB V)) @-}
-{-@ predicate Inv2 V = ((isRB V) => (isARB V))              @-}
-
-{-@ invariant {v: Color | (v = R || v = B)}                 @-}
-
-{-@ invariant {v: RBTree a | (Invs v)}                      @-}
-
-{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
-inv Leaf           = Leaf
-inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree-height.hs b/tests/pos/RBTree-height.hs
deleted file mode 100644
--- a/tests/pos/RBTree-height.hs
+++ /dev/null
@@ -1,177 +0,0 @@
-
-{-@ LIQUID "--no-termination"   @-}
-{-@ LIQUID "--no-totality"      @-}
-
-module RedBlackTree where
-
-import Language.Haskell.Liquid.Prelude
-
-data RBTree a = Leaf 
-              | Node Color a !(RBTree a) !(RBTree a)
-              deriving (Show)
-
-data Color = B -- ^ Black
-           | R -- ^ Red
-           deriving (Eq,Show)
-
----------------------------------------------------------------------------
--- | Add an element -------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
-add x s = makeBlack (ins x s)
-
-{-@ ins :: (Ord a) => a -> t:RBT a -> RBTN a {(bh t)}  @-}
-ins kx Leaf             = Node R kx Leaf Leaf
-ins kx s@(Node B x l r) = case compare kx x of
-                            LT -> let t = lbal x (ins kx l) r in t 
-                            GT -> let t = rbal x l (ins kx r) in t 
-                            EQ -> s
-ins kx s@(Node R x l r) = case compare kx x of
-                            LT -> Node R x (ins kx l) r
-                            GT -> Node R x l (ins kx r)
-                            EQ -> s
-
----------------------------------------------------------------------------
--- | Delete an element ----------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
-remove x t = makeBlack (del x t)
-
-{-@ predicate HDel T V = (bh V) = (if (isB T) then (bh T) - 1 else (bh T)) @-}
-
-{-@ del              :: (Ord a) => a -> t:RBT a -> {v:RBT a | (HDel t v)} @-}
-del x Leaf           = Leaf
-del x (Node _ y a b) = case compare x y of
-   EQ -> append y a b 
-   LT -> case a of
-           Leaf         -> Node R y Leaf b
-           Node B _ _ _ -> lbalS y (del x a) b
-           _            -> let t = Node R y (del x a) b in t 
-   GT -> case b of
-           Leaf         -> Node R y a Leaf 
-           Node B _ _ _ -> rbalS y a (del x b)
-           _            -> Node R y a (del x b)
-
-{-@ append :: y:a -> l:RBT a -> r:RBTN a {(bh l)} -> RBTN a {(bh l)} @-}
-append :: a -> RBTree a -> RBTree a -> RBTree a
-
-append _ Leaf r                               
-  = r
-
-append _ l Leaf                               
-  = l
-
-append piv (Node R lx ll lr) (Node R rx rl rr)  
-  = case append piv lr rl of 
-     Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
-     lrl              -> Node R lx ll (Node R rx lrl rr)
-
-append piv (Node B lx ll lr) (Node B rx rl rr)  
-  = case append piv lr rl of 
-      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
-      lrl              -> lbalS lx ll (Node B rx lrl rr)
-
-append piv l@(Node B _ _ _) (Node R rx rl rr)   
-  = Node R rx (append piv l rl) rr
-
-append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
-  = Node R lx ll (append piv lr r)
-
----------------------------------------------------------------------------
--- | Delete Minimum Element -----------------------------------------------
----------------------------------------------------------------------------
-
-{-@ deleteMin            :: RBT a -> RBT a @-}
-deleteMin (Leaf)         = Leaf
-deleteMin (Node _ x l r) = makeBlack t
-  where 
-    (_, t)               = deleteMin' x l r
-
-
-{-@ deleteMin'                   :: k:a -> l:RBT a -> r:RBTN a {(bh l)} -> (a, RBTN a {(bh l)}) @-}
-deleteMin' k Leaf r              = (k, r)
-deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
-deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
-
----------------------------------------------------------------------------
--- | Rotations ------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ lbalS  :: k:a -> l:RBT a -> r:RBTN a {1 + (bh l)} -> RBTN a {1 + (bh l)} @-}
-lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
-lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
-lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
-lbalS k l r                           = unsafeError "nein"
-
-{-@ rbalS  :: k:a -> l:RBT a -> r:RBTN a {(bh l) - 1} -> RBTN a {(bh l)}    @-}
-rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
-rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
-rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
-rbalS k l r                           = unsafeError "nein"
-
-{-@ lbal  :: k:a -> l:RBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
-lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k l r                            = Node B k l r
-
-{-@ rbal  :: k:a -> l:RBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
-rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
-rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
-rbal x l r                            = Node B x l r
-
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ makeRed :: l:RBT a -> RBTN a {(bh l) - 1} @-}
-makeRed (Node B x l r) = Node R x l r
-makeRed _              = unsafeError "nein"
-
-{-@ makeBlack :: RBT a -> RBT a @-}
-makeBlack Leaf           = Leaf
-makeBlack (Node _ x l r) = Node B x l r
-
----------------------------------------------------------------------------
--- | Specifications -------------------------------------------------------
----------------------------------------------------------------------------
-
--- | Red-Black Trees
-
-{-@ type RBT a    = {v: RBTree a | (isBH v) }   @-}
-
-{-@ type RBTN a N = {v: RBT a  | (bh v) = N }   @-}
-
--- | Color of a tree
-
-{-@ measure isB        :: RBTree a -> Bool
-      isB Leaf         = false
-      isB (Node c x l r) = c == B 
-  @-}
-
--- | Black Height
-
-{-@ measure isBH        :: RBTree a -> Bool
-      isBH Leaf         = true
-      isBH (Node c x l r) = ((isBH l) && (isBH r) && (bh l) = (bh r))
-  @-}
-
-{-@ measure bh        :: RBTree a -> Int
-      bh Leaf         = 0
-      bh (Node c x l r) = (bh l) + (if (c == R) then 0 else 1) 
-  @-}
-
--------------------------------------------------------------------------------
--- Auxiliary Invariants -------------------------------------------------------
--------------------------------------------------------------------------------
-
-{-@ invariant {v: RBTree a | (Invs v)}        @-}
-{-@ predicate Invs V = (Inv3 V)               @-}
-{-@ predicate Inv3 V = 0 <= (bh V)            @-}
-
-{-@ invariant {v: Color | (v = R || v = B)}   @-}
-
-{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
-inv Leaf           = Leaf
-inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree-ord.hs b/tests/pos/RBTree-ord.hs
deleted file mode 100644
--- a/tests/pos/RBTree-ord.hs
+++ /dev/null
@@ -1,148 +0,0 @@
-
-{-@ LIQUID "--no-termination"   @-}
-{-@ LIQUID "--no-totality"      @-}
-
-module Foo (add, remove, deleteMin, deleteMin') where
-
-import Language.Haskell.Liquid.Prelude
-
-data RBTree a = Leaf
-              | Node { nCol   :: Color
-                     , nKey   :: a
-                     , nLeft  :: !(RBTree a)
-                     , nRight :: !(RBTree a)
-                     }
-              deriving (Show)
-
-data Color = B -- ^ Black
-           | R -- ^ Red
-           deriving (Eq,Show)
-
----------------------------------------------------------------------------
--- | Add an element -------------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ add :: (Ord a) => a -> ORBT a -> ORBT a @-}
-add x s = makeBlack (ins x s)
-
-{-@ ins :: (Ord a) => a -> ORBT a -> ORBT a @-}
-ins kx Leaf             = Node R kx Leaf Leaf
-ins kx s@(Node B x l r) = case compare kx x of
-                            LT -> let t = lbal x (ins kx l) r in t
-                            GT -> let t = rbal x l (ins kx r) in t
-                            EQ -> s
-ins kx s@(Node R x l r) = case compare kx x of
-                            LT -> Node R x (ins kx l) r
-                            GT -> Node R x l (ins kx r)
-                            EQ -> s
-
----------------------------------------------------------------------------
--- | Delete an element ----------------------------------------------------
----------------------------------------------------------------------------
-
-{-@ remove :: (Ord a) => a -> ORBT a -> ORBT a @-}
-remove x t = makeBlack (del x t)
-
-{-@ del              :: (Ord a) => a -> ORBT a -> ORBT a @-}
-del x Leaf           = Leaf
-del x (Node _ y a b) = case compare x y of
-   EQ -> append y a b
-   LT -> case a of
-           Leaf         -> Node R y Leaf b
-           Node B _ _ _ -> lbalS y (del x a) b
-           _            -> let t = Node R y (del x a) b in t
-   GT -> case b of
-           Leaf         -> Node R y a Leaf
-           Node B _ _ _ -> rbalS y a (del x b)
-           _            -> Node R y a (del x b)
-
-{-@ append  :: y:a -> ORBT {v:a | v < y} -> ORBT {v:a | y < v} -> ORBT a @-}
-append :: a -> RBTree a -> RBTree a -> RBTree a
-
-append _ Leaf r
-  = r
-
-append _ l Leaf
-  = l
-
-append piv (Node R lx ll lr) (Node R rx rl rr)
-  = case append piv lr rl of
-      Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
-      lrl              -> Node R lx ll (Node R rx lrl rr)
-
-append piv (Node B lx ll lr) (Node B rx rl rr)
-  = case append piv lr rl of
-      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
-      lrl              -> lbalS lx ll (Node B rx lrl rr)
-
-append piv l@(Node B _ _ _) (Node R rx rl rr)
-  = Node R rx (append piv l rl) rr
-
-append piv l@(Node R lx ll lr) r@(Node B _ _ _)
-  = Node R lx ll (append piv lr r)
-
----------------------------------------------------------------------------
--- | Delete Minimum Element -----------------------------------------------
----------------------------------------------------------------------------
-
-{-@ deleteMin  :: ORBT a -> ORBT a @-}
-deleteMin (Leaf)         = Leaf
-deleteMin (Node _ x l r) = makeBlack t
-  where
-    (_, t)               = deleteMin' x l r
-
-
-{-@ deleteMin' :: k:a -> ORBT {v:a | v < k} -> ORBT {v:a | k < v} -> (a, ORBT a) @-}
-deleteMin' k Leaf r              = (k, r)
-deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr
-deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr
-
----------------------------------------------------------------------------
--- | Rotations ------------------------------------------------------------
----------------------------------------------------------------------------
-
-lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
-lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t
-lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
-lbalS k l r                           = unsafeError "nein"
-
-rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
-rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t
-rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
-rbalS k l r                           = unsafeError "nein"
-
-lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
-lbal k l r                            = Node B k l r
-
-rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
-rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
-rbal x l r                            = Node B x l r
-
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-
-makeRed (Node _ x l r) = Node R x l r
-makeRed Leaf           = unsafeError "nein"
-
-makeBlack Leaf           = Leaf
-makeBlack (Node _ x l r) = Node B x l r
-
----------------------------------------------------------------------------
--- | Specifications -------------------------------------------------------
----------------------------------------------------------------------------
-
--- | Ordered Red-Black Trees
-
-{-@ type ORBT a = RBTree <{\root v -> v < root }, {\root v -> v > root}> a @-}
-
--- | Binary Search Ordering
-
-{-@ data RBTree a <l :: a -> a -> Bool, r :: a -> a -> Bool>
-              = Leaf
-              | Node { nCol   :: Color
-                     , nKey   :: a
-                     , nLeft  :: RBTree <l, r> (a <l nKey>)
-                     , nRight :: RBTree <l, r> (a <r nKey>) }
-  @-}
diff --git a/tests/pos/RBTree.hs b/tests/pos/RBTree.hs
--- a/tests/pos/RBTree.hs
+++ b/tests/pos/RBTree.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--no-termination" @-}
 
-module Foo where
+module RBTree where
 
 import Language.Haskell.Liquid.Prelude
 
diff --git a/tests/pos/RBTree_col_height.hs b/tests/pos/RBTree_col_height.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RBTree_col_height.hs
@@ -0,0 +1,208 @@
+
+{-@ LIQUID "--no-termination"   @-}
+
+module RBTree_col_height where
+
+import Language.Haskell.Liquid.Prelude
+
+data RBTree a = Leaf 
+              | Node Color a !(RBTree a) !(RBTree a)
+              deriving (Show)
+
+data Color = B -- ^ Black
+           | R -- ^ Red
+           deriving (Eq,Show)
+
+---------------------------------------------------------------------------
+-- | Add an element -------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
+add x s = makeBlack (ins x s)
+
+{-@ ins :: (Ord a) => a -> t:RBT a -> {v: ARBTN a {(bh t)} | ((IsB t) => (isRB v))} @-}
+ins kx Leaf             = Node R kx Leaf Leaf
+ins kx s@(Node B x l r) = case compare kx x of
+                            LT -> let t = lbal x (ins kx l) r in t 
+                            GT -> let t = rbal x l (ins kx r) in t 
+                            EQ -> s
+ins kx s@(Node R x l r) = case compare kx x of
+                            LT -> Node R x (ins kx l) r
+                            GT -> Node R x l (ins kx r)
+                            EQ -> s
+
+---------------------------------------------------------------------------
+-- | Delete an element ----------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
+remove x t = makeBlack (del x t)
+
+{-@ predicate HDel T V = (bh V) = (if (isB T) then (bh T) - 1 else (bh T)) @-}
+
+{-@ del              :: (Ord a) => a -> t:RBT a -> {v:ARBT a | ((HDel t v) && ((isB t) || (isRB v)))} @-}
+del x Leaf           = Leaf
+del x (Node _ y a b) = case compare x y of
+   EQ -> append y a b 
+   LT -> case a of
+           Leaf         -> Node R y Leaf b
+           Node B _ _ _ -> lbalS y (del x a) b
+           _            -> let t = Node R y (del x a) b in t 
+   GT -> case b of
+           Leaf         -> Node R y a Leaf 
+           Node B _ _ _ -> rbalS y a (del x b)
+           _            -> Node R y a (del x b)
+
+{-@ append :: y:a -> l:RBT a -> r:RBTN a {(bh l)} -> (ARBT2 a l r) @-}
+append :: a -> RBTree a -> RBTree a -> RBTree a
+
+append _ Leaf r                               
+  = r
+
+append _ l Leaf                               
+  = l
+
+append piv (Node R lx ll lr) (Node R rx rl rr)  
+  = case append piv lr rl of 
+     Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
+     lrl              -> Node R lx ll (Node R rx lrl rr)
+
+append piv (Node B lx ll lr) (Node B rx rl rr)  
+  = case append piv lr rl of 
+      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
+      lrl              -> lbalS lx ll (Node B rx lrl rr)
+
+append piv l@(Node B _ _ _) (Node R rx rl rr)   
+  = Node R rx (append piv l rl) rr
+
+append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
+  = Node R lx ll (append piv lr r)
+
+---------------------------------------------------------------------------
+-- | Delete Minimum Element -----------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ deleteMin            :: RBT a -> RBT a @-}
+deleteMin (Leaf)         = Leaf
+deleteMin (Node _ x l r) = makeBlack t
+  where 
+    (_, t)               = deleteMin' x l r
+
+
+{-@ deleteMin'                   :: k:a -> l:RBT a -> r:RBTN a {(bh l)} -> (a, ARBT2 a l r) @-}
+deleteMin' k Leaf r              = (k, r)
+deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
+deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
+
+---------------------------------------------------------------------------
+-- | Rotations ------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ lbalS  :: k:a -> l:ARBT a -> r:RBTN a {1 + (bh l)} -> {v: ARBTN a {1 + (bh l)} | ((IsB r) => (isRB v))} @-}
+lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
+lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
+lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
+lbalS k l r                           = liquidError "nein" -- Node R l k r
+
+{-@ rbalS  :: k:a -> l:RBT a -> r:ARBTN a {(bh l) - 1} -> {v: ARBTN a {(bh l)} | ((IsB l) => (isRB v))} @-}
+rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
+rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
+rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
+rbalS k l r                           = liquidError "nein" -- Node R l k r
+
+{-@ lbal  :: k:a -> l:ARBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
+lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k l r                            = Node B k l r
+
+{-@ rbal  :: k:a -> l:RBT a -> ARBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
+rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
+rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
+rbal x l r                            = Node B x l r
+
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ type BlackRBT a = {v: RBT a | ((IsB v) && (bh v) > 0)} @-}
+
+{-@ makeRed :: l:BlackRBT a -> ARBTN a {(bh l) - 1} @-}
+makeRed (Node _ x l r) = Node R x l r
+makeRed Leaf           = liquidError "nein" 
+
+{-@ makeBlack :: ARBT a -> RBT a @-}
+makeBlack Leaf           = Leaf
+makeBlack (Node _ x l r) = Node B x l r
+
+---------------------------------------------------------------------------
+-- | Specifications -------------------------------------------------------
+---------------------------------------------------------------------------
+
+-- | Red-Black Trees
+
+{-@ type RBT a    = {v: RBTree a | ((isRB v) && (isBH v)) } @-}
+
+{-@ type RBTN a N = {v: (RBT a) | (bh v) = N }              @-}
+
+{-@ measure isRB        :: RBTree a -> Bool
+      isRB Leaf         = true
+      isRB (Node c x l r) = ((isRB l) && (isRB r) && ((c == R) => ((IsB l) && (IsB r))))
+  @-}
+
+-- | Almost Red-Black Trees
+
+{-@ type ARBT a    = {v: RBTree a | ((isARB v) && (isBH v))} @-}
+
+{-@ type ARBTN a N = {v: ARBT a   | (bh v) = N }             @-}
+
+{-@ measure isARB        :: (RBTree a) -> Bool
+      isARB Leaf         = true 
+      isARB (Node c x l r) = ((isRB l) && (isRB r))
+  @-}
+
+-- | Conditionally Red-Black Tree
+
+{-@ type ARBT2 a L R = {v:ARBTN a {(bh L)} | (((IsB L) && (IsB R)) => (isRB v))} @-}
+
+-- | Color of a tree
+
+{-@ measure col         :: RBTree a -> Color
+      col (Node c x l r)  = c
+      col Leaf          = B
+  @-}
+
+{-@ measure isB        :: RBTree a -> Bool
+      isB Leaf         = false
+      isB (Node c x l r) = c == B 
+  @-}
+
+{-@ predicate IsB T = not ((col T) == R) @-}
+
+-- | Black Height
+
+{-@ measure isBH        :: RBTree a -> Bool
+      isBH Leaf         = true
+      isBH (Node c x l r) = ((isBH l) && (isBH r) && (bh l) = (bh r))
+  @-}
+
+{-@ measure bh        :: RBTree a -> Int
+      bh Leaf         = 0
+      bh (Node c x l r) = (bh l) + (if (c == R) then 0 else 1) 
+  @-}
+
+-------------------------------------------------------------------------------
+-- Auxiliary Invariants -------------------------------------------------------
+-------------------------------------------------------------------------------
+
+{-@ predicate Invs V = ((Inv1 V) && (Inv2 V) && (Inv3 V))   @-}
+{-@ predicate Inv1 V = (((isARB V) && (IsB V)) => (isRB V)) @-}
+{-@ predicate Inv2 V = ((isRB V) => (isARB V))              @-}
+{-@ predicate Inv3 V = 0 <= (bh V)                          @-}
+
+{-@ invariant {v: Color | (v = R || v = B)}                 @-}
+
+{-@ invariant {v: RBTree a | (Invs v)}                      @-}
+
+{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
+inv Leaf           = Leaf
+inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree_color.hs b/tests/pos/RBTree_color.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RBTree_color.hs
@@ -0,0 +1,191 @@
+{-@ LIQUID "--no-termination"   @-}
+
+module RBTree_color where
+
+import Language.Haskell.Liquid.Prelude
+
+data RBTree a = Leaf 
+              | Node Color a !(RBTree a) !(RBTree a)
+              deriving (Show)
+
+data Color = B -- ^ Black
+           | R -- ^ Red
+           deriving (Eq,Show)
+
+---------------------------------------------------------------------------
+-- | Add an element -------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
+add x s = makeBlack (ins x s)
+
+{-@ ins :: (Ord a) => a -> t:RBT a -> {v: ARBT a | ((notR t) => (isRB v))} @-}
+ins kx Leaf             = Node R kx Leaf Leaf
+ins kx s@(Node B x l r) = case compare kx x of
+                            LT -> let t = lbal x (ins kx l) r in t 
+                            GT -> let t = rbal x l (ins kx r) in t 
+                            EQ -> s
+ins kx s@(Node R x l r) = case compare kx x of
+                            LT -> Node R x (ins kx l) r
+                            GT -> Node R x l (ins kx r)
+                            EQ -> s
+
+---------------------------------------------------------------------------
+-- | Delete an element ----------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
+remove x t = makeBlack (del x t)
+
+{-@ del              :: (Ord a) => a -> t:RBT a -> {v:ARBT a | ((isB t) || (isRB v))} @-}
+del x Leaf           = Leaf
+del x (Node _ y a b) = case compare x y of
+   EQ -> append y a b 
+   LT -> case a of
+           Leaf         -> Node R y Leaf b
+           Node B _ _ _ -> lbalS y (del x a) b
+           _            -> let t = Node R y (del x a) b in t 
+   GT -> case b of
+           Leaf         -> Node R y a Leaf 
+           Node B _ _ _ -> rbalS y a (del x b)
+           _            -> Node R y a (del x b)
+
+{-@ append :: y:a -> l:RBT a -> r:RBT a -> (ARBT2 a l r) @-}
+
+append :: a -> RBTree a -> RBTree a -> RBTree a
+
+append _ Leaf r 
+  = r
+
+append _ l Leaf 
+  = l
+
+append piv (Node R lx ll lr) (Node R rx rl rr)  
+  = case append piv lr rl of 
+      Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
+      lrl              -> Node R lx ll (Node R rx lrl rr)
+
+append piv (Node B lx ll lr) (Node B rx rl rr)  
+  = case append piv lr rl of 
+      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
+      lrl              -> lbalS lx ll (Node B rx lrl rr)
+
+append piv l@(Node B _ _ _) (Node R rx rl rr)   
+  = Node R rx (append piv l rl) rr
+
+append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
+  = Node R lx ll (append piv lr r)
+
+---------------------------------------------------------------------------
+-- | Delete Minimum Element -----------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ deleteMin :: RBT a -> RBT a @-}
+deleteMin (Leaf)         = Leaf
+deleteMin (Node _ x l r) = makeBlack t
+  where 
+    (_, t)               = deleteMin' x l r
+
+
+{-@ deleteMin' :: k:a -> l:RBT a -> r:RBT a -> (a, ARBT2 a l r) @-}
+deleteMin' k Leaf r              = (k, r)
+deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
+deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
+
+---------------------------------------------------------------------------
+-- | Rotations ------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ lbalS                             :: k:a -> l:ARBT a -> r:RBT a -> {v: ARBT a | ((notR r) => (isRB v))} @-}
+lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
+lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
+lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
+lbalS k l r                           = unsafeError "nein"
+
+{-@ rbalS                             :: k:a -> l:RBT a -> r:ARBT a -> {v: ARBT a | ((notR l) => (isRB v))} @-}
+rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
+rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
+rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
+rbalS k l r                           = unsafeError "nein" 
+
+{-@ lbal                              :: k:a -> l:ARBT a -> RBT a -> RBT a @-}
+lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k l r                            = Node B k l r
+
+{-@ rbal                              :: k:a -> l:RBT a -> ARBT a -> RBT a  @-}
+rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
+rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
+rbal x l r                            = Node B x l r
+
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ type BlackRBT a = {v: RBT a | (notR v)} @-}
+
+{-@ makeRed :: l:BlackRBT a -> ARBT a @-}
+makeRed (Node B x l r) = Node R x l r
+makeRed _              = unsafeError "nein" 
+
+{-@ makeBlack :: ARBT a -> RBT a @-}
+makeBlack Leaf           = Leaf
+makeBlack (Node _ x l r) = Node B x l r
+
+---------------------------------------------------------------------------
+-- | Specifications -------------------------------------------------------
+---------------------------------------------------------------------------
+
+-- | Red-Black Trees
+
+{-@ type RBT a    = {v: RBTree a | (isRB v)} @-}
+
+{-@ measure isRB @-}
+isRB :: RBTree a -> Bool
+isRB Leaf           = True
+isRB (Node c x l r) = (isRB l) && (isRB r) && ((c /= R) || ((notR l) && (notR r)))
+
+-- | Almost Red-Black Trees
+
+{-@ type ARBT a    = {v: RBTree a | (isARB v) } @-}
+
+{-@ measure isARB @-} 
+isARB :: RBTree a -> Bool
+isARB Leaf         = True 
+isARB (Node c x l r) = isRB l && isRB r
+
+-- | Conditionally Red-Black Tree
+
+{-@ type ARBT2 a L R = {v:ARBT a | (((notR L) && (notR R)) => (isRB v))} @-}
+
+-- | Color of a tree
+
+{-@ measure col @-}
+col :: RBTree a -> Color
+col (Node c x l r) = c
+col Leaf           = B
+
+{-@ measure isB @-} 
+isB :: RBTree a -> Bool
+isB Leaf           = False
+isB (Node c x l r) = (c == B) 
+
+{-@ inline notR @-}
+notR :: RBTree a -> Bool
+notR t = not ((col t) == R)
+
+------------------------------------------------------------------
+-- | Auxiliary Invariants ----------------------------------------
+------------------------------------------------------------------
+
+{-@ predicate Invs V = ((Inv1 V) && (Inv2 V))               @-}
+{-@ predicate Inv1 V = (((isARB V) && (notR V)) => (isRB V)) @-}
+{-@ predicate Inv2 V = ((isRB V) => (isARB V))              @-}
+
+{-@ invariant {v: Color | (v = R || v = B)}                 @-}
+
+{-@ invariant {v: RBTree a | (Invs v)}                      @-}
+
+{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
+inv Leaf           = Leaf
+inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree_height.hs b/tests/pos/RBTree_height.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RBTree_height.hs
@@ -0,0 +1,177 @@
+
+{-@ LIQUID "--no-termination"   @-}
+{-@ LIQUID "--no-totality"      @-}
+
+module RBTree_height where
+
+import Language.Haskell.Liquid.Prelude
+
+data RBTree a = Leaf 
+              | Node Color a !(RBTree a) !(RBTree a)
+              deriving (Show)
+
+data Color = B -- ^ Black
+           | R -- ^ Red
+           deriving (Eq,Show)
+
+---------------------------------------------------------------------------
+-- | Add an element -------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ add :: (Ord a) => a -> RBT a -> RBT a @-}
+add x s = makeBlack (ins x s)
+
+{-@ ins :: (Ord a) => a -> t:RBT a -> RBTN a {(bh t)}  @-}
+ins kx Leaf             = Node R kx Leaf Leaf
+ins kx s@(Node B x l r) = case compare kx x of
+                            LT -> let t = lbal x (ins kx l) r in t 
+                            GT -> let t = rbal x l (ins kx r) in t 
+                            EQ -> s
+ins kx s@(Node R x l r) = case compare kx x of
+                            LT -> Node R x (ins kx l) r
+                            GT -> Node R x l (ins kx r)
+                            EQ -> s
+
+---------------------------------------------------------------------------
+-- | Delete an element ----------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ remove :: (Ord a) => a -> RBT a -> RBT a @-}
+remove x t = makeBlack (del x t)
+
+{-@ predicate HDel T V = (bh V) = (if (isB T) then (bh T) - 1 else (bh T)) @-}
+
+{-@ del              :: (Ord a) => a -> t:RBT a -> {v:RBT a | (HDel t v)} @-}
+del x Leaf           = Leaf
+del x (Node _ y a b) = case compare x y of
+   EQ -> append y a b 
+   LT -> case a of
+           Leaf         -> Node R y Leaf b
+           Node B _ _ _ -> lbalS y (del x a) b
+           _            -> let t = Node R y (del x a) b in t 
+   GT -> case b of
+           Leaf         -> Node R y a Leaf 
+           Node B _ _ _ -> rbalS y a (del x b)
+           _            -> Node R y a (del x b)
+
+{-@ append :: y:a -> l:RBT a -> r:RBTN a {(bh l)} -> RBTN a {(bh l)} @-}
+append :: a -> RBTree a -> RBTree a -> RBTree a
+
+append _ Leaf r                               
+  = r
+
+append _ l Leaf                               
+  = l
+
+append piv (Node R lx ll lr) (Node R rx rl rr)  
+  = case append piv lr rl of 
+     Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
+     lrl              -> Node R lx ll (Node R rx lrl rr)
+
+append piv (Node B lx ll lr) (Node B rx rl rr)  
+  = case append piv lr rl of 
+      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
+      lrl              -> lbalS lx ll (Node B rx lrl rr)
+
+append piv l@(Node B _ _ _) (Node R rx rl rr)   
+  = Node R rx (append piv l rl) rr
+
+append piv l@(Node R lx ll lr) r@(Node B _ _ _) 
+  = Node R lx ll (append piv lr r)
+
+---------------------------------------------------------------------------
+-- | Delete Minimum Element -----------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ deleteMin            :: RBT a -> RBT a @-}
+deleteMin (Leaf)         = Leaf
+deleteMin (Node _ x l r) = makeBlack t
+  where 
+    (_, t)               = deleteMin' x l r
+
+
+{-@ deleteMin'                   :: k:a -> l:RBT a -> r:RBTN a {(bh l)} -> (a, RBTN a {(bh l)}) @-}
+deleteMin' k Leaf r              = (k, r)
+deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr 
+deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr 
+
+---------------------------------------------------------------------------
+-- | Rotations ------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ lbalS  :: k:a -> l:RBT a -> r:RBTN a {1 + (bh l)} -> RBTN a {1 + (bh l)} @-}
+lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
+lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t 
+lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
+lbalS k l r                           = unsafeError "nein"
+
+{-@ rbalS  :: k:a -> l:RBT a -> r:RBTN a {(bh l) - 1} -> RBTN a {(bh l)}    @-}
+rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
+rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t 
+rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
+rbalS k l r                           = unsafeError "nein"
+
+{-@ lbal  :: k:a -> l:RBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
+lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k l r                            = Node B k l r
+
+{-@ rbal  :: k:a -> l:RBT a -> RBTN a {(bh l)} -> RBTN a {1 + (bh l)} @-}
+rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
+rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
+rbal x l r                            = Node B x l r
+
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ makeRed :: l:RBT a -> RBTN a {(bh l) - 1} @-}
+makeRed (Node B x l r) = Node R x l r
+makeRed _              = unsafeError "nein"
+
+{-@ makeBlack :: RBT a -> RBT a @-}
+makeBlack Leaf           = Leaf
+makeBlack (Node _ x l r) = Node B x l r
+
+---------------------------------------------------------------------------
+-- | Specifications -------------------------------------------------------
+---------------------------------------------------------------------------
+
+-- | Red-Black Trees
+
+{-@ type RBT a    = {v: RBTree a | (isBH v) }   @-}
+
+{-@ type RBTN a N = {v: RBT a  | (bh v) = N }   @-}
+
+-- | Color of a tree
+
+{-@ measure isB        :: RBTree a -> Bool
+      isB Leaf         = false
+      isB (Node c x l r) = c == B 
+  @-}
+
+-- | Black Height
+
+{-@ measure isBH        :: RBTree a -> Bool
+      isBH Leaf         = true
+      isBH (Node c x l r) = ((isBH l) && (isBH r) && (bh l) = (bh r))
+  @-}
+
+{-@ measure bh        :: RBTree a -> Int
+      bh Leaf         = 0
+      bh (Node c x l r) = (bh l) + (if (c == R) then 0 else 1) 
+  @-}
+
+-------------------------------------------------------------------------------
+-- Auxiliary Invariants -------------------------------------------------------
+-------------------------------------------------------------------------------
+
+{-@ invariant {v: RBTree a | (Invs v)}        @-}
+{-@ predicate Invs V = (Inv3 V)               @-}
+{-@ predicate Inv3 V = 0 <= (bh V)            @-}
+
+{-@ invariant {v: Color | (v = R || v = B)}   @-}
+
+{-@ inv            :: RBTree a -> {v:RBTree a | (Invs v)}   @-}
+inv Leaf           = Leaf
+inv (Node c x l r) = Node c x (inv l) (inv r)
diff --git a/tests/pos/RBTree_ord.hs b/tests/pos/RBTree_ord.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RBTree_ord.hs
@@ -0,0 +1,148 @@
+
+{-@ LIQUID "--no-termination"   @-}
+{-@ LIQUID "--no-totality"      @-}
+
+module RBTree_ord (add, remove, deleteMin, deleteMin') where
+
+import Language.Haskell.Liquid.Prelude
+
+data RBTree a = Leaf
+              | Node { nCol   :: Color
+                     , nKey   :: a
+                     , nLeft  :: !(RBTree a)
+                     , nRight :: !(RBTree a)
+                     }
+              deriving (Show)
+
+data Color = B -- ^ Black
+           | R -- ^ Red
+           deriving (Eq,Show)
+
+---------------------------------------------------------------------------
+-- | Add an element -------------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ add :: (Ord a) => a -> ORBT a -> ORBT a @-}
+add x s = makeBlack (ins x s)
+
+{-@ ins :: (Ord a) => a -> ORBT a -> ORBT a @-}
+ins kx Leaf             = Node R kx Leaf Leaf
+ins kx s@(Node B x l r) = case compare kx x of
+                            LT -> let t = lbal x (ins kx l) r in t
+                            GT -> let t = rbal x l (ins kx r) in t
+                            EQ -> s
+ins kx s@(Node R x l r) = case compare kx x of
+                            LT -> Node R x (ins kx l) r
+                            GT -> Node R x l (ins kx r)
+                            EQ -> s
+
+---------------------------------------------------------------------------
+-- | Delete an element ----------------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ remove :: (Ord a) => a -> ORBT a -> ORBT a @-}
+remove x t = makeBlack (del x t)
+
+{-@ del              :: (Ord a) => a -> ORBT a -> ORBT a @-}
+del x Leaf           = Leaf
+del x (Node _ y a b) = case compare x y of
+   EQ -> append y a b
+   LT -> case a of
+           Leaf         -> Node R y Leaf b
+           Node B _ _ _ -> lbalS y (del x a) b
+           _            -> let t = Node R y (del x a) b in t
+   GT -> case b of
+           Leaf         -> Node R y a Leaf
+           Node B _ _ _ -> rbalS y a (del x b)
+           _            -> Node R y a (del x b)
+
+{-@ append  :: y:a -> ORBT {v:a | v < y} -> ORBT {v:a | y < v} -> ORBT a @-}
+append :: a -> RBTree a -> RBTree a -> RBTree a
+
+append _ Leaf r
+  = r
+
+append _ l Leaf
+  = l
+
+append piv (Node R lx ll lr) (Node R rx rl rr)
+  = case append piv lr rl of
+      Node R x lr' rl' -> Node R x (Node R lx ll lr') (Node R rx rl' rr)
+      lrl              -> Node R lx ll (Node R rx lrl rr)
+
+append piv (Node B lx ll lr) (Node B rx rl rr)
+  = case append piv lr rl of
+      Node R x lr' rl' -> Node R x (Node B lx ll lr') (Node B rx rl' rr)
+      lrl              -> lbalS lx ll (Node B rx lrl rr)
+
+append piv l@(Node B _ _ _) (Node R rx rl rr)
+  = Node R rx (append piv l rl) rr
+
+append piv l@(Node R lx ll lr) r@(Node B _ _ _)
+  = Node R lx ll (append piv lr r)
+
+---------------------------------------------------------------------------
+-- | Delete Minimum Element -----------------------------------------------
+---------------------------------------------------------------------------
+
+{-@ deleteMin  :: ORBT a -> ORBT a @-}
+deleteMin (Leaf)         = Leaf
+deleteMin (Node _ x l r) = makeBlack t
+  where
+    (_, t)               = deleteMin' x l r
+
+
+{-@ deleteMin' :: k:a -> ORBT {v:a | v < k} -> ORBT {v:a | k < v} -> (a, ORBT a) @-}
+deleteMin' k Leaf r              = (k, r)
+deleteMin' x (Node R lx ll lr) r = (k, Node R x l' r)   where (k, l') = deleteMin' lx ll lr
+deleteMin' x (Node B lx ll lr) r = (k, lbalS x l' r )   where (k, l') = deleteMin' lx ll lr
+
+---------------------------------------------------------------------------
+-- | Rotations ------------------------------------------------------------
+---------------------------------------------------------------------------
+
+lbalS k (Node R x a b) r              = Node R k (Node B x a b) r
+lbalS k l (Node B y a b)              = let t = rbal k l (Node R y a b) in t
+lbalS k l (Node R z (Node B y a b) c) = Node R y (Node B k l a) (rbal z b (makeRed c))
+lbalS k l r                           = unsafeError "nein"
+
+rbalS k l (Node R y b c)              = Node R k l (Node B y b c)
+rbalS k (Node B x a b) r              = let t = lbal k (Node R x a b) r in t
+rbalS k (Node R x a (Node B y b c)) r = Node R y (lbal x (makeRed a) b) (Node B k c r)
+rbalS k l r                           = unsafeError "nein"
+
+lbal k (Node R y (Node R x a b) c) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k (Node R x a (Node R y b c)) r  = Node R y (Node B x a b) (Node B k c r)
+lbal k l r                            = Node B k l r
+
+rbal x a (Node R y b (Node R z c d))  = Node R y (Node B x a b) (Node B z c d)
+rbal x a (Node R z (Node R y b c) d)  = Node R y (Node B x a b) (Node B z c d)
+rbal x l r                            = Node B x l r
+
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+---------------------------------------------------------------------------
+
+makeRed (Node _ x l r) = Node R x l r
+makeRed Leaf           = unsafeError "nein"
+
+makeBlack Leaf           = Leaf
+makeBlack (Node _ x l r) = Node B x l r
+
+---------------------------------------------------------------------------
+-- | Specifications -------------------------------------------------------
+---------------------------------------------------------------------------
+
+-- | Ordered Red-Black Trees
+
+{-@ type ORBT a = RBTree <{\root v -> v < root }, {\root v -> v > root}> a @-}
+
+-- | Binary Search Ordering
+
+{-@ data RBTree a <l :: a -> a -> Bool, r :: a -> a -> Bool>
+              = Leaf
+              | Node { nCol   :: Color
+                     , nKey   :: a
+                     , nLeft  :: RBTree <l, r> (a <l nKey>)
+                     , nRight :: RBTree <l, r> (a <r nKey>) }
+  @-}
diff --git a/tests/pos/Range.hs b/tests/pos/Range.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Range.hs
@@ -0,0 +1,31 @@
+module Range (prop_rng5, myfoldl) where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ invariant {v:Int| v >= 0} @-}
+
+range :: Int -> Int -> [Int]
+range i j = range' (j - i) i j
+
+range' :: Int -> Int -> Int -> [Int]
+range' d i j  
+  | i < j     = i : (range' (d-1) (i + 1) j)
+  | otherwise = []  
+
+
+sumTo = foldl (+) 0 . range 0 
+
+{-@ decrease lgo 2 @-}
+--myfoldl :: (Int -> Int -> Int) -> Int -> [Int] -> Int
+myfoldl f z0 xs0 = lgo z0 xs0
+             where
+                lgo z []     =  z
+                lgo z (x:xs) = lgo (f z x) xs
+n = choose 0 
+m = choose 1
+
+-- prop_rng1 = map (liquidAssertB . (0 <=)) $ range 0 n
+-- prop_rng2 = map (liquidAssertB . (n <=)) $ range n 100
+-- prop_rng3 = map (liquidAssertB . (n <=)) $ range n m
+-- prop_rng4 = map (liquidAssertB . (<= m)) $ range n m 
+prop_rng5 = liquidAssertB (0 <= sumTo n)
diff --git a/tests/pos/Range1.hs b/tests/pos/Range1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Range1.hs
@@ -0,0 +1,12 @@
+module Range1 (single, prop_rng1) where
+
+import Language.Haskell.Liquid.Prelude
+
+mynil  = []
+
+single x = [x] 
+
+range :: Int -> Int -> [Int]
+range i j = [i]
+
+prop_rng1 n   = map (liquidAssertB . (0 <=)) $ range 0 n
diff --git a/tests/pos/RangeAdt.hs b/tests/pos/RangeAdt.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RangeAdt.hs
@@ -0,0 +1,37 @@
+module RangeAdt (llen) where
+
+import Language.Haskell.Liquid.Prelude
+
+data L a = Nil | Con a (L a)
+{-@ data L [llen] a = Nil | Con { lHd ::a, lTl :: L a } @-}
+
+{-@ measure llen @-}
+{-@ llen :: L a -> Nat @-}
+llen :: L a -> Int 
+llen Nil = 0 
+llen (Con _ xs) = 1 + llen xs 
+
+range :: Int -> Int -> L Int
+range i j = range' (j-i) i j
+
+range' :: Int -> Int -> Int -> L Int
+range' d i j
+  | i < j  = i `Con` (range' (d-1) (i + 1) j)
+  | otherwise = Nil
+
+mapL f Nil        = Nil
+mapL f (Con x xs) = (f x) `Con` (mapL f xs)
+
+foldL f b Nil        = b
+foldL f b (Con x xs) = foldL f (f b x) xs
+
+sumTo = foldL plus 0 . range 0
+
+n = choose 0
+m = choose 1
+
+prop_rng1 = mapL (liquidAssertB . (0 <=)) $ range 0 n
+prop_rng2 = mapL (liquidAssertB . (n <=)) $ range n 100
+prop_rng3 = mapL (liquidAssertB . (n <=)) $ range n m
+prop_rng4 = mapL (liquidAssertB . (<= m)) $ range n m
+prop_rng5 = liquidAssertB (0 <= sumTo n)
diff --git a/tests/pos/ReWrite.hs b/tests/pos/ReWrite.hs
--- a/tests/pos/ReWrite.hs
+++ b/tests/pos/ReWrite.hs
@@ -1,4 +1,4 @@
-module ReWrite where 
+module ReWrite where
 
 {-@ LIQUID "--rw-termination-check" @-}
 {-@ LIQUID "--reflection" @-}
diff --git a/tests/pos/ReWrite10.hs b/tests/pos/ReWrite10.hs
--- a/tests/pos/ReWrite10.hs
+++ b/tests/pos/ReWrite10.hs
@@ -10,10 +10,12 @@
 data N = S N | Z
 
 
+{-@ lazy    f @-}
 {-@ reflect f @-}
 f :: N -> N
 f x = g x
 
+{-@ lazy    g @-}
 {-@ reflect g @-}
 g (S x) = f x
 g Z     = Z
diff --git a/tests/pos/ReWrite3.hs b/tests/pos/ReWrite3.hs
--- a/tests/pos/ReWrite3.hs
+++ b/tests/pos/ReWrite3.hs
@@ -1,5 +1,6 @@
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
 -- Ensure that rewrites work with refinements
-module ReWrite3 where 
+module ReWrite3 where
 
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple" @-}
diff --git a/tests/pos/RealProps.hs b/tests/pos/RealProps.hs
--- a/tests/pos/RealProps.hs
+++ b/tests/pos/RealProps.hs
@@ -2,7 +2,7 @@
 
 -- TAG: class
 
-module Div where
+module RealProps where
 
 {-@ type Valid = {v:Bool | v } @-}
 
diff --git a/tests/pos/Rebind.hs b/tests/pos/Rebind.hs
--- a/tests/pos/Rebind.hs
+++ b/tests/pos/Rebind.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE RebindableSyntax #-}
 
-module Rebind () where 
+module Rebind () where
 
 import Prelude hiding ((>>), (>>=), return)
 
diff --git a/tests/pos/RecQSort.hs b/tests/pos/RecQSort.hs
--- a/tests/pos/RecQSort.hs
+++ b/tests/pos/RecQSort.hs
@@ -1,6 +1,6 @@
 -- TAG: abref 
 
-module GhcSort (qsort) where
+module RecQSort (qsort) where
 
 {-@ type OList a =  [a]<{\fld v -> (v >= fld)}>  @-}
 
diff --git a/tests/pos/RecQSort0.hs b/tests/pos/RecQSort0.hs
--- a/tests/pos/RecQSort0.hs
+++ b/tests/pos/RecQSort0.hs
@@ -1,4 +1,4 @@
-module GhcSort () where
+module RecQSort0 () where
 
 {-@ type OList a =  [a]<{\fld v -> (v >= fld)}>  @-}
 
diff --git a/tests/pos/RecSelector.hs b/tests/pos/RecSelector.hs
--- a/tests/pos/RecSelector.hs
+++ b/tests/pos/RecSelector.hs
@@ -1,4 +1,4 @@
-module Invariant where
+module RecSelector where
 
 data F a = F {fx :: a, fy :: a, fzz :: a} | G {fx :: a}
 
diff --git a/tests/pos/Rec_annot_go.hs b/tests/pos/Rec_annot_go.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Rec_annot_go.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Rec_annot_go () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+{-@ invariant {v:Int | v >= 0} @-}
+
+{-@ decrease go 1 @-}
+loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
+loop lo hi base f = go (hi-lo) base lo
+  where
+    go (d::Int) acc i     
+      | i /= hi   = go (d-1) (f i acc) (i + 1)
+      | otherwise = acc
+
+poo = loop 0 10 0 (+)
+
diff --git a/tests/pos/Record0.hs b/tests/pos/Record0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Record0.hs
@@ -0,0 +1,25 @@
+{-@ LIQUID "--exact-data-cons" @-}
+
+module Record0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ data LL a = BXYZ { size  :: {v: Int | v > 0 }
+                     , elems :: {v: [a] | (len v) = size }
+                     }
+  @-}
+
+data LL a = BXYZ { size  :: Int
+                 , elems :: [a]
+                 }
+
+{-@ mk :: a -> Int -> LL a @-}
+mk x n | n > 0     = BXYZ n (clone x n)
+       | otherwise = BXYZ 1 [x]
+
+{-@ bk :: LL a -> {v: Int | v > 0} @-}
+bk (BXYZ n xs) = liquidAssert (length xs == n) n
+
+{-@ clone :: x:a -> n:Int -> {v:[a]| (len v) = n} @-}
+clone :: a -> Int -> [a]
+clone = unsafeError "FOO"
diff --git a/tests/pos/Record1.hs b/tests/pos/Record1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Record1.hs
@@ -0,0 +1,15 @@
+module Record1 (trim) where
+
+data Map k a  = Tip
+
+{-@ data Map k a <l :: root:k -> k -> Bool>
+         = Tip
+  @-}
+
+{-@ measure isBin @-}
+isBin :: Map k a -> Bool
+isBin Tip = False
+
+trim :: Map k a
+trim = undefined 
+
diff --git a/tests/pos/RecordSelectorError.hs b/tests/pos/RecordSelectorError.hs
--- a/tests/pos/RecordSelectorError.hs
+++ b/tests/pos/RecordSelectorError.hs
@@ -1,4 +1,4 @@
-module Foo where
+module RecordSelectorError where
 
 data F a b = F {fx :: a, fy :: b} | G {fx :: a}
 {-@ data F a b = F {fx :: a, fy :: b} | G {fx :: a} @-}
diff --git a/tests/pos/Recursion0.hs b/tests/pos/Recursion0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Recursion0.hs
@@ -0,0 +1,8 @@
+module Recursion0 where
+
+
+{-@ total :: Nat -> Nat @-}
+total :: Int -> Int 
+total 0 = 0
+total n = 1 + total (n-1)
+
diff --git a/tests/pos/Reduction.hs b/tests/pos/Reduction.hs
--- a/tests/pos/Reduction.hs
+++ b/tests/pos/Reduction.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--higherorder"    @-}
 
-module Reductions where
+module Reduction where
 
 {-@ reduction :: forall<p :: a -> Bool -> Bool>. 
                  f:(a -> a) 
diff --git a/tests/pos/Reflect0.hs b/tests/pos/Reflect0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Reflect0.hs
@@ -0,0 +1,16 @@
+{-@ LIQUID "--higherorder"     @-}
+
+module Reflect0 where
+
+{-@ fib :: n:Nat -> Nat @-}
+{-@ reflect fib @-}
+fib :: Int -> Int
+fib n
+  | n == 0    = 0
+  | n == 1    = 1
+  | otherwise = fib (n-1) + fib (n-2)
+
+
+{-@ goo :: Nat -> Nat @-}
+goo :: Int -> Int
+goo x = fib x
diff --git a/tests/pos/ReflectAlias.hs b/tests/pos/ReflectAlias.hs
--- a/tests/pos/ReflectAlias.hs
+++ b/tests/pos/ReflectAlias.hs
@@ -2,7 +2,7 @@
 
 {-# LANGUAGE ScopedTypeVariables #-}
 
-module Bob where
+module ReflectAlias where
 
 type Val = Int
 
diff --git a/tests/pos/ReflectBooleanFunctions.hs b/tests/pos/ReflectBooleanFunctions.hs
--- a/tests/pos/ReflectBooleanFunctions.hs
+++ b/tests/pos/ReflectBooleanFunctions.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--exactdc"      @-}
 {-@ LIQUID "--higherorder"  @-}
-module Data.Foo where
+module ReflectBooleanFunctions where
 
 
 {-@ reflect foo @-}
diff --git a/tests/pos/ReflectMutual.hs b/tests/pos/ReflectMutual.hs
--- a/tests/pos/ReflectMutual.hs
+++ b/tests/pos/ReflectMutual.hs
diff --git a/tests/pos/RelativeComplete.hs b/tests/pos/RelativeComplete.hs
--- a/tests/pos/RelativeComplete.hs
+++ b/tests/pos/RelativeComplete.hs
@@ -1,4 +1,4 @@
-module Compose where
+module RelativeComplete where
 
 {-@ LIQUID "--no-termination" @-}
 
diff --git a/tests/pos/Repeat.hs b/tests/pos/Repeat.hs
--- a/tests/pos/Repeat.hs
+++ b/tests/pos/Repeat.hs
@@ -1,4 +1,4 @@
-module Foo where
+module Repeat where
 import Prelude hiding (repeat, take)
 
 data L a = N | C a (L a)
diff --git a/tests/pos/RepeatHigherOrder.hs b/tests/pos/RepeatHigherOrder.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/RepeatHigherOrder.hs
@@ -0,0 +1,34 @@
+{-@ LIQUID "--no-termination" @-}
+
+-- TAG: bound 
+-- TAG: absref 
+
+module RepeatHigherOrder where
+
+import Prelude hiding (repeat, succ)
+import Language.Haskell.Liquid.Prelude
+
+repeat :: Int -> (a -> a) -> a -> a
+goal   :: Int -> Int
+     
+{-@ bound step @-}
+step :: (a -> a -> Bool) -> (Int -> a -> Bool) -> Int -> a -> a -> Bool
+step pf pr = \ i x x' -> pr (i - 1) x ==> pf x x' ==> pr i x'
+
+-- This syntax is not yet supported in liquidhaskell-8
+{- repeat :: forall a <f :: a -> a -> Bool, r :: Int -> a -> Bool>.
+                (Step a f r) => 
+                 n:Nat -> (y:a -> a<f y>) -> a<r 0> -> a<r n>
+  @-}
+
+
+{-@ repeat :: forall a <f :: a -> a -> Bool, r :: Int -> a -> Bool>.
+                {i::Int, x::a<r (i-1)>|- a<f x> <:a <r i>}
+                 n:Nat -> (y:a -> a<f y>) -> a<r 0> -> a<r n>
+  @-}
+repeat 0 _ x = x
+repeat n f x = repeat (n - 1) f (f x)
+
+{-@ goal :: n:Nat -> {r:Nat | n <= r} @-}
+goal n = repeat n (+ 1) 0
+
diff --git a/tests/pos/ResolveA.hs b/tests/pos/ResolveA.hs
--- a/tests/pos/ResolveA.hs
+++ b/tests/pos/ResolveA.hs
@@ -1,4 +1,4 @@
-module ResolveA  where
+module ResolveA where
 
 import qualified ResolveB as RB
 import qualified ResolveB
diff --git a/tests/pos/ResolveALib.hs b/tests/pos/ResolveALib.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ResolveALib.hs
@@ -0,0 +1,22 @@
+module ResolveA where
+
+import qualified ResolveBLib as RB
+import qualified ResolveBLib
+
+{-@ measure getFooA :: Foo -> Int
+      getFooA (Foo x) = x
+  @-}
+
+data Foo = Foo Int
+
+y = RB.Foo 1
+z = RB.A 
+{-@ qualif NotA(v:RB.Bar): (notA v) @-}
+
+{-@ measure notA :: RB.Bar -> Bool
+      notA RB.A = false
+      notA RB.B = true
+      notA RB.C = false
+  @-}
+
+{-@ predicate NotA V = V != RB.A @-}
diff --git a/tests/pos/ResolveBLib.hs b/tests/pos/ResolveBLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ResolveBLib.hs
@@ -0,0 +1,9 @@
+module ResolveBLib where
+
+{-@ measure getFoo :: Foo -> Int
+      getFoo (Foo x) = x
+  @-}
+
+data Foo = Foo Int
+
+data Bar = A | B | C
diff --git a/tests/pos/Rest.hs b/tests/pos/Rest.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Rest.hs
@@ -0,0 +1,227 @@
+{-@ LIQUID "--exact-data-cons" @-}
+{-@ LIQUID "--ple" @-}
+
+module Rest where
+
+import Language.Haskell.Liquid.ProofCombinators
+import Prelude hiding (length, max)
+
+-- | The type of a Stitch expression
+data Ty = TInt
+        | TBool
+        | TFun { funArgTy :: Ty, funResTy :: Ty }
+  deriving (Show, Eq)
+
+{-@
+data Ty = TInt
+        | TBool
+        | TFun { funArgTy :: Ty, funResTy :: Ty }
+@-}
+
+{-@ measure isFunTy @-}
+isFunTy :: Ty -> Bool
+isFunTy (TFun _ _) = True
+isFunTy _ = False
+
+
+-- | An @ArithOp ty@ is an operator on numbers that produces a result
+-- of type @ty@
+data ArithOp
+  = Plus
+  | Minus
+  | Times
+  | Divide
+  | Mod
+  | Less
+  | LessE
+  | Greater
+  | GreaterE
+  | Equals
+  deriving (Eq, Show)
+
+-- | Extract the result type of an Op
+{-@ measure arithType @-}
+arithType :: ArithOp -> Ty
+arithType Plus     = TInt
+arithType Minus    = TInt
+arithType Times    = TInt
+arithType Divide   = TInt
+arithType Mod      = TInt
+arithType Less     = TBool
+arithType LessE    = TBool
+arithType Greater  = TBool
+arithType GreaterE = TBool
+arithType Equals   = TBool
+
+{-@ invariant { op:ArithOp | arithType op = TBool || arithType op = TInt } @-}
+
+
+{-@ type Nat = { v : Int | v >= 0 } @-}
+type Nat = Int
+
+{-@ inline max @-}
+max :: Ord a => a -> a -> a
+max a b = if a > b then a else b
+
+{-@ inline minus @-}
+minus :: Nat -> Nat -> Nat
+minus a b = max 0 (a - b)
+
+{-@
+reflect elemAt
+elemAt :: n : Nat -> { xs:[a] | length xs > n } -> a
+@-}
+elemAt :: Nat -> [a] -> a
+elemAt 0 (x:_) = x
+elemAt i (_:xs) = elemAt (i-1) xs
+
+{-@
+measure length
+length :: xs : [a] -> Nat
+@-}
+length :: [a] -> Nat
+length [] = 0
+length (_:xs) = 1 + length xs
+
+{-@
+reflect append
+append ::
+  xs : [a] ->
+  ys : [a] ->
+  { zs:[a] | length zs == length xs + length ys }
+ @-}
+append :: [a] -> [a] -> [a]
+append [] ys = ys
+append (x:xs) ys = x : append xs ys
+
+{-@
+appendLengh
+  :: xs : [a]
+  -> ys : [a]
+  -> { length (append xs ys) == length xs + length ys}
+@-}
+appendLengh :: [a] -> [a] -> ()
+appendLengh xs ys = () ? append xs ys
+
+{-@
+elemAtThroughAppend
+  :: i : Nat
+  -> xs : { xs:[a] | i < length xs }
+  -> ys : [a]
+  -> { elemAt i (append xs ys) = elemAt i xs }
+@-}
+elemAtThroughAppend :: Nat -> [a] -> [a] -> ()
+elemAtThroughAppend 0 (_:_) ys = ()
+elemAtThroughAppend i (_:xss) ys = elemAtThroughAppend (i - 1) xss ys
+
+{-@
+predicate WellTyped E CTX = checkBindings CTX E && numFreeVarsExp E <= length CTX
+type WellTypedExp CTX = { e : Exp | WellTyped e CTX }
+type FunExp = { e : Exp | isFunTy (exprType e) }
+type ExpT T = { e : Exp | T = exprType e }
+data Exp
+  = Var Ty Nat
+  | Lam Ty Exp
+  | App (e1 :: FunExp) (ExpT (funArgTy (exprType e1)))
+  | Let Exp Exp
+  | Arith (ExpT TInt) ArithOp (ExpT TInt)
+  | Cond (ExpT TBool) (a :: Exp) (ExpT (exprType a))
+  | Fix ({ e:FunExp | funArgTy (exprType e) = funResTy (exprType e) })
+  | IntE Int
+  | BoolE Bool
+@-}
+
+-- | Checked expression
+data Exp
+  = Var Ty Nat
+  | Lam Ty Exp
+  | App Exp Exp
+  | Let Exp Exp
+  | Arith Exp ArithOp Exp
+  | Cond Exp Exp Exp
+  | Fix Exp
+  | IntE Int
+  | BoolE Bool
+  deriving Show
+
+{-@ measure exprType @-}
+exprType :: Exp -> Ty
+exprType (Var ty _) = ty
+exprType (Lam ty e) = TFun ty (exprType e)
+exprType (App e1 _) = funResTy (exprType e1)
+exprType (Let _ e2) = exprType e2
+exprType (Arith _ op _) = arithType op
+exprType (Cond _ e2 _) = exprType e2
+exprType (Fix e) = funResTy (exprType e)
+exprType (IntE _) = TInt
+exprType (BoolE _) = TBool
+
+-- | Check that all occurrences of a variable have the given type
+{-@
+reflect checkBindings
+checkBindings
+  :: ctx : [Ty]
+  -> { e : Exp | numFreeVarsExp e <= length ctx }
+  -> Bool
+@-}
+checkBindings :: [Ty] -> Exp -> Bool
+checkBindings ctx (Var vty i) = elemAt i ctx == vty
+checkBindings ctx (Lam t e) = checkBindings (t:ctx) e
+checkBindings ctx (App e1 e2) = checkBindings ctx e1 && checkBindings ctx e2
+checkBindings ctx (Let e1 e2) = checkBindings ctx e1 && checkBindings (exprType e1 : ctx) e2
+checkBindings ctx (Arith e1 _ e2) = checkBindings ctx e1 && checkBindings ctx e2
+checkBindings ctx (Cond e1 e2 e3) = checkBindings ctx e1 && checkBindings ctx e2 && checkBindings ctx e3
+checkBindings ctx (Fix e) = checkBindings ctx e
+checkBindings _ (IntE _) = True
+checkBindings _ (BoolE _) = True
+
+{-@
+rewriteWith aClosedExpIsValidInAnyContext [appendLengh]
+aClosedExpIsValidInAnyContext
+  :: ctx0 : [Ty]
+  -> ctx1 : [Ty]
+  -> e : Exp
+  -> { WellTyped e ctx0 <=>
+       WellTyped e (append ctx0 ctx1) && numFreeVarsExp e <= length ctx0
+     }
+@-}
+aClosedExpIsValidInAnyContext :: [Ty] -> [Ty] -> Exp -> ()
+aClosedExpIsValidInAnyContext ctx0 ctx1 e = case e of
+  Var _ i ->
+    if i < length ctx0 then elemAtThroughAppend i ctx0 ctx1
+    else ()
+  Lam ty body ->
+    aClosedExpIsValidInAnyContext (ty:ctx0) ctx1 body
+  App e1 e2 ->
+    aClosedExpIsValidInAnyContext ctx0 ctx1 e1 ? aClosedExpIsValidInAnyContext ctx0 ctx1 e2
+  Let e1 e2 ->
+    aClosedExpIsValidInAnyContext ctx0 ctx1 e1 ? aClosedExpIsValidInAnyContext (exprType e1 : ctx0) ctx1 e2
+  Arith e1 _ e2 ->
+    aClosedExpIsValidInAnyContext ctx0 ctx1 e1 ? aClosedExpIsValidInAnyContext ctx0 ctx1 e2
+  Cond e1 e2 e3 ->
+    aClosedExpIsValidInAnyContext ctx0 ctx1 e1
+      ? aClosedExpIsValidInAnyContext ctx0 ctx1 e2
+      ? aClosedExpIsValidInAnyContext ctx0 ctx1 e3
+  Fix body ->
+    aClosedExpIsValidInAnyContext ctx0 ctx1 body
+  IntE _ -> ()
+  BoolE _ -> ()
+
+{-@
+measure numFreeVarsExp
+numFreeVarsExp :: Exp -> Nat
+@-}
+numFreeVarsExp :: Exp -> Nat
+numFreeVarsExp (Var _ v) = v + 1
+numFreeVarsExp (Lam _ body) = minus (numFreeVarsExp body) 1
+numFreeVarsExp (App e1 e2) = max (numFreeVarsExp e1) (numFreeVarsExp e2)
+numFreeVarsExp (Let e1 e2) =
+    max (numFreeVarsExp e1) (minus (numFreeVarsExp e2) 1)
+numFreeVarsExp (Arith e1 _ e2) = max (numFreeVarsExp e1) (numFreeVarsExp e2)
+numFreeVarsExp (Cond e1 e2 e3) =
+    max (max (numFreeVarsExp e1) (numFreeVarsExp e2)) (numFreeVarsExp e3)
+numFreeVarsExp (Fix body) = numFreeVarsExp body
+numFreeVarsExp (IntE _) = 0
+numFreeVarsExp (BoolE _) = 0
+
+
diff --git a/tests/pos/Risers.hs b/tests/pos/Risers.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Risers.hs
@@ -0,0 +1,12 @@
+module Risers () where
+
+{-@ predicate NonNull X = ((len X) > 0) @-}
+
+{-@ risers :: (Ord a) => zs:[a] -> {v: [[a]] | ((NonNull zs) => (NonNull v)) } @-} 
+risers []        
+  = []
+risers [x]       
+  = [[x]]
+risers (x:y:etc) 
+  = if x <= y then (x:s):ss else [x]:(s:ss)
+    where (s:ss) = risers (y:etc)
diff --git a/tests/pos/Rta.hs b/tests/pos/Rta.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Rta.hs
@@ -0,0 +1,19 @@
+module Rta where
+
+{-@ predicate Mouse X Y = X > Y @-}
+
+{-@ inline mickey @-}
+mickey :: (Ord a) => a -> a -> Bool
+mickey x y = x > y
+
+{-@ type PosInline    a N = {v:a | mickey v N} @-}
+
+{-@ type PosPredicate a N = {v:a | Mouse v N} @-}
+
+{-@ incrI :: PosInline Int 0 -> PosInline Int 0 @-}
+incrI :: Int -> Int
+incrI x = x + 1
+
+{-@ incrP :: PosPredicate Int 0 -> PosPredicate Int 0 @-}
+incrP :: Int -> Int
+incrP x = x + 1
diff --git a/tests/pos/Scanr.hs b/tests/pos/Scanr.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Scanr.hs
@@ -0,0 +1,7 @@
+module Scanr () where
+
+{-@ scanrr  :: (a -> b -> b) -> b -> xs:[a] -> {v: [b] | len v = 1 + len xs } @-}
+-- scanrr             :: (a -> b -> b) -> b -> [a] -> [b]
+scanrr _ q0 []     =  [q0]
+scanrr f q0 (x:xs) =  f x q : qs
+                      where qs@(q:_) = scanrr f q0 xs 
diff --git a/tests/pos/SelfList.hs b/tests/pos/SelfList.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/SelfList.hs
@@ -0,0 +1,26 @@
+module SelfList () where
+
+{-@ LIQUID "--bscope" @-}
+
+import Data.Set (Set(..)) 
+
+{-@ include <selfList.hquals> @-}
+
+{-@ invariant {v0:[{v: a | (Set_mem v (listElts v0))}] | true } @-}
+
+{-@ type IList a  = {v0: [{v:a | (Set_mem v (listElts v0))}] | true } @-}
+
+{-@ moo :: [a] -> IList a @-}
+moo []     = [] 
+moo (_:xs) = xs
+
+goo []     = [] 
+goo (_:xs) = xs
+
+{-@ poo :: IList Int @-}
+poo = goo xs
+  where 
+    xs :: [Int]
+    xs = [2,1,3,2]
+
+
diff --git a/tests/pos/SimplifyTup00.hs b/tests/pos/SimplifyTup00.hs
--- a/tests/pos/SimplifyTup00.hs
+++ b/tests/pos/SimplifyTup00.hs
@@ -1,7 +1,7 @@
 
 -- See: https://github.com/ucsd-progsys/liquidhaskell/pull/752
 
-module FOO (mkSessData) where
+module SimplifyTup00 (mkSessData) where
 
 mkSessData :: TcpEndPoint -> Bool
 mkSessData = isSrcTCP
diff --git a/tests/pos/Solver.hs b/tests/pos/Solver.hs
--- a/tests/pos/Solver.hs
+++ b/tests/pos/Solver.hs
@@ -5,7 +5,7 @@
 {-@ LIQUID "--no-termination" @-}
 {-@ LIQUID "--short-names"    @-}
 
-module MultiParams where
+module Solver where
 
 import Data.Tuple
 import Language.Haskell.Liquid.Prelude ((==>))
@@ -33,10 +33,10 @@
             {y::a, b::{v:Bool<w y> | v} |- {v:a | v == y} <: a<p>}
             (x:a -> Bool<w x>) -> [a] -> Maybe (a<p>) @-}
 find :: (a -> Bool) -> [a] -> Maybe a
-find f (x:xs) 
-	| f x       = Just x
+find f (x:xs)
+    | f x       = Just x
     | otherwise = Nothing
-find f [] 	    = Nothing
+find f []       = Nothing
 
 cons x xs = (x:xs)
 nil       = []
@@ -46,19 +46,19 @@
 asgns :: Formula -> [Asgn] -- generates all possible T/F vectors
 asgns = go . vars
   where
-  	go [] = []
-  	go (x:xs) = let ass = go xs in (inject (x, VTrue) ass) ++ (inject (x, VFalse) ass)
+    go [] = []
+    go (x:xs) = let ass = go xs in (inject (x, VTrue) ass) ++ (inject (x, VFalse) ass)
 
-  	inject x xs = map (\y -> x:y) xs
+    inject x xs = map (\y -> x:y) xs
 
 vars :: Formula -> [Var]
 vars = nub . go
   where
-  	go [] = []
-  	go (ls:xs) = map go' ls ++ go xs
+    go [] = []
+    go (ls:xs) = map go' ls ++ go xs
 
-  	go' (Pos x) = x
-  	go' (Neg x) = x
+    go' (Pos x) = x
+    go' (Neg x) = x
 
 -- | Satisfaction
 
diff --git a/tests/pos/Spec0.hs b/tests/pos/Spec0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Spec0.hs
@@ -0,0 +1,12 @@
+module Spec0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ assert incr :: x:{v: Int | v >= 0} -> {v: Int | v > x} @-}
+incr   :: Int -> Int
+incr x = x + 1
+
+myabs x = if x >= 0 then incr x else (0 - x)
+
+prop_abs   = let n1 = choose 0 in
+             liquidAssertB ((myabs n1) >= 0)
diff --git a/tests/pos/StackClass.hs b/tests/pos/StackClass.hs
--- a/tests/pos/StackClass.hs
+++ b/tests/pos/StackClass.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--pruneunsorted" @-}
 
-module SClass where
+module StackClass where
 
 import qualified Data.Set
 
diff --git a/tests/pos/Stacks0.hs b/tests/pos/Stacks0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Stacks0.hs
@@ -0,0 +1,48 @@
+module Stacks0 () where
+
+import qualified Data.Set as S -- (Set(..))
+
+data LL a = Nil | Cons { headC :: a
+                       , tailC :: LL a
+                       }
+
+{-@ data LL a = Nil | Cons { headC :: a
+                           , tailC :: {v: LL a | not (Set_mem headC (elts v)) }
+                           }
+  @-}
+
+{-@ measure elts @-} 
+elts :: (Ord a) => LL a -> S.Set a
+elts (Nil)       = S.empty
+elts (Cons x xs) = S.union (S.singleton x) (elts xs)
+
+{-@ predicate Disjoint X Y = (Set_emp (Set_cap (elts X) (elts Y))) @-}
+{-@ predicate NotIn    X Y = not (Set_mem X (elts Y))              @-}
+
+ll2 = Cons x0 (Cons x1 (Cons x2 Nil))
+  where x0 :: Int
+        x0  = 0
+        x1  = 1
+        x2  = 2
+
+{-@ data Stack a = St { focus  :: a
+                      , up     :: {vu: LL a | (NotIn focus vu) }
+                      , down   :: {vd: LL a | ((NotIn focus vd) && (Disjoint up vd)) }
+                      }
+  @-}
+
+data Stack a = St { focus  :: !a
+                  , up     :: !(LL a)
+                  , down   :: !(LL a)
+                  }
+
+{-@ fresh :: a -> Stack a @-}
+fresh x = St x Nil Nil
+
+{-@ moveUp :: Stack a -> Stack a @-}
+moveUp (St x (Cons y ys) zs) = St y ys (Cons x zs)
+moveUp s                     = s
+
+{-@ moveDn :: Stack a -> Stack a @-}
+moveDn (St x ys (Cons z zs)) = St z (Cons x ys) zs
+moveDn s                     = s
diff --git a/tests/pos/State00.hs b/tests/pos/State00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/State00.hs
@@ -0,0 +1,10 @@
+module State00 () where
+
+type State  = Int
+data ST a b = Superb (b -> (a, b)) 
+
+{-@ fresh :: ST {v:Int | v >= 0} {v:Int | v >= 0} @-}
+fresh :: ST Int Int
+fresh = Superb (\n -> (n, n+1))
+
+
diff --git a/tests/pos/StateConstraints.hs b/tests/pos/StateConstraints.hs
--- a/tests/pos/StateConstraints.hs
+++ b/tests/pos/StateConstraints.hs
@@ -1,4 +1,4 @@
-module Compose where
+module StateConstraints where
 
 
 
diff --git a/tests/pos/StateConstraints0.hs b/tests/pos/StateConstraints0.hs
--- a/tests/pos/StateConstraints0.hs
+++ b/tests/pos/StateConstraints0.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--noclasscheck"    @-}
-module Compose where
+module StateConstraints0 where
 
 import Prelude hiding (Monad(..))
 
diff --git a/tests/pos/StateConstraints00.hs b/tests/pos/StateConstraints00.hs
--- a/tests/pos/StateConstraints00.hs
+++ b/tests/pos/StateConstraints00.hs
@@ -1,4 +1,4 @@
-module Compose where
+module StateConstraints00 where
 
 import Prelude hiding (Monad, return )
 
diff --git a/tests/pos/StateF00.hs b/tests/pos/StateF00.hs
--- a/tests/pos/StateF00.hs
+++ b/tests/pos/StateF00.hs
@@ -1,6 +1,6 @@
 -- TAG: absref
 
-module State (
+module StateF00 (
    returnST -- :: a -> ST a s
 --  , bindST   -- :: ST a s -> (a -> ST b s) -> ST b s
  , ST(..)
diff --git a/tests/pos/StateInvarint.hs b/tests/pos/StateInvarint.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/StateInvarint.hs
@@ -0,0 +1,43 @@
+module StateInvarint () where
+
+import Prelude hiding (return, (>>=))
+
+data ST s a = S (s -> (a, s))
+{-@ data ST s a <p :: s -> Bool> 
+     = S { x:: (f:s<p> -> (a, s<p>)) } 
+  @-}
+
+{-@ foo :: (Int, {v:Int|v >=0})@-}
+foo = apply action 0
+
+{-@ action :: ST <{\v -> v>=0 }> Int Int@-}
+action :: ST Int Int
+action
+ = act1 `comp` \n1 -> 
+   act2 `comp` \n2 -> 
+   return n1
+
+
+{-@ act1 :: ST <{\v -> v>=0 } > Int Int @-}
+act1 :: ST Int Int
+act1 = S (\n -> (n, n+1))
+
+act2 :: ST Int Int
+act2 = S (\n -> (n, n+9))
+
+{-@ apply :: forall <p :: s -> Bool>. ST <p> s a -> f:s<p> -> (a, s <p>) @-}
+apply :: ST s a -> s -> (a, s)
+apply (S f) x = f x
+
+{-@ return :: forall <p:: s -> Bool>. x:a -> ST <p> s {v:a|v=x} @-}
+return ::  a -> ST s a
+return x = S $ \s -> (x, s)
+
+{-@ comp :: forall < p :: s -> Bool>. ST <p> s a -> (a -> ST <p> s b) -> ST <p> s b @-}
+comp :: ST s a -> (a -> ST s b) -> ST s b
+(S m) `comp` k 
+  = S $ \s -> case (m s) of { (r, new_s) -> 
+              case (k r) of { S k2 -> 
+                (k2 new_s) }}
+
+
diff --git a/tests/pos/StateLib.hs b/tests/pos/StateLib.hs
--- a/tests/pos/StateLib.hs
+++ b/tests/pos/StateLib.hs
@@ -1,4 +1,4 @@
-module StateLib 
+module StateLib
   ( returnST -- :: a -> ST a s
   , bindST   -- :: ST a s -> (a -> ST b s) -> ST b s
   , ST(..)
diff --git a/tests/pos/StrictPair0.hs b/tests/pos/StrictPair0.hs
--- a/tests/pos/StrictPair0.hs
+++ b/tests/pos/StrictPair0.hs
@@ -1,6 +1,6 @@
 -- Compare with tests/pos/StrictPair1.hs
 
-module SPair (poo) where
+module StrictPair0 (poo) where
 
 import Language.Haskell.Liquid.Prelude (liquidAssert)
 
diff --git a/tests/pos/StrictPair1.hs b/tests/pos/StrictPair1.hs
--- a/tests/pos/StrictPair1.hs
+++ b/tests/pos/StrictPair1.hs
@@ -2,7 +2,7 @@
 
 -- Compare with tests/pos/StrictPair1.hs
 
-module SPair (
+module StrictPair1 (
     PairS(..)
   , moo
   , psnd
diff --git a/tests/pos/String00.hs b/tests/pos/String00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/String00.hs
@@ -0,0 +1,8 @@
+module String00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+foo = "dog"
+
+prop1 = liquidAssertB (0 == 0)
+prop2 = liquidAssertB (1 /= 0)
diff --git a/tests/pos/Strings.hs b/tests/pos/Strings.hs
--- a/tests/pos/Strings.hs
+++ b/tests/pos/Strings.hs
@@ -1,4 +1,4 @@
-module DBC where
+module Strings where
 
 import GHC.CString  -- This import interprets Strings as constants!
 
diff --git a/tests/pos/StructRec.hs b/tests/pos/StructRec.hs
--- a/tests/pos/StructRec.hs
+++ b/tests/pos/StructRec.hs
@@ -1,4 +1,4 @@
-module ListLen () where
+module StructRec () where
 
 {-@ autosize OList @-}
 
diff --git a/tests/pos/Sum.hs b/tests/pos/Sum.hs
--- a/tests/pos/Sum.hs
+++ b/tests/pos/Sum.hs
diff --git a/tests/pos/T1013.hs b/tests/pos/T1013.hs
--- a/tests/pos/T1013.hs
+++ b/tests/pos/T1013.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection"    @-}
 
 {-# LANGUAGE RankNTypes #-}
-module Generics2 where
+module T1013 where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/T1013A.hs b/tests/pos/T1013A.hs
--- a/tests/pos/T1013A.hs
+++ b/tests/pos/T1013A.hs
@@ -2,7 +2,7 @@
 
 {-# LANGUAGE RankNTypes #-}
 
-module Bug where
+module T1013A where
 
 import Prelude hiding (fmap)
 
diff --git a/tests/pos/T1024.hs b/tests/pos/T1024.hs
--- a/tests/pos/T1024.hs
+++ b/tests/pos/T1024.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exactdc"     @-}
 {-@ LIQUID "--higherorder" @-}
 
-module Bug where
+module T1024 where
 
 
 {-@ data Par1 p = Par1 { unPar1 :: p } @-}
diff --git a/tests/pos/T1025.hs b/tests/pos/T1025.hs
--- a/tests/pos/T1025.hs
+++ b/tests/pos/T1025.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--reflection"     @-}
 
-module Bug where
+module T1025 where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/T1025a.hs b/tests/pos/T1025a.hs
--- a/tests/pos/T1025a.hs
+++ b/tests/pos/T1025a.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exactdc"     @-}                                                            
 {-@ LIQUID "--higherorder" @-}                                                            
 
-module Bug where                                                                          
+module T1025a where
                                                                                           
 import Language.Haskell.Liquid.ProofCombinators                                           
 import Prelude hiding (Either (..))
diff --git a/tests/pos/T1034.hs b/tests/pos/T1034.hs
--- a/tests/pos/T1034.hs
+++ b/tests/pos/T1034.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--higherorder" @-}
-module Iso where
+module T1034 where
 
 data P a b  = P {p1 :: a, p2 :: b}
 {-@ data P a b = P {p1 :: a, p2 :: b}@-}
diff --git a/tests/pos/T1045aLib.hs b/tests/pos/T1045aLib.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1045aLib.hs
@@ -0,0 +1,5 @@
+module T1045aLib where
+
+import {-# SOURCE #-} T1045
+
+bar = foo
diff --git a/tests/pos/T1060.hs b/tests/pos/T1060.hs
--- a/tests/pos/T1060.hs
+++ b/tests/pos/T1060.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--higherorder"                         @-}
 {-@ LIQUID "--ple" @-}
 
-module Lists where
+module T1060 where
 
 import Prelude hiding (map, rev, sum) -- ((+), (+), Eq (..), Ord (..), Char, Int, Bool (..))
 import Language.Haskell.Liquid.ProofCombinators
diff --git a/tests/pos/T1074.hs b/tests/pos/T1074.hs
--- a/tests/pos/T1074.hs
+++ b/tests/pos/T1074.hs
@@ -1,7 +1,7 @@
 -- see https://github.com/ucsd-progsys/liquidhaskell/issues/1074
 {-@ LIQUID "--bscope"         @-}
 
-module Blank where
+module T1074 where
 
 {-@ type Geq X = {v:Int | X <= v} @-}
 
diff --git a/tests/pos/T1092.hs b/tests/pos/T1092.hs
--- a/tests/pos/T1092.hs
+++ b/tests/pos/T1092.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--higherorder"        @-}
 {-@ LIQUID "--exactdc"            @-}
-module VerifiedEqInstances where
+module T1092 where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/T1095A.hs b/tests/pos/T1095A.hs
--- a/tests/pos/T1095A.hs
+++ b/tests/pos/T1095A.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection"        @-}
 {-@ LIQUID "--max-case-expand=0" @-}
 
-module Foo where
+module T1095A where
 
 {-@  data Foo [size] @-}
 data Foo 
diff --git a/tests/pos/T1095C.hs b/tests/pos/T1095C.hs
--- a/tests/pos/T1095C.hs
+++ b/tests/pos/T1095C.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--max-case-expand=0" @-}
 {-@ LIQUID "--no-termination"    @-}
 
-module Foo where
+module T1095C where
 
 data Foo 
   = A Foo 
diff --git a/tests/pos/T1120A.hs b/tests/pos/T1120A.hs
--- a/tests/pos/T1120A.hs
+++ b/tests/pos/T1120A.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--reflection" @-}
 
-module Bug where
+module T1120A where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/T1126.hs b/tests/pos/T1126.hs
--- a/tests/pos/T1126.hs
+++ b/tests/pos/T1126.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE FlexibleInstances #-}
 
-module Instances where
+module T1126 where
 
 class OptEq a where
   (==.) :: a -> a -> a
diff --git a/tests/pos/T1126a.hs b/tests/pos/T1126a.hs
--- a/tests/pos/T1126a.hs
+++ b/tests/pos/T1126a.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE FlexibleInstances #-}
 
-module Instances where
+module T1126a where
 
 class OptEq a where
   zoo :: a -> a -> a
diff --git a/tests/pos/T1198.1.hs b/tests/pos/T1198.1.hs
deleted file mode 100644
--- a/tests/pos/T1198.1.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Term where
-
-{-@ data Tree [sz] @-}
-data Tree a =  Bin | Node (Tree a) (Tree a)
-
-{-@ measure sz @-}
-sz :: Tree a -> Int
-sz Bin = 0 
-sz (Node t1 t2) = 1 + sz t1 + sz  t2
diff --git a/tests/pos/T1198.2.hs b/tests/pos/T1198.2.hs
deleted file mode 100644
--- a/tests/pos/T1198.2.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Term where
-
-{-@ data Tree [sz] @-}
-data Tree a =  Bin | Node (Tree a)
-
-{-@ measure sz @-}
-sz :: Tree a -> Int
-sz Bin = 0 
-sz (Node t1) = 1 + sz t1
diff --git a/tests/pos/T1198.3.hs b/tests/pos/T1198.3.hs
deleted file mode 100644
--- a/tests/pos/T1198.3.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Term where
-
-{-@ data Tree [sz] @-}
-data Tree =  Bin | Node Tree Tree 
-
-{-@ measure sz @-}
-sz :: Tree -> Int
-sz Bin = 0 
-sz (Node t1 t2) = 1 + sz t1 + sz t2 
diff --git a/tests/pos/T1198.4.hs b/tests/pos/T1198.4.hs
deleted file mode 100644
--- a/tests/pos/T1198.4.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Term where
-
-{-@ data Tree [sz] @-}
-data Tree a =  Node (Tree a) (Tree a)
-
-{-@ measure sz @-}
-sz :: Tree a -> Int
-sz (Node t1 t2) = 1 + sz  t1 + sz  t2
diff --git a/tests/pos/T1198_1.hs b/tests/pos/T1198_1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1198_1.hs
@@ -0,0 +1,9 @@
+module T1198_1 where
+
+{-@ data Tree [sz] @-}
+data Tree a =  Bin | Node (Tree a) (Tree a)
+
+{-@ measure sz @-}
+sz :: Tree a -> Int
+sz Bin = 0 
+sz (Node t1 t2) = 1 + sz t1 + sz  t2
diff --git a/tests/pos/T1198_2.hs b/tests/pos/T1198_2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1198_2.hs
@@ -0,0 +1,9 @@
+module T1198_2 where
+
+{-@ data Tree [sz] @-}
+data Tree a =  Bin | Node (Tree a)
+
+{-@ measure sz @-}
+sz :: Tree a -> Int
+sz Bin = 0 
+sz (Node t1) = 1 + sz t1
diff --git a/tests/pos/T1198_3.hs b/tests/pos/T1198_3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1198_3.hs
@@ -0,0 +1,9 @@
+module T1198_3 where
+
+{-@ data Tree [sz] @-}
+data Tree =  Bin | Node Tree Tree 
+
+{-@ measure sz @-}
+sz :: Tree -> Int
+sz Bin = 0 
+sz (Node t1 t2) = 1 + sz t1 + sz t2 
diff --git a/tests/pos/T1198_4.hs b/tests/pos/T1198_4.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1198_4.hs
@@ -0,0 +1,8 @@
+module T1198_4 where
+
+{-@ data Tree [sz] @-}
+data Tree a =  Node (Tree a) (Tree a)
+
+{-@ measure sz @-}
+sz :: Tree a -> Int
+sz (Node t1 t2) = 1 + sz  t1 + sz  t2
diff --git a/tests/pos/T1220.hs b/tests/pos/T1220.hs
--- a/tests/pos/T1220.hs
+++ b/tests/pos/T1220.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--exactdc" @-}
 
-module AB where
+module T1220 where
 
 {-@ unsafe :: {t : AB | not (isA t)} -> {t /= A}  @-}
 unsafe :: AB -> ()
diff --git a/tests/pos/T1223.hs b/tests/pos/T1223.hs
--- a/tests/pos/T1223.hs
+++ b/tests/pos/T1223.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--ple-local" @-}
 {-@ infix   ++ @-}
 
-module Reverse where
+module T1223 where
 
 import Prelude hiding (reverse, (++))
 
diff --git a/tests/pos/T1267.hs b/tests/pos/T1267.hs
--- a/tests/pos/T1267.hs
+++ b/tests/pos/T1267.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--max-case-expand=0" @-}
 {-@ LIQUID "--exactdc" @-}
 
-module NoCaseExpand where
+module T1267 where
 
 data ABC = A | B | C 
 
diff --git a/tests/pos/T1278.2.hs b/tests/pos/T1278.2.hs
deleted file mode 100644
--- a/tests/pos/T1278.2.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-{-@ LIQUID "--exact-data-cons" @-}
-
-module Term where
-
-{-@ data List [sz] @-}
-data List a = Nil | Cons a (List a)
-
-{-@ measure sz @-}
-sz :: List a -> Int
-sz Nil = 0
-sz (Cons _ Nil) = 1
-sz (Cons _ (Cons _ l)) = 2 + sz l
diff --git a/tests/pos/T1278.3.hs b/tests/pos/T1278.3.hs
deleted file mode 100644
--- a/tests/pos/T1278.3.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Term where
-
-data List a = Nil | Cons a (List a)
-
--- First argument constant
-mymap :: (a -> b) -> List a -> List b
-mymap f Nil = Nil
-mymap f (Cons x xs) = Cons (f x) (mymap f xs)
-
--- Lexicographic
-ack :: List () -> List () -> List ()
-ack Nil n = Cons () n
-ack (Cons () m) Nil = ack m (Cons () Nil)
-ack m'@(Cons () m) (Cons () n) = ack m (ack m' n)
diff --git a/tests/pos/T1278.hs b/tests/pos/T1278.hs
--- a/tests/pos/T1278.hs
+++ b/tests/pos/T1278.hs
@@ -1,4 +1,4 @@
-module Term where
+module T1278 where
 
 data List a = Nil | Cons a (List a)
 
diff --git a/tests/pos/T1278_2.hs b/tests/pos/T1278_2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1278_2.hs
@@ -0,0 +1,12 @@
+{-@ LIQUID "--exact-data-cons" @-}
+
+module T1278_2 where
+
+{-@ data List [sz] @-}
+data List a = Nil | Cons a (List a)
+
+{-@ measure sz @-}
+sz :: List a -> Int
+sz Nil = 0
+sz (Cons _ Nil) = 1
+sz (Cons _ (Cons _ l)) = 2 + sz l
diff --git a/tests/pos/T1278_3.hs b/tests/pos/T1278_3.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T1278_3.hs
@@ -0,0 +1,14 @@
+module T1278_3 where
+
+data List a = Nil | Cons a (List a)
+
+-- First argument constant
+mymap :: (a -> b) -> List a -> List b
+mymap f Nil = Nil
+mymap f (Cons x xs) = Cons (f x) (mymap f xs)
+
+-- Lexicographic
+ack :: List () -> List () -> List ()
+ack Nil n = Cons () n
+ack (Cons () m) Nil = ack m (Cons () Nil)
+ack m'@(Cons () m) (Cons () n) = ack m (ack m' n)
diff --git a/tests/pos/T1286.hs b/tests/pos/T1286.hs
--- a/tests/pos/T1286.hs
+++ b/tests/pos/T1286.hs
@@ -1,4 +1,4 @@
-module Example where
+module T1286 where
 
 {-@ fails :: {v:Bool | v} @-}
 fails =  'a' == 'a'
diff --git a/tests/pos/T1302.hs b/tests/pos/T1302.hs
--- a/tests/pos/T1302.hs
+++ b/tests/pos/T1302.hs
@@ -3,7 +3,7 @@
 {-@ LIQUID "--exact-data-con" @-}
 {-@ LIQUID "--higherorder"    @-}
 
-module Field where
+module T1302 where
 
 data CreditCard = CreditCard { creditCardNumber :: Int, creditCardHolder :: [Char]}
 
diff --git a/tests/pos/T1336.hs b/tests/pos/T1336.hs
--- a/tests/pos/T1336.hs
+++ b/tests/pos/T1336.hs
@@ -1,4 +1,4 @@
-module T1336 where 
+module T1336 where
 
 import Data.Ratio 
 
diff --git a/tests/pos/T1543.hs b/tests/pos/T1543.hs
--- a/tests/pos/T1543.hs
+++ b/tests/pos/T1543.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--reflection" @-}
-module Fixme where
+module T1543 where
 
 foo :: (Int -> Int) ->  (Int -> Int, ())
 {-@ foo :: f:(Int -> Int) ->  (g::(Int -> Int),{v:() | f == g}) @-}
diff --git a/tests/pos/T1547.hs b/tests/pos/T1547.hs
--- a/tests/pos/T1547.hs
+++ b/tests/pos/T1547.hs
diff --git a/tests/pos/T1548.hs b/tests/pos/T1548.hs
--- a/tests/pos/T1548.hs
+++ b/tests/pos/T1548.hs
diff --git a/tests/pos/T1550.hs b/tests/pos/T1550.hs
--- a/tests/pos/T1550.hs
+++ b/tests/pos/T1550.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--reflection" @-}
 
-module Foo where 
+module T1550 where
 
 import Language.Haskell.Liquid.Equational
 
diff --git a/tests/pos/T1555.hs b/tests/pos/T1555.hs
--- a/tests/pos/T1555.hs
+++ b/tests/pos/T1555.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--rankNTypes" @-}
 {-# LANGUAGE RankNTypes   #-}
 
-module Theorems where
+module T1555 where
 
 import Language.Haskell.Liquid.Equational 
 
diff --git a/tests/pos/T1556.hs b/tests/pos/T1556.hs
--- a/tests/pos/T1556.hs
+++ b/tests/pos/T1556.hs
@@ -1,4 +1,4 @@
-module Foo where 
+module T1556 where
 
 {-@ type Alias a b = (a,b) @-}
 type Alias a b = (a,b)
diff --git a/tests/pos/T1560.hs b/tests/pos/T1560.hs
--- a/tests/pos/T1560.hs
+++ b/tests/pos/T1560.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--extensionality" @-}
 
-module T1560 where 
+module T1560 where
 
 k :: a -> b -> b
 k _ b = b
diff --git a/tests/pos/T1560B.hs b/tests/pos/T1560B.hs
--- a/tests/pos/T1560B.hs
+++ b/tests/pos/T1560B.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--extensionality" @-}
 
-module T1560 where 
+module T1560B where
 
 k :: a -> b -> b
 k _ b = b
diff --git a/tests/pos/T1568.hs b/tests/pos/T1568.hs
--- a/tests/pos/T1568.hs
+++ b/tests/pos/T1568.hs
@@ -1,4 +1,4 @@
-module MalformedTypeclass where
+module T1568 where
 
     {-@ data IdentityT m a = IdentityT (m a) @-}
     data IdentityT m a = IdentityT (m a)
diff --git a/tests/pos/T1571.hs b/tests/pos/T1571.hs
--- a/tests/pos/T1571.hs
+++ b/tests/pos/T1571.hs
@@ -1,4 +1,4 @@
-module MalformedTypeclass where
+module T1571 where
 
   data TaggedT m a = TaggedT (m a)
   
diff --git a/tests/pos/T1577.hs b/tests/pos/T1577.hs
--- a/tests/pos/T1577.hs
+++ b/tests/pos/T1577.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--extensionality" @-}
 {-@ LIQUID "--ple"            @-}
 
-module T1577 where 
+module T1577 where
 
 -- | 1 . ints
 
diff --git a/tests/pos/T1633.hs b/tests/pos/T1633.hs
--- a/tests/pos/T1633.hs
+++ b/tests/pos/T1633.hs
@@ -1,3 +1,4 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-}
 {-# LANGUAGE GADTs               #-}
 {-# LANGUAGE DeriveAnyClass      #-}
 {-@ LIQUID "--max-case-expand=0" @-}
diff --git a/tests/pos/T1634.hs b/tests/pos/T1634.hs
--- a/tests/pos/T1634.hs
+++ b/tests/pos/T1634.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection" @-} 
 {-@ LIQUID "--ple"        @-} 
 
-module Readers where
+module T1634 where
 
 import Language.Haskell.Liquid.ProofCombinators 
 type Reader a b = a -> b
diff --git a/tests/pos/T1636.hs b/tests/pos/T1636.hs
--- a/tests/pos/T1636.hs
+++ b/tests/pos/T1636.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple"        @-}
 
-module Qualify where 
+module T1636 where
 
 data RA a  = RA  
 
diff --git a/tests/pos/T1642.hs b/tests/pos/T1642.hs
--- a/tests/pos/T1642.hs
+++ b/tests/pos/T1642.hs
@@ -2,7 +2,7 @@
 {-# LANGUAGE GADTs          #-}
 {-# LANGUAGE KindSignatures #-}
 
-module Foo where 
+module T1642 where
  
 data A  :: * -> *  where 
    A  :: Eq a => a -> () -> A a 
diff --git a/tests/pos/T1642A.hs b/tests/pos/T1642A.hs
--- a/tests/pos/T1642A.hs
+++ b/tests/pos/T1642A.hs
@@ -4,7 +4,7 @@
 {-# LANGUAGE GADTs          #-}
 {-# LANGUAGE KindSignatures #-}
 
-module RefinedEquality where 
+module T1642A where
 
 
 {-@ measure eqT :: a -> a -> Bool @-}
diff --git a/tests/pos/T1647.hs b/tests/pos/T1647.hs
--- a/tests/pos/T1647.hs
+++ b/tests/pos/T1647.hs
@@ -1,7 +1,7 @@
 {-# LANGUAGE GADTs        #-}
 {-@ LIQUID "--reflection" @-} 
 
-module Properties where 
+module T1647 where
 
 {-@ type ExtTR a E1 E2 = {v:ExtT a | E1 == E2 } @-}
 
diff --git a/tests/pos/T1649MeasuresDef.hs b/tests/pos/T1649MeasuresDef.hs
--- a/tests/pos/T1649MeasuresDef.hs
+++ b/tests/pos/T1649MeasuresDef.hs
@@ -1,54 +1,55 @@
+{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
 {-# LANGUAGE RankNTypes      #-}
 {-# LANGUAGE GADTs           #-}
 {-# LANGUAGE KindSignatures  #-}
 
-{-@ LIQUID "--reflection" @-} 
+{-@ LIQUID "--reflection" @-}
 
--- Z3 encoding cannot be used until this is fixed: 
+-- Z3 encoding cannot be used until this is fixed:
 -- https://github.com/Z3Prover/z3/issues/3930
-{- LIQUID "--no-adt"         @-} 
-{-@ LIQUID "--ple-local"      @-} 
-{-@ LIQUID "--prune-unsorted" @-} 
+{- LIQUID "--no-adt"         @-}
+{-@ LIQUID "--ple-local"      @-}
+{-@ LIQUID "--prune-unsorted" @-}
 
-module Properties where 
+module T1649MeasuresDef where
 
 
 
-{-@ assume injectiveEqRTFun :: x:(a->b) -> y:(a->b) -> d:{EqRT (a->b) {x} {y} | isEqFun d} 
+{-@ assume injectiveEqRTFun :: x:(a->b) -> y:(a->b) -> d:{EqRT (a->b) {x} {y} | isEqFun d}
                          -> {x = eqFunX d && y = eqFunY d} @-}
-injectiveEqRTFun :: (a->b) -> (a->b) -> EqT (a->b) -> () 
-injectiveEqRTFun _ _ _ = () 
+injectiveEqRTFun :: (a->b) -> (a->b) -> EqT (a->b) -> ()
+injectiveEqRTFun _ _ _ = ()
 
 
 {-@ measure isEqFun @-}
-isEqFun :: EqT a -> Bool 
-isEqFun (EqFun _ _ _) = True 
-isEqFun _             = False 
+isEqFun :: EqT a -> Bool
+isEqFun (EqFun _ _ _) = True
+isEqFun _             = False
 
 {-@ reflect eqFunX @-}
 {-@ eqFunX :: {d:EqT (a -> b) | isEqFun d} -> (a -> b) @-}
-eqFunX :: EqT (a -> b) ->  (a -> b) 
-eqFunX (EqFun x _ _) = x 
+eqFunX :: EqT (a -> b) ->  (a -> b)
+eqFunX (EqFun x _ _) = x
 
 {-@ reflect eqFunY @-}
 {-@ eqFunY :: {d:EqT (a -> b) | isEqFun d} -> (a -> b) @-}
-eqFunY :: EqT (a -> b) ->  (a -> b) 
-eqFunY (EqFun _ y _) = y 
+eqFunY :: EqT (a -> b) ->  (a -> b)
+eqFunY (EqFun _ y _) = y
 
 
 {-@ ple     eqFunP @-}
 {-@ reflect eqFunP @-}
 {-@ eqFunP :: d:{EqT (a -> b) | isEqFun d} -> (x:a -> EqRT b {eqFunX d x} {eqFunY d x}) @-}
-eqFunP :: EqT (a -> b) ->  (a -> EqT b) 
+eqFunP :: EqT (a -> b) ->  (a -> EqT b)
 eqFunP (EqFun _ _ p) = p
 
 
-data EqT  :: * -> *  where 
+data EqT  :: * -> *  where
    EqFun  :: (a -> b) -> (a -> b) -> (a -> EqT b) -> EqT (a -> b)
 
-{-@ data EqT  :: * -> *  where 
+{-@ data EqT  :: * -> *  where
      EqFun  :: ff:(a -> b) -> gg:(a -> b) -> (x:a -> EqRT b {ff x} {gg x}) -> EqRT (a -> b) {ff} {gg}
-@-}   
+@-}
 
 
 {-@ type EqRT a E1 E2 = {v:EqT a | E1 = E2} @-}
diff --git a/tests/pos/T1649WorkTypes.hs b/tests/pos/T1649WorkTypes.hs
--- a/tests/pos/T1649WorkTypes.hs
+++ b/tests/pos/T1649WorkTypes.hs
@@ -7,7 +7,7 @@
 {- LIQUID "--no-adt"         @-} 
 {-@ LIQUID "--ple-local"      @-} 
 
-module Properties where 
+module T1649WorkTypes where
 
 
 {-@ assume injectiveEqRTFun :: x:(a->b) -> y:(a->b) -> d:{EqRT (a->b) {x} {y} | isEqFun d} 
diff --git a/tests/pos/T1660.hs b/tests/pos/T1660.hs
--- a/tests/pos/T1660.hs
+++ b/tests/pos/T1660.hs
@@ -6,7 +6,7 @@
 {-@ LIQUID "--ple"         @-}
 {-@ LIQUID "--fast"        @-}
 
-module Readers where
+module T1660 where
 
 import Language.Haskell.Liquid.ProofCombinators
 import Prelude hiding (id, fmap)
diff --git a/tests/pos/T1669.hs b/tests/pos/T1669.hs
--- a/tests/pos/T1669.hs
+++ b/tests/pos/T1669.hs
@@ -2,7 +2,7 @@
 {-@ LIQUID "--ple" @-}
 {-@ LIQUID "--no-totality" @-}
 
-module A where
+module T1669 where
 import           Prelude                 hiding ( Semigroup
                                                 , mappend
                                                 )
diff --git a/tests/pos/T1670A.hs b/tests/pos/T1670A.hs
--- a/tests/pos/T1670A.hs
+++ b/tests/pos/T1670A.hs
@@ -1,8 +1,9 @@
 {-# LANGUAGE TypeFamilies #-}
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple" @-}
+{-@ LIQUID "--ple-with-undecided-guards" @-}
 
-module B where
+module T1670A where
 
 data LWW t a = LWW {
     lwwTime  :: t
diff --git a/tests/pos/T1670B.hs b/tests/pos/T1670B.hs
--- a/tests/pos/T1670B.hs
+++ b/tests/pos/T1670B.hs
@@ -2,8 +2,9 @@
 
 {-@ LIQUID "--reflection" @-}
 {-@ LIQUID "--ple" @-}
+{-@ LIQUID "--ple-with-undecided-guards" @-}
 
-module B where
+module T1670B where
 
 data LWW t a = LWW {
     lwwTime  :: t
diff --git a/tests/pos/T1697.hs b/tests/pos/T1697.hs
--- a/tests/pos/T1697.hs
+++ b/tests/pos/T1697.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--no-pattern-inline" @-}
 
-module B where
+module T1697 where
 
 data User = U
 
diff --git a/tests/pos/T1697A.hs b/tests/pos/T1697A.hs
--- a/tests/pos/T1697A.hs
+++ b/tests/pos/T1697A.hs
@@ -2,7 +2,7 @@
 -- | Fixed User (WORKING)
 -------------------------------------------------------------------------------------------
 
-module A where
+module T1697A where
 
 data User = U
 
diff --git a/tests/pos/T1697C.hs b/tests/pos/T1697C.hs
--- a/tests/pos/T1697C.hs
+++ b/tests/pos/T1697C.hs
@@ -2,7 +2,7 @@
 -- | Polymorphic user but defining bind and return as normal functions (WORKING)
 -------------------------------------------------------------------------------------------
 
-module C where
+module T1697C where
 
 data User = U
 
diff --git a/tests/pos/T1709.hs b/tests/pos/T1709.hs
--- a/tests/pos/T1709.hs
+++ b/tests/pos/T1709.hs
@@ -1,4 +1,4 @@
-module T1709 where 
+module T1709 where
 
 {-@ incr :: x:Int -> {v:Int | x < v } @-}
 incr :: Int -> Int 
diff --git a/tests/pos/T1749.hs b/tests/pos/T1749.hs
--- a/tests/pos/T1749.hs
+++ b/tests/pos/T1749.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--ple" @-}
 {-@ LIQUID "--reflection" @-}
-module T1749 where 
+module T1749 where
 
 data Value = B Bool | I Int
 
diff --git a/tests/pos/T1775.hs b/tests/pos/T1775.hs
--- a/tests/pos/T1775.hs
+++ b/tests/pos/T1775.hs
@@ -1,4 +1,4 @@
-module T1775 where 
+module T1775 where
 
 {-@ measure listLength @-}
 {-@ listLength :: xs:_ -> {n:Nat | n == len xs } @-}
diff --git a/tests/pos/T1812.hs b/tests/pos/T1812.hs
--- a/tests/pos/T1812.hs
+++ b/tests/pos/T1812.hs
@@ -4,7 +4,7 @@
 {- LIQUID "--ple"            @-}
 {-@ LIQUID "--no-termination" @-}
 
-module CCC where
+module T1812 where
 
 import qualified Data.Set as S 
 
diff --git a/tests/pos/T2091.hs b/tests/pos/T2091.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T2091.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE GADTs #-}
+
+module T2091 where 
+    
+import Prelude (Bool(..))
+import GHC.TypeLits
+
+data Vec (n :: Nat) a where
+    VCons :: a -> Vec n a -> Vec (1 + n) a
+    VNil :: Vec 0 a
+
+{-@ ys0 :: Vec _ Bool @-}
+ys0 :: Vec 0 Bool
+ys0 = VNil
+
+type Vec1 = Vec 1 
+{-@ type T = {v:Bool | v } @-}
+{-@ ys1 :: Vec _ T @-}
+ys1 :: Vec 1 Bool
+ys1 = VCons True VNil
diff --git a/tests/pos/T2093.hs b/tests/pos/T2093.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T2093.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE GADTs #-}
+{-@ embed GHC.Natural.Natural as int @-}
+{-@ embed GHC.Num.Natural.Natural as int @-}
+{-@ LIQUID "--no-totality" @-}
+
+module T2093 where 
+    
+import Prelude 
+import GHC.TypeLits
+import GHC.Natural
+
+newtype Unsigned (n :: Nat) = U Natural
+instance KnownNat n => Num (Unsigned n)
+  
+instance Ord (Unsigned n)
+instance Eq (Unsigned n)
+
+type Hex = Unsigned 4
+{-@ type Digit = {v : Hex | v <= 9 } @-}
+
+{-@ x :: Digit @-}
+x :: Hex
+x = 3
diff --git a/tests/pos/T2096.hs b/tests/pos/T2096.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/T2096.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE GADTs #-}
+{-@ embed GHC.Natural.Natural as int @-}
+{-@ LIQUID "--no-totality" @-}
+
+module T2096 where
+
+import Prelude 
+import GHC.TypeLits
+import GHC.Natural
+import Unsafe.Coerce
+
+-- See https://github.com/ucsd-progsys/liquidhaskell/issues/2095
+workaround :: (n1 + 1) ~ (n2 + 1) => Vec n1 a -> Vec n2 a
+workaround = unsafeCoerce
+
+data Vec (n :: Nat) a where
+    Nil :: Vec 0 a
+    Cons :: a -> Vec n a -> Vec (n + 1) a
+
+foo :: Vec n a -> Vec n a -> Vec n a
+foo Nil Nil = Nil
+foo (Cons x xs) (Cons y ys) = Cons x zs
+  where
+    zs = foo xs $ workaround ys
+foo _ _ = undefined
+
diff --git a/tests/pos/T385.hs b/tests/pos/T385.hs
--- a/tests/pos/T385.hs
+++ b/tests/pos/T385.hs
@@ -1,5 +1,5 @@
 {-@ LIQUID "--noclasscheck"    @-}
-module Compose where
+module T385 where
 
 import Prelude hiding (Functor, Monad)
 
diff --git a/tests/pos/T595.hs b/tests/pos/T595.hs
--- a/tests/pos/T595.hs
+++ b/tests/pos/T595.hs
@@ -1,4 +1,4 @@
-module Issue595 where
+module T595 where
 
 import Data.Vector
 
diff --git a/tests/pos/T716.hs b/tests/pos/T716.hs
--- a/tests/pos/T716.hs
+++ b/tests/pos/T716.hs
@@ -6,7 +6,7 @@
 
 {-@ LIQUID "--scrape-used-imports" @-}
 
-module Blank where
+module T716 where
 
 import GHC.Exts
 import GHC.Word
diff --git a/tests/pos/T819.hs b/tests/pos/T819.hs
--- a/tests/pos/T819.hs
+++ b/tests/pos/T819.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--reflection" @-}
 
-module Data.Foo where
+module T819 where
 
 import Language.Haskell.Liquid.ProofCombinators
 import Prelude hiding ((<>))
diff --git a/tests/pos/T820.hs b/tests/pos/T820.hs
--- a/tests/pos/T820.hs
+++ b/tests/pos/T820.hs
@@ -1,7 +1,7 @@
 {-@ LIQUID "--exactdc"      @-}
 {-@ LIQUID "--higherorder"  @-}
 
-module Data.Foo where
+module T820 where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/T866.hs b/tests/pos/T866.hs
--- a/tests/pos/T866.hs
+++ b/tests/pos/T866.hs
@@ -2,7 +2,7 @@
 
 -- see https://github.com/ucsd-progsys/liquidhaskell/issues/866
 
-module T866 where 
+module T866 where
 
 data Body = Body Int Int 
 
diff --git a/tests/pos/T914.hs b/tests/pos/T914.hs
--- a/tests/pos/T914.hs
+++ b/tests/pos/T914.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--higherorder" @-}
 
-module MapFusion where
+module T914 where
 
 import Language.Haskell.Liquid.ProofCombinators
 
diff --git a/tests/pos/TagBinder.hs b/tests/pos/TagBinder.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/TagBinder.hs
@@ -0,0 +1,7 @@
+module TagBinder () where
+
+data Foo a = F Int a
+
+{-@ data Foo a = F {tag :: Int, f :: a} @-}
+
+foo = F
diff --git a/tests/pos/Take.hs b/tests/pos/Take.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Take.hs
@@ -0,0 +1,60 @@
+{-@ LIQUID "--no-totality"    @-}
+
+{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE CPP,  NoImplicitPrelude, MagicHash #-}
+{-# OPTIONS_HADDOCK hide #-}
+
+module Take (
+    take0
+  , take
+  ) where
+
+import Data.Maybe
+import GHC.Base 
+import Language.Haskell.Liquid.Prelude (liquidAssert, liquidError, unsafeError) 
+
+
+
+{-@ assert take0  :: n: {v: Int | 0 <= v} -> [a] -> {v:[a] | (len(v) = n)} @-}
+take0 :: Int -> [a] -> [a]
+take0 (I# n#) xs = take_unsafe_UInt0 n# xs
+
+take_unsafe_UInt0 :: Int# -> [a] -> [a]
+take_unsafe_UInt0 0#  _     = []
+take_unsafe_UInt0 n  (x:xs) = x : take_unsafe_UInt0 (n -# 1#) xs
+take_unsafe_UInt0 _   _     = unsafeError "unsafe take"
+
+{-@ assert take  :: n: {v: Int | v >= 0 } -> xs:[a] -> {v:[a] | len v = if len xs < n then (len xs) else n } @-}
+take (I# n#) xs = takeUInt n# xs
+-- take (I# n#) xs = take_unsafe_UInt n# xs
+
+takeUInt :: Int# -> [a] -> [a]
+takeUInt n xs
+  | isTrue# (n >=# 0#) =  take_unsafe_UInt n xs
+  | otherwise          =  liquidAssert False []
+
+take_unsafe_UInt :: Int# -> [a] -> [a]
+take_unsafe_UInt 0#  _     = []
+take_unsafe_UInt n ls      =
+  case ls of
+    []     -> []
+    (x:xs) -> x : take_unsafe_UInt (n -# 1#) xs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/pos/Term0.hs b/tests/pos/Term0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Term0.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Term0 () where
+
+import Prelude hiding (sum)
+
+{-@ sum :: Nat -> Nat @-}
+sum   :: Int -> Int
+sum 0 = 0
+sum n = n + sum (n-1)
+
+{-@ fib :: Nat -> Nat @-}
+fib :: Int -> Int 
+fib 0 = 1
+fib 1 = 1 
+fib n = fib (n-1) + fib (n-2)
+
+{-@ sumUp :: Nat -> Nat @-}
+sumUp :: Int -> Int
+sumUp n  = go n 0 0
+  where 
+    go (d :: Int) acc i
+      | i < n     = go (d - 1) (acc + i) (i + 1) 
+      | otherwise = acc
+
+{-@ qualif Diff(v:Int, x:Int, y:Int): v = x - y @-} 
+
+{-@ nonTerm :: Nat -> Nat @-}
+nonTerm :: Int -> Int
+nonTerm n = nonTerm (n+1)
+
+{-@ lazy nonTerm @-}
+
diff --git a/tests/pos/TerminationNum.hs b/tests/pos/TerminationNum.hs
--- a/tests/pos/TerminationNum.hs
+++ b/tests/pos/TerminationNum.hs
@@ -1,4 +1,4 @@
-module Fixme where
+module TerminationNum where
 
 {-@ fak2 :: (Ord a, Eq a, Num a) => y:{x: a | x >= 0} -> a /[y]@-}
 fak2 :: (Ord a, Eq a, Num a) => a -> a
diff --git a/tests/pos/TerminationNum0.hs b/tests/pos/TerminationNum0.hs
--- a/tests/pos/TerminationNum0.hs
+++ b/tests/pos/TerminationNum0.hs
@@ -1,4 +1,4 @@
-module Fixme where
+module TerminationNum0 where
 
 {-@fak2 :: (Ord a, Eq a, Num a) => {x: a | x >= 0} -> a @-}
 fak2 :: (Ord a, Eq a, Num a) => a -> a
diff --git a/tests/pos/Test0.hs b/tests/pos/Test0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test0.hs
@@ -0,0 +1,8 @@
+module Test0 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x = if x > 0 then x else (0 - x)
+
+prop_abs   = let n1 = choose 0 in 
+             liquidAssertB ((myabs n1) >= 0)
diff --git a/tests/pos/Test00.hs b/tests/pos/Test00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test00.hs
@@ -0,0 +1,11 @@
+module Test00 () where
+
+import Language.Haskell.Liquid.Prelude
+
+
+prop_abs ::  Bool
+prop_abs = if x > 0 then baz x else False
+  where 
+    x    = choose 0
+
+baz gooberding = liquidAssertB (gooberding >= 0)
diff --git a/tests/pos/Test000.hs b/tests/pos/Test000.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test000.hs
@@ -0,0 +1,7 @@
+module Test000 () where
+
+-- import Language.Haskell.Liquid.Prelude
+{-@ toss :: Bool @-}
+toss :: Bool
+toss = (undefined 0) > 10
+
diff --git a/tests/pos/Test00_int.hs b/tests/pos/Test00_int.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test00_int.hs
@@ -0,0 +1,12 @@
+module Test00_int () where
+
+import Language.Haskell.Liquid.Prelude 
+
+x :: Int
+x = choose 0
+
+prop_abs ::  Bool
+prop_abs = if x > 0 then baz x else False
+
+baz :: Int -> Bool
+baz gooberding = liquidAssertB (gooberding >= 0)
diff --git a/tests/pos/Test00_old.hs b/tests/pos/Test00_old.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test00_old.hs
@@ -0,0 +1,11 @@
+module Test00_old () where
+
+import Language.Haskell.Liquid.Prelude
+
+x = choose 0
+
+prop_abs = if x `gt` 0 then baz x else False
+
+baz   :: Int -> Bool
+baz z = liquidAssertB (z `geq` 0)
+
diff --git a/tests/pos/Test00b.hs b/tests/pos/Test00b.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test00b.hs
@@ -0,0 +1,12 @@
+module Test00b () where
+
+import Language.Haskell.Liquid.Prelude
+
+x = choose 0
+
+foo x = x
+
+prop_abs = if x > 0 then baz (foo x) else False
+
+baz ::  (Num a, Ord a) => a -> Bool
+baz z = liquidAssertB (z > 0)
diff --git a/tests/pos/Test00c.hs b/tests/pos/Test00c.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test00c.hs
@@ -0,0 +1,11 @@
+module Test00c () where
+
+import Language.Haskell.Liquid.Prelude
+
+getEqs x ys = filter (x ==) ys 
+
+xs :: [Int]
+xs = [1, 2, 3, 4, 5, 6]
+
+prop_abs = map (\z -> liquidAssertB (z >= 0)) ys
+             where ys = getEqs 5 xs
diff --git a/tests/pos/Test1.hs b/tests/pos/Test1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test1.hs
@@ -0,0 +1,9 @@
+module Test1 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x = if x > 0 then x else 0 - x
+
+n = choose 0
+
+prop_absf = liquidAssertB ((myabs n) >= 0)
diff --git a/tests/pos/Test2.hs b/tests/pos/Test2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Test2.hs
@@ -0,0 +1,11 @@
+module Test2 () where
+
+import Language.Haskell.Liquid.Prelude
+
+myabs x = if x > 0 then x else 0 - x
+
+n = choose 0
+
+prop_absf = 
+  let zz = (myabs n) >= 0 in
+  liquidAssertB zz
diff --git a/tests/pos/TestRec.hs b/tests/pos/TestRec.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/TestRec.hs
@@ -0,0 +1,33 @@
+{-@ LIQUID "--no-termination" @-}
+
+module TestRec where
+
+import Prelude hiding (foldl)
+
+data L a = N | C { hd :: a
+                 , tl :: L a }
+
+{-@ data L [llen] a = N | C { hd :: a
+                            , tl :: L a }
+  @-}
+
+
+{-@ invariant {v:L a | 0 <= llen v} @-}
+
+{-@ measure llen @-}
+llen :: L a -> Int
+llen N        = 0
+llen (C x xs) = 1 + llen xs
+
+reverse :: L a -> L a
+reverse xs = go N xs
+  where 
+    {-@ go :: acc:_ -> xs:_ -> _ / [llen xs] @-}
+    go :: L a -> L a -> L a 
+    go acc N        = acc
+    go acc (C x xs) = go (C x acc) xs
+
+mapL f N = N
+mapL f (C x xs) = C (f x) (mapL f xs)
+
+
diff --git a/tests/pos/TokenType.hs b/tests/pos/TokenType.hs
--- a/tests/pos/TokenType.hs
+++ b/tests/pos/TokenType.hs
@@ -1,4 +1,4 @@
-module Fixme where
+module TokenType where
 
 
 data TokenType = Foo | CChar
diff --git a/tests/pos/Top0.hs b/tests/pos/Top0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Top0.hs
@@ -0,0 +1,27 @@
+module Top0 (poop, loop, zoo) where
+
+{-@ invariant {v:Int | v >= 0} @-}
+
+{-@ qualif Sum(v:Int, x: Int, y: Int): v = x + y @-}
+
+-- | This should get a TOP type
+poop x = zoo x 
+
+-- | This is USED but should ALSO get a TOP type (since exported)
+loop x     = go x 0
+  where 
+    go     :: Int -> Int -> Int 
+    go 0 m = m
+    go n m = go (n-1) (m+1)
+
+zoo     = loop
+
+loop' x     = go x 0
+  where 
+    go     :: Int -> Int -> Int 
+    go 0 m = m
+    go n m = go (n-1) (m+1)
+
+-- | This HAS a sig so it should NOT get a TOP type
+{-@ zoo' :: x:Int -> {v:Int | v = x} @-}
+zoo'     = loop'
diff --git a/tests/pos/ToyMVar.hs b/tests/pos/ToyMVar.hs
--- a/tests/pos/ToyMVar.hs
+++ b/tests/pos/ToyMVar.hs
@@ -1,5 +1,6 @@
 {-# LANGUAGE MagicHash     #-}
 {-# LANGUAGE UnboxedTuples #-}
+{-# OPTIONS_GHC -Wno-missing-methods #-}
 
 {-@ LIQUID "--no-totality"       @-}
 {-@ LIQUID "--no-termination"    @-}
diff --git a/tests/pos/Trans.hs b/tests/pos/Trans.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Trans.hs
@@ -0,0 +1,26 @@
+{-@ LIQUID "--no-termination" @-}
+module Trans () where
+
+import Language.Haskell.Liquid.Prelude
+
+{- THIS IS A RANDOM COMMENT -}
+
+{-@ foo :: x: Int -> Int @-}
+foo :: Int -> Int
+foo x = x + 1
+
+{-@ transpose :: n:Int
+              -> m:{v:Int | v > 0} 
+              -> {v:[{v:[a] | len(v) = n}] | len(v) = m} 
+              -> {v:[{v:[a] | len(v) = m}] | len(v) = n} 
+  @-}
+transpose :: Int -> Int -> [[a]] -> [[a]]
+transpose 0 _ _              = []
+transpose n m ((x:xs) : xss) = (x : map head xss) : transpose (n - 1) m (xs : map tail xss)
+transpose n m ([] : _)       = liquidError "transpose1" 
+transpose n m []             = liquidError "transpose2"
+
+-- NEEDS TAGS: map head xss = [ h | (h:_) <- xss]
+-- NEEDS TAGS: map tail xss = [t | (_:t) <- xss]
+
+
diff --git a/tests/pos/TransTAG.hs b/tests/pos/TransTAG.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/TransTAG.hs
@@ -0,0 +1,23 @@
+module TransTAG () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ foo :: x: Int -> Int @-}
+foo :: Int -> Int
+foo x = x + 1
+
+{-@ transpose :: n:Int
+              -> m:{v:Int | v > 0} 
+              -> {v:[{v:[a] | len(v) = n}] | len(v) = m} 
+              -> {v:[{v:[a] | len(v) = m}] | len(v) = n} 
+  @-}
+transpose :: Int -> Int -> [[a]] -> [[a]]
+transpose 0 _ _              = []
+transpose n m ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (n - 1) m (xs : [t | (_:t) <- xss])
+transpose n m ([] : _)       = liquidError "transpose1" 
+transpose n m []             = liquidError "transpose2"
+
+-- NEEDS TAGS: map head xss = [ h | (h:_) <- xss]
+-- NEEDS TAGS: map tail xss = [t | (_:t) <- xss]
+
+
diff --git a/tests/pos/Transpose.hs b/tests/pos/Transpose.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Transpose.hs
@@ -0,0 +1,62 @@
+{-@ LIQUID "--no-termination" @-}
+{-@ LIQUID "--prune-unsorted" @-}
+{-@ LIQUID "--bscope"         @-}
+
+module Transpose (transpose, transpose', transpose'') where
+
+import Language.Haskell.Liquid.Prelude
+
+-- | Specifying a matrix
+
+{-@ type Matrix a       = {m0:[{v:[a] | (len v) = (cols m0)}] | true } @-}
+
+{-@ type MatrixCR a C R = {m0:[{v:[a] | (len v) = C}] | (((len m0) = R) && (R > 0 => (cols m0) = C)) } @-}
+
+{-@ measure cols :: [[a]] -> Int
+      cols []   = 0
+      cols (x:xs) = (len x)
+  @-}
+
+-- | A Few Simple Examples (which run VERY slowly)
+
+{-@ predicate Dim V C R = (((len V) = R) && ((cols V) = C)) @-}
+
+{-@ mat_3_2 :: {v: Matrix Int | (Dim v 3 2)} @-}
+mat_3_2 :: [[Int]]
+mat_3_2 = [ [1,2,3]
+          , [4,5,6] ]
+
+{-@ mat_2_4 :: {v: Matrix Int | (Dim v 2 4)} @-}
+mat_2_4 :: [[Int]]
+mat_2_4 = [ [1,2]
+          , [3,4]
+          , [5,6]
+          , [7,8] ]
+
+-- | Old fashioned transpose with explicit dimensions
+
+{- transpose :: c:Nat
+             -> r:{v:Nat | v > 0}
+             -> {v:[{v:[a] | (len v) = c}] | (len v) = r}
+             -> {v:[{v:[a] | (len v) = r}] | (len v) = c}
+  -}
+
+{-@ transpose :: c:Nat -> r:{v:Nat | v > 0}  -> (MatrixCR a c r) -> (MatrixCR a r c) @-}
+transpose     :: Int -> Int -> [[a]] -> [[a]]
+transpose 0 _ _              = []
+transpose n m ((x:xs) : xss) = (x : map head xss) : transpose (n - 1) m (xs : map tail xss)
+transpose n m ([] : _)       = liquidError "transpose1"
+transpose n m []             = liquidError "transpose2"
+
+
+{-@ transpose' :: m:{v:(Matrix a) | ((len v) > 0)} -> (MatrixCR a (len m) (cols m)) @-}
+transpose' :: [[a]] -> [[a]]
+transpose' ([]:_)         = []
+transpose' ((x:xs) : xss) = (x : map head xss) : transpose' (xs : map tail xss)
+transpose' []             = liquidError "transpose'"
+
+-- | A wrapper implementing the explicit transpose using the implicit one
+
+{-@ transpose''     :: c:Nat -> r:{v:Nat | v > 0}  -> (MatrixCR a c r) -> (MatrixCR a r c) @-}
+transpose''         :: Int -> Int -> [[a]] -> [[a]]
+transpose'' n m xss = transpose' xss
diff --git a/tests/pos/Tup0.hs b/tests/pos/Tup0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Tup0.hs
@@ -0,0 +1,11 @@
+module Tup0 () where
+
+{-@ type PlusOne = (Int, Int)<{\x v -> v > x}> @-}
+
+{-@ plusOne :: PlusOne @-}
+plusOne :: (Int, Int)
+plusOne = (0, 1)
+
+{-@ plusOnes :: Maybe PlusOne @-}
+plusOnes :: Maybe (Int, Int) 
+plusOnes = Just plusOne -- (0, 1) (5,6), (999,1000)]
diff --git a/tests/pos/Tupparse.hs b/tests/pos/Tupparse.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Tupparse.hs
@@ -0,0 +1,34 @@
+module Tupparse () where
+
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+
+data Vec a = V a deriving (Eq)
+
+-- this is verified ...
+{-@ bar :: x:Int 
+        -> y:{v: Int | v = x } 
+        -> Int 
+  @-}
+bar     :: Int -> Int -> Int
+bar x y = liquidAssert (x == y) 0
+
+-- and so is this...
+
+{-@ goo :: x:[Int] 
+        -> y:{v: [Int] | v = x } 
+        -> Int 
+  @-}
+goo     :: [Int] -> [Int] -> Int
+goo x y = liquidAssert (x == y) 0
+
+
+-- BUT THIS IS NOT!!
+{-@ foo :: x: (Vec Int)
+        -> y:{v: Vec Int | v = x } 
+        -> Int 
+  @-}
+foo     :: Vec Int -> Vec Int -> Int
+foo x y = liquidAssert (x == y) 0
+
+
+
diff --git a/tests/pos/TyExpr.hs b/tests/pos/TyExpr.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/TyExpr.hs
@@ -0,0 +1,7 @@
+module TyExpr where
+
+{-@ type Range Lo Hi = {v:Int | Lo <= v && v < Hi} @-}
+
+{-@ bow :: Range 0 100 @-}
+bow :: Int
+bow = 12
diff --git a/tests/pos/Tyclass0.hs b/tests/pos/Tyclass0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Tyclass0.hs
@@ -0,0 +1,11 @@
+module Tyclass0 (poop) where
+
+class Zog a where
+  zoom :: a -> Int
+
+-- Assume the relevant behavior for the method.
+{-@ zoom :: (Zog a) => a -> Nat @-}
+
+-- Uses the behavior of `zoom`
+{-@ poop :: (Zog a) => a -> Nat @-}
+poop x = zoom x
diff --git a/tests/pos/Tyfam0.hs b/tests/pos/Tyfam0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Tyfam0.hs
@@ -0,0 +1,17 @@
+module Tyfam0 () where
+
+import Control.Monad.Primitive
+
+import Data.Vector.Generic.Mutable
+
+{-@ copyOffset :: (PrimMonad m, MVector v e)
+           => v (PrimState m) e -> v (PrimState m) e -> Int -> Int -> Int -> m ()
+  @-}
+
+copyOffset :: (PrimMonad m, MVector v e)
+           => v (PrimState m) e -> v (PrimState m) e -> Int -> Int -> Int -> m ()
+copyOffset = undefined
+
+{-@ zog :: (m s a) -> Nat @-}
+zog :: (m s a) -> Int
+zog = undefined
diff --git a/tests/pos/TypeLitNat.hs b/tests/pos/TypeLitNat.hs
--- a/tests/pos/TypeLitNat.hs
+++ b/tests/pos/TypeLitNat.hs
@@ -7,7 +7,7 @@
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeOperators       #-}
 
-module TypeLits where
+module TypeLitNat where
 
 import GHC.TypeLits
 
diff --git a/tests/pos/TypeLitString.hs b/tests/pos/TypeLitString.hs
--- a/tests/pos/TypeLitString.hs
+++ b/tests/pos/TypeLitString.hs
@@ -4,7 +4,7 @@
 {-# LANGUAGE RankNTypes          #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 
-module DependeTypes where
+module TypeLitString where
 
 import GHC.TypeLits
 
diff --git a/tests/pos/Tyvar.hs b/tests/pos/Tyvar.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Tyvar.hs
@@ -0,0 +1,5 @@
+module Tyvar () where
+
+{-@ foo :: Eq b => a -> b -> a @-}
+foo :: Eq b => a -> b -> a
+foo = undefined
diff --git a/tests/pos/UnboxedTuples.hs b/tests/pos/UnboxedTuples.hs
--- a/tests/pos/UnboxedTuples.hs
+++ b/tests/pos/UnboxedTuples.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE MagicHash #-}
 {-# LANGUAGE UnboxedTuples #-}
-module Blank where
+module UnboxedTuples where
 
 import GHC.Int
 
diff --git a/tests/pos/UnboxedTuplesAndTH.hs b/tests/pos/UnboxedTuplesAndTH.hs
--- a/tests/pos/UnboxedTuplesAndTH.hs
+++ b/tests/pos/UnboxedTuplesAndTH.hs
@@ -2,7 +2,7 @@
 {-# LANGUAGE TemplateHaskell #-}
 {-# LANGUAGE UnboxedTuples #-}
 
-module Blank where
+module UnboxedTuplesAndTH where
 
 import GHC.Int
 import Language.Haskell.TH.Syntax
diff --git a/tests/pos/UndecidedGuards.hs b/tests/pos/UndecidedGuards.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/UndecidedGuards.hs
@@ -0,0 +1,19 @@
+-- Tests that --ple-with-undecided-guards has an effect on verification
+{-@ LIQUID "--ple-with-undecided-guards" @-}
+{-@ LIQUID "--ple" @-}
+
+module UndecidedGuards where
+
+{-@ reflect boolToInt @-}
+boolToInt :: Bool -> Int
+boolToInt False = 0
+boolToInt True = 1
+
+-- | This property would usually not be provable without spliting in cases
+-- because PLE doesn't unfold @boolToInt@ if @b@ is not known to be empty
+-- or non-empty. But here @--ple-with-undecided-guards@ is in effect, so
+-- @boolToInt@ is expanded anyway.
+--
+{-@ nonNegativeInt :: b:_ -> { boolToInt b >= 0 } @-}
+nonNegativeInt :: Bool -> ()
+nonNegativeInt _ = ()
diff --git a/tests/pos/Unusedtyvars.hs b/tests/pos/Unusedtyvars.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Unusedtyvars.hs
@@ -0,0 +1,17 @@
+module Unusedtyvars () where
+
+data F a b c = F (Int -> b -> c)
+{- data F a b c = F (x::(Int -> b -> c)) @-}
+
+
+{-@ bar :: F {v:Int| v >= 0} b c @-}
+bar :: F Int b c
+bar = undefined
+
+
+{-@ foo :: F {v:Int| v >= 0} b c  -> Int @-}
+foo :: F Int b c -> Int
+foo = undefined
+
+{-@ hoo :: Int @-}
+hoo = foo bar
diff --git a/tests/pos/Variance2.hs b/tests/pos/Variance2.hs
--- a/tests/pos/Variance2.hs
+++ b/tests/pos/Variance2.hs
@@ -1,7 +1,7 @@
 {-# LANGUAGE Rank2Types, ExistentialQuantification #-}
 
 
-module Variance where
+module Variance2 where
 
 
 import Control.Monad.Trans.Except
diff --git a/tests/pos/Vector00.hs b/tests/pos/Vector00.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Vector00.hs
@@ -0,0 +1,11 @@
+module Vector00 () where
+
+import Language.Haskell.Liquid.Prelude
+-- import Data.List
+import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
+
+propVec = (vs ! 3) == 3
+  where xs    = [1,2,3,4] :: [Int]
+        vs    = fromList xs
+        
+
diff --git a/tests/pos/Vector1.hs b/tests/pos/Vector1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Vector1.hs
@@ -0,0 +1,21 @@
+module Vector1 () where
+
+{-@ LIQUID "--no-termination" @-}
+
+import Language.Haskell.Liquid.Prelude
+import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
+
+for lo hi acc f 
+  | lo < hi   = for (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) {- * (v2!i) -}) +)
+  where n = Data.Vector.length v1
+
+sumSquare v = dotProd v v
+
+total = sumSquare $ Data.Vector.fromList [0..100] -- nums
+range i j = for i j [] (:)
+nums  = range 0 100 -- [0..100]
+
+-- prop = liquidAssertB (total >= 0)
diff --git a/tests/pos/Vector1a.hs b/tests/pos/Vector1a.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Vector1a.hs
@@ -0,0 +1,23 @@
+module Vector1a () where
+
+import Language.Haskell.Liquid.Prelude
+import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
+
+
+{-@ invariant {v:Int | v >= 0} @-}
+for :: Int -> Int -> a -> (Int -> a -> a) -> a
+for lo hi  = for' (hi-lo) lo hi
+
+for' :: Int -> Int -> Int -> a -> (Int -> a -> a) -> a
+for' d lo hi acc f 
+  | lo < hi   = for' (d-1) (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+dotProd       :: Vector Int -> Vector Int -> Int
+dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
+  where n = Data.Vector.length v1
+
+sumSquare   :: Vector Int -> Int
+sumSquare v = dotProd v v
+
+total = sumSquare $ Data.Vector.fromList [0..100]
diff --git a/tests/pos/Vector1b.hs b/tests/pos/Vector1b.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Vector1b.hs
@@ -0,0 +1,19 @@
+module Vector1b () where
+
+{-@ LIQUID "--no-termination" @-}
+
+import Language.Haskell.Liquid.Prelude
+import Data.Vector hiding (map, concat, zipWith, filter, foldl, foldr, (++))
+
+for lo hi acc f 
+  | lo < hi   = for (lo + 1) hi (f lo acc) f
+  | otherwise = acc 
+
+dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
+  where n = Data.Vector.length v1
+
+sumSquare v = dotProd v v
+
+total = sumSquare $ Data.Vector.fromList [0..100] -- nums
+range i j = for i j [] (:)
+nums  = range 0 100 -- [0..100]
diff --git a/tests/pos/Vector2.hs b/tests/pos/Vector2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Vector2.hs
@@ -0,0 +1,70 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Vector2 (dotProduct, safeLookup) where
+
+import Prelude hiding (length)
+import Data.Vector
+import Language.Haskell.Liquid.Prelude (liquidAssert)
+    
+{-@ predicate Lt X Y      = X < Y                         @-}
+{-@ predicate Ge X Y      = not (Lt X Y)                  @-}
+{-@ predicate InBound I A = ((Ge I 0) && (Lt I (vlen A))) @-}
+
+{-@ invariant {v:Int | v >= 0} @-}
+{-@ unsafeLookup :: vec:Vector a 
+                 -> {v: Int | (0 <= v && v < (vlen vec)) } 
+                 -> a @-}
+unsafeLookup vec i = vec ! i
+
+{-@ unsafeLookup' :: vec:Vector a -> {v: Int | (InBound v vec)} -> a @-}
+unsafeLookup' vec i = vec ! i
+
+safeLookup x i 
+  | 0 <= i && i < length x = Just (x ! i)
+  | otherwise              = Nothing 
+
+{-@ absoluteSum   :: Vector Int -> {v: Int | 0 <= v}  @-}
+absoluteSum       :: Vector Int -> Int 
+absoluteSum vec   = if 0 < n then go n 0 0 else 0
+  where
+    go (d::Int) acc i 
+      | i /= n    = go (d-1) (acc + abz (vec ! i)) (i + 1)
+      | otherwise = acc 
+    n             = length vec
+
+abz n = if 0 <= n then n else (0 - n) 
+
+loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
+loop lo hi base f = go (hi-lo) base lo
+  where
+    {-@ decrease go 1 @-}
+    go (d::Int) acc i     
+      | i /= hi   = go (d-1) (f i acc) (i + 1)
+      | otherwise = acc
+
+incr x = x + 1
+
+zoo = incr 29
+
+{-@ dotProduct :: x:(Vector Int) 
+               -> y:{v: Vector Int | (vlen v) = (vlen x)} 
+               -> Int 
+  @-}
+dotProduct     :: Vector Int -> Vector Int -> Int
+dotProduct x y 
+  | length x == length y
+  = loop 0 (length x) 0 (\i -> (+ (x ! i) * (y ! i))) 
+  | otherwise
+  = error "dotProduct only on equal-sized vectors!"
+
+
+{-@ type SparseVector a N = [({v: Int | (0 <= v && v < N)}, a)] @-}
+
+{-@ sparseDotProduct :: (Num a) => x:(Vector a) -> (SparseVector a {(vlen x)}) -> a @-}
+sparseDotProduct x y  = go 0 y
+  where
+    {-@ decrease go 2 @-}
+    go sum ((i, v) : y') = go (sum + (x ! i) * v) y' 
+    go sum []            = sum
+
+
diff --git a/tests/pos/VerifiedNum.hs b/tests/pos/VerifiedNum.hs
--- a/tests/pos/VerifiedNum.hs
+++ b/tests/pos/VerifiedNum.hs
@@ -3,11 +3,11 @@
 -- Hiding numeric operations, because they get by default translated to SMT equivalent
 import Prelude hiding (Num(..))
 
-import qualified Prelude as Prelude 
+import qualified Prelude as Prelude
 
-class VerifiedNum a where 
-  (+) :: a -> a -> a 
-  (-) :: a -> a -> a 
+class VerifiedNum a where
+  (+) :: a -> a -> a
+  (-) :: a -> a -> a
 
 {-@ predicate BoundInt X = 0 < X + 10000 && X < 10000 @-}
 
@@ -17,12 +17,12 @@
 
 
 instance VerifiedNum Int where
-{-@ instance VerifiedNum Int where 
-      + :: x:Int -> y:Int -> OkInt {x + y} 
+{-@ instance VerifiedNum Int where
+      + :: x:Int -> y:Int -> OkInt {x + y}
   @-}
-	x + y = (Prelude.+) x y  
-{-@ instance VerifiedNum Int where 
-      - :: x:Int -> y:Int -> OkInt {x - y} 
+    x + y = (Prelude.+) x y
+{-@ instance VerifiedNum Int where
+      - :: x:Int -> y:Int -> OkInt {x - y}
   @-}
-	x - y = (Prelude.-) x y  
+    x - y = (Prelude.-) x y
 
diff --git a/tests/pos/WBL0.hs b/tests/pos/WBL0.hs
--- a/tests/pos/WBL0.hs
+++ b/tests/pos/WBL0.hs
@@ -15,7 +15,7 @@
 
 {-@ LIQUID "--no-termination" @-}
 
-module WBL where
+module WBL0 where
 
 type Priority = Int
 
diff --git a/tests/pos/WhyLH.hs b/tests/pos/WhyLH.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/WhyLH.hs
@@ -0,0 +1,139 @@
+module WhyLH where
+
+{-@ LIQUID "--ple" @-}
+{-@ LIQUID "--exact-data-cons" @-}
+
+-- This test contains the examples of the blogpost at
+-- https://www.tweag.io/blog/2022-01-19-why-liquid-haskell/
+--
+import Language.Haskell.Liquid.ProofCombinators (pleUnfold)
+import Prelude hiding (length, max)
+
+{-@
+type Nat = {i:Int | 0 <= i}
+
+data UExp
+  = UVar Nat
+  | ULam Ty UExp
+  | UApp { uapp1 :: UExp, uapp2 :: UExp }
+ @-}
+-- | Lambda expressions with types at the bindings.
+data UExp
+  = UVar Int
+  | ULam Ty UExp
+  | UApp { uapp1 :: UExp, uapp2 :: UExp }
+
+-- | The types are the types of functions manipulating some opaque type @T@.
+data Ty = T | TyFun Ty Ty
+  deriving Eq
+
+-- XXX: Using inline instead of reflect causes verification to fail
+{-@ reflect max @-}
+max :: Int -> Int -> Int
+max a b = pleUnfold (if a > b then a else b)
+
+-- XXX: using max causes verification to fail if not using
+-- --ple-with-undecided-guards. Arguably, PLE should unfold max
+-- since it is not doing pattern matching.
+{-@
+reflect freeVarBound
+freeVarBound :: UExp -> Int
+@-}
+-- | Compute the lowest upper-bound of de Bruijn indices appearing
+-- free in an expression.
+freeVarBound :: UExp -> Int
+freeVarBound (UVar v) = v + 1
+freeVarBound (ULam _ body) = max (freeVarBound body - 1) 0
+freeVarBound (UApp e1 e2) = max (freeVarBound e1) (freeVarBound e2)
+
+{-@
+type UExpN N = { e:UExp | freeVarBound e <= N }
+type ClosedUExp = UExpN 0
+@-}
+
+{-@ exp0 :: ClosedUExp @-}
+exp0 :: UExp
+exp0 = ULam T (UVar 0)
+
+{-@ exp1 :: UExpN 1 @-}
+exp1 :: UExp
+exp1 = UVar 0
+
+{-@ exp2 :: ClosedUExp @-}
+exp2 :: UExp
+exp2 = ULam T (ULam T (UVar 0))
+
+{-@ exp3 :: UExpN 1 @-}
+exp3 :: UExp
+exp3 = ULam T (ULam T (UVar 2))
+
+
+{-@ reflect elemAt @-}
+{-@ elemAt :: xs:[a] -> { i:Int | 0 <= i && i < length xs } -> a @-}
+elemAt :: [a] -> Int -> a
+elemAt (x:_) 0 = x
+elemAt (_:xs) i = elemAt xs (i - 1)
+
+{-@ reflect length @-}
+length :: [a] -> Int
+length [] = 0
+length (_:xs) = 1 + length xs
+
+{-@ reflect inferType @-}
+{-@ inferType :: ctx:[Ty] -> UExpN (length ctx) -> Maybe Ty @-}
+inferType :: [Ty] -> UExp -> Maybe Ty
+inferType ctx (UVar i) = Just (elemAt ctx i)
+inferType ctx (ULam t body) = case inferType (t:ctx) body of
+  Just r -> Just (TyFun t r)
+  Nothing -> Nothing
+inferType ctx (UApp e0 e1) =
+  pleUnfold  -- needed by uappArgT to avoid breaking the verification
+             -- in all of these cases
+    (case inferType ctx e0 of
+      Just (TyFun a r) -> case inferType ctx e1 of
+        Just t -> if a == t then Just r else Nothing
+        Nothing -> Nothing
+      _ -> Nothing
+    )
+
+{-@ type WellTypedExp CTX TY = { e:UExp | freeVarBound e <= length CTX && inferType CTX e == Just TY } @-}
+
+{-@ reflect cons @-}
+cons :: a -> [a] -> [a]
+cons = (:)
+
+{-@ exp4 :: WellTypedExp (cons T []) T @-}
+exp4 :: UExp
+exp4 = UVar 0
+
+{-@ exp5 :: WellTypedExp [] (TyFun T T) @-}
+exp5 :: UExp
+exp5 = ULam T (UVar 0)
+
+main :: IO ()
+main = print ()
+
+-- The following functions are an experiment on what LH can infer from
+-- the arguments of a data constructor. Given a well-typed application
+-- @UApp e0 e1@, can LH infer that @e0@ must have a function type and
+-- that the type of @e1@ must match the argument type of @e0@.
+
+{-@ uappArgT :: ctx:[Ty] -> e : { e:UExp | isUApp e && isJustTy (inferType ctx e) } -> { funTyM (inferType ctx (uapp2 e)) (inferType ctx e) == inferType ctx (uapp1 e) } @-}
+uappArgT :: [Ty] -> UExp -> ()
+uappArgT _ _ = ()
+
+{-@ inline isUApp @-}
+isUApp :: UExp -> Bool
+isUApp (UApp _ _) = True
+isUApp _ = False
+
+-- Either inline or both reflect and pleUnfold are needed by `uappArgT`.
+{-@ inline isJustTy @-}
+isJustTy :: Maybe a -> Bool
+isJustTy (Just _) = True
+isJustTy _ = False
+
+{-@ inline funTyM @-}
+funTyM :: Maybe Ty -> Maybe Ty -> Maybe Ty
+funTyM (Just a) (Just b) = Just (TyFun a b)
+funTyM _ _ = Nothing
diff --git a/tests/pos/Words1.hs b/tests/pos/Words1.hs
--- a/tests/pos/Words1.hs
+++ b/tests/pos/Words1.hs
@@ -1,3 +1,5 @@
+module Words1 where
+
 import Data.Word
 
 main = print (quotRem (4 :: Word8) 128)
diff --git a/tests/pos/Wrap0.hs b/tests/pos/Wrap0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Wrap0.hs
@@ -0,0 +1,20 @@
+module Wrap0 () where
+
+import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
+
+data Foo a = F a
+
+type IntFoo = Foo Int
+
+{-@ flibberty :: (Eq a) => a -> Bool @-}
+flibberty x   = prop x (F x)
+prop x (F y)  = liquidAssertB (x == y)
+
+{-@ flibInt :: (Num a, Ord a) => a -> Bool @-}
+flibInt x     = prop1 x (F (x + 1))
+prop1 x (F y) = liquidAssertB (x < y) 
+
+{-@ flibXs :: a -> Bool @-}
+flibXs x     = prop2 (F [x, x, x])
+prop2 (F []) = liquidError "not-the-hippopotamus"
+prop2 (F _ ) = True
diff --git a/tests/pos/Wrap1.hs b/tests/pos/Wrap1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Wrap1.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
+
+module Wrap1 () where
+
+
+import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
+import Data.Function (on)
+import Data.Ord (comparing)
+
+data WrapType b a = WrapType {getVect :: b, getVal :: a}
+
+instance Eq (WrapType [Double] a) where
+   (==) = (==) `on` getVect
+
+instance Ord (WrapType [Double] a) where
+    compare = comparing getVect
+
+{-@ assert flibXs :: a -> Bool @-}
+flibXs x              = prop1 (WrapType [x, x, x] x)
+prop1 (WrapType [] _) = liquidError "no!"
+prop1 (WrapType _  _) = True
+
+{-@ assert nflibXs :: Nat -> a -> Bool @-}
+nflibXs n x           = prop2 n (WrapType nxs x)
+                        where nxs = replicate n x 
+
+prop2 :: Int -> WrapType [a] t -> Bool
+prop2 n (WrapType xs _) = liquidAssertB (n == length xs) 
+
+
+
+
+
diff --git a/tests/pos/WrapUnWrap.hs b/tests/pos/WrapUnWrap.hs
--- a/tests/pos/WrapUnWrap.hs
+++ b/tests/pos/WrapUnWrap.hs
@@ -1,6 +1,6 @@
 {-@ LIQUID "--higherorder"  @-}
 {-@ LIQUID "--exactdc"      @-}
-module Data.Foo where
+module WrapUnWrap where
 
 
 import Language.Haskell.Liquid.ProofCombinators
diff --git a/tests/pos/ZipSO.hs b/tests/pos/ZipSO.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ZipSO.hs
@@ -0,0 +1,20 @@
+module ZipSO () where
+
+-- From
+-- http://stackoverflow.com/questions/17501777/implementing-a-zipper-for-length-indexed-lists/17503667#17503667
+
+import Prelude hiding ((++))
+
+{-@ zipper :: zs:[a] -> [(a, {v:[a] | (len v) = (len zs) - 1})] @-}
+zipper zs          = go [] zs
+  
+{-@ go :: prev:[a] -> rest:[a] -> [(a, {v:[a] | (len v) = (len prev) + (len rest) - 1})] / [len rest]  @-}
+go :: [a] -> [a] -> [(a, [a])]
+go _    []     = []
+go prev (x:xs) = (x, prev ++ xs) : go (prev ++ [x]) xs
+
+{-@ append :: xs:[a] -> ys:[a] -> {v:[a] | (len v) = (len xs) + (len ys)} @-}
+append [] ys     = ys
+append (x:xs) ys = x : append xs ys
+
+(++) = append
diff --git a/tests/pos/ZipW.hs b/tests/pos/ZipW.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ZipW.hs
@@ -0,0 +1,14 @@
+module ZipW () where
+
+import Language.Haskell.Liquid.Prelude
+
+{-@ assert zipW :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len(v) = len(xs)} -> {v : [c] | len(v) = len(xs)} @-}
+zipW :: (a->b->c) -> [a]->[b]->[c]
+zipW f (a:as) (b:bs) = f a b : zipW f as bs
+zipW _ [] []         = []
+zipW _ [] (_:_)      = liquidError "zipWith1"
+zipW _ (_:_) []      = liquidError "zipWith1"
+
+{-@ assert foo :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len(v) = len(xs)} -> {v : [c] | len(v) = len(xs)} @-}
+foo = zipW
+
diff --git a/tests/pos/ZipW1.hs b/tests/pos/ZipW1.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ZipW1.hs
@@ -0,0 +1,11 @@
+module ZipW1 where
+
+import Language.Haskell.Liquid.Prelude -- (safeZipWith)
+
+{-@ foo :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len v = len xs}
+        -> {v : [c] | len v  = len xs} @-}
+foo = safeZipWith
+
+
+{- safeZipWith :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len v = len xs}
+                -> {v : [c] | len v = len xs} @-}
diff --git a/tests/pos/ZipW2.hs b/tests/pos/ZipW2.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/ZipW2.hs
@@ -0,0 +1,5 @@
+module ZipW2 where
+
+
+foo :: [Int] -> [Int]
+foo zs = zipWith (+) zs zs
diff --git a/tests/pos/Zipper.hs b/tests/pos/Zipper.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Zipper.hs
@@ -0,0 +1,165 @@
+module Zipper (getFocus, getUp, getDown) where
+
+import Prelude hiding (reverse, (++))
+
+import Data.Set
+
+data Stack a = Stack { focus  :: !a        -- focused thing in this set
+                     , up     :: [a]       -- jokers to the left
+                     , down   :: [a] }     -- jokers to the right
+    deriving (Show, Eq)
+-- LIQUID     deriving (Show, Read, Eq)
+
+-------------------------------------------------------------------------------
+----------------------------- Refinements on  Lists ---------------------------
+-------------------------------------------------------------------------------
+
+-- measures
+
+{-@
+  measure listDup :: forall a. [a] -> (Set a)
+    listDup [] = {v | Set_emp v }
+    listDup (x:xs) = {v | v = if (Set_mem x (listElts xs)) then (Set_cup (Set_sng x) (listDup xs)) else (listDup xs) }
+  @-}
+
+-- predicates
+
+{-@ predicate EqElts X Y =
+       ((listElts X) = (listElts Y)) @-}
+
+{-@ predicate SubElts X Y =
+       (Set_sub (listElts X) (listElts Y)) @-}
+
+{-@ predicate UnionElts X Y Z =
+       ((listElts X) = (Set_cup (listElts Y) (listElts Z))) @-}
+
+{-@ predicate ListElt N LS =
+       (Set_mem N (listElts LS)) @-}
+
+{-@ predicate ListUnique LS =
+       (Set_emp (listDup LS)) @-}
+
+{-@ predicate ListDisjoint X Y =
+       (Set_emp (Set_cap (listElts X) (listElts Y))) @-}
+
+
+-- types
+
+{-@ type UList a = {v:[a] | (ListUnique v)} @-}
+
+{-@ type UListDif a N = {v:[a] | ((not (ListElt N v)) && (ListUnique v))} @-}
+
+
+
+-------------------------------------------------------------------------------
+----------------------------- Refinements on Stacks ---------------------------
+-------------------------------------------------------------------------------
+
+{-@
+data Stack a = Stack { focus :: a
+                     , up    :: UListDif a focus
+                     , down  :: UListDif a focus }
+@-}
+
+{-@ type UStack a = {v:Stack a | (ListDisjoint (getUp v) (getDown v))}@-}
+
+{-@ measure getFocus @-}
+getFocus :: Stack a -> a
+getFocus (Stack xfocus _ _) = xfocus
+
+{-@ measure getUp @-}
+getUp :: Stack a -> [a]
+getUp (Stack xfocus xup xdown) = xup
+
+{-@ measure getDown @-}
+getDown :: Stack a -> [a]
+getDown (Stack xfocus xup xdown) = xdown
+
+
+-------------------------------------------------------------------------------
+------------------------------ Functions on Stacks ----------------------------
+-------------------------------------------------------------------------------
+
+
+{-@ differentiate :: UList a -> Maybe (UStack a) @-}
+differentiate :: [a] -> Maybe (Stack a)
+differentiate []     = Nothing
+differentiate (x:xs) = Just $ Stack x [] xs
+
+{-@ integrate :: UStack a -> UList a @-}
+integrate :: Stack a -> [a]
+integrate (Stack x l r) = reverse l ++ x : r
+
+{-@ integrate' :: Maybe (UStack a) -> UList a @-}
+integrate' :: Maybe (Stack a) -> [a]
+integrate' = maybe [] integrate
+
+
+{-@ focusUp :: UStack a -> UStack a @-}
+focusUp :: Stack a -> Stack a
+focusUp (Stack t [] rs)     = Stack x xs [] where (x:xs) = reverse (t:rs)
+focusUp (Stack t (l:ls) rs) = Stack l ls (t:rs)
+
+{-@ focusDown :: UStack a -> UStack a @-}
+focusDown :: Stack a -> Stack a
+focusDown = reverseStack . focusUp . reverseStack
+
+{-@ reverseStack :: UStack a -> UStack a @-}
+reverseStack :: Stack a -> Stack a
+reverseStack (Stack t ls rs) = Stack t rs ls
+
+{-@ swapUp :: UStack a -> UStack a @-}
+swapUp :: Stack a -> Stack a
+swapUp  (Stack t (l:ls) rs) = Stack t ls (l:rs)
+swapUp  (Stack t []     rs) = Stack t (reverse  rs) []
+
+{-@ filter :: (a -> Bool) -> UStack a -> Maybe (UStack a) @-}
+filter :: (a -> Bool) -> Stack a -> Maybe (Stack a)
+filter p (Stack f ls rs) = case filterL p (f:rs) of
+    f':rs' -> Just $ Stack f' (filterL p ls) rs'    -- maybe move focus down
+    []     -> case filterL p ls of                  -- filter back up
+                    f':ls' -> Just $ Stack f' ls' [] -- else up
+                    []     -> Nothing
+
+
+-------------------------------------------------------------------------------
+------------------------------- Functions on Lists ----------------------------
+-------------------------------------------------------------------------------
+
+
+infixr 5 ++
+{-@ Zipper.++ :: xs:(UList a)
+         -> ys:{v: UList a | (ListDisjoint v xs)}
+         -> {v: UList a | (UnionElts v xs ys)}
+  @-}
+(++) :: [a] -> [a] -> [a]
+[] ++ ys = ys
+(x:xs) ++ ys = x: (xs ++ ys)
+
+
+{-@ reverse :: xs:(UList a)
+            -> {v: UList a | (EqElts v xs)}
+  @-}
+reverse :: [a] -> [a]
+reverse = rev []
+
+
+{-@ rev :: acc:(UList a)
+        -> xs:{v: UList a | ListDisjoint acc v }
+        -> {v:UList a | UnionElts v xs acc } / [len xs]
+  @-}
+rev :: [a] -> [a] -> [a]
+rev a []     = a
+rev a (x:xs) = rev (x:a) xs
+
+{-@ filterL :: (a -> Bool) -> xs:(UList a) -> {v:UList a | (SubElts v xs)} @-}
+filterL :: (a -> Bool) -> [a] -> [a]
+filterL p [] = []
+filterL p (x:xs) | p x       = x : filterL p xs
+                 | otherwise = filterL p xs
+
+
+-- QUALIFIERS
+{-@ q :: x:a ->  {v:[a] |(not (Set_mem x (listElts v)))} @-}
+q :: a -> [a]
+q = undefined
diff --git a/tests/pos/Zipper0.hs b/tests/pos/Zipper0.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Zipper0.hs
@@ -0,0 +1,71 @@
+{-@ LIQUID "--no-totality" @-}
+
+module Zipper0 (getUp, getDown, getFocus) where
+
+import Prelude hiding (reverse)
+
+import Data.Set
+
+data Stack a = Stack { focus  :: !a        -- focused thing in this set
+                     , up     :: [a]       -- jokers to the left
+                     , down   :: [a] }     -- jokers to the right
+
+{-@ type UListDif a N = {v:[a] | ((not (Set_mem N (listElts v))) && (Set_emp (listDup v)))} @-}
+
+{-@
+data Stack a = Stack { focus :: a
+                     , up    :: UListDif a focus
+                     , down  :: UListDif a focus }
+@-}
+
+{-@ measure listDup :: [a] -> (Set a)
+      listDup [] = {v | Set_emp v }
+      listDup (x:xs) = {v | v = if (Set_mem x (listElts xs)) then (Set_cup (Set_sng x) (listDup xs)) else (listDup xs) }
+  @-}
+
+{-@ type UStack a = {v:Stack a |(Set_emp (Set_cap (listElts (getUp v)) (listElts (getDown v))))}@-}
+
+{-@ measure getFocus @-}
+getFocus :: Stack a -> a
+getFocus (Stack xfocus _ _) = xfocus
+
+{-@ measure getUp @-}
+getUp :: Stack a -> [a]
+getUp (Stack xfocus xup xdown) = xup
+
+{-@ measure getDown @-}
+getDown :: Stack a -> [a]
+getDown (Stack xfocus xup xdown) = xdown
+
+
+-- QUALIFIERS
+{-@ q :: x:a ->  {v:[a] |(not (Set_mem x (listElts v)))} @-}
+q :: a -> [a]
+q = undefined
+{-@ q1 :: x:a ->  {v:[a] |(Set_mem x (listElts v))} @-}
+q1 :: a -> [a]
+q1 = undefined
+{-@ q0 :: x:a ->  {v:[a] |(Set_emp(listDup v))} @-}
+q0 :: a -> [a]
+q0 = undefined
+
+
+{-@ focusUp :: UStack a -> UStack a @-}
+focusUp :: Stack a -> Stack a
+focusUp (Stack t [] rs)     = Stack xiggety xs [] where (xiggety:xs) = reverse (t:rs)
+focusUp (Stack t (l:ls) rs) = Stack l ls (t:rs)
+
+{-@ focusDown :: UStack a -> UStack a @-}
+focusDown :: Stack a -> Stack a
+focusDown = reverseStack . focusUp . reverseStack
+
+-- | reverse a stack: up becomes down and down becomes up.
+{-@ reverseStack :: UStack a -> UStack a @-}
+reverseStack :: Stack a -> Stack a
+reverseStack (Stack t ls rs) = Stack t rs ls
+
+
+-- TODO ASSUMES
+{-@ reverse :: {v:[a] | (Set_emp (listDup v))} -> {v:[a]|(Set_emp (listDup v))} @-}
+reverse :: [a] -> [a]
+reverse = undefined
diff --git a/tests/pos/Zipper000.hs b/tests/pos/Zipper000.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/Zipper000.hs
@@ -0,0 +1,44 @@
+{-@ LIQUID "--no-totality" @-}
+
+module Zipper000 (getUp, getDown) where
+
+import Data.Set
+
+data Stack a = Stack { focus  :: a        -- focused thing in this set
+                     , up     :: [a]       -- jokers to the left
+                     , down   :: [a] }     -- jokers to the right
+
+{-@ type UListDif a N = {v:[a] | not (Set_mem N (listElts v)) } @-}
+
+{-@ data Stack a = Stack 
+      { focus :: a
+      , up    :: UListDif a focus
+      , down  :: UListDif a focus 
+      }
+  @-}
+
+{-@ type UStack a = {v:Stack a | (Set_emp (Set_cap (listElts (getUp v)) (listElts (getDown v))))} @-}
+
+{-@ measure getUp @-}
+getUp :: Stack a -> [a]
+getUp (Stack xfocus xup xdown) = xup
+
+{-@ measure getDown @-}
+getDown :: Stack a -> [a]
+getDown (Stack xfocus xup xdown) = xdown
+
+data Foo a b = J | P a b
+
+--------------------------------------------------------------------------------------
+{-@ focusUp :: UStack a -> UStack a @-}
+focusUp :: Stack a -> Stack a
+focusUp (Stack t [] rs) = Stack xiggety xs []
+  where P xiggety xs    = P t rs
+
+-- focusUp (Stack t [] rs) = Stack t rs []
+
+
+
+
+
+--------------------------------------------------------------------------------------
diff --git a/tests/pos/absref-crash.hs b/tests/pos/absref-crash.hs
deleted file mode 100644
--- a/tests/pos/absref-crash.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Foo where
-
-data L a = C (L a)
-
-{-@ data L a <p :: L a -> Bool> = C { xs :: L<p> a } @-}
-
-{-@ lazy foo @-}
-foo :: b -> L a
-foo x = C $ foo x
diff --git a/tests/pos/absref-crash0.hs b/tests/pos/absref-crash0.hs
deleted file mode 100644
--- a/tests/pos/absref-crash0.hs
+++ /dev/null
@@ -1,36 +0,0 @@
-{-@ LIQUID "--short-names"    @-}
-{-@ LIQUID "--no-warnings"    @-}
-{-@ LIQUID "--no-termination" @-}
-
-
-module Foo (insertSort) where
-
-data List a = N | C a (List a)
-
-infixr 9 `C`
-
-{-@ ifoldr :: forall a b <p :: List a -> b -> Bool>. 
-                 (xs:_ -> x:_ -> b<p xs> -> b<p(C x xs)>) 
-               -> b<p N> 
-               -> ys:List a
-               -> b<p ys>                            @-}
-ifoldr :: (List a -> a -> b -> b) -> b -> List a -> b
-ifoldr = undefined
-
-{-@ data List a <p :: a -> a -> Bool> 
-     = N | C {x :: a, xs :: List<p> a<p x>} @-}
-
-{-@ type IncrList a = List <{\x y -> x <= y}> a @-} 
-
-{-@ insert :: a -> IncrList a -> IncrList a @-}
-insert :: a -> List a -> List a
-insert = undefined
-
-{-@ insertSort      :: xs:List a -> {v:IncrList a | true } @-}
-insertSort :: List a -> List a
-insertSort = undefined
-
-
-
-nil :: List a 
-nil = N
diff --git a/tests/pos/adt0.hs b/tests/pos/adt0.hs
deleted file mode 100644
--- a/tests/pos/adt0.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Adt () where
-
-import Language.Haskell.Liquid.Prelude
-
-data Pair a = P a Int | D a Bool
-
-
-goo z = P z z
-
-baz = goo 10
diff --git a/tests/pos/alias00.hs b/tests/pos/alias00.hs
deleted file mode 100644
--- a/tests/pos/alias00.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Test0 () where
-
-{-@ type PosInt = {v: Int | v >= 0} @-}
-
-{-@ assert myabs :: Int -> PosInt @-}
-myabs   :: Int -> Int
-myabs x = if (x > 0) then x else (0 - x)
-
-{-@ type NNList a = {v: [a] | len v > 0} @-}
-
-{-@ assert single :: a -> NNList a @-}
-single x = [x] 
diff --git a/tests/pos/alias01.hs b/tests/pos/alias01.hs
deleted file mode 100644
--- a/tests/pos/alias01.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Test0 () where
-
-{-@ type GeNum a N = {v: a | N <= v} @-}
-
-{-@ type PosInt = GeNum Int {0} @-}
-
-{-@ myabs :: Int -> PosInt @-}
-myabs :: Int -> Int
-myabs x = if (x > 0) then x else (0 - x)
-
-{-@ incr :: x:Int -> GeNum Int {x} @-}
-incr :: Int -> Int
-incr x = x + 1
-
diff --git a/tests/pos/alphaconvert-List.hs b/tests/pos/alphaconvert-List.hs
deleted file mode 100644
--- a/tests/pos/alphaconvert-List.hs
+++ /dev/null
@@ -1,140 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-{-@ LIQUID "--fullcheck"      @-}
-{-@ LIQUID "--maxparams=3"    @-}
-
--- | An example from "A Relational Framework for Higher-Order Shape Analysis",
---   by Gowtham Kaki Suresh Jagannathan, ICFP 2014.
-
-module AlphaConvert (subst, alpha, isAbs, maxs) where
-
-import Prelude hiding ((++), elem)
-import qualified Data.Set as S
-import Language.Haskell.Liquid.Prelude
-
-alpha  :: [Bndr] -> Expr -> Expr
-subst  :: Expr -> Bndr -> Expr -> Expr
-lemma1 :: Int -> [Int] -> Bool
-fresh  :: [Bndr] -> Bndr
-free   :: Expr -> [Bndr]
-
----------------------------------------------------------------------
--- | Datatype Definition --------------------------------------------
----------------------------------------------------------------------
-
-type Bndr
-  = Int
-
-data Expr
-  = Var Bndr
-  | Abs Bndr Expr
-  | App Expr Expr
-
-{-@ measure fv @-}
-fv :: Expr -> S.Set Bndr
-fv (Var x)   = S.singleton x
-fv (Abs x e) = S.difference (fv e) (S.singleton x)
-fv (App e a) = S.union (fv e) (fv a)
-
-{-@ measure isAbs  @-}
-isAbs :: Expr -> Bool
-isAbs (Abs v e)  = True
-isAbs (Var v)    = False
-isAbs (App e a)  = False
-
-{-@ predicate AddV E E2 X E1   = fv E = Set_cup (Set_dif (fv E2) (Set_sng X)) (fv E1) @-}
-{-@ predicate EqV E1 E2        = fv E1 = fv E2                                        @-}
-{-@ predicate Occ X E          = Set_mem X (fv E)                                     @-}
-{-@ predicate Subst E E1 X E2  = if (Occ X E2) then (AddV E E2 X E1) else (EqV E E2)  @-}
-
-----------------------------------------------------------------------------
--- | Part 5: Capture Avoiding Substitution ---------------------------------
-----------------------------------------------------------------------------
-{-@ subst :: e1:Expr -> x:Bndr -> e2:Expr -> {e:Expr | Subst e e1 x e2} @-}
-----------------------------------------------------------------------------
-
-subst e1 x e2@(Var y)
-  | x == y                = e1
-  | otherwise             = e2
-
-subst e1 x (App ea eb)    = App ea' eb'
-  where
-    ea'                   = subst e1 x ea
-    eb'                   = subst e1 x eb
-
-subst e1 x e2@(Abs y e)
-  | x == y                = e2
-  | y `elem` xs           = subst e1 x (alpha xs e2)
-  | otherwise             = Abs y      (subst e1 x e)
-     where
-      xs                  = free e1
-
-----------------------------------------------------------------------------
--- | Part 4: Alpha Conversion ----------------------------------------------
-----------------------------------------------------------------------------
-{-@ alpha :: ys:[Bndr] -> e:{Expr | isAbs e} -> {v:Expr | EqV v e} @-}
-----------------------------------------------------------------------------
-alpha ys (Abs x e) = Abs x' (subst (Var x') x e)
-  where
-    xs             = free e
-    x'             = fresh (x : ys ++ xs)
-
-alpha _  _         = liquidError "never"
-
-
-----------------------------------------------------------------------------
--- | Part 3: Fresh Variables -----------------------------------------------
-----------------------------------------------------------------------------
-{-@ fresh :: xs:[Bndr] -> {v:Bndr | NotElem v xs} @-}
-----------------------------------------------------------------------------
-fresh bs = liquidAssert (lemma1 n bs) n
-  where
-    n    = 1 + maxs bs
-
-{-@ measure maxs @-}
-maxs   :: [Int] -> Int
-maxs ([])   = 0
-maxs (x:xs) = if (x > maxs xs) then x else (maxs xs)
-
-{-@ lemma1 :: x:Int -> xs:{[Int] | x > maxs xs} -> {v:Bool | v && NotElem x xs} @-}
-lemma1 _ []     = True
-lemma1 x (_:ys) = lemma1 x ys
-
-
-----------------------------------------------------------------------------
--- | Part 2: Free Variables ------------------------------------------------
-----------------------------------------------------------------------------
-
-----------------------------------------------------------------------------
-{-@ free         :: e:Expr -> {v:[Bndr] | elts v = fv e} @-}
-----------------------------------------------------------------------------
-free (Var x)     = [x]
-free (App e e')  = free e ++ free e'
-free (Abs x e)   = free e \\ x
-
-
-----------------------------------------------------------------------------
--- | Part I: Sets with Lists -----------------------------------------------
-----------------------------------------------------------------------------
-
-{-@ predicate IsCup X Y Z  = elts X = Set_cup (elts Y) (elts Z)    @-}
-{-@ predicate IsDel X Y Z  = elts X = Set_dif (elts Y) (Set_sng Z) @-}
-{-@ predicate Elem  X Ys   = Set_mem X (elts Ys)                   @-}
-{-@ predicate NotElem X Ys = not (Elem X Ys)                       @-}
-
-{-@ (++)      :: xs:[a] -> ys:[a] -> {v:[a] | IsCup v xs ys}  @-}
-[]     ++ ys  = ys
-(x:xs) ++ ys  = x : (xs ++ ys)
-
-{-@ (\\)      :: (Eq a) => xs:[a] -> y:a -> {v:[a] | IsDel v xs y} @-}
-xs   \\ y     = [x | x <- xs, x /= y]
-
-{-@ elem      :: (Eq a) => x:a -> ys:[a] -> {v:Bool | v <=> Elem x ys} @-}
-elem x []     = False
-elem x (y:ys) = x == y || elem x ys
-
-{-@ measure elts @-}
-elts :: (Ord a) => [a] -> S.Set a
-elts []     = S.empty
-elts (x:xs) = S.union (S.singleton x) (elts xs)
diff --git a/tests/pos/alphaconvert-Set.hs b/tests/pos/alphaconvert-Set.hs
deleted file mode 100644
--- a/tests/pos/alphaconvert-Set.hs
+++ /dev/null
@@ -1,101 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-{-@ LIQUID "--fullcheck"      @-}
-{-@ LIQUID "--maxparams=3"    @-}
-
-module AlphaConvert (isAbs, subst) where
-
-import qualified Data.Set as S
-
-import Language.Haskell.Liquid.Prelude
-
-freshS  :: S.Set Bndr -> Bndr
-alpha   :: S.Set Bndr -> Expr -> Expr
-subst   :: Expr -> Bndr -> Expr -> Expr
-free    :: Expr -> S.Set Bndr
-
-
----------------------------------------------------------------------
--- | Datatype Definition --------------------------------------------
----------------------------------------------------------------------
-
-type Bndr
-  = Int
-
-data Expr
-  = Var Bndr
-  | Abs Bndr Expr
-  | App Expr Expr
-
-{-@ measure fv @-}
-fv :: Expr -> S.Set Bndr
-fv (Var x)   = S.singleton x
-fv (Abs x e) = S.difference (fv e) (S.singleton x)
-fv (App e a) = S.union (fv e) (fv a)
-
-{-@ measure isAbs @-}
-isAbs (Var v)    = False
-isAbs (Abs v e)  = True
-isAbs (App e a)  = False
-
-{-@ predicate Elem  X Ys       = Set_mem X Ys               @-}
-{-@ predicate NotElem X Ys     = not (Elem X Ys)            @-}
-{-@ predicate AddV E E2 X E1   = fv E = Set_cup (Set_dif (fv E2) (Set_sng X)) (fv E1) @-}
-{-@ predicate EqV E1 E2        = fv E1 = fv E2                                        @-}
-{-@ predicate Occ X E          = Set_mem X (fv E)                                     @-}
-{-@ predicate Subst E E1 X E2  = if (Occ X E2) then (AddV E E2 X E1) else (EqV E E2)  @-}
-
-----------------------------------------------------------------------------
--- | Part 5: Capture Avoiding Substitution ---------------------------------
-----------------------------------------------------------------------------
-{-@ subst :: e1:Expr -> x:Bndr -> e2:Expr -> {e:Expr | Subst e e1 x e2} @-}
-----------------------------------------------------------------------------
-
-subst e' x e@(Var y)
-  | x == y                = e'
-  | otherwise             = e
-
-subst e' x (App ea eb)    = App ea' eb'
-  where
-    ea'                   = subst e' x ea
-    eb'                   = subst e' x eb
-
-subst e1 x e2@(Abs y e)
-  | x == y                = e2
-  | y `S.member` xs       = subst e1 x (alpha xs e2)
-  | otherwise             = Abs y (subst e1 x e)
-    where
-      xs                  = free e1
-
-----------------------------------------------------------------------------
--- | Part 4: Alpha Conversion ----------------------------------------------
-----------------------------------------------------------------------------
-{-@ alpha :: ys:(S.Set Bndr) -> e:{Expr | isAbs e} -> {v:Expr | EqV v e} @-}
-----------------------------------------------------------------------------
-alpha ys (Abs x e) = Abs x' (subst (Var x') x e)
-  where
-    xs             = free e
-    x'             = freshS zs
-    zs             = S.insert x (S.union ys xs)
-
-alpha _  _         = liquidError "never"
-
-
-----------------------------------------------------------------------------
--- | Part 3: Fresh Variables -----------------------------------------------
-----------------------------------------------------------------------------
-{-@ freshS :: xs:(S.Set Bndr) -> {v:Bndr | NotElem v xs} @-}
-----------------------------------------------------------------------------
-freshS xs = undefined
-
-
-----------------------------------------------------------------------------
--- | Part 2: Free Variables ------------------------------------------------
-----------------------------------------------------------------------------
-
-----------------------------------------------------------------------------
-{-@ free         :: e:Expr -> {v : S.Set Bndr | v = fv e} @-}
-----------------------------------------------------------------------------
-free (Var x)     = S.singleton x
-free (App e e')  = S.union  (free e) (free e')
-free (Abs x e)   = S.delete x (free e)
diff --git a/tests/pos/anfbug.hs b/tests/pos/anfbug.hs
deleted file mode 100644
--- a/tests/pos/anfbug.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-module Tx (x,y) where
-
-import Control.Exception (assert)
-
--- TransformRec BUG: this causes a temporary to get hoisted out of scope
-getTails' :: Int -> [[a]] -> [[a]]
-getTails' n xss = assert (n > 0) [t | (_:t) <- xss]
-
-x = getTails' 1 []
-
--- HACK give hints for internal variables....
-{- decrease ds_d258 3 @-}
-{- decrease ds_d25g 3 @-}
-
--- TransformRec BUG: this causes some weird unused variable error (occurrence of DEAD ID)?
-getTails'' :: Int -> [[a]] -> [[a]]
-getTails'' n xss = [t | (_:t) <- xss]
-
-y = getTails'' 1 []
diff --git a/tests/pos/anftest.hs b/tests/pos/anftest.hs
deleted file mode 100644
--- a/tests/pos/anftest.hs
+++ /dev/null
@@ -1,29 +0,0 @@
-module AnfWierd () where
-
--- xs :: [Int]
--- xs = let x0 = 0
---          x1 = 1
---          x2 = 2
---          x3 = 3
---          x4 = 4
---          x5 = 5
---          x6 = 6
---          x7 = 7
---          x8 = 8
---          x9 = 9
---      in [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9]
-
-xs :: [Int]
-xs = let x0 = 0
-         x1 = 1
-     in [x0, x1]
-
-ys :: [Int]
-ys = [y0, y1]
-     where y0 = 0
-           y1 = 1
-
-{-@ incr :: x: Int -> {v: Int | v > x} @-}
-incr :: Int -> Int
-incr y = y + length xs 
-  
diff --git a/tests/pos/anish1.hs b/tests/pos/anish1.hs
deleted file mode 100644
--- a/tests/pos/anish1.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test1 () where
-
-inc :: Int -> Int
-inc xoooo = xoooo + 1
-
-test1 :: Int -> Int
-test1 nine = let b = 0 <= nine in
-          if b then
-            let a = inc nine
-            in
-               div nine a
-          else
-            1
diff --git a/tests/pos/bag1.hs b/tests/pos/bag1.hs
deleted file mode 100644
--- a/tests/pos/bag1.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module BagTest where
-
-import qualified Data.Set as S
-import Language.Haskell.Liquid.Bag as B
-
-{-@ zorg :: {v:B.Bag Int | v = B.empty} @-}
-zorg :: B.Bag Int
-zorg = B.empty
-
-{-@ measure elems @-}
-elems :: (Ord a) => [a] -> B.Bag a
-elems []     = B.empty
-elems (x:xs) = B.put x (elems xs)
-
-{-@ prop0 :: x:_ -> TT @-}
-prop0 :: Int -> Bool
-prop0 x = (B.get x b == 4) 
-  where
-    a   = elems [x, x]
-    b   = B.union a a 
diff --git a/tests/pos/bangPatterns.hs b/tests/pos/bangPatterns.hs
deleted file mode 100644
--- a/tests/pos/bangPatterns.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-module Min where
-
-import Data.IORef
-
-import Language.Haskell.Liquid.Prelude
-
-foo :: IORef a -> IORef a
-{-@ foo :: x:IORef a -> {v:IORef a |  v = x} @-}
-foo !x = x
diff --git a/tests/pos/bool0.hs b/tests/pos/bool0.hs
deleted file mode 100644
--- a/tests/pos/bool0.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module BoolMeasure where
-
-{-@ myhead :: {v:[a] | nonEmpty v} -> a @-}
-myhead (x:_) = x
-
-{-@ measure nonEmpty @-}   
-nonEmpty :: [a] -> Bool
-nonEmpty (x:xs) = True 
-nonEmpty []     = False
-
-
-
-
-
-
-
diff --git a/tests/pos/bool1.hs b/tests/pos/bool1.hs
deleted file mode 100644
--- a/tests/pos/bool1.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module EqBool where 
-
-{-@ baz :: x:Bool -> {v:Bool | v == x} @-}
-baz :: Bool -> Bool 
-baz x = x 
diff --git a/tests/pos/bool2.hs b/tests/pos/bool2.hs
deleted file mode 100644
--- a/tests/pos/bool2.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module EqBool where 
-
-
-{-@ gerb :: (Ord a) => x:a -> {v:a | x <= v } -> {v:a | x <= v} @-}
-gerb :: (Ord a) => a -> a -> a 
-gerb x y = y 
-
- 
-moo = gerb False False 
diff --git a/tests/pos/bounds1.hs b/tests/pos/bounds1.hs
deleted file mode 100644
--- a/tests/pos/bounds1.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Fixme where
-
-{-
-Interesting example as subtyping of bounds is instantiated
-with function types!
--}
-
-zipWith :: (b -> Char -> a) 
-        -> b -> b -> a
-zipWith f =  (bar . f)
-
-bar :: (Char -> c) -> a -> c
-bar = undefined
-
diff --git a/tests/pos/case-lambda-join.hs b/tests/pos/case-lambda-join.hs
deleted file mode 100644
--- a/tests/pos/case-lambda-join.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-{-@ LIQUID "--no-termination"   @-}
-
-module Foo where
-
-import Language.Haskell.Liquid.Prelude
-import Data.Set (Set (..))
-
-data RBTree a = Leaf | Node Color a !(RBTree a) !(RBTree a)
-data Color    = B | R deriving (Eq)
-
-{-@ rbalBAD, rbalOK :: k:_ -> l:_ -> r:_ -> {v:_ | Join v k l r} @-}
-rbalBAD x l r = case r of
-  Node R y b (Node R z c d) -> unsafeError "ASD" -- Node R y (Node B x l b) (Node B z c d)
-  Node R z (Node R y b c) d -> Node R y (Node B x l b) (Node B z c d)
-
-rbalOK x l r = case r of
-  -- Node R y b (Node R z c d) -> Node R y (Node B x l b) (Node B z c d)
-  Node R z (Node R y b c) d -> Node R y (Node B x l b) (Node B z c d)
-
-{-@ measure elems :: RBTree a -> (Set a)
-      elems Leaf         = (Set_empty 0)
-      elems (Node c k l r) = (Set_cup (Set_sng k) (Set_cup (elems l) (elems r))) 
-  @-}
-
-{-@ predicate Union V L R  = elems V = Set_cup (elems L) (elems R)                       @-}
-{-@ predicate Join V X L R = elems V = Set_cup (Set_sng X) (Set_cup (elems L) (elems R)) @-}
diff --git a/tests/pos/cmptag0.hs b/tests/pos/cmptag0.hs
deleted file mode 100644
--- a/tests/pos/cmptag0.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test () where
-
-{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
-
-{-@ foo :: (Ord a) => z:a -> OList a -> [{v:a | z <= v}] @-}
-foo y xs = bar y xs
-
-bar :: (Ord a) => a -> [a] -> [a]
-bar y []     = []
-bar y z@(x:xs) = case compare y x of 
-                   EQ -> xs
-                   GT -> bar y xs
-                   LT -> x:xs
diff --git a/tests/pos/comma.hs b/tests/pos/comma.hs
deleted file mode 100644
--- a/tests/pos/comma.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Comma where
-
-{-@ measure mysnd @-}
-mysnd :: (a, b) -> b
-mysnd (_, y) = y
-
-{-@ foo :: x:Int -> {v:Int | v == x} @-}
-foo :: Int -> Int 
-foo x = mysnd (x, x)
-
diff --git a/tests/pos/compare.hs b/tests/pos/compare.hs
deleted file mode 100644
--- a/tests/pos/compare.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Cmp () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo x y
- = case compare x y of 
-    EQ -> liquidAssertB (x == y)
-    LT -> liquidAssertB (x < y)
-    GT -> liquidAssertB (x > y)
-
-prop = foo n m 
-  where n = choose 0
-        m = choose 1
diff --git a/tests/pos/compare1.hs b/tests/pos/compare1.hs
deleted file mode 100644
--- a/tests/pos/compare1.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Cmp () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo x y
- | compare x y == EQ = liquidAssertB (x == y)
- | compare x y == LT = liquidAssertB (x < y)
- | compare x y == GT = liquidAssertB (x >  y)
-
-prop = foo n m 
-  where n = choose 0
-        m = choose 1
diff --git a/tests/pos/compare2.hs b/tests/pos/compare2.hs
deleted file mode 100644
--- a/tests/pos/compare2.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Cmp () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo x y
- | compare x y == EQ = liquidAssertB (x == y)
- | otherwise         = liquidAssertB (True)
-
-prop = foo n m 
-  where n = choose 0
-        m = choose 1
diff --git a/tests/pos/comprehension.hs b/tests/pos/comprehension.hs
deleted file mode 100644
--- a/tests/pos/comprehension.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Comprehension where
-
-{-@ foo :: n:Int -> [{v:Nat | v <= n}] @-}
-foo :: Int -> [Int]
-foo n = [0 .. n]
-
-{-@ assume GHC.Enum.enumFromTo :: (Enum a) => lo:a -> hi:a -> [{v:a | lo <= v && v <= hi}] @-}
diff --git a/tests/pos/comprehensionTerm.hs b/tests/pos/comprehensionTerm.hs
deleted file mode 100644
--- a/tests/pos/comprehensionTerm.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-module Blank (quickSort, foo, qsort) where
-
--- This is a blank file.
-
-{- foo :: xs:[Int] -> {v:[Int] | (len v) = (len xs)} @-}
-foo :: [Int] -> [Int]
-foo []     = []
-foo (x:xs) = (x+1) : foo [y | y <- xs] 
-
-{- qsort :: (Ord a) => xs:[a] -> {v:[a] | (len v) <= (len xs)} @-}
-qsort []     = []
-qsort (x:xs) = x : qsort [y | y <- xs, y < x]
-
-{-@ quickSort    :: (Ord a) => [a] -> SList a @-}
-quickSort []       = []
-quickSort xs@(x:_) = append x lts gts 
-  where 
-    lts          = quickSort [y | y <- xs, y < x]
-    gts          = quickSort [z | z <- xs, z >= x]
-
-{- append :: k:a -> SList {v:a | v<k} -> SList {v:a | v >= k} -> SList a @-}
-append k []     ys  = k : ys
-append k (x:xs) ys  = x : append k xs ys
-
-{-@ type SList a = [a]<{\x v -> (v >= x)}> @-}
-
diff --git a/tests/pos/coretologic.hs b/tests/pos/coretologic.hs
deleted file mode 100644
--- a/tests/pos/coretologic.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-module CoreToLog where
-
-import Data.Set
-
--- ISSUE: can we please allow things like `empty` to also
--- appear in type and alias specifications, not just in
--- measures as in `goo` below?
-
-{-@ type IsEmp a = {v:[a] | Data.Set.fromList v = Data.Set.empty } @-}
-
-{-@ foo :: IsEmp Int @-}
-foo :: [Int]
-foo = []
-
-{-@ measure goo @-}
-goo        :: (Ord a) => [a] -> Set a
-goo []     = empty
-goo (x:xs) = (singleton x) `union` (goo xs)
diff --git a/tests/pos/csgordon_issue_296.hs b/tests/pos/csgordon_issue_296.hs
deleted file mode 100644
--- a/tests/pos/csgordon_issue_296.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module BadMeasureType where 
-
-{-@ measure fwd_extends :: IO () -> IO () -> Bool @-}
-{-@ assume fwd_extends_refl :: m:IO () -> {v:Bool | (fwd_extends m m)} @-}
-fwd_extends_refl :: IO () -> Bool
-fwd_extends_refl = undefined
diff --git a/tests/pos/cut00.hs b/tests/pos/cut00.hs
deleted file mode 100644
--- a/tests/pos/cut00.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-module Cut (foo0) where
-
-{-@ foo0 :: Nat -> Nat @-}
-
-foo0 x = 1 + foo1 x
-foo1 x = 1 + foo2 x
-foo2 x = 1 + foo3 x
-foo3 x = 1 + foo4 x
-foo4 x = 1 + foo5 x
-foo5 x = 1 + foo  x
-
-foo :: Int -> Int
-foo x = 1 + x
-
-bar :: Int -> Int
-bar y = y + 10
-
--- foo x = 1 + foo (x - 1)
diff --git a/tests/pos/data2.hs b/tests/pos/data2.hs
deleted file mode 100644
--- a/tests/pos/data2.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-module Range (prop_rng1, llen) where
-
-import Control.Applicative
-import Language.Haskell.Liquid.Prelude
-
-data LL a = N | C { headC :: a, tailC :: (LL a) }
-{-@ data LL [llen] a = N | C { headC :: a, tailC :: (LL a) } @-}
-
-{-@ measure llen @-}
-llen :: LL a -> Int 
-{-@ llen :: LL a -> Nat @-}
-llen N = 0 
-llen (C _ xs) = 1 + llen xs 
-
---instance Functor LL where
---  fmap f N                = N
---  fmap f (C jhala jhalas) = C (f jhala) (fmap f jhalas)
-
-lmap f N = N
-lmap f (C jhala jhalas) = C (f jhala) (lmap f jhalas)
-
-range :: Int -> Int -> LL Int
-range i j = C i N
-
-prop_rng1 n   = (liquidAssertB . (0 <=)) `lmap` range 0 n
diff --git a/tests/pos/dataConQuals.hs b/tests/pos/dataConQuals.hs
deleted file mode 100644
--- a/tests/pos/dataConQuals.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-module Quals () where
-
-data G = G { gx :: Int, gy :: Int }
-
-
--- | We should scrape qualifiers from data definitions; why doesn't it happen
---   "automatically" from the data-con-function signature anyway?
-
-{-@ data G = G { gx :: Int, gy :: {v:Int | v = gx + 5} } @-}
-
-poo :: Int -> Int
-poo n = n + 5
-
--- | `goo` fails because `poo` doesn't have the type `n -> n + 5` because no qual...
-
-{-@ goo :: {v:Int | v = 105} @-}
-goo :: Int
-goo = poo 100
-
--- | But `goo` succeeds if we add `chump` into the mix, because
---   it picks up the qualifers.
-
-{- chump :: z:Int -> {v:Int | v = z + 5} @-}
-chump   :: Int -> Int
-chump z = z + 5
-
-         
diff --git a/tests/pos/datacon-inv.hs b/tests/pos/datacon-inv.hs
deleted file mode 100644
--- a/tests/pos/datacon-inv.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Zoo where
-
-data T =  A | B
-
-{-@ invariant {v:T | (v = A || v = B)} @-}
-
-thisIsA = A
-thisIsB = B
diff --git a/tests/pos/datacon0.hs b/tests/pos/datacon0.hs
deleted file mode 100644
--- a/tests/pos/datacon0.hs
+++ /dev/null
@@ -1,29 +0,0 @@
-module Range (llen) where
-
-import Language.Haskell.Liquid.Prelude
-
-data Foo a = F a a a 
-
-data LL a = N | C a (LL a)
-
-{-@ data LL [llen] @-} 
-
-
-{-@ measure llen @-}
-llen :: LL a -> Int 
-{-@ llen :: LL a -> Nat @-}
-llen N = 0 
-llen (C _ xs) = 1 + llen xs 
-
-lmap f N = N
-lmap f (C x xs) = C (f x) (lmap f xs)
-
-range :: Int -> Int -> LL Int
-range i j = C i N
-
-n = choose 0
-
-prop_rng1 = (liquidAssertB . (0 <=)) `lmap` range 0 n
-
---poo :: LL Int
-poo = C (1 :: Int) 
diff --git a/tests/pos/datacon1.hs b/tests/pos/datacon1.hs
deleted file mode 100644
--- a/tests/pos/datacon1.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module DC () where
-
-data Foo a = F a a a 
-
-z :: Foo Int
-z = F 1 2 3 
-
diff --git a/tests/pos/deepmeas0.hs b/tests/pos/deepmeas0.hs
deleted file mode 100644
--- a/tests/pos/deepmeas0.hs
+++ /dev/null
@@ -1,29 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module DeepMeasure () where
-
-import Language.Haskell.Liquid.Prelude (liquidError)
-import Data.Set
-
-{-@ measure getfst :: (a, b) -> a
-      getfst (x, y) = x
-  @-}
-
-{-@ measure keys :: [(k, v)] -> (Set k) 
-      keys []   = {v | Set_emp v }
-      keys (x:xs) = {v | (v = (Set_cup (Set_sng (getfst x)) (keys xs))) }
-  @-}
-
-{-@ getKeys :: kvs:[(a, b)] -> {v:[a] | ((keys kvs) = (listElts v))} @-}
-getKeys []           = [] 
-getKeys ((x,_) : xs) = x : getKeys xs
-
-{-@ klookup :: forall k v. (Eq k) => k:k -> {v: [(k, v)] | (Set_mem k (keys v))} -> v @-}
-
-klookup k ((k',v):kvs)
-  | k == k'          = v
-  | otherwise        = klookup k kvs
-klookup _ []         = liquidError "Never!"
-
-
-
-
diff --git a/tests/pos/deptup.hs b/tests/pos/deptup.hs
deleted file mode 100644
--- a/tests/pos/deptup.hs
+++ /dev/null
@@ -1,30 +0,0 @@
-module Deptup0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
-data Pair a b = P a b
-
-
-{-- TODO: mkP :: forall a b <p :: a -> b -> Bool>. x: a -> y: b<p x> -> Pair <p> a b  --}
-
-mkP :: a -> a -> Pair a a
-mkP x y = P x y
-
-incr x = x + 1
-
-baz x  = mkP x (incr x)
-
-chk (P x y) = liquidAssertB (x < y)
-
-prop = chk $ baz n
-  where n = choose 100
-
-
-bazList  xs = map baz xs
-
-n           = choose 0
-
-xs          = [0,1,2,3,4]
-
-prop_baz    = map chk $ bazList xs
diff --git a/tests/pos/deptup1.hs b/tests/pos/deptup1.hs
deleted file mode 100644
--- a/tests/pos/deptup1.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Deptup () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
-data Pair a b = P a b
-
-incr        :: Int -> Int
-incr x      = x + 1
-
-baz x       = P x (incr x)
-
-bazList xs  = map baz xs
-
-n           = choose 0
-xs          = [0..n]
-
-chk (P x y) = liquidAssertB (x < y)
-prop_baz    = map chk $ bazList xs
diff --git a/tests/pos/deptup3.hs b/tests/pos/deptup3.hs
deleted file mode 100644
--- a/tests/pos/deptup3.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Deptup () where
-
-import Language.Haskell.Liquid.Prelude
-
-data Pair a b = P a b
-
-incr :: Int -> Int
-incr x = x + 1
-
-baz    :: Int -> Pair Int Int
-baz x  = P x (incr x)
-
-n :: Int
-n           = choose 0
-
-prop_baz    = chk (baz n)
-
-chk :: Pair Int Int -> Bool
-chk (P x y) = liquidAssertB (x <= y)
diff --git a/tests/pos/deptupW.hs b/tests/pos/deptupW.hs
deleted file mode 100644
--- a/tests/pos/deptupW.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Deptup0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P {pX :: a, pY :: b<p pX> } @-}
-data Pair a b = P a b
-
-{-@ mkP :: forall a <q :: y0:a -> y1:a -> Bool>. x: a -> y: a<q x> -> Pair <q> a a @-}
-mkP :: a -> a -> Pair a a
-mkP x y = P x y
-
-incr :: Int -> Int
-incr x = x + 1
-
-baz x = mkP x (incr x)
-
-chk :: Pair Int Int -> Bool
-chk (P x y) = liquidAssertB (x < y)
-
-prop = chk $ baz n
-  where n = choose 100
diff --git a/tests/pos/div000.hs b/tests/pos/div000.hs
deleted file mode 100644
--- a/tests/pos/div000.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test0 (bar) where
-
-{-@ mydiv :: Int -> {v:Int | v /= 0} -> Int @-}
-mydiv :: Int -> Int -> Int
-mydiv = undefined
-
-foo :: Int -> Int
-foo _ = 12
-
-bar :: Int -> Int
-bar m = mydiv m z where z = foo m
diff --git a/tests/pos/dropwhile.hs b/tests/pos/dropwhile.hs
deleted file mode 100644
--- a/tests/pos/dropwhile.hs
+++ /dev/null
@@ -1,82 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--no-totality"    @-}
-
-module DropWhile where
-
-import Language.Haskell.Liquid.Prelude
-import Prelude hiding (head, dropWhile, (.), filter)
-
---main :: IO ()
-foo =  
-  if head (dropWhile ((/=) 3) (1:::2:::3:::Emp)) == 3
-     then ()
-     else liquidError "Not going to happen"
-
--------------------------------------------------------------------------------
--- | The `head` function returns a value that satisfies the abstract refinement
--------------------------------------------------------------------------------
-
-{-@ head ::  forall <p :: a -> Bool>. List <p> a -> a<p> @-}
-head (x ::: _) = x
-
--------------------------------------------------------------------------------
--- | A List 
--------------------------------------------------------------------------------
-
-data List a = Emp | (:::) { hd :: a
-                          , tl :: List a }
-infixr 5 :::
-
--------------------------------------------------------------------------------
--- | A list whose head satisfies an abstract refinement `p`
--------------------------------------------------------------------------------
-
--- in the below, `hd :: a<p>` means the "head" is a value of type `a` that
--- additionally, satisfies `p hd`.
-
-{-@ data List a <p :: a -> Bool> = Emp
-                                 | (:::) { hd :: a<p>
-                                         , tl :: List a }
-  @-}
-
--- | e.g. a list whose head equals `3`
-
-{-@ type OneList = List <{\v -> v == 3}> Int @-}
-
-{-@ one :: OneList @-}
-one :: List Int
-one = 3 ::: 2 ::: 1 ::: Emp
-
--------------------------------------------------------------------------------
--- | dropWhile some predicate `f` is not satisfied
--------------------------------------------------------------------------------
-
-{-@ dropWhile :: forall <p :: a -> Bool, w :: a -> Bool -> Bool>.
-                   {y::a, b::{v:Bool<w y> | not v} |- {v:a | v == y} <: a<p>}
-                   (x:a -> Bool<w x>) -> List a -> List <p> a
-  @-}
-dropWhile :: (a -> Bool) -> List a -> List a
-dropWhile f (x:::xs)
-  | not (f x)    = x ::: xs
-  | otherwise    = dropWhile f xs
-dropWhile f Emp  = Emp
-
--- | This `witness` bound relates the predicate used in dropWhile
-
-{-@ bound witness @-}
-witness :: Eq a => (a -> Bool) -> (a -> Bool -> Bool) -> a -> Bool -> a -> Bool
-witness p w = \ y b v -> (not b) ==> w y b ==> (v == y) ==> p v
-
--------------------------------------------------------------------------------
--- | Drop elements until you hit a `3`
--------------------------------------------------------------------------------
-
-{-@ dropUntilOne' :: List Int -> OneList @-}
-dropUntilOne' :: List Int -> List Int
-dropUntilOne' = dropWhile (/= 3)
-
--- | Currently needed for the qual; should be made redundant by `--eliminate`
-
-{-@ eqOne :: x:Int -> {v:Bool | v <=> x /= 3} @-}
-eqOne :: Int -> Bool
-eqOne x = x /= 3
diff --git a/tests/pos/duplicate-bind.hs b/tests/pos/duplicate-bind.hs
deleted file mode 100644
--- a/tests/pos/duplicate-bind.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Meas where
-
-import Language.Haskell.Liquid.Prelude
-
-insert key value [] = [(key, value)]
-insert _ _ _        = unsafeError ""
diff --git a/tests/pos/elements.hs b/tests/pos/elements.hs
deleted file mode 100644
--- a/tests/pos/elements.hs
+++ /dev/null
@@ -1,67 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Elems where
-
-import Prelude hiding (elem)
-
-import Data.Set (Set (..))
-
-{-@ append  :: xs:_ -> ys:_ -> {v:_ | UnElts v xs ys} @-}
-append [] ys     = ys
-append (x:xs) ys = x : append xs ys
-
-
-{-@ reverse :: xs:_ -> {v:_ | EqElts v xs} @-}
-reverse xs           = revAcc xs []
-  where
-   revAcc []     acc = acc
-   revAcc (x:xs) acc = revAcc xs (x:acc)
-
-
-
-{-@ nub :: (Eq a) => xs:_ -> {v:_ | nodups v && EqElts v xs} @-}
-nub xs             = go xs []
-  where
-    go (x:xs) l
-      | x `elem` l = go xs l
-      | otherwise  = go xs (x:l)
-    go [] l        = l
-
-
-{-@ elem :: (Eq a) => x:_ -> ys:_ -> {v:Bool | v <=> Set_mem x (elems ys)} @-}
-elem x []     = False
-elem x (y:ys) = x == y || elem x ys
-
-
-
-{-@ find :: (Eq a) => key:_ -> {map:_ | ValidKey key map} -> b @-}
-find key ((k,v):kvs)
-  | key == k  = v
-  | otherwise = find key kvs
-find _ []     = die "Lookup failed!"
-
-
-{-@ die :: {v:String | false} -> b @-}
-die x = error x
-
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-
-{-@ predicate ValidKey K M    = Set_mem K (keys M)                       @-}
-{-@ predicate EqElts Xs Ys    = elems Xs = elems Ys                      @-}
-{-@ predicate UnElts Xs Ys Zs = elems Xs = Set_cup (elems Ys) (elems Zs) @-}
-
-{-@ measure keys  :: [(a, b)] -> (Set a)
-      keys []     = (Set_empty 0)
-      keys (kv:kvs) = (Set_cup (Set_sng (fst kv)) (keys kvs))
-  @-}
-
-{-@ measure elems :: [a] -> (Set a)
-      elems []    = (Set_empty 0)
-      elems (x:xs)  = (Set_cup (Set_sng x) (elems xs))
-  @-}
-
-{-@ measure nodups :: [a] -> Bool
-      nodups []   = true
-      nodups (x:xs) = (not (Set_mem x (elems xs)) && nodups xs)
-  @-}
diff --git a/tests/pos/elems.hs b/tests/pos/elems.hs
deleted file mode 100644
--- a/tests/pos/elems.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Goo where
-
-import qualified Data.Set as S
-
-data T a = T a
-
-{-@ measure elems @-}
-elems       :: T a -> S.Set a
-elems (T a) = S.singleton a
-
-{-@ member :: x:a -> t:T a -> {v:Bool | v <=> S.member x (elems t)} @-}
-member :: a -> T a -> Bool
-member = undefined
diff --git a/tests/pos/elim-ex-compose.hs b/tests/pos/elim-ex-compose.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-compose.hs
+++ /dev/null
@@ -1,11 +0,0 @@
--- TAG: absref 
-
-module ElimExCompose (prop) where
-
-{-@ prop :: x:Nat -> {v:Int | v = x + 5} @-}
-prop :: Int -> Int
-prop = incr . incr . incr . incr . incr
-
-{-@ incr :: dog:Int -> {v:Int | v == dog + 1} @-}
-incr :: Int -> Int
-incr cat = cat + 1
diff --git a/tests/pos/elim-ex-let.hs b/tests/pos/elim-ex-let.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-let.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExLet (prop) where
-
-import LiquidHaskell
-
-[lq| type Nat = {v:Int | 0 <= v} |]
-
-[lq| prop :: a -> Nat |]
-prop _ = let x _ = let y = 0 
-                   in
-                     y - 1
-         in 
-           x () + 2
diff --git a/tests/pos/elim-ex-list.hs b/tests/pos/elim-ex-list.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-list.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExList (prop) where
-
-import LiquidHaskell
-import Prelude hiding (head)
-
---------------------------------------------------------------------------
-[lq| prop :: a -> Even |]
-prop _ = (head ys) - 1
-  where 
-    ys = Cons 1 (Cons 3 (Cons 5 Nil))
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-head :: List a -> a 
-head (Cons x _) = x
-
diff --git a/tests/pos/elim-ex-map-1.hs b/tests/pos/elim-ex-map-1.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-map-1.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop xs = map (+ 1) (map (+ 1) xs)
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/elim-ex-map-2.hs b/tests/pos/elim-ex-map-2.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-map-2.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop = map (+ 1) . map (+ 1)
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/elim-ex-map-3.hs b/tests/pos/elim-ex-map-3.hs
deleted file mode 100644
--- a/tests/pos/elim-ex-map-3.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-{-# LANGUAGE QuasiQuotes #-}
-
-module ElimExMap (prop) where
-
-import LiquidHaskell
-
-import Prelude hiding (map)
-
---------------------------------------------------------------------------
-[lq| prop :: List Even -> List Even |]
-prop = map ((+ 1) . (+ 1))
---------------------------------------------------------------------------
-
-[lq| type Even = {v:Int | v mod 2 == 0 } |]
-
-data List a = Nil | Cons a (List a)
-
-map f Nil         = Nil
-map f (Cons x xs) = Cons (f x) (map f xs)
diff --git a/tests/pos/elim00.hs b/tests/pos/elim00.hs
deleted file mode 100644
--- a/tests/pos/elim00.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-{-@ LIQUID "--short-names"  @-}
-
-module Elim where
-
-data Pair a b = PP a b | Emp
-
-data Foo = Foo { xx :: Int, yy :: Int }
-
-{-@ data Foo = Foo {xx :: Int, yy :: {v:Int | xx < v} }  @-}
-
-foo :: Foo -> Foo
-foo (Foo xig yog) = Foo wink cow
-  where
-    PP wink cow   = PP xig yog
-
diff --git a/tests/pos/elim01.hs b/tests/pos/elim01.hs
deleted file mode 100644
--- a/tests/pos/elim01.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module EliminateCuts (bar) where
-
-{-@ bar :: n:{Int | n > 0} -> {v:Int | v = n + 4 } @-}
-bar :: Int -> Int 
-bar n0 = let 
-            n1 = if (n0 == 0) then 0 else 1 + n0
-            n2 = if (n1 == 0) then 0 else 1 + n1
-            n3 = if (n2 == 0) then 0 else 1 + n2
-            n4 = if (n3 == 0) then 0 else 1 + n3
-         in 
-            n4
diff --git a/tests/pos/eq-poly-measure.hs b/tests/pos/eq-poly-measure.hs
deleted file mode 100644
--- a/tests/pos/eq-poly-measure.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Pair () where 
-
-import Language.Haskell.Liquid.Prelude 
-
-{-@ data Thing a = P (unThing :: a) @-} 
-data Thing a = P a
-
-property :: Bool
-property = chk t1 
-  where 
-  chk (P x) = liquidAssertB x 
-
-  t1 :: Thing Bool 
-  t1 = P True 
diff --git a/tests/pos/eqelems.hs b/tests/pos/eqelems.hs
deleted file mode 100644
--- a/tests/pos/eqelems.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Goo where
-
-import qualified Data.Set as S
-
-data T a = T a
-
-{-@ measure elems @-}
-elems       :: T a -> S.Set a
-elems (T a) = S.singleton a
-
-{-@ inline eqelems @-}
-eqelems :: Eq a => T a -> T a -> Bool
-eqelems s t = (elems s) == (elems t)
-         
diff --git a/tests/pos/ex0.hs b/tests/pos/ex0.hs
deleted file mode 100644
--- a/tests/pos/ex0.hs
+++ /dev/null
@@ -1,41 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-{-@ LIQUID "--no-termination" @-}
-
-module Ex  where
-
--- Testing "existential-types"
-
-{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-                (i:Int -> a<p i> -> a<p (i+1)>) 
-              -> n:{v: Int | v >= 0}
-              -> a <p 0> 
-              -> a <p n>
-  @-}
-
-foldN :: (Int -> a -> a) -> Int -> a -> a
-foldN f n = go 0 
-  where 
-    go i x 
-      | i < n     = go (i+1) (f i x)
-      | otherwise = x
-
-{-@ goo :: forall a <pig :: x0:Int -> x1:a -> Bool>. 
-                (i:Int -> a<pig i> -> a<pig (i+1)>) 
-              -> i:{v: Int | 0 <= v}
-              -> n:{v: Int | i <= v}
-              -> a <pig i> 
-              -> a <pig n>
-  @-}
-
-goo :: (Int -> a -> a) -> Int -> Int -> a -> a
-goo f i n x 
-  | i < n     = goo f (i+1) n (f i x) 
-  | otherwise = x
-
-
-
-
-{-@ count :: m: {v: Int | v > 0 } -> {v: Int | v = m} @-}
-count :: Int -> Int
-count m = foldN (\_ n -> n + 1) m 0
-
diff --git a/tests/pos/ex01.hs b/tests/pos/ex01.hs
deleted file mode 100644
--- a/tests/pos/ex01.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-
--- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
-
-module Ex () where
-
-
--------------------------------------------------------------------------
--- | Data types ---------------------------------------------------------
--------------------------------------------------------------------------
-
-data Vec a = Nil 
-
-{-@ efoldr :: forall b a <p :: x0:Vec a -> x1:b -> Bool>. 
-              b <p Ex.Nil>
-              -> ys: Vec a
-              -> b <p ys>
-  @-}
-efoldr :: b -> Vec a -> b
-efoldr b Nil         = b
-
diff --git a/tests/pos/ex1.hs b/tests/pos/ex1.hs
deleted file mode 100644
--- a/tests/pos/ex1.hs
+++ /dev/null
@@ -1,64 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-
--- | A somewhat fancier example demonstrating the use of Abstract Predicates and exist-types
-
-module Ex (llen) where
-
--------------------------------------------------------------------------
--- | Data types ---------------------------------------------------------
--------------------------------------------------------------------------
-
-data Vec a = Nil | Cons a (Vec a)
-
-{-@ data Vec [llen] a = Nil | Cons { vx::a, vxs :: Vec a } @-}
-
--- | We can encode the notion of length as an inductive measure @llen@
-
-{-@ measure llen @-}
-llen :: Vec a -> Int
-llen (Nil)       = 0
-llen (Cons x xs) = 1 + llen xs
-
-
--- | As a warmup, lets check that a /real/ length function indeed computes
--- the length of the list.
-
-{-@ sizeOf :: xs:Vec a -> {v: Int | v = llen xs} @-}
-sizeOf             :: Vec a -> Int
-sizeOf Nil         = 0
-sizeOf (Cons _ xs) = 1 + sizeOf xs
-
--------------------------------------------------------------------------
--- | Higher-order fold --------------------------------------------------
--------------------------------------------------------------------------
-
--- | Time to roll up the sleeves. Here's a a higher-order @foldr@ function
--- for our `Vec` type. Note that the `op` argument takes an extra /ghost/
--- parameter that will let us properly describe the type of `efoldr`
-
-{-@ efoldr :: forall a b <p :: x0:Vec a -> x1:b -> Bool>.
-                (xs:Vec a -> x:a -> b <p xs> -> b <p (Ex.Cons x xs)>)
-              -> b <p Ex.Nil>
-              -> ys: Vec a
-              -> b <p ys>
-  @-}
-efoldr :: (Vec a -> a -> b -> b) -> b -> Vec a -> b
-efoldr op b Nil         = b
-efoldr op b (Cons x xs) = op xs x (efoldr op b xs)
-
--------------------------------------------------------------------------
--- | Clients of `efold` -------------------------------------------------
--------------------------------------------------------------------------
-
--- | Finally, lets write a few /client/ functions that use `efoldr` to
--- operate on the `Vec`s.
-
--- | First: Computing the length using `efoldr`
-{-@ size :: xs:Vec a -> {v: Int | v = llen xs} @-}
-size :: Vec a -> Int
-size = efoldr (\_ _ n -> n + 1) 0
-
--- | Second: Appending two lists using `efoldr`
-{-@ app  :: xs: Vec Int -> ys: Vec Int -> {v: Vec Int | llen v = llen xs + llen ys } @-}
-app :: Vec Int -> Vec Int -> Vec Int
-app xs ys = efoldr (\_ z zs -> Cons z zs) ys xs
diff --git a/tests/pos/exp0.hs b/tests/pos/exp0.hs
deleted file mode 100644
--- a/tests/pos/exp0.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-
--- small test for playing around with exports.
-
-module Moo (f) where
-
-import Language.Haskell.Liquid.Prelude
-
-data Goo = G Int
-
-{-@ data Goo = G (x :: {v:Int | v > 0}) @-}
-
-{-@ f :: Goo -> Goo @-} 
-f (G n) 
-  | n > 0     = G (n +  1)
-  | otherwise = liquidError "ad"
-
diff --git a/tests/pos/extype.hs b/tests/pos/extype.hs
deleted file mode 100644
--- a/tests/pos/extype.hs
+++ /dev/null
@@ -1,26 +0,0 @@
-{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses #-}
-module ExTy where
-
-class Show (layout a) => LayoutClass layout a where
-
-data Layout a = forall l. Layout (l a)
-
-
-readsLayout :: Layout a -> String -> Layout a
-readsLayout (Layout l) s = Layout (asTypeOf undefined l)
-
-type Size = Int
-data Step s a = S s a
-
-data Stream a =
-    forall s. Stream
-    (s -> Step s a)             -- stepper function
-    !s                          -- current state
-    !Size                       -- size hint
-
-
-foo :: Stream a -> Size
-foo (Stream _ _ s) = s
-
-
-stream = Stream (\_ -> S 1 True) 0 0
diff --git a/tests/pos/failName.hs b/tests/pos/failName.hs
deleted file mode 100644
--- a/tests/pos/failName.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Crash where
-
-bar = fail
-  where fail = foo
-        foo = 3 -- undefined
-
-
-bar1 = fail ()
-  where fail = foo
-        foo = undefined
diff --git a/tests/pos/filterAbs.hs b/tests/pos/filterAbs.hs
deleted file mode 100644
--- a/tests/pos/filterAbs.hs
+++ /dev/null
@@ -1,45 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-
-
-
-module Filter where
-
-import Prelude hiding (filter)
-
-{-@ filter :: forall <p :: a -> Bool, q :: a -> Bool -> Bool>.
-                  {y::a, flag::{v:Bool<q y> | v} |- {v:a | v = y} <: a<p>}
-                  (x:a -> Bool<q x>) -> [a] -> [a<p>]
-  @-}
-
-filter :: (a -> Bool) -> [a] -> [a]
-filter f (x:xs)
-  | f x       = x : filter f xs
-  | otherwise = filter f xs
-filter _ []   = []
-
-{-@ isPos :: x:Int -> {v:Bool | v <=> x > 0} @-}
-isPos :: Int -> Bool
-isPos n = n > 0
-
-
-{-@ isNeg :: x:Int -> {v:Bool | v <=> x < 0} @-}
-isNeg :: Int -> Bool
-isNeg n = n < 0
-
-
--- | `positives` works by instantiating:
--- p := \v   -> 0 < v
--- q := \x v -> v <=> 0 < x  (NV ??)
-
-
-{-@ positives :: [Int] -> [{v:Int | v > 0}] @-}
-positives xs = filter isPos xs
-
-
--- | `negatives` works by instantiating:
--- p := \v   -> 0 > v
--- q := \x v -> v <=> x < 0
-
-{-@ negatives :: [Int] -> [{v:Int | v < 0}] @-}
-negatives xs = filter isNeg xs
diff --git a/tests/pos/foldN.hs b/tests/pos/foldN.hs
deleted file mode 100644
--- a/tests/pos/foldN.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-{-@ LIQUID "--no-termination" @-}
-
-module Ex () where
-
--- Testing "existential-types"
-
-{-@ foldN :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-                (i:Int -> a<p i> -> a<p (i+1)>) 
-              -> n:{v: Int | v >= 0}
-              -> a <p 0> 
-              -> a <p n>
-  @-}
-
-foldN :: (Int -> a -> a) -> Int -> a -> a
-foldN f n = go 0 
-  where go i x | i < n     = go (i+1) (f i x)
-               | otherwise = x
diff --git a/tests/pos/foldr.hs b/tests/pos/foldr.hs
deleted file mode 100644
--- a/tests/pos/foldr.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Foldr where
-
-import Language.Haskell.Liquid.Prelude
-import Data.List (foldl')
-
-foo ::  a -> b -> c -> d
-foo = \_ _ _ -> unsafeError "False" 
-
-bar ::  p -> [(q, r)] -> p
-bar = foldr (\(k, v) -> foo k v)
diff --git a/tests/pos/for.hs b/tests/pos/for.hs
deleted file mode 100644
--- a/tests/pos/for.hs
+++ /dev/null
@@ -1,32 +0,0 @@
-module For (prop, prop2, even_, minifac) where
-
-{-@ LIQUID "--no-termination-check" @-}
-
-import Language.Haskell.Liquid.Prelude
-
-even_ arg = if arg == 0 then True else odd_ (arg - 1)
-
-odd_  arg = if arg == 0 then False else even_ (arg - 1)
-
-mmax x y 
-  | x < y     = y
-  | otherwise = x
-
-minifac foobar 
-  | foobar > 1 =  minifac (foobar - 1)
-  | otherwise  =  1
-
-for lo hi acc f 
-  | lo < hi   = for (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-sumRange i j = for i j 0 (+)
-
-prop = liquidAssertB (m >= 0)
-  where m = sumRange 0 k
-        k = choose 0
-
-prop2 = liquidAssertB (z >= x && z >= y)
-  where x = choose 0
-        y = choose 1
-        z = mmax x y
diff --git a/tests/pos/forloop.hs b/tests/pos/forloop.hs
deleted file mode 100644
--- a/tests/pos/forloop.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Vec1 () where
-
-{-@ LIQUID "--no-termination" @-}
-import Language.Haskell.Liquid.Prelude
-
-mmax x y 
-  | x < y     = y
-  | otherwise = x
-
-for lo hi acc f 
-  | lo < hi   = for (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-sumRange i j = for i j 0 (+)
-
-prop = liquidAssertB (m >= 0)
-  where m = sumRange 0 k
-        k = choose 0
-
-prop2 = liquidAssertB (z >= x && z >= y)
-  where x = choose 0
-        y = choose 1
-        z = mmax x y
diff --git a/tests/pos/gadtEval.hs b/tests/pos/gadtEval.hs
deleted file mode 100644
--- a/tests/pos/gadtEval.hs
+++ /dev/null
@@ -1,91 +0,0 @@
-
-module Eval () where 
-
-import Language.Haskell.Liquid.Prelude (liquidError)
-
--- "Classic" GADT 
--- 
--- data Expr a where
---   I :: Int -> Expr Int
---   B :: Bool -> Expr Bool
---   Eq :: Expr a -> Expr a -> Expr Bool
---   Pl :: Expr Int -> Expr Int -> Expr Int
--- 
--- eval :: Expr a -> a
--- eval (I i)      = i
--- eval (B b)      = b
--- eval (Eq e1 e2) = (eval e1) == (eval e2)
--- eval (Pl e1 e2) = (eval e1) + (eval e2)
-
-data Ty   = TInt 
-          | TBool
-
-data Expr = I     Int
-          | B     Bool
-          | Equal Expr Expr
-          | Plus  Expr Expr
-          deriving (Eq, Show)
-
-
-{-@ check          :: e:ValidExpr  -> {v:Ty | (v = (eType e))} @-}
-check (I _)        = TInt
-check (B _)        = TBool
-check (Plus e1 e2) = TInt
-check (Equal _ _)  = TBool
-
-{-@ lazy eval @-}
-
-{-@ eval           :: e:ValidExpr  -> {v:ValidExpr | ((isValue v) && (((eType e) = (eType v))))} @-}
-eval e@(I _)       = e
-eval e@(B _)       = e
-eval (Plus e1 e2)  = (eval e1) `plus` (eval e2)
-eval (Equal e1 e2) = (eval e1) `equal` (eval e2)
-
-plus (I i) (I j)   = I (i + j)
-plus _       _     = liquidError "don't worry, its impossible" 
-
-equal (I i) (I j)  = B (i == j)
-equal (B x) (B y)  = B (x == y)
-equal _       _    = liquidError "don't worry, its impossible" 
-
--- | The next two are silly, for scraping quals. Yuck. Should scrape from measure-DEFS etc.
-
-{-@ toInt :: IntExpr -> Int @-}
-toInt (I i) = i
-toInt _     = liquidError "impossible"
-
-{-@ toBool :: BoolExpr -> Bool @-}
-toBool (B b) = b
-toBool _     = liquidError "impossible"
-
-
-{-@ predicate IsTInt X   = ((eType X) = TInt)  @-}
-{-@ predicate IsTBool X  = ((eType X) = TBool) @-}
-
-
-{-@ type ValidExpr     = {v: Expr | (isValid v)}                @-}
-{-@ type IntExpr       = {v: Expr | ((isValue v) && (IsTInt  v))} @-}
-{-@ type BoolExpr      = {v: Expr | ((isValue v) && (IsTBool v))} @-}
-
-
-{-@ measure isValue       :: Expr -> Bool
-      isValue (I i)         = true
-      isValue (B b)         = true
-      isValue (Equal e1 e2) = false 
-      isValue (Plus e1 e2)  = false
-  @-}  
-
-{-@ measure eType       :: Expr -> Ty 
-      eType (I i)         = TInt  
-      eType (Plus  e1 e2) = TInt 
-      eType (B b)         = TBool 
-      eType (Equal e1 e2) = TBool 
-  @-}
-
-{-@ measure isValid       :: Expr -> Bool
-      isValid (I i)         = true
-      isValid (B b)         = true
-      isValid (Equal e1 e2) = (((eType e1) = (eType e2)) && (isValid e1) && (isValid e2))
-      isValid (Plus e1 e2)  = ((IsTInt e1) && (IsTInt e2) && (isValid e1) && (isValid e2))
-  @-}
-
diff --git a/tests/pos/gimme.hs b/tests/pos/gimme.hs
deleted file mode 100644
--- a/tests/pos/gimme.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Blank () where
-
-import Language.Haskell.Liquid.Prelude
-
-{- qualif Gimme(v:[a], n:int, acc:[a]): (len v == n + 1 + len acc) -}
-
-{-@ gimme :: xs:[a] -> n:Int -> acc:[a] -> {v:[a] | len v = n + 1 + len acc} @-}
-gimme :: [a] -> Int -> [a] -> [a]
-gimme xs (-1) acc  = acc
-gimme (x:xs) n acc = gimme xs (n-1) (x : acc)
-gimme _ _ _        = unsafeError "gimme"
-
-{-@ boober :: n:Int -> Int -> {v:[Int] | (len v) = n} @-}
-boober :: Int -> Int -> [Int]
-boober n y = gimme [y..] (n-1) []
diff --git a/tests/pos/go.hs b/tests/pos/go.hs
deleted file mode 100644
--- a/tests/pos/go.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Moo (poop) where
-
-{-@ invariant {v:Int | v >= 0} @-}
-
-{-@ qualif Sum(v:Int, x: Int, y: Int): v = x + y @-}
-
-{-@ invariant {v:Int | v >= 0} @-}
-
-{-@ foo  :: x:Int -> {v:Int | v = x} @-}
-foo x    = go x 0
-  where 
-    go     :: Int -> Int -> Int 
-    go 0 m = m
-    go n m = go (n-1) (m+1)
-
-
-poop x = foo x 
-
-
-
diff --git a/tests/pos/go_ugly_type.hs b/tests/pos/go_ugly_type.hs
deleted file mode 100644
--- a/tests/pos/go_ugly_type.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-{- decrease go 2 @-}
-
-{-@ rev :: xs:[a] -> {v: [a] | len v = len xs} @-}
-rev = go [] 
-  where 
-    {-@ go :: acc:_ -> xs:_ -> {v:_ | len v = len acc + len xs} @-}
-    go acc []     = acc
-    go acc (x:xs) = go (x:acc) xs
-
-main :: IO ()
-main = pure ()
diff --git a/tests/pos/grty0.hs b/tests/pos/grty0.hs
deleted file mode 100644
--- a/tests/pos/grty0.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test () where
-
-{-@ stupid :: Int -> Int @-}
-stupid :: Int -> Int
-stupid x = 0
-
-{-@ myId :: x:a -> {v:a | v = x } @-}
-myId x = x 
-
-{-@ assert single :: a -> {v: [a] | len(v) > 0} @-}
-single x = [x] 
-
-
diff --git a/tests/pos/grty1.hs b/tests/pos/grty1.hs
deleted file mode 100644
--- a/tests/pos/grty1.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test () where
-import Language.Haskell.Liquid.Prelude 
-
-{-@ sz :: {v:[a]|((len v) = 1)} -> a @-}
--- sz (x:xs) = sz xs
-sz [x]    = x
-
-{-@ poo :: [a] -> a @-}
-poo (x:xs) = poo xs
-poo [x]    = x
-poo _      = unsafeError "poo"
diff --git a/tests/pos/grty2.hs b/tests/pos/grty2.hs
deleted file mode 100644
--- a/tests/pos/grty2.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Test () where
-
-{-@ foo :: {vv:[{v:[a]|((len v) = 1)}]|((len vv)= 1)} -> [[a]] @-}
-foo [[x]] = [[x]]
-
-
-
diff --git a/tests/pos/grty3.hs b/tests/pos/grty3.hs
deleted file mode 100644
--- a/tests/pos/grty3.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Test () where
-
-{-@ bar :: (a, {v:[b]|((len v) = 1)}) -> b @-}
-bar (_, [x]) = x
-
-
-
diff --git a/tests/pos/hello.hs b/tests/pos/hello.hs
deleted file mode 100644
--- a/tests/pos/hello.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-{-@ LIQUID "-v" @-}
-
-module Hello () where
-
-{-@ abz :: (Num a, Ord a) => x:a -> {v: a | v >= x} @-}
-abz x   = if (x > 0) then x else (0 - x)  
-
-{-@ incr :: (Num a) => x:a -> {v: a | v > x}        @-}
-incr x  = x + 1 
-
-{-@ decr :: (Num a) => x:a -> {v: a | v < x}        @-}
-decr x  = x - 1 
-
-
diff --git a/tests/pos/hole-app.hs b/tests/pos/hole-app.hs
deleted file mode 100644
--- a/tests/pos/hole-app.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Zoo where
-
-{-@ type Vec a N = {v:[a] | len v = N } @-}
-
-{-@ ok :: Vec Int 3 @-}
-ok = [1,2,3] :: [Int]
-
-{-@ ok' :: Vec _ 3 @-}  -- would be nice to support the hole in the application..
-ok'     = [1,2,3]
-
-
-
diff --git a/tests/pos/hole-fun.hs b/tests/pos/hole-fun.hs
deleted file mode 100644
--- a/tests/pos/hole-fun.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Zoo (test) where
-
-inc :: Int -> Int 
-inc x = x + 1
-
-{-@ app :: _ -> Nat -> Nat @-} 
-app :: (Int -> Int) -> Int -> Int
-app f x = f x
-
-test = app inc 7
diff --git a/tests/pos/idNat.hs b/tests/pos/idNat.hs
deleted file mode 100644
--- a/tests/pos/idNat.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module IdNat where 
-
-{-@ nat :: Nat @-}
-nat :: Int
-nat = id 0 -- (id (id (id (id 0))))
diff --git a/tests/pos/idNat0.hs b/tests/pos/idNat0.hs
deleted file mode 100644
--- a/tests/pos/idNat0.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module IdNat where 
-
-{-@ nat :: Nat @-}
-nat :: Int
-nat = idd 0 
-
-idd :: a -> a
-idd = undefined 
diff --git a/tests/pos/imp0.hs b/tests/pos/imp0.hs
deleted file mode 100644
--- a/tests/pos/imp0.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Import0 () where
-
-import Language.Haskell.Liquid.Prelude
-import Foreign.Storable
-
--- ERROR goes away if we:
--- import Language.Haskell.Liquid.Foreign
-
--- We shouldn't have to do so since, 
---   include/Foreign/Storable.Spec
--- has the line:
---   import Language.Haskell.Liquid.Foreign
-
--- HYPOTHESIS: the import in the spec file above ONLY
---             imports other .spec files... and hence 
---             ignores include/Language/Haskell/Liquid/Foreign.hs 
-
-{-@ inc :: x:Nat -> {v:Nat | v > x} @-}
-inc :: Int -> Int
-inc x = x + 1
diff --git a/tests/pos/implies.hs b/tests/pos/implies.hs
deleted file mode 100644
--- a/tests/pos/implies.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module Imp where
-
-{-@ inline implies @-}
-implies p q = (not p) || q
-
diff --git a/tests/pos/infix.hs b/tests/pos/infix.hs
deleted file mode 100644
--- a/tests/pos/infix.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ (!) :: zogbert:{v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
-(!) :: Int -> Int -> Int
-x ! y = x + y
-
-
-{-@ (!!) :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
-(!!)   :: Int -> Int -> Int 
-x !! y = liquidAssert (x /= 0) $ x + y 
-
-{-@ zoo :: {v: Int | v > 0} -> {v: Int | v > 0} -> Int @-}
-zoo   :: Int -> Int -> Int 
-zoo x y = liquidAssert (x /= 0) $ x + y 
-
-
diff --git a/tests/pos/inline.hs b/tests/pos/inline.hs
deleted file mode 100644
--- a/tests/pos/inline.hs
+++ /dev/null
@@ -1,39 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-module Fixme where
-
-{-@ inline eqq @-}
-eqq :: Ord a => a -> a -> Bool
-eqq x y = x > y
-
-{-@ eqqtest :: Eq a => x:a -> y:a -> {v:Bool | v <=> (eqq x y) } @-}
-eqqtest :: Ord a => a -> a -> Bool
-eqqtest x y = x > y
-
-{-@ inline mymax @-}
-mymax :: Ord a => a -> a -> a
-mymax x y = if x >= y then x else y
-
-{-@ inline mymin @-}
-mymin :: Ord a => a -> a -> a
-mymin x y = mymax y x
-
-{-@ measure foo @-}
-foo :: Ord a => D a -> a
-foo (D x y) = mymax x y
-foo (F x)   = x
-
-{-@ measure bar @-}
-bar :: Ord a => D a -> a
-bar (D x y) = mymax x y
-
-{-@ measure bar2 @-}
-bar2 :: Ord a => D a -> a
-bar2 (D x y) = mymin y x
-
-foooo = D
-
-data D a = D a a | F a
-
-{-@ mymax3, mymax :: x:a -> y:a -> {v:a | v = mymax x y} @-}
-mymax3 :: Ord a => a -> a -> a
-mymax3 x y = if x >= y then x else y
diff --git a/tests/pos/inline1.hs b/tests/pos/inline1.hs
deleted file mode 100644
--- a/tests/pos/inline1.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module InlineMeasure where
-
-data Zoo a = Z { elts :: [a], sz :: Int }
-
--- | this is not ok (unbound symbol `boo`)
-{-@ data Zoo a = Z { elts :: [a], sz :: {v: Int | isBoo v elts} } @-}
-
-{-@ inline isBoo @-}
-isBoo :: Int -> [a] -> Bool
-isBoo v e = v == boo e
-
-{-@ type Moo a = {v:Zoo a | sz v = boo (elts v)} @-}
-
-{-@ inline boo @-}
-boo    :: [a] -> Int
-boo xs = 0
diff --git a/tests/pos/invlhs.hs b/tests/pos/invlhs.hs
deleted file mode 100644
--- a/tests/pos/invlhs.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Foo where
-
-data Bob = B {foo :: Int}
-{-@ data Bob = B {foo :: Int} @-}
-
-{-@ foo :: x:Bob -> {v:Int | v = foo x} @-}
-
-{-@ invariant {v:Bob | foo v == 10} @-}
-
-mk :: a -> Bob
-mk = undefined
-
-{-@ propFAIL :: {v:_ | foo v = 10} @-}
-propFAIL = mk ()
-
-{-@ propOK :: {v:_ | foo v = 10} @-}
-propOK = let z = mk () in z 
-
-
diff --git a/tests/pos/isort_erase.hs b/tests/pos/isort_erase.hs
new file mode 100644
--- /dev/null
+++ b/tests/pos/isort_erase.hs
@@ -0,0 +1,33 @@
+{-@ LIQUID "--reflection" @-}
+{-@ LIQUID "--ple"        @-}
+
+module Isort_erase where 
+
+import Prelude hiding (id, sum)
+import Language.Haskell.Liquid.ProofCombinators
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+data List = Emp | Cons Int List
+
+{-@ reflect isSorted @-}
+isSorted :: List -> Bool
+isSorted Emp = True
+isSorted (Cons x xs) = case xs of
+                        Emp -> True
+                        Cons x1 xs1 -> (x <= x1) && (isSorted xs)
+
+
+{-@ reflect insert @-}
+{-@ insert :: x:Int -> {xs:List | isSorted xs} -> {xs:List | isSorted xs} @-}
+insert :: Int -> List -> List 
+insert x Emp     = Cons x Emp
+insert x (Cons y ys)
+  | x <= y        = Cons x (Cons y ys)
+  | otherwise     = (Cons y (insert x ys)) `withProof` (lem_ins y x ys) 
+
+{-@ lem_ins :: y:Int -> {x:Int | y < x} -> {ys:List | isSorted (Cons y ys)} -> {isSorted (Cons y (insert x ys))} @-}
+lem_ins :: Int -> Int -> List -> Bool
+lem_ins y x Emp = True
+lem_ins y x (Cons y1 ys) = if y1 < x then lem_ins y1 x ys else True
+
diff --git a/tests/pos/ite.hs b/tests/pos/ite.hs
deleted file mode 100644
--- a/tests/pos/ite.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Test0 () where
-
-{-@ assert myabs :: x:Int -> {v: Int | if x > 0 then v = x else v + x = 0 } @-}
-myabs :: Int -> Int
-myabs x | x > 0     = x
-        | otherwise = (0 - x)
diff --git a/tests/pos/ite1.hs b/tests/pos/ite1.hs
deleted file mode 100644
--- a/tests/pos/ite1.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Test0 () where
-
-{-@ assert myabs :: x:Int -> {v: Int | v = (if x > 0 then x else (0 - x)) } @-}
-myabs :: Int -> Int
-myabs x | x > 0     = x
-        | otherwise = (0 - x)
diff --git a/tests/pos/jeff.hs b/tests/pos/jeff.hs
deleted file mode 100644
--- a/tests/pos/jeff.hs
+++ /dev/null
@@ -1,261 +0,0 @@
-{-
-
-This code implements a Monoid for string matching; i.e. a data
-structure, MatchIdxs, which has the result of a string match function
-plus a little extra information for monoidally combining things
-together; the purpose of course is to parallelize string matching
-computations. This is the original version I wrote which uses type
-level strings to guarantee that only computations done with the same
-target string are combinable.
-
-The invariants I'd like to prove are in the comments on the MatchIdxs
-constructors. I'd be interested in a way to do it directly with this
-code (though it seems that would require extending LH), or doing it in
-a version of this code where the constructors have an extra argument
-with the value of the target-- however that formulation seems to raise
-issues about forcing those values to be the same.
-
-I have a version of the code lying around which tries this approach,
-but I couldn't get it to work. I chose to send this version first so
-you have the chance to see where I started; I could send you my version
-with the explicit terms if you like.
-
-If this goes well, then there are a couple of further things to think
-about:
-
-  1) I have another Monoid construction for actual splitting, but
-     I don't think LH can handle the invariants as they require an
-     isInfixOf operation; but I could be wrong about what LH can do.
-
-  2) It would be interesting to think about whether one can encode
-     correctness, rather than just some invariants. By correctness
-     I mean both that the monoid laws are satisfied, and that there
-     is a homomorphic-like property to the effect of:
-
-     match (x <> y) == match x <> match y
-
-Let me know if you have any questions about the code, or need more
-comments/explanation.
--}
-
-
-{- LIQUID "--diff" @-}
-{-@ LIQUID "--scrape-used-imports" @-}
-{-@ LIQUID "--short-names" @-}
-
-{-# LANGUAGE DataKinds #-}
-{-# LANGUAGE DeriveAnyClass #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-
-module MatchIdxs where
-
-import qualified Data.ByteString as BS
--- RJ import qualified Data.ByteString.Search as BS
-import Data.Char
--- RJ import Data.List.Split(chunksOf)
-
-import Data.Monoid
-import Data.Proxy
-import Debug.Trace
-import GHC.TypeLits
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-import Prelude hiding (head, min, max)
-
-junk = BS.head
-
-
-traceMsg msg x = trace (msg ++ show x) x
-
-{-@ chunksBS :: Int -> b:BS.ByteString -> [BS.ByteString] / [(bLength b)] @-}
-chunksBS n' xs | BS.null xs = []
-               | otherwise = x : chunksBS n xs'
-    where (x,xs') = BS.splitAt  (liquidAssert (n > 0) n) xs
-          n       = max 1 n'
-
-bsToString :: BS.ByteString -> String
-bsToString = map (chr . fromIntegral) . BS.unpack
-
-stringToBS :: String -> BS.ByteString
-stringToBS = BS.pack . map (fromIntegral . ord)
-
--- | get the (proxied and existentially boxed) type level Symbol for a bytestring
-someSymbolValBS :: BS.ByteString -> SomeSymbol
-someSymbolValBS = someSymbolVal . bsToString
-
--- | get the bytestring corresponding to a type level Symbol
-mkTarg :: forall t . KnownSymbol t => Proxy t -> BS.ByteString
-mkTarg = stringToBS . symbolVal
-
-
--- | Naive specification of string matching (from Bird)
-{-@ indicesSpec :: t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
--- indicesSpec targ = map ((BS.length targ -) . BS.length) . filter (targ `BS.isSuffixOf`) . BS.inits
-indicesSpec targ s = [ BS.length s' - BS.length targ | s' <- BS.inits s
-                                                     , targ `BS.isSuffixOf` s' ]
-
-indicesSpec :: BS.ByteString -> BS.ByteString -> [Int]
-
-
-
--- | Datatype to name string matching algorithms; will use it's lifted
--- version put choice in type.
-data Alg = BM  -- ^ Boyer-Moore from stringsearch package
-         | Spec  -- ^ Naive spec
-
-{-@ indices :: Alg -> t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
-indices BM   = assumeIndices -- RJ BS.indices
-indices Spec = indicesSpec
-
-
--- | Monoid
---
--- 'MatchIdxs alg targ' denotes the result of running string matching
--- algorithm 'alg' search for target 'targ' in some input. In addition
--- to the match indices, information needed to combine this result
--- with similar results on input to the left and right are also
--- included.
---
--- We'd like to prove that the invariants in the comments hold (|x|
--- denotes the length of x).
-data MatchIdxs
-    = Small { targ :: BS.ByteString
-            , bs   :: BS.ByteString
-            }
-    | MatchIdxs { targ    :: BS.ByteString
-                , input   :: Int
-                , left    :: BS.ByteString
-                , matches :: [Int]
-                , right   :: BS.ByteString
-                }
-  deriving (Eq, Show)
-
-{-@ data MatchIdxs
-      = Small { targ    :: ByteStringNE
-              , bs      :: {b:BS.ByteString | bLength b < bLength targ}
-              }
-
-      | MatchIdxs
-              { targ    :: ByteStringNE
-              , input   :: {i  : Int | i >= bLength targ}
-              , left    :: {l  : BS.ByteString | bLength l == bLength targ - 1}
-              , matches :: [{v : Int | v <= input - bLength targ}]
-              , right   :: {r  : BS.ByteString | bLength r == bLength targ - 1}
-              }
-  @-}
-
-
-matchIdxsIs :: MatchIdxs -> [Int]
-matchIdxsIs (Small _ _) = []
-matchIdxsIs (MatchIdxs _ _ _ is _) = is
-
--- | create a 'MatchIdxs'
-{-@ myIndices :: Alg -> t:ByteStringNE -> BS.ByteString -> MatchIdxsT t @-}
-myIndices alg t bs
-  | BS.length bs > fringeLen = let right1 = BS.drop (BS.length bs - fringeLen) bs in
-                                MatchIdxs t (BS.length bs) left is right1
-  | otherwise = Small t bs
-  where
-    is        = indices alg t bs
-    fringeLen = BS.length t - 1
-    left      = BS.take fringeLen bs
-    -- right1    = BS.drop (BS.length bs - fringeLen) bs
-
--- ISSUE: get contextual output with --diff
--- ISSUE: why does lazyvar right1 not work? it drops the output type on right1!
-
-{- lazyvar right1 -}
-
-{-@ type OkPos Targ Str = {v:Nat | v <= bLength Str - bLength Targ} @-}
-{-@ type ByteStringNE   = {v:BS.ByteString | bLength v > 0 }   @-}
-{-@ type ByteStringN N  = {v:BS.ByteString | bLength v == N}   @-}
-{-@ type MatchIdxsT T   = {v:MatchIdxs | targ v == T}          @-}
-
-{-@ assume BS.isSuffixOf :: targ:_ -> s:_ -> {v:_ | v => (bLength targ <= bLength s) } @-}
-{-@ assume BS.length  :: b:BS.ByteString -> {v:Nat | v == bLength b}  @-}
-{-@ assume BS.empty   :: {v:BS.ByteString | bLength v == 0}    @-}
-{-@ assume BS.take    :: n:Nat -> b:BS.ByteString -> ByteStringN {min n (bLength b)} @-}
-{-@ assume BS.drop    :: n:Nat -> b:{BS.ByteString | n <= bLength b} -> ByteStringN {bLength b - n} @-}
-{-@ assume BS.inits   :: b:BS.ByteString -> [{v:BS.ByteString | bLength v <= bLength b}] @-}
-{-@ assume BS.append  :: b1:BS.ByteString -> b2:BS.ByteString -> ByteStringN {bLength b1 + bLength b2} @-}
-{-@ assume BS.null    :: b:BS.ByteString -> {v:Bool | v <=> (bLength b == 0)} @-}
-{-@ assume BS.splitAt :: n:Nat -> b:BS.ByteString -> (ByteStringN {min n (bLength b)}, ByteStringN {max 0 (bLength b - n)}) @-}
-{-@ assume BS.head    :: BS.ByteString -> _ @-}
-
-{-@ measure target @-}
-target :: MatchIdxs -> BS.ByteString
-target (Small t _)           = t
-target (MatchIdxs t _ _ _ _) = t
-
-{-@ inline min @-}
-min :: Int -> Int -> Int
-min x y = if x <= y then x else y
-
-{-@ inline max @-}
-max :: Int -> Int -> Int
-max x y = if x <= y then y else x
-
--- RJ instance (KnownSymbol t, StringMatch alg) => Monoid (MatchIdxs alg t) where
-{-@ mmempty :: t:ByteStringNE -> MatchIdxsT t @-}
-mmempty t = Small t BS.empty
-
-{-@ mmconcat :: (Foldable t) => Alg -> tg:ByteStringNE -> t (MatchIdxsT tg) -> (MatchIdxsT tg) @-}
-mmconcat alg t = foldr (mmappend alg t) (mmempty t)
-
-{-@ qualif BB(v:Int, n:Int, d:Int, b:BS.ByteString): v <= (n + d) - bLength b @-}
-
-{-@ mmappend :: Alg -> t:ByteStringNE -> MatchIdxsT t -> MatchIdxsT t -> MatchIdxsT t @-}
-mmappend alg t mx my =
-  let fringeLen = BS.length t - 1
-      idxFun    = indices alg t
-  in
-  case (mx, my) of
-    (Small tx x, Small _ y) -> myIndices alg tx (x <> y)
-    (Small tx x, MatchIdxs _ yLen ly iy rt) -> MatchIdxs tx xyLen lt is rt
-       where
-         xyLen = xLen + yLen
-         xLen  = BS.length x
-         xly   = BS.append x ly
-         lt    = BS.take fringeLen xly
-         is    = idxFun xly ++ map (+ xLen) iy
-    (MatchIdxs tx xLen lt ix rx, Small ty y) -> MatchIdxs tx xyLen lt (ix ++ is) rt
-       where
-         xyLen = xLen + yLen
-         yLen  = BS.length y
-         is    = map (+ (xLen - fringeLen)) (idxFun rxy)
-         rt    = BS.drop (BS.length rxy - fringeLen) rxy
-         rxy   = BS.append rx y
-    (MatchIdxs tx xLen lt ix rx, MatchIdxs ty yLen ly iy rt) -> MatchIdxs tx xyLen lt (ix ++ is) rt
-       where
-         xyLen = xLen + yLen
-         is    = ixy ++ map (+ xLen) iy
-         ixy   = map (+ (xLen - fringeLen)) $ idxFun (BS.append rx ly)
-
--- | Example applications
---
--- The bufLen and chunkSz arguments are there to exercise the monoid,
--- though they also foreshadow a parallel implementation.
-{-@ indicesBS' :: Alg -> Int -> Int -> ByteStringNE -> BS.ByteString -> [Int] @-}
-indicesBS' alg bufLen chunkSz t bs =
-  let si = mmconcat alg t . map (mmconcat alg t) . chunksOf bufLen . map (myIndices alg t) $ chunksBS chunkSz bs in
-  matchIdxsIs si
-
-{-@ indicesBS, indicesNaive :: Int -> Int -> ByteStringNE -> BS.ByteString -> [Int] @-}
-indicesBS    = indicesBS' BM   -- RJ (Proxy :: Proxy BM)
-indicesNaive = indicesBS' Spec -- RJ (Proxy :: Proxy Spec)
-
-{-@ isInfixOfBS :: Int -> Int -> ByteStringNE -> BS.ByteString -> Bool @-}
-isInfixOfBS bufLen chunkSz t = not . null . indicesBS bufLen chunkSz t
-
-------------------------------------------------------------------------------------------
-{-@ invariant {v:BS.ByteString | 0 <= bLength v } @-}
-{-@ measure bLength :: BS.ByteString -> Int @-}
-{-@ type LNat N = {v:Nat | v < N} @-}
-
-chunksOf :: Int -> [a] -> [[a]]
-chunksOf =  undefined
-
-{-@ assumeIndices :: t:ByteStringNE -> s:BS.ByteString -> [OkPos t s] @-}
-assumeIndices :: BS.ByteString -> BS.ByteString -> [Int]
-assumeIndices = undefined
diff --git a/tests/pos/kmp.hs b/tests/pos/kmp.hs
deleted file mode 100644
--- a/tests/pos/kmp.hs
+++ /dev/null
@@ -1,95 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-
-module KMP (search) where
-
-import Language.Haskell.Liquid.Prelude (liquidError)
-
-search pat str = kmpSearch (ofList pat) (ofList str) 
-
--------------------------------------------------------------
--- | Do the Search ------------------------------------------
--------------------------------------------------------------
-
-kmpSearch p@(A m _) s@(A n _) = go 0 0 
-  where
-    t              = kmpTable p
-    go i j
-      | j >= m     = i - m
-      | i >= n     = (-1)
-      | s!i == p!j = go (i+1) (j+1)
-      | j == 0     = go (i+1) j
-      | otherwise  = go i     (t!j) 
-
-
--------------------------------------------------------------
--- | Make Table ---------------------------------------------
--------------------------------------------------------------
-
-{-@ kmpTable :: (Eq a) => p:Arr a -> {v:DArr Nat | alen v = alen p} @-}
-kmpTable p@(A m _) = go 1 0 t
-  where
-    t              = new m (\_ -> 0)
-    go i j t
-      | i >= m - 1 = t
-
-      | p!i == p!j = let i' = i + 1
-                         j' = j + 1
-                         t' = wipe $ set t i' j'
-                     in go i' j' t'           
-    
-      | (j == 0)   = let i' = i + 1
-                         t' = wipe $ set t i' 0
-                     in go i' j t'
-                             
-      | otherwise  = let j' = t ! j
-                     in go i j' t 
-
-{-@ wipe :: a:DArr Nat -> {v:DArr Nat | alen v = alen a} @-}
-wipe :: Arr Int -> Arr Int
-wipe = undefined
-
-
-{-@ type DArr a = Arr<{\k v -> v <= k}> a @-}
-{-@ type Upto N = {v:Nat | v < N} @-} 
-
--------------------------------------------------------------
--- | An Array type ------------------------------------------
--------------------------------------------------------------
-
-data Arr a = A { alen :: Int
-               , aval :: Int -> a
-               }
-
-{-@ data Arr a <rng :: Int -> a -> Bool>
-      = A { alen :: Nat 
-          , aval :: i:Upto alen -> a<rng i>
-          }
-  @-}
-
-
-{-@ new :: forall <p :: Int -> a -> Bool>.
-             n:Nat -> (i:Upto n -> a<p i>) -> {v: Arr<p> a | alen v = n}
-  @-}
-new n v = A { alen = n
-            , aval = \i -> if (0 <= i && i < n)
-                             then v i
-                             else liquidError "Out of Bounds!"
-            }
-
-{-@ (!) :: forall <p :: Int -> a -> Bool>.
-             a:Arr<p> a -> i:Upto (alen a) -> a<p i>
-  @-}
-
-(A _ f) ! i = f i
-  
-{-@ set :: forall <p :: Int -> a -> Bool>.
-             a:Arr<p> a -> i:Upto (alen a) -> a<p i> -> {v:Arr<p> a | alen v = alen a}
-  @-}
-set a@(A _ f) i v = a { aval = \j -> if (i == j) then v else f j }
-
-
-{-@ ofList :: xs:[a] -> {v:Arr a | alen v = len xs} @-} 
-ofList :: [a] -> Arr a
-ofList = undefined
-
diff --git a/tests/pos/kmpIO.hs b/tests/pos/kmpIO.hs
deleted file mode 100644
--- a/tests/pos/kmpIO.hs
+++ /dev/null
@@ -1,140 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-{-@ LIQUID "--diff"           @-}
-
-module KMP (search) where
-
-import Language.Haskell.Liquid.Prelude (liquidError)
-import Data.IORef
-import Control.Applicative ((<$>))
-import qualified Data.Map as M
-
-{-@ type Upto N = {v:Nat | v < N} @-}
-
----------------------------------------------------------------------------
-{-@ search :: String -> str:String -> Maybe (Upto (len str)) @-}
----------------------------------------------------------------------------
-search :: String -> String -> Maybe Int
-search pat str = kmpSearch (ofList pat) (ofList str)
-
-
--------------------------------------------------------------
--- | Do the Search ------------------------------------------
--------------------------------------------------------------
-
-{-@ kmpSearch :: (Eq a) => p:Arr a -> s:Arr a -> Maybe (Upto (alen s)) @-}
-kmpSearch p@(A m _) s@(A n _) = go 0 0
-  where
-    t              = kmpTable p
-    go i j
-      | i >= n     = Nothing
-      | j >= m     = Just (i - m)
-      | s!i == p!j = go (i+1) (j+1)
-      | j == 0     = go (i+1) j
-      | otherwise  = go i     (t!j)
-
-
--------------------------------------------------------------
--- | Make Table ---------------------------------------------
--------------------------------------------------------------
-
-kmpTable p@(A m _) = go t 1 0
-  where
-    t              = new m (\_ -> 0)
-    go t i j
-      | i >= m - 1 = t
-
-      | p!i == p!j = let i' = i + 1
-                         j' = j + 1
-                         t' = set t i' j'
-                     in go t' i' j'
-
-      | (j == 0)   = let i' = i + 1
-                         t' = set t i' 0
-                     in go t' i' j
-
-      | otherwise  = let j' = t ! j
-                     in go t i j'
-
-
--------------------------------------------------------------
--- | A Pure Array -------------------------------------------
--------------------------------------------------------------
-
-data Arr a   = A { alen :: Int
-                 , aval :: Int -> a
-                 }
-
-{-@ data Arr a <p :: Int -> a -> Bool>
-             = A { alen :: Nat
-                 , aval :: i:Upto alen -> a<p i>
-                 }
-  @-}
-
-
-{-@ new :: forall <p :: Int -> a -> Bool>.
-             n:Nat -> (i:Upto n -> a<p i>) -> {v: Arr<p> a | alen v = n}
-  @-}
-new n v = A { alen = n
-            , aval = \i -> if (0 <= i && i < n)
-                             then v i
-                             else liquidError "Out of Bounds!"
-            }
-
-{-@ (!) :: forall <p :: Int -> a -> Bool>.
-             a:Arr<p> a -> i:Upto (alen a) -> a<p i>
-  @-}
-
-(A _ f) ! i = f i
-
-{-@ set :: forall <p :: Int -> a -> Bool>.
-             a:Arr<p> a -> i:Upto (alen a) -> a<p i> -> {v:Arr<p> a | alen v = alen a}
-  @-}
-set a@(A _ f) i v = a { aval = \j -> if (i == j) then v else f j }
-
-
-{-@ ofList :: xs:[a] -> {v:Arr a | alen v = len xs} @-}
-ofList xs = new n f
-  where
-    n     = length xs
-    m     = M.fromList $ zip [0..] xs
-    f i   = (M.!) m i
-
-{-@ map :: (a -> b) -> a:Arr a -> {v:Arr b | alen v = alen a} @-}
-map f a@(A n z) = A n (f . z)
-
-
-
--------------------------------------------------------------
--- | An Imperative Array ------------------------------------
--------------------------------------------------------------
-
-data IOArr a = IOA { size :: Int
-                   , pntr :: IORef (Arr a)
-                   }
-
-{-@ data IOArr a <p :: Int -> a -> Bool>
-      = IOA { size :: Nat
-            , pntr :: IORef ({v:Arr<p> a | alen v = size})
-            }
-  @-}
-
-{-@ newIO :: forall <p :: Int -> a -> Bool>.
-               n:Nat -> (i:Upto n -> a<p i>) -> IO ({v: IOArr<p> a | size v = n})
-  @-}
-newIO n f = IOA n <$> newIORef (new n f)
-
-{-@ getIO :: forall <p :: Int -> a -> Bool>.
-              a:IOArr<p> a -> i:Upto (size a) -> IO (a<p i>)
-  @-}
-getIO a@(IOA sz p) i
-  = do arr   <- readIORef p
-       return $ (arr ! i)
-
-{-@ setIO :: forall <p :: Int -> a -> Bool>.
-              a:IOArr<p> a -> i:Upto (size a) -> a<p i> -> IO ()
-  @-}
-setIO a@(IOA sz p) i v
-  = do arr     <- readIORef p
-       let arr' = set arr i v
-       writeIORef p arr'
diff --git a/tests/pos/kmpVec.hs b/tests/pos/kmpVec.hs
deleted file mode 100644
--- a/tests/pos/kmpVec.hs
+++ /dev/null
@@ -1,63 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--short-names"    @-}
-
-module KMP (search) where
-
-import Language.Haskell.Liquid.Prelude (liquidError)
-import Data.Vector
-import Data.Vector.Mutable (write)
-import Prelude hiding (length, replicate)
-
-{-@ type Idx X = {v:Nat | v < vlen X} @-}
-
-
-search pat str = kmpSearch (fromList pat) (fromList str) 
-
--------------------------------------------------------------
--- | Do the Search ------------------------------------------
--------------------------------------------------------------
-
-kmpSearch p s      = go 0 0 
-  where
-    t              = kmpTable p
-    m              = length p
-    n              = length s
-    go i j
-      | j >= m     = i - m
-      | i >= n     = (-1)
-      | s!i == p!j = go (i+1) (j+1)
-      | j == 0     = go (i+1) j
-      | otherwise  = go i     (t!j) 
-
-
--------------------------------------------------------------
--- | Make Table ---------------------------------------------
--------------------------------------------------------------
-
-{-@ kmpTable :: (Eq a) => p:Vector a -> {v:Vector Nat | vlen v = vlen p} @-}
-kmpTable p         = go 1 0 t
-  where
-    m              = length p
-    t              = replicate m 0 
-    go i j t
-      | i >= m - 1 = t
-
-      | p!i == p!j = let i' = i + 1
-                         j' = j + 1
-                         t' = set t i' j'
-                     in go i' j' t'           
-    
-      | (j == 0)   = let i' = i + 1
-                         t' = set t i' 0
-                     in go i' j t'
-                             
-      | otherwise  = let j' = t ! j
-                     in go i j' t 
-
-
-{-@ type Upto N = {v:Nat | v < N} @-} 
-
-{-@ set :: a:Vector a -> i:Idx a -> a -> {v:Vector a | vlen v = vlen a} @-}
-set :: Vector a -> Int -> a -> Vector a
-set = undefined
-
diff --git a/tests/pos/lets.hs b/tests/pos/lets.hs
deleted file mode 100644
--- a/tests/pos/lets.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo :: Int -> (Int, Int)
-foo z = (z, z + 1)
-
-baz :: Int -> (Int, Int)
-baz z = let (i, j) = foo z 
-        in (i, j + 1)
-
-{-@ prop :: Int -> Bool @-}
-prop x = let (a, b) = baz x in
-         liquidAssertB (a < b)
diff --git a/tests/pos/lex.hs b/tests/pos/lex.hs
deleted file mode 100644
--- a/tests/pos/lex.hs
+++ /dev/null
@@ -1,10 +0,0 @@
--- TAG: termination
-
-module Lex (foo) where
-
-bar = foo [1, 2, 3] [2, 3, 4]
-
-{- decrease foo 1 2 @-}
-foo xs    (y:ys) = foo xs ys
-foo (x:xs) ys    = foo xs ys
-foo xs     ys    = xs
diff --git a/tests/pos/listAnf.hs b/tests/pos/listAnf.hs
deleted file mode 100644
--- a/tests/pos/listAnf.hs
+++ /dev/null
@@ -1,90 +0,0 @@
-module ListRange (llen) where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@  
-data List [llen] a <p :: x0:a -> x1:a -> Bool>  
-  = Nil 
-  | Cons (h :: a) (t :: List <p> (a <p h>))
-@-}
-
-{-@ measure llen @-}
-llen :: List a -> Int 
-{-@ llen :: List a -> Nat @-} 
-llen Nil = 0 
-llen (Cons _ xs) = 1 + llen xs 
-
-data List a 
-   = Nil 
-   | Cons a (List a)
-
-checkSort Nil                        = True
-checkSort (_ `Cons` Nil)             = True
-checkSort (x1 `Cons` (x2 `Cons` xs)) = liquidAssertB (x1 <= x2) && checkSort (x2 `Cons` xs)
-
-z3 :: List Integer 
-z3    = 3 `Cons` (6 `Cons` Nil)
-prop3 = checkSort z3
-
--- The below works because it is properly ANF-ed
--- The above fails because the "3" is not hoisted out into its own binding.
-
---three :: Integer
---three = 3
---
---six :: Integer
---six = 6
---
---z2 :: List Integer 
---z2    = three `Cons` (six `Cons` Nil) 
---prop2 = checkSort z2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/pos/listSet.hs b/tests/pos/listSet.hs
deleted file mode 100644
--- a/tests/pos/listSet.hs
+++ /dev/null
@@ -1,56 +0,0 @@
-module ListSets () where
-
--------------------------------------------------------------------------
--- | Encoding Sets of Values With Liquid Types --------------------------
--------------------------------------------------------------------------
-
--- TODO: make this self-enclosed
-
-import Data.Set (Set(..))  
-
--- | To start with, lets check that the `listElts` measure is sensible
-
-{-@ myid0 :: xs:[a] -> {v:[a]| (len v) = (len xs)} @-}
-myid0 []     = []
-myid0 (x:xs) = x : myid0 xs
-
-
-{-@ myid :: xs:[a] -> {v:[a]| (listElts v) = (listElts xs)} @-}
-myid []     = []
-myid (x:xs) = x : myid xs
-
--- | The reverse function should also return the same set of values.
--- Note that the reverse uses the tail-recursive helper @go@. 
--- Mouse over and see what type is inferred for it!
-
-{-@ decrease go 2 @-}
-{-@ myrev :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
-myrev :: [a] -> [a]
-myrev = go [] 
-  where 
-    go acc []     = acc
-    go acc (y:ys) = go (y:acc) ys
-
--- | Next, here's good old List-append, but now with a specification about
--- the sets of values in the input and output.
-
-{-@ myapp :: xs:[a] 
-          -> ys:[a] 
-          -> {v:[a] | listElts v = Set_cup (listElts xs) (listElts ys) } @-}
-myapp :: [a] -> [a] -> [a]
-myapp []     ys = ys
-myapp (x:xs) ys = x : myapp xs ys
-
--- | Finally, to round off this little demo, here's @filter@, which returns a subset.
-
-{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a] | Set_sub (listElts v) (listElts xs) } @-}
-myfilter :: (a -> Bool) -> [a] -> [a]
-myfilter f []     = []
-myfilter f (x:xs) = if f x 
-                      then x : myfilter f xs 
-                      else myfilter f xs
-
-
-
-
-
diff --git a/tests/pos/listSetDemo.hs b/tests/pos/listSetDemo.hs
deleted file mode 100644
--- a/tests/pos/listSetDemo.hs
+++ /dev/null
@@ -1,55 +0,0 @@
-module ListSets () where
-
--------------------------------------------------------------------------
--- | Encoding Sets of Values With Liquid Types --------------------------
--------------------------------------------------------------------------
-
--- First, lets import the `Set` type from @Data.Set@
-
-import qualified Data.Set as S 
-
--- Next, lets write a measure for the set of elements in a list.
-
-{-@ measure elts @-}
-elts :: (Ord a) => [a] -> S.Set a 
-elts []     = S.empty
-elts (x:xs) = S.union (S.singleton x) (elts xs)
-
--- OK, now we can write some specifications!
-
--- | To start with, lets check that the `elts` measure is sensible
-
-{-@ myid :: xs:[a] -> {v:[a]| (elts v) = (elts xs)} @-}
-myid []     = []
-myid (x:xs) = x : myid xs
-
--- | The reverse function should also return the same set of values.
--- Note that the reverse uses the tail-recursive helper @go@. 
--- Mouse over and see what type is inferred for it!
-
-{-@ decrease go 2 @-}
-{-@ myrev :: xs:[a] -> {v:[a]| (elts v) = (elts xs)} @-}
-myrev = go [] 
-  where 
-    go acc []     = acc
-    go acc (y:ys) = go (y:acc) ys
-
--- | Next, here's good old List-append, but now with a specification about
--- the sets of values in the input and output.
-
-{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | (elts v) = (Set_cup (elts xs) (elts ys))} @-}
-myapp []     ys = ys
-myapp (x:xs) ys = x : myapp xs ys
-
--- | Finally, to round off this little demo, here's @filter@, which returns a subset.
-
-{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a]| Set_sub (elts v) (elts xs) } @-}
-myfilter f []     = []
-myfilter f (x:xs) 
-  | f x           = x : myfilter f xs 
-  | otherwise     = myfilter f xs
-
-
-
-
-
diff --git a/tests/pos/listqual.hs b/tests/pos/listqual.hs
deleted file mode 100644
--- a/tests/pos/listqual.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module ListQual (boo) where
-
-{-@ qualif BadAppend(v:[a], xs:[a], ys:[a]): len v = len xs + len ys @-}
-
-append [] ys     = ys
-append (x:xs) ys = x : append xs ys
-
-{-@ boo :: {v:[Int] | len v = 2} @-}
-boo :: [Int]
-boo = append [1] [2]
diff --git a/tests/pos/lit.hs b/tests/pos/lit.hs
deleted file mode 100644
--- a/tests/pos/lit.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Lit where
-
-{-@ test :: {v:Int | v == 3} @-}
-test = length "cat"
diff --git a/tests/pos/lit00.hs b/tests/pos/lit00.hs
deleted file mode 100644
--- a/tests/pos/lit00.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Nats where
-
-import Language.Haskell.Liquid.Prelude 
-
-poo :: () 
-poo = liquidAssert (zero /= one) ()
-
-data Peano = Z | O deriving (Eq)
-
-bob :: String 
-bob = "I am a cat"
-
-{-@ axiomatize one @-}
-one :: Peano 
-one = O 
-
-{-@ axiomatize zero @-}
-zero :: Peano
-zero = Z
diff --git a/tests/pos/lit02.hs b/tests/pos/lit02.hs
deleted file mode 100644
--- a/tests/pos/lit02.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Goo where 
-
-import Data.Set as S 
-
-{-@ predicate ValidMovieScheme V =
-	  ((listElts V == Set_cup (Set_sng "year")
-	  	                      (Set_cup (Set_sng "star")
-	  	                      (Set_cup (Set_sng "director")
-	  	                               (Set_sng "title"))))) @-}
-
-{-@ foo :: xs:[String] -> {ys: [String] | Set_sub (listElts xs) (listElts ys)} -> Int @-}
-foo :: [String] -> [String] -> Int 
-foo = undefined
-
-{-@ assume things :: {v:[String] | ValidMovieScheme v} @-}
-things :: [String] 
-things = undefined 
-
-bar = foo ["director"] things 
diff --git a/tests/pos/malformed0.hs b/tests/pos/malformed0.hs
deleted file mode 100644
--- a/tests/pos/malformed0.hs
+++ /dev/null
@@ -1,29 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-
--- TODO: Fix resolve so we can remove this/add termination metrics
-{-@ LIQUID "--no-termination" @-}
-
-module List () where
-
-{-@ decrease go 3 4 5 @-}
-{-@ decrease perms 4 5 6 @-}
-
-{-@ foo :: xs:[a] -> ys:[a] -> {v:Int| v = (len xs)- (len ys)} -> Int @-}
-foo :: [a] -> [a] -> Int -> Int
-foo = undefined
-
-permutations         :: [a] -> [[a]]
-permutations xs     =  go xs xs (length xs) (length xs) 1
-  where
-    go xs0 xs (d2 :: Int) d1 (d3::Int) = xs : perms xs0 xs [] d2 d1 0
-    perms _ []     _  _ _ _ = []
-    perms xs0 (t:ts) is (d2 :: Int) (d1::Int) (d3 :: Int) = (perms ts xs0 (t:is) d2 (length ts) d3) ++ (go xs0 is (length xs0 - length is) d1 1)
-
--- permutations         :: [a] -> [[a]]
--- permutations xs     =  go xs xs (length xs) (0::Int) 1
---   where
---     go xs0 xs d1 (d2::Int) (d3::Int) = xs : perms xs0 xs [] d1 0 0
---     perms _ []     _  _ _ _ = []
---     perms xs0 (t:ts) is (d1::Int) (d2 :: Int) (d3 :: Int) = (perms ts xs0 (t:is) (length ts) 0 d3) ++ (go xs0 is (length is) 0 1)
--- 
--- 
diff --git a/tests/pos/mapTvCrash.hs b/tests/pos/mapTvCrash.hs
deleted file mode 100644
--- a/tests/pos/mapTvCrash.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Foo (foo) where
-
-import Foreign.ForeignPtr
-
-{-@ foo :: FinalizerPtr a -> a @-}
-foo :: FinalizerPtr a -> a
-foo = undefined
diff --git a/tests/pos/mapreduce-bare.hs b/tests/pos/mapreduce-bare.hs
deleted file mode 100644
--- a/tests/pos/mapreduce-bare.hs
+++ /dev/null
@@ -1,71 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-import Data.List (foldl')
-
-----------------------------------------------------------------
---- Step 1: Map each element into key-value list (concatMap) ---
-----------------------------------------------------------------
-
-expand          :: (a -> [(k,v)]) -> [a] -> [(k, v)]
-expand f []     = []
-expand f (x:xs) = (f x) ++ (expand f xs)
-
-----------------------------------------------------------------
---- Step 2: Group By Key ---------------------------------------
-----------------------------------------------------------------
-
-group ::[(Int, v)] -> [(Int, [v])]
-group = foldl' addKV [] 
-  
-addKV m (k, v) = insert k vs' m
-  where vs' = v : (findWithDefault [] k m)
-
-insert key value [] 
-  = [(key, value)]
-insert key value ((k,_):kvs)
-  | k == key
-  = (key, value):kvs
-insert key value (kv:kvs)
-  = kv : insert key value kvs  
-
-findWithDefault r _ ([]) 
-  = r
-findWithDefault r k ((key,value):_) 
-  | k `eq` key 
-  = value
-findWithDefault r k (_:kvs) 
-  = findWithDefault r k kvs 
-
-----------------------------------------------------------------
---- Step 3: Group By Key ---------------------------------------
-----------------------------------------------------------------
-
-collapse f = foldrWithKey reduceKV []
-  where reduceKV k (v:vs) acc = (k, foldl' f v vs) : acc
-        reduceKV k []     _   = crash False -- error $ show (liquidAssertB False)
-
-foldrWithKey f = foldr (\(k, v) acc -> f k v acc) 
-
-----------------------------------------------------------------
---- Putting it All Together ------------------------------------
-----------------------------------------------------------------
-
-mapReduce fmap fred xs = collapse fred $ group $ expand fmap xs
-
-----------------------------------------------------------------
---- "Word Count" -----------------------------------------------
-----------------------------------------------------------------
-
-wordCount  = mapReduce fm plus 
-  where fm = \doc -> [ (length w, 1) | w <- words doc]
-
-mytest = 
-  let docs = [ "this is the end"
-             , "go to the end"
-             , "the end is the beginning"]
-  in putStrLn $ isZero {- show -} $ wordCount docs
- 
-isZero [_]  = "Positive" 
-isZero _    = "Negative"
-
diff --git a/tests/pos/maps.hs b/tests/pos/maps.hs
deleted file mode 100644
--- a/tests/pos/maps.hs
+++ /dev/null
@@ -1,41 +0,0 @@
-module Maps where
-
-
-{-@ prop0 :: x:_ -> y:{_ | y == x} -> TT @-}
-prop0 x y = (a == b)
-  where
-    a     = get x emp  
-    b     = get y emp 
-
-{-@ prop1 :: x:_ -> y:{_ | y /= x} -> TT @-}
-prop1 x y = (z == 10)
-  where
-    m1    = put x 10 emp  
-    m2    = put y 20 m1
-    z     = get x m2
-
-{-@ prop2 :: x:_ -> y:{_ | y == x} -> TT @-}
-prop2 x y = (z == 20)
-  where
-    m1    = put x 10 emp 
-    m2    = put y 20 m1
-    z     = get x m2
-
------------------------------------------------------------------------
-
-data Map k v = M
-
-{-@ embed Map as Map_t @-}
-{-@ measure Map_select :: Map k v -> k -> v @-}
-{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
-
-emp :: Map Int Int
-emp = undefined   
-     
-{-@ get :: k:k -> m:Map k v -> {v:v | v = Map_select m k} @-}
-get :: k -> Map k v -> v
-get = undefined 
-
-{-@ put :: k:k -> v:v -> m:Map k v -> {n:Map k v | n = Map_store m k v} @-}
-put :: k -> v -> Map k v -> Map k v
-put = undefined 
diff --git a/tests/pos/maps1.hs b/tests/pos/maps1.hs
deleted file mode 100644
--- a/tests/pos/maps1.hs
+++ /dev/null
@@ -1,36 +0,0 @@
-module Maps where
-
-import Prelude hiding (lookup)
-import Data.Map
-
-{-@ prop0   :: _ -> x:_ -> y:{_ | y == x} -> TT @-}
-prop0       :: Map Int Int -> Int -> Int -> Bool
-prop0 m x y = (a == b)
-  where
-    a       = m ! x
-    b       = m ! y
-
-{-@ prop1   :: _ -> x:_ -> y:{_ | y /= x} -> TT @-}
-prop1       :: Map Int Int -> Int -> Int -> Bool
-prop1 m x y = (z == 10)
-  where
-    m1      = insert x 10 m
-    m2      = insert y 20 m1
-    z       = m2 ! x
-
-{-@ prop2   :: _ -> x:_ -> y:{_ | y == x} -> TT @-}
-prop2 m x y = (z == 20)
-  where
-    m1      = insert x 10 m
-    m2      = insert y 20 m1
-    z       = m2 ! x
-
------------------------------------------------------------------------
-
-{-@ embed Map as Map_t @-}
-{-@ measure Map_select :: Map k v -> k -> v @-}
-{-@ measure Map_store  :: Map k v -> k -> v -> Map k v @-}
-{-@ assume (!)         :: (Ord k) => m:Map k v -> k:k -> {v:v | v = Map_select m k} @-}
-{-@ assume insert      :: (Ord k) => key:k -> value:v -> m:Map k v -> {n:Map k v | n = Map_store m key value} @-}
-
------------------------------------------------------------------------
diff --git a/tests/pos/maybe.hs b/tests/pos/maybe.hs
deleted file mode 100644
--- a/tests/pos/maybe.hs
+++ /dev/null
@@ -1,32 +0,0 @@
-module Test () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
-
-{-@ filterGt :: (Ord a) => x:Maybe a -> OList a -> OList {v:a | (( isJust x ) => (fromJust x <= v)) } @-}
-
-filterGt ::  Ord a => Maybe a -> [a] -> [a]
-filterGt Nothing  xs = xs
-filterGt (Just x) xs = foo x xs
-  
-foo y xs = foo' y xs
-
-foo' :: (Ord a) => a -> [a] -> [a]
-foo' y []     = []
-foo' y (x:xs) 
- = case compare y x of 
-     GT -> foo' y xs 
-     LT -> x:xs 
-     EQ -> xs 
-
-{-@ bar :: (Ord a) => z:a -> OList a -> OList {v:a | z <= v} @-}
-bar y xs = bar' y xs
-
-bar' y []     = []
-bar' y (x:xs) 
-  | y > x    = bar' y xs 
-  | y < x    = x:xs 
-  | y == x   = xs 
-
-
diff --git a/tests/pos/maybe0.hs b/tests/pos/maybe0.hs
deleted file mode 100644
--- a/tests/pos/maybe0.hs
+++ /dev/null
@@ -1,13 +0,0 @@
-module Test () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ foo :: x:Maybe a -> {v:a | ((isJust(x)) => (fromJust(x) = v)) } @-}
-foo :: Maybe a -> a 
-foo (Just x)  = x 
-foo (Nothing) = unsafeError "foo"
-
-{-@ bar :: x:Maybe a -> {v:Bool | v <=> isJust x } @-}
-bar (Just x)  = True 
-bar (Nothing) = False
-
diff --git a/tests/pos/maybe000.hs b/tests/pos/maybe000.hs
deleted file mode 100644
--- a/tests/pos/maybe000.hs
+++ /dev/null
@@ -1,48 +0,0 @@
-module Foo () where
--- TODO: get this working with the ! annots.
-
-import Language.Haskell.Liquid.Prelude
--- remove the ! and it is safe...
-data MaybeS a = NothingS | JustS !a
--- (SAFE) data MaybeS a = NothingS | JustS a
-
-{-@ measure isJustS :: forall a. MaybeS a -> Bool 
-      isJustS (JustS x)  = true
-      isJustS (NothingS) = false
-  @-}
-
-{-@ measure fromJustS :: forall a. MaybeS a -> a
-      fromJustS (JustS x) = x 
-  @-}
-
-gloop = poop True
-
-{-@ poop :: z:a -> {v: MaybeS a | fromJustS(v) = z} @-}
-poop z = JustS z
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/pos/maybe1.hs b/tests/pos/maybe1.hs
deleted file mode 100644
--- a/tests/pos/maybe1.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-module Test (isJustS, fromJustS) where
-
-data MaybeS a = NothingS | JustS !a
-
-{-@ measure isJustS @-}
-isJustS :: MaybeS a -> Bool
-isJustS (JustS x)  = True
-isJustS (NothingS) = False
-
-{-@ measure fromJustS @-}
-fromJustS :: MaybeS a -> a
-fromJustS (JustS x) = x
-
-{-@ type OList a = [a]<{\fld v -> (v >= fld)}> @-}
-
-{-@ filterGt :: (Ord a) => x:MaybeS a -> OList a -> OList {v:a | isJustS x => fromJustS x <= v } @-}
-
-filterGt ::  Ord a => MaybeS a -> [a] -> [a]
-filterGt NothingS  xs = xs
-filterGt (JustS x) xs = foo' x xs
-  where foo' y []     = []
-        foo' y (x:xs) = case compare y x of
-                          GT -> foo' y xs
-                          LT -> x:xs
-                          EQ -> xs
diff --git a/tests/pos/maybe2.hs b/tests/pos/maybe2.hs
deleted file mode 100644
--- a/tests/pos/maybe2.hs
+++ /dev/null
@@ -1,70 +0,0 @@
-module Data.Map.Base (Map(..), isRoot, filterLt, filterGt, mlen) where
-
-data Map k a  = Bin Size k a (Map k a) (Map k a)
-              | Tip
-
-type Size     = Int
-
-data MaybeS a = NothingS | JustS !a
-
-{-@ 
-  data Map [mlen] k a <l :: root:k -> k -> Bool, r :: root:k -> k -> Bool>
-       = Bin (sz    :: Size) 
-             (key   :: k) 
-             (value :: a) 
-             (left  :: Map <l, r> (k <l key>) a) 
-             (right :: Map <l, r> (k <r key>) a) 
-       | Tip 
-  @-}
-
-{-@ measure mlen @-}
-mlen :: Map k a -> Int 
-{-@ mlen :: Map k a -> Nat @-}
-mlen Tip = 0 
-mlen (Bin _ _ _ l r) = 1 + mlen l + mlen r  
-
-{-@ measure isJustS @-}
-isJustS :: MaybeS a -> Bool 
-isJustS (JustS x)  = True
-isJustS (NothingS) = False
-
-{-@ measure fromJustS :: forall a. MaybeS a -> a 
-      fromJustS (JustS x) = x 
-  @-}
-
-{-@ type OMap k a = Map <{\root v -> v < root}, {\root v -> v > root}> k a @-}
-
-{-@ measure isBin @-} 
-isBin :: Map k a -> Bool
-isBin (Bin sz kx x l r) = True
-isBin Tip             = False
-
-{-@ isRoot :: t:Map k a -> {v: Bool | v <=> isBin t} @-}
-isRoot (Bin _ _ _ _ _) = True
-isRoot (Tip)           = False
-
-{-@ filterGt :: (Ord k) => x:MaybeS k -> OMap k v -> OMap {v:k | ((isJustS(x)) => (v > fromJustS(x))) } v @-}
-filterGt :: Ord k => MaybeS k -> Map k v -> Map k v
-filterGt NothingS t = t
-filterGt (JustS b) t = filterGt' b t
-  
-filterGt' _   Tip = Tip
-filterGt' b' (Bin _ kx x l r) =
-          case compare b' kx of LT -> join kx x (filterGt' b' l) r
-                                EQ -> r
-                                GT -> filterGt' b' r
-
-{-@ filterLt :: (Ord k) => x:MaybeS k -> OMap k v -> OMap {v:k | ((isJustS(x)) => (v < fromJustS(x))) } v @-}
-filterLt :: Ord k => MaybeS k -> Map k v -> Map k v
-filterLt NothingS t = t
-filterLt (JustS b) t = filterLt' b t
-  
-filterLt' _   Tip = Tip
-filterLt' b' (Bin _ kx x l r) =
-  case compare kx b' of LT -> join kx x l (filterLt' b' r)
-                        EQ -> l
-                        GT -> filterLt' b' l
-
-{-@ join :: kcut:k -> a -> OMap {v:k | v < kcut} a -> OMap {v:k| v > kcut} a -> OMap k a @-}
-join :: k -> a -> Map k a -> Map k a -> Map k a
-join kx x l r = Bin 1 kx x l r 
diff --git a/tests/pos/maybe3.hs b/tests/pos/maybe3.hs
deleted file mode 100644
--- a/tests/pos/maybe3.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Foo () where
-
-
-{-@ foo :: lo0 : Maybe a
-        -> lo  : {v: Maybe {v: a | isJust lo0 && v = fromJust lo0 } | v = lo0 }  
-        -> hi0 : Maybe a
-        -> hi  : {v: Maybe {v: a | isJust hi0 && v = fromJust hi0 } 
-                   | (((isJust lo && isJust v) => (fromJust v >= fromJust lo)) && (v = hi0)) }   
-        -> Bool @-}
-foo :: Maybe a -> Maybe a -> Maybe a -> Maybe a -> Bool
-foo lo0 lo hi0 hi = bar (id hi) (id lo)
-
-{-@ bar :: hi: Maybe a 
-        -> lo:Maybe {v: a | ((isJust hi) => (v <= fromJust hi)) }  
-        -> Bool @-}
-bar :: Maybe a -> Maybe a -> Bool
-bar hi lo = True
-
-
-
diff --git a/tests/pos/maybe4.hs b/tests/pos/maybe4.hs
deleted file mode 100644
--- a/tests/pos/maybe4.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Foo () where
-
-{-@ LIQUID "--bscope" @-}
-
-{-@ goo   :: lo:{v0a: Maybe {v:a | ((isJust v0a) && (v = (fromJust v0a)))} | true } 
-          -> hi:{v0b: Maybe {v:a | ((isJust v0b) && (v = (fromJust v0b)))} | (((isJust(lo) && isJust(v0b)) => (fromJust(v0b) >= fromJust(lo)))) }   
-          -> Bool 
-  @-}
-goo       :: Maybe a -> Maybe a -> Bool
-goo lo hi = bar (id hi) (id lo)
-
-{-@ bar :: hi: Maybe a -> lo:Maybe {v: a | ((isJust(hi)) => (v <= fromJust(hi)))} -> Bool @-}
-bar :: Maybe a -> Maybe a -> Bool
-bar hi lo = True
-
-
-
diff --git a/tests/pos/maybe5.hs b/tests/pos/maybe5.hs
deleted file mode 100644
--- a/tests/pos/maybe5.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Foo where
-
-import Data.Maybe
-
-
-{-@ foo :: {x:_ | isJust x} -> a @-}
-foo :: Maybe a -> a
-foo x = fromJust x
diff --git a/tests/pos/meas0.hs b/tests/pos/meas0.hs
deleted file mode 100644
--- a/tests/pos/meas0.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Range () where
-
-import Language.Haskell.Liquid.Prelude
-
-goo x = let z = [x] in z
-
-z0 _  = True
-z1 _  = False
-
-poo (x:_) = 0 == 0 
-poo ([])  = liquidAssertB False
-
-xs = goo (choose 0)
-
-prop1 = liquidAssertB (poo xs)
diff --git a/tests/pos/meas00.hs b/tests/pos/meas00.hs
deleted file mode 100644
--- a/tests/pos/meas00.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-module Zog () where
-
-import Language.Haskell.Liquid.Prelude
-
-xs :: [Int]
-xs = [1]
-
-poo [] = liquidAssertB False
-
-prop1  = liquidAssertB (poo xs)
-
-{- qualif PosLen(v:[a]): (len v) > 0 @-}
-
-{- zooper :: {v:[a] | (len v) > 0} -> a -}
-zooper :: [a] -> a
-zooper = undefined
diff --git a/tests/pos/meas00a.hs b/tests/pos/meas00a.hs
deleted file mode 100644
--- a/tests/pos/meas00a.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module Range () where
-
-import Language.Haskell.Liquid.Prelude
-
-prop0 = liquidAssertB True 
diff --git a/tests/pos/meas0a.hs b/tests/pos/meas0a.hs
deleted file mode 100644
--- a/tests/pos/meas0a.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Range () where
-
-import Language.Haskell.Liquid.Prelude
-
-goo x = let z = [x] in z
-
-z0 _  = True
-z1 _  = False
-
-poo (x:_) = True 
-poo ([])  = liquidAssertB False 
-
-xs = goo (choose 0)
-
-prop0 = liquidAssertB True 
-prop1 = liquidAssertB (poo xs)
diff --git a/tests/pos/meas1.hs b/tests/pos/meas1.hs
deleted file mode 100644
--- a/tests/pos/meas1.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Range () where
-
-import Control.Applicative
-import Language.Haskell.Liquid.Prelude
-
-goo x = [x]
-
-xs = goo (choose 0)
-
-nullity :: [a] -> Int
-nullity []    = 0
-nullity (x:_) = 1
-
-prop2 = liquidAssertB (1 == nullity xs) 
diff --git a/tests/pos/meas10.hs b/tests/pos/meas10.hs
deleted file mode 100644
--- a/tests/pos/meas10.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module Meas where
-
-import qualified Data.Set as S 
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ myrev :: xs:[a] -> {v:[a] | listElts v = listElts xs} @-}
-myrev :: [a] -> [a]
-myrev xs = go [] xs 
-   where 
-      go acc []     = acc
-      go acc (y:ys) = go (y:acc) ys
-
--- WHY DOES THIS JUST NOT GET ANY MEANINGFUL TYPE?
-{-@ goo :: xs:[a] -> ys:[a] -> {v:[a] | listElts v = S.union (listElts xs) (listElts ys) } @-}
-goo :: [a] -> [a] -> [a]
-goo acc []     = acc
-goo acc (y:ys) = unsafeError "foo" -- goRev (y:acc) ys
-
-{-@ emptySet :: a -> {v:[b] | listElts v == S.empty } @-}
-emptySet :: a -> [b]
-emptySet x = []
diff --git a/tests/pos/meas11.hs b/tests/pos/meas11.hs
deleted file mode 100644
--- a/tests/pos/meas11.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Meas () where
-
-import Data.Set (Set(..))
-
-{-@ myfilter :: (a -> Bool) -> xs:[a] -> {v:[a] | Set_sub (listElts v) (listElts xs) } @-}
-myfilter :: (a -> Bool) -> [a] -> [a]
-myfilter f []     = []
-myfilter f (x:xs) = if f x 
-                      then x : myfilter f xs 
-                      else myfilter f xs
-
diff --git a/tests/pos/meas2.hs b/tests/pos/meas2.hs
deleted file mode 100644
--- a/tests/pos/meas2.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Meas (n) where
-
-import Language.Haskell.Liquid.Prelude
-
-mylen :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-
-zs :: [Int]
-zs = [1..100]
-
-n  = mylen zs
-
diff --git a/tests/pos/meas4.hs b/tests/pos/meas4.hs
deleted file mode 100644
--- a/tests/pos/meas4.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-mymap f []     = []
-mymap f (x:xs) = (f x) : (mymap f xs)
-
-zs :: [Int]
-zs = [1..100]
-
-prop2 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ mymap (`plus` 1) zs 
diff --git a/tests/pos/meas5.hs b/tests/pos/meas5.hs
deleted file mode 100644
--- a/tests/pos/meas5.hs
+++ /dev/null
@@ -1,47 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ include <len.hquals> @-}
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-
-mymap f []     = []
-mymap f (x:xs) = (f x) : (mymap f xs)
-
-
-{-@ myreverse :: xs:_ -> {v:_ | len v = len xs} @-} 
-myreverse = go []
-  where 
-    {-@ go :: acc:_ -> xs:_ -> {v:_ | len v = len acc + len xs} @-}
-    go acc (x:xs) = go (x:acc) xs
-    go acc []     = acc
-    
-{-@ myapp :: xs:_ -> ys:_ -> {v:_ | len v = len xs + len ys} @-}
-myapp [] ys     = ys
-myapp (x:xs) ys = x:(myapp xs ys)
-
-zs :: [Int]
-zs = [1..100]
-
-zs' :: [Int]
-zs' = [500..1000]
-
-prop2 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ mymap (+ 1) zs 
-
-prop3 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ myreverse zs 
-
-prop4 = liquidAssertB ((n1 + n2) == n3) 
-  where n1 = mylen zs
-        n2 = mylen zs'
-        n3 = mylen $ myapp zs zs' 
-
-prop5 = liquidAssertB (length zs'' == length zs) 
-        where zs'' = safeZipWith (+) zs (myreverse zs)
diff --git a/tests/pos/meas6.hs b/tests/pos/meas6.hs
deleted file mode 100644
--- a/tests/pos/meas6.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-mymap f []     = []
-mymap f (x:xs) = (f x) : (mymap f xs)
-
-zs = [1..100]
-
-prop2 = liquidAssertB (n1 == n2) 
-  where n1 = mylen zs
-        n2 = mylen $ mymap (+ 1) zs 
diff --git a/tests/pos/meas7.hs b/tests/pos/meas7.hs
deleted file mode 100644
--- a/tests/pos/meas7.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-
-module Meas () where
-
--- some tests for the 'expandDefaultCase' trick to case-split 
--- on the "missing" constructors.
-
-
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-
-{-@ foo :: [a] -> {v: Int | v = 0} @-}
-foo :: [a] -> Int
-foo zs = case zs of
-           (x:xs) -> 0
-           _      -> mylen zs
-
-
-{-@ bar :: [a] -> {v: Int | v > 0} @-}
-bar :: [a] -> Int
-bar zs = case zs of
-           [] -> 1
-           _  -> mylen zs
-
diff --git a/tests/pos/meas8.hs b/tests/pos/meas8.hs
deleted file mode 100644
--- a/tests/pos/meas8.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Meas () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ include <len.hquals> @-}
-
-{-@ measure rlen :: [a] -> Int 
-      rlen []   = {v | v = 0}
-      rlen (y:ys) = {v | v = (1 + rlen(ys))}
-  @-}
-
-{-@ foo :: a -> {v:[b] | rlen(v) = 0} @-}
-foo x = []
-
-{-@ mylen :: xs:[a] -> {v:Int | v = rlen(xs)} @-}
-mylen          :: [a] -> Int
-mylen []       = 0
-mylen (_:xs)   = 1 + mylen xs
-
-{-@ mymap :: (a -> b) -> xs:[a] -> {v:[b] | rlen(v) = rlen(xs)} @-}
-mymap f []     = []
-mymap f (x:xs) = (f x) : (mymap f xs)
-
diff --git a/tests/pos/meas9.hs b/tests/pos/meas9.hs
deleted file mode 100644
--- a/tests/pos/meas9.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Meas () where
-
-import Data.Set (Set(..))
-
-{-@ myid :: xs:[a] -> {v:[a]| listElts(v) = listElts(xs)} @-}
-myid []     = []
-myid (x:xs) = x : myid xs
-
-{-@ myapp :: xs:[a] -> ys:[a] -> {v:[a] | listElts v = Set_cup (listElts xs) (listElts ys)} @-}
-myapp :: [a] -> [a] -> [a]
-myapp []     ys = ys
-myapp (x:xs) ys = x : myapp xs ys
-
-{-@ myrev :: xs:[a] -> {v:[a]| listElts v = listElts xs} @-}
-myrev :: [a] -> [a]
-myrev = go [] 
-  where 
-    go acc []     = acc
-    go acc (y:ys) = go (y:acc) ys
-
diff --git a/tests/pos/modTest.hs b/tests/pos/modTest.hs
deleted file mode 100644
--- a/tests/pos/modTest.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Goober () where
-
-import Language.Haskell.Liquid.Prelude (isEven)
-
-{-@ takeEvens :: [Int] -> [{v: Int | v mod 2 = 0}] @-}
-takeEvens :: [Int] -> [Int]
-takeEvens []     = []
-takeEvens (x:xs) = if isEven x
-                     then x : takeEvens xs 
-                     else takeEvens xs 
diff --git a/tests/pos/monad2.hs b/tests/pos/monad2.hs
deleted file mode 100644
--- a/tests/pos/monad2.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Monad () where
-
-goo c = return c
-
-foo = 
-  do x <- Just 1
-     y <- goo 3
-     return $ x + y 
diff --git a/tests/pos/monad5.hs b/tests/pos/monad5.hs
deleted file mode 100644
--- a/tests/pos/monad5.hs
+++ /dev/null
@@ -1,28 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude
-
--- gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x >= 0) (x + 1)
-
-gpp' z n = do x <- z n
-              return $ liquidAssert (x >= 0) (x + 1)
-
-
-myabs :: Int -> Int
-myabs x | x >= 0     = x
-        | otherwise  = 0-x
-
-myabsM :: Monad m => Int -> m Int
-myabsM x | x >= 0     = return $ x
-         | otherwise  = return $ 0-x
-
-
-posM :: Monad m => m Int
-posM = return $ myabs $ choose 0
-
-
-xM, yM :: Monad m => m Int
-yM = gpp posM
-xM = gpp' myabsM $ choose 0
diff --git a/tests/pos/monad6.hs b/tests/pos/monad6.hs
deleted file mode 100644
--- a/tests/pos/monad6.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Foo () where
-
-import Language.Haskell.Liquid.Prelude 
-
-{-@ gpp :: Monad m => m {v:Int|v>=0} -> m {v:Int|v>=0} @-}
-gpp :: Monad m => m Int -> m Int
-gpp z = do x <- z
-           return $ liquidAssert (x >= 0) (x + 1)
-
-
-xM :: [Int]
-xM = gpp [0]
diff --git a/tests/pos/multi-pred-app-00.hs b/tests/pos/multi-pred-app-00.hs
deleted file mode 100644
--- a/tests/pos/multi-pred-app-00.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Blank () where
-
-{-@ foo :: forall < p :: Int -> Bool
-                  , q :: Int -> Bool >. Int<p,q> -> Int<p> @-}
-foo :: Int -> Int
-foo x = x
diff --git a/tests/pos/mutrec.hs b/tests/pos/mutrec.hs
deleted file mode 100644
--- a/tests/pos/mutrec.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module MutRec () where
-
-{-@ isEven :: n:Nat -> Bool / [n, 0] @-}
-isEven :: Int -> Bool
-isEven 0 = True
-isEven n = isOdd (n-1)
-
-{-@ isOdd :: n:Nat -> Bool / [n, 1] @-}
-isOdd :: Int -> Bool
-isOdd  n = not $ isEven n
-
-
-{- decrease isEven 1 2 -}
-{- decrease isOdd 1 2  -}
diff --git a/tests/pos/nats.hs b/tests/pos/nats.hs
deleted file mode 100644
--- a/tests/pos/nats.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module Nats where 
-
-{-@ nats :: [Nat] @-}
-nats :: [Int]
-nats = [1,2,3,4,5,6,7,8,9,10]
diff --git a/tests/pos/niki.hs b/tests/pos/niki.hs
deleted file mode 100644
--- a/tests/pos/niki.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Niki () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P (x :: a) (y :: b<p x>) @-} 
-data Pair a b = P a b
-
-bar = P (0::Int) (1::Int)
-foo = chk bar
-
-chk (P x1 y1) = liquidAssertB (x1 <= y1)
diff --git a/tests/pos/niki1.hs b/tests/pos/niki1.hs
deleted file mode 100644
--- a/tests/pos/niki1.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Niki () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P (px :: a) (py :: b<p px>) @-} 
-data Pair a b = P a b
-
-incr :: Int -> Int
-incr x = x + 1
-
-baz :: Int -> Pair Int Int
-baz x = P x (incr x)
-
-prop :: Bool
-prop = chk (baz n)
-  where n = choose 100
-{-
-foo = baz n
- where n = choose 10
--}
-chk :: Pair Int Int -> Bool
-chk (P x y) = liquidAssertB (x < y)
-
diff --git a/tests/pos/null.hs b/tests/pos/null.hs
deleted file mode 100644
--- a/tests/pos/null.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Foo where
-
-foo :: [a] -> [a]
-foo xs = if null xs then [] else tail xs
diff --git a/tests/pos/pair.hs b/tests/pos/pair.hs
deleted file mode 100644
--- a/tests/pos/pair.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-module Pair () where 
-
-import Language.Haskell.Liquid.Prelude 
-
-{-@ data Pair a b <p :: x0:a -> x1:b -> Bool> = P { px :: a, py :: b<p px> } @-} 
-data Pair a b = P a b
-
-incr x = let p = P x ((x+1)) in p
-chk (P x (y)) = liquidAssertB (x<y) 
-prop  = chk $ incr n
-  where n = choose 0
-
-incr2 x = 
-  let p1 = (P True (x+1)) in 
-  let p2 = P x p1 in 
-   p2
-chk2 (P x w) = 
-   case w of (P z y) -> liquidAssertB (x<y) 
-prop2  = chk2 $ incr2 n
-  where n = choose 0
-
-incr3 x = P x (P True (P 0 (x+1)))
-chk3 (P x (P _(P _ y))) = liquidAssertB (x<y) 
-prop3  = chk3 $ incr3 n
-  where n = choose 0
diff --git a/tests/pos/pair0.hs b/tests/pos/pair0.hs
deleted file mode 100644
--- a/tests/pos/pair0.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-module Pair () where 
-
-{-@ LIQUID "--no-termination" @-}
-import Language.Haskell.Liquid.Prelude 
-
-data Pair a b = P a b
-
-
-incr x = (x, x+1)
-chk (x, y) = liquidAssertB (x <y) 
-prop  = chk $ incr n
-  where n = choose 0
-
-incr2 x = (x, True, x+1)
-chk2 (x, _, y) = liquidAssertB (x <y) 
-prop2  = chk2 $ incr2 n
-  where n = choose 0
-
-incr3 x = (x, (True, (0, x+1)))
-chk3 (x, (_, (_, y))) = liquidAssertB (x <y) 
-prop3  = chk3 $ incr3 n
-  where n = choose 0
diff --git a/tests/pos/pair00.hs b/tests/pos/pair00.hs
deleted file mode 100644
--- a/tests/pos/pair00.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-module Pair () where
-
-{-@ LIQUID "--no-termination" @-}
-
-import Language.Haskell.Liquid.Prelude
-
-incr z = (x, [x + 1])
-  where
-    x  = choose z
-chk (x, [y]) = liquidAssertB (x < y)
-prop  = chk $ incr n
-  where
-    n = choose 0
-
-incr2 pig = (True, 9, pig, 'o', pig + 1)
-
-chk2 (_, _, cow, _,  dog) = liquidAssertB (cow < dog)
-
-prop2  = chk2 $ incr2 mouse
-  where mouse = choose 0
-
-incr3 x = (x, ( (0, x+1)))
-chk3 (x, ((_, y))) = liquidAssertB (x < y)
-prop3  = chk3 (incr3 n)
- where n = choose 0
diff --git a/tests/pos/pargs.hs b/tests/pos/pargs.hs
deleted file mode 100644
--- a/tests/pos/pargs.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Foo () where
-
-{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-             (i:Int -> a<p i>) -> {v:Int| v=0}
-              -> a <p 0>
-  @-}
-
-foo ::  (Int -> a) -> Int ->  a
-foo f i = f i
-
diff --git a/tests/pos/pargs1.hs b/tests/pos/pargs1.hs
deleted file mode 100644
--- a/tests/pos/pargs1.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-{-@ LIQUID "--pruneunsorted" @-}
-module Foo () where
-
-{-@ foo :: forall a <p :: x0:Int -> x1:a -> Bool>. 
-             (i:Int  -> j : Int-> a<p (i+j)>) -> 
-               ii:Int -> jj:Int
-              -> a <p (ii+jj)>
-  @-}
-
-foo ::  (Int -> Int -> a) -> Int -> Int ->  a
-foo f i j = f i j
-
diff --git a/tests/pos/partial-tycon.hs b/tests/pos/partial-tycon.hs
deleted file mode 100644
--- a/tests/pos/partial-tycon.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Foo () where
-
-data Id a = Id a
-
-data Foo m a = Foo (m a)
-
-foo :: Foo Id a
-foo = undefined
diff --git a/tests/pos/partialmeasure.hs b/tests/pos/partialmeasure.hs
deleted file mode 100644
--- a/tests/pos/partialmeasure.hs
+++ /dev/null
@@ -1,28 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-module Head where
-
--- Note: `partialmeasureOld.hs` works fine 
-
-{-@ cons :: x:a -> _ -> {v:[a] | hd v = x} @-}
-cons x xs = x : xs
-
-{-@ test :: {v:_ | hd v = 0} @-}
-test :: [Int]
-test =  cons 0 [1,2,3,4]
-
-{-@ measure hd @-}
-hd       :: [a] -> a
-hd (x:_) = x
-
-
--- Instead of rejecting, can we just default to "un-refined" constructors?
-
--- Strengthened constructors
---   data [a] where
---     []  :: [a]    -- as before
---     (:) :: x:a -> xs:[a] -> {v:[a] | hd v = x}
-
-
-
-
diff --git a/tests/pos/ple1.hs b/tests/pos/ple1.hs
deleted file mode 100644
--- a/tests/pos/ple1.hs
+++ /dev/null
@@ -1,52 +0,0 @@
-{-@ LIQUID "--reflection" @-} 
-
-module PLE where
-
-import Prelude hiding ((++))
-import Language.Haskell.Liquid.ProofCombinators
-
-assocThm :: (Eq a) => [a] -> [a] -> [a] -> Bool
-assocProof :: [a] -> [a] -> [a] -> Proof
-
-{-@ infix ++ @-}
-
-{-@ reflect ++ @-}
-(++) :: [a] -> [a] -> [a]
-[]     ++ ys = ys
-(x:xs) ++ ys = x : (xs ++ ys)
-
-{-@ inline assocThm @-}
-assocThm xs ys zs = (xs ++ ys) ++ zs == xs ++ (ys ++ zs)
-
-{-@ assocProof :: xs:[a] -> ys:[a] -> zs:[a] -> { assocThm xs ys zs } @-}
-assocProof []     ys zs
-  =   ([] ++ ys) ++ zs
-  === [] ++ (ys ++ zs)
-  *** QED
-
-assocProof (x:xs) ys zs
-  =   ((x:xs) ++ ys) ++ zs
-  === (x : (xs ++ ys)) ++ zs
-  === x : ((xs ++ ys) ++ zs)
-    ? assocProof xs ys zs
-  === x : (xs ++ (ys ++ zs)) 
-  === (x:xs) ++ (ys ++ zs)
-  ***  QED
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
----
diff --git a/tests/pos/poly0.hs b/tests/pos/poly0.hs
deleted file mode 100644
--- a/tests/pos/poly0.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-myabs x    = if x > 0 then x else 0 - x
-
-myid arg   = arg
-
-----------------------------------------------------------
-
-x = choose 0
-
-prop_id1 = let x'  = myabs x in 
-           let x'' = myid x' in 
-           liquidAssertB (x'' >= 0)
-
-prop_id2 = liquidAssertB (x'' >= 0)
-  where x'  = myabs x 
-        x'' = myid x' 
-
-prop_id3 = liquidAssertB (x' >= 0)
-  where x' = myid $ myabs x
diff --git a/tests/pos/poly1.hs b/tests/pos/poly1.hs
deleted file mode 100644
--- a/tests/pos/poly1.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x > 0 then x else (0 - x)
-
-myid2 a b  = a  
-
-----------------------------------------------------------
-
-x =  choose 0
-
-prop_id4 = let x'  = myabs x in 
-           let x'' = myid2 x' [] in 
-           liquidAssertB (x'' >= 0) 
-
-prop_id5 = liquidAssertB (x'' >= 0)
-  where x'  = myabs x 
-        x'' = myid2 x' [] 
diff --git a/tests/pos/poly2-degenerate.hs b/tests/pos/poly2-degenerate.hs
deleted file mode 100644
--- a/tests/pos/poly2-degenerate.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Poly0 (prop_id6) where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-----------------------------------------------------------
-
-myid3 x y  = y
-
-prop_id6 x = liquidAssertB (x' `geq` 0)
-  where x' = myid3 [] $ myabs x 
-
-
diff --git a/tests/pos/poly2.hs b/tests/pos/poly2.hs
deleted file mode 100644
--- a/tests/pos/poly2.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Poly0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-----------------------------------------------------------
-
-myid3 x y  = y
-
-x = choose 0 
-
-prop_id6 = liquidAssertB (x' `geq` 0)
-  where x' = myid3 [] $ myabs x 
diff --git a/tests/pos/poly3.hs b/tests/pos/poly3.hs
deleted file mode 100644
--- a/tests/pos/poly3.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Meas (goo) where
-
-expand          :: (a -> [b]) -> [a] -> [b]
-expand f []     = []
-expand f (x:xs) = (f x) ++ (expand f xs)
-
-baz :: a -> [Int]
-baz _ = [0]
-
-goo = expand baz
-
diff --git a/tests/pos/poly3a.hs b/tests/pos/poly3a.hs
deleted file mode 100644
--- a/tests/pos/poly3a.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Meas (goo) where
-
-expand f []     = []
-expand f (x:xs) = (f x) ++ (expand f xs)
-
-baz :: a -> [Int]
-baz _ = [0]
-
-goo = expand baz
-
diff --git a/tests/pos/poly4.hs b/tests/pos/poly4.hs
deleted file mode 100644
--- a/tests/pos/poly4.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Poly4 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x     = choose 0
-
-baz y = y
-
-prop  = liquidAssertB (baz True)
diff --git a/tests/pos/polyfun.hs b/tests/pos/polyfun.hs
deleted file mode 100644
--- a/tests/pos/polyfun.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Poly4 () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo :: a -> [Int]
-foo f = [0]
-
-prop  = all (\z -> liquidAssertB (z >= 0)) zs
-          where zs = foo id 
diff --git a/tests/pos/polyqual.hs b/tests/pos/polyqual.hs
deleted file mode 100644
--- a/tests/pos/polyqual.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-module Poo (nearestCenter) where
-
-import Data.List (minimumBy)
-
-data WrapType b a = WrapType {getVect :: b, getVal :: a}
-
-{-@ type List a N     = {v : [a] | (len v) = N} @-}
-{-@ type Point N      = List Double N           @-}
-{-@ type GenPoint a N = WrapType (Point N) a    @-}
-
-
-{-@ nearestCenter :: n:Int -> (GenPoint a n) -> [(Point n)] -> (Point n) @-} 
-nearestCenter     :: Int -> WrapType [Double] a -> [[Double]] -> [Double] 
-nearestCenter n x = minKey . map (\c -> (c, distance c (getVect x)))
-
-minKey  :: (Ord v) => [(k, v)] -> k
-minKey  = fst . minimumBy (\x y -> compare (snd x) (snd y)) 
-
-{- distance :: a:[Double] -> {v:[Double] | (len v) = (len a)} -> Double -}
-distance     :: [Double] -> [Double] -> Double 
-distance a b = sqrt . sum $ safeZipWith (\v1 v2 -> (v1 - v2) ^ 2) a b
-
-{-@ safeZipWith :: (a -> b -> c) -> xs:[a] -> (List b (len xs)) -> (List c (len xs)) @-}
-safeZipWith f (a:as) (b:bs) = f a b : safeZipWith f as bs
-safeZipWith _ [] []         = []
-
-
diff --git a/tests/pos/poslist.hs b/tests/pos/poslist.hs
deleted file mode 100644
--- a/tests/pos/poslist.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Poslist () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-
-absList xs = map myabs xs
-
-prop1 = map (liquidAssertB . (`geq` 0)) $ absList $ map choose [1..]
-
-
-numAbs x   = if x > 0 then x else (0 - x)
-
-numAbsList = map numAbs 
-
-prop2      = map (liquidAssertB . (>= 0)) $ numAbsList $ map choose [1..]
diff --git a/tests/pos/poslist_dc.hs b/tests/pos/poslist_dc.hs
deleted file mode 100644
--- a/tests/pos/poslist_dc.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Poslist () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x    = if x `gt` 0 then x else 0 `minus` x
-----------------------------------------------------------
-
-checkPos [] = True
-checkPos (z:zs) = liquidAssertB (z `geq` 0) &&  (checkPos zs)
-
-xs   = [-100..100]
-prop = checkPos $ map myabs xs
diff --git a/tests/pos/pragma0.hs b/tests/pos/pragma0.hs
deleted file mode 100644
--- a/tests/pos/pragma0.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-{-@ LIQUID "--notermination" @-}
-
-module Test0 where
-
-
--- an obviously non-terminating function
-zoo   :: Int -> Int
-zoo x = zoo x
diff --git a/tests/pos/pred.hs b/tests/pos/pred.hs
deleted file mode 100644
--- a/tests/pos/pred.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Foo () where
-
-{-@ predicate Lt X Y = X < Y        @-}
-{-@ predicate Ge X Y = not (Lt X Y) @-}
-{-@ predicate Pos X  = X > 0        @-}
-
-{-@ incr :: x:{v:Int | (Pos v)} -> { v:Int | ((Pos v) && (Ge v x))} @-}
-incr :: Int -> Int
-incr x = x + 1
diff --git a/tests/pos/primInt0.hs b/tests/pos/primInt0.hs
deleted file mode 100644
--- a/tests/pos/primInt0.hs
+++ /dev/null
@@ -1,48 +0,0 @@
-{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP,  MagicHash #-}
-{-# OPTIONS_HADDOCK hide #-}
-
-module PrimInt (ptake, mtake, ztake, itake) where
-
-import Data.Maybe
-import GHC.Base
-
-{-@ ztake  :: n: {v: Int# | 0 <= v} -> {v: Int | v = n } @-}
-ztake :: Int# -> Int
-ztake 0# = 0
-ztake n# = 1 + ztake (n# -# 1#)
-
-{-@ itake  :: n: {v: Int | 0 <= v} -> {v: Int | v = n } @-}
-itake :: Int -> Int
-itake 0 = 0
-itake n = 1 + itake (n - 1)
-
-{-@ ptake  :: n: {v: GHC.Prim.Int# | 0 <= v} -> {v:[a] | ((len v) >= n)} -> {v:[a] | (len(v) = n)} @-}
-ptake :: Int# -> [a] -> [a]
-ptake 0# _      = []
-ptake n# (x:xs) = x : ptake (n# -# 1#) xs
-
-{-@ mtake  :: n: {v: Int | 0 <= v} -> {v:[a]|((len v) >= n)} -> {v:[a] | (len(v) = n)} @-}
-mtake          :: Int -> [a] -> [a]
-mtake 0 _      = []
-mtake n (x:xs) = x : mtake (n - 1) xs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/pos/profcrasher.hs b/tests/pos/profcrasher.hs
deleted file mode 100644
--- a/tests/pos/profcrasher.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x :: Int
-x = 4
diff --git a/tests/pos/propmeasure.hs b/tests/pos/propmeasure.hs
deleted file mode 100644
--- a/tests/pos/propmeasure.hs
+++ /dev/null
@@ -1,59 +0,0 @@
-{-# LANGUAGE EmptyDataDecls #-}
-
-module BoolMeasure where
-
-import Prelude hiding (length)
-
-{-@ myhead :: {v:[a] | nonEmpty v} -> a @-}
-myhead (x:_) = x
-
-{-@ measure nonEmpty @-}   
-nonEmpty (x:xs) = True 
-nonEmpty []     = False
-
-{-@ measure length @-}   
-length :: [a] -> Int
-length (x:xs) = 1 + length xs 
-length []     = 0
-
-
-{-@ measure lenEqFive @-}   
-lenEqFive (x:xs) = length xs == 4
-lenEqFive []     = False
-
-{-@ measure lenNEqFive @-}   
-lenNEqFive (x:xs) = not (length xs == 4)
-lenNEqFive []     = True
-
-
-{-@ measure lenGEFour @-}   
-lenGEFour (x:xs) = length xs >= 3
-lenGEFour []     = False
-
-
-{-@ len3 :: {v:[Int] | (not (lenEqFive v))} @-}
-len3 :: [Int]
-len3 = [1, 2, 3]
-
-
-{-@ len5 :: {v:[Int] | (lenEqFive v) && (lenGEFour v) } @-}
-len5 :: [Int]
-len5 = [1, 2, 3, 4, 5]
-
-{-@ measure length @-}
-
-{-@ foo  :: x:[a] -> {v: Bool | v <=> (nonEmpty x) } @-}
-foo  :: [a] -> Bool
-foo x = nonEmpty x
-
-
-cons = (:)
-nil  = []
-
-
-
-
-
-
-
-
diff --git a/tests/pos/propmeasure1.hs b/tests/pos/propmeasure1.hs
deleted file mode 100644
--- a/tests/pos/propmeasure1.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module BoolMeasure where
-
-nil  = []
-
-
-
-
-
-
-
-
diff --git a/tests/pos/qualTest.hs b/tests/pos/qualTest.hs
deleted file mode 100644
--- a/tests/pos/qualTest.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module QT () where
-
--- this test demonstrates the inclusion of qualifiers in source files
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ qualif Plus100(v:Int, a:Int): (v = a + 100) @-}
- 
-incr :: Int -> Int
-incr x = x + 100
-
-prop = liquidAssert (y == 100) y
-  where 
-    y  = incr 0 
diff --git a/tests/pos/range.hs b/tests/pos/range.hs
deleted file mode 100644
--- a/tests/pos/range.hs
+++ /dev/null
@@ -1,31 +0,0 @@
-module Range (prop_rng5, myfoldl) where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ invariant {v:Int| v >= 0} @-}
-
-range :: Int -> Int -> [Int]
-range i j = range' (j - i) i j
-
-range' :: Int -> Int -> Int -> [Int]
-range' d i j  
-  | i < j     = i : (range' (d-1) (i + 1) j)
-  | otherwise = []  
-
-
-sumTo = foldl (+) 0 . range 0 
-
-{-@ decrease lgo 2 @-}
---myfoldl :: (Int -> Int -> Int) -> Int -> [Int] -> Int
-myfoldl f z0 xs0 = lgo z0 xs0
-             where
-                lgo z []     =  z
-                lgo z (x:xs) = lgo (f z x) xs
-n = choose 0 
-m = choose 1
-
--- prop_rng1 = map (liquidAssertB . (0 <=)) $ range 0 n
--- prop_rng2 = map (liquidAssertB . (n <=)) $ range n 100
--- prop_rng3 = map (liquidAssertB . (n <=)) $ range n m
--- prop_rng4 = map (liquidAssertB . (<= m)) $ range n m 
-prop_rng5 = liquidAssertB (0 <= sumTo n)
diff --git a/tests/pos/range1.hs b/tests/pos/range1.hs
deleted file mode 100644
--- a/tests/pos/range1.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Range (single, prop_rng1) where
-
-import Language.Haskell.Liquid.Prelude
-
-mynil  = []
-
-single x = [x] 
-
-range :: Int -> Int -> [Int]
-range i j = [i]
-
-prop_rng1 n   = map (liquidAssertB . (0 <=)) $ range 0 n
diff --git a/tests/pos/rangeAdt.hs b/tests/pos/rangeAdt.hs
deleted file mode 100644
--- a/tests/pos/rangeAdt.hs
+++ /dev/null
@@ -1,37 +0,0 @@
-module Range (llen) where
-
-import Language.Haskell.Liquid.Prelude
-
-data L a = Nil | Con a (L a)
-{-@ data L [llen] a = Nil | Con { lHd ::a, lTl :: L a } @-}
-
-{-@ measure llen @-}
-{-@ llen :: L a -> Nat @-}
-llen :: L a -> Int 
-llen Nil = 0 
-llen (Con _ xs) = 1 + llen xs 
-
-range :: Int -> Int -> L Int
-range i j = range' (j-i) i j
-
-range' :: Int -> Int -> Int -> L Int
-range' d i j
-  | i < j  = i `Con` (range' (d-1) (i + 1) j)
-  | otherwise = Nil
-
-mapL f Nil        = Nil
-mapL f (Con x xs) = (f x) `Con` (mapL f xs)
-
-foldL f b Nil        = b
-foldL f b (Con x xs) = foldL f (f b x) xs
-
-sumTo = foldL plus 0 . range 0
-
-n = choose 0
-m = choose 1
-
-prop_rng1 = mapL (liquidAssertB . (0 <=)) $ range 0 n
-prop_rng2 = mapL (liquidAssertB . (n <=)) $ range n 100
-prop_rng3 = mapL (liquidAssertB . (n <=)) $ range n m
-prop_rng4 = mapL (liquidAssertB . (<= m)) $ range n m
-prop_rng5 = liquidAssertB (0 <= sumTo n)
diff --git a/tests/pos/rec_annot_go.hs b/tests/pos/rec_annot_go.hs
deleted file mode 100644
--- a/tests/pos/rec_annot_go.hs
+++ /dev/null
@@ -1,18 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-
-module Fixme () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-{-@ invariant {v:Int | v >= 0} @-}
-
-{-@ decrease go 1 @-}
-loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
-loop lo hi base f = go (hi-lo) base lo
-  where
-    go (d::Int) acc i     
-      | i /= hi   = go (d-1) (f i acc) (i + 1)
-      | otherwise = acc
-
-poo = loop 0 10 0 (+)
-
diff --git a/tests/pos/record0.hs b/tests/pos/record0.hs
deleted file mode 100644
--- a/tests/pos/record0.hs
+++ /dev/null
@@ -1,25 +0,0 @@
-{-@ LIQUID "--exact-data-cons" @-}
-
-module Rec0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ data LL a = BXYZ { size  :: {v: Int | v > 0 }
-                     , elems :: {v: [a] | (len v) = size }
-                     }
-  @-}
-
-data LL a = BXYZ { size  :: Int
-                 , elems :: [a]
-                 }
-
-{-@ mk :: a -> Int -> LL a @-}
-mk x n | n > 0     = BXYZ n (clone x n)
-       | otherwise = BXYZ 1 [x]
-
-{-@ bk :: LL a -> {v: Int | v > 0} @-}
-bk (BXYZ n xs) = liquidAssert (length xs == n) n
-
-{-@ clone :: x:a -> n:Int -> {v:[a]| (len v) = n} @-}
-clone :: a -> Int -> [a]
-clone = unsafeError "FOO"
diff --git a/tests/pos/record1.hs b/tests/pos/record1.hs
deleted file mode 100644
--- a/tests/pos/record1.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Data.Map.Base (trim) where
-
-data Map k a  = Tip
-
-{-@ data Map k a <l :: root:k -> k -> Bool>
-         = Tip
-  @-}
-
-{-@ measure isBin @-}
-isBin :: Map k a -> Bool
-isBin Tip = False
-
-trim :: Map k a
-trim = undefined 
-
diff --git a/tests/pos/recursion0.hs b/tests/pos/recursion0.hs
deleted file mode 100644
--- a/tests/pos/recursion0.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Recursion where
-
-
-{-@ total :: Nat -> Nat @-}
-total :: Int -> Int 
-total 0 = 0
-total n = 1 + total (n-1)
-
diff --git a/tests/pos/reflect0.hs b/tests/pos/reflect0.hs
deleted file mode 100644
--- a/tests/pos/reflect0.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-{-@ LIQUID "--higherorder"     @-}
-
-module FunctionAbstraction where
-
-{-@ fib :: n:Nat -> Nat @-}
-{-@ reflect fib @-}
-fib :: Int -> Int
-fib n
-  | n == 0    = 0
-  | n == 1    = 1
-  | otherwise = fib (n-1) + fib (n-2)
-
-
-{-@ goo :: Nat -> Nat @-}
-goo :: Int -> Int
-goo x = fib x
diff --git a/tests/pos/repeatHigherOrder.hs b/tests/pos/repeatHigherOrder.hs
deleted file mode 100644
--- a/tests/pos/repeatHigherOrder.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
--- TAG: bound 
--- TAG: absref 
-
-module Repeat where
-
-import Prelude hiding (repeat, succ)
-import Language.Haskell.Liquid.Prelude
-
-repeat :: Int -> (a -> a) -> a -> a
-goal   :: Int -> Int
-     
-{-@ bound step @-}
-step :: (a -> a -> Bool) -> (Int -> a -> Bool) -> Int -> a -> a -> Bool
-step pf pr = \ i x x' -> pr (i - 1) x ==> pf x x' ==> pr i x'
-
--- This syntax is not yet supported in liquidhaskell-8
-{- repeat :: forall a <f :: a -> a -> Bool, r :: Int -> a -> Bool>.
-                (Step a f r) => 
-                 n:Nat -> (y:a -> a<f y>) -> a<r 0> -> a<r n>
-  @-}
-
-
-{-@ repeat :: forall a <f :: a -> a -> Bool, r :: Int -> a -> Bool>.
-                {i::Int, x::a<r (i-1)>|- a<f x> <:a <r i>}
-                 n:Nat -> (y:a -> a<f y>) -> a<r 0> -> a<r n>
-  @-}
-repeat 0 _ x = x
-repeat n f x = repeat (n - 1) f (f x)
-
-{-@ goal :: n:Nat -> {r:Nat | n <= r} @-}
-goal n = repeat n (+ 1) 0
-
diff --git a/tests/pos/risers.hs b/tests/pos/risers.hs
deleted file mode 100644
--- a/tests/pos/risers.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Risers () where
-
-{-@ predicate NonNull X = ((len X) > 0) @-}
-
-{-@ risers :: (Ord a) => zs:[a] -> {v: [[a]] | ((NonNull zs) => (NonNull v)) } @-} 
-risers []        
-  = []
-risers [x]       
-  = [[x]]
-risers (x:y:etc) 
-  = if x <= y then (x:s):ss else [x]:(s:ss)
-    where (s:ss) = risers (y:etc)
diff --git a/tests/pos/rta.hs b/tests/pos/rta.hs
deleted file mode 100644
--- a/tests/pos/rta.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module RTA where
-
-{-@ predicate Mouse X Y = X > Y @-}
-
-{-@ inline mickey @-}
-mickey :: (Ord a) => a -> a -> Bool
-mickey x y = x > y
-
-{-@ type PosInline    a N = {v:a | mickey v N} @-}
-
-{-@ type PosPredicate a N = {v:a | Mouse v N} @-}
-
-{-@ incrI :: PosInline Int 0 -> PosInline Int 0 @-}
-incrI :: Int -> Int
-incrI x = x + 1
-
-{-@ incrP :: PosPredicate Int 0 -> PosPredicate Int 0 @-}
-incrP :: Int -> Int
-incrP x = x + 1
diff --git a/tests/pos/scanr.hs b/tests/pos/scanr.hs
deleted file mode 100644
--- a/tests/pos/scanr.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Goo () where
-
-{-@ scanrr  :: (a -> b -> b) -> b -> xs:[a] -> {v: [b] | len v = 1 + len xs } @-}
--- scanrr             :: (a -> b -> b) -> b -> [a] -> [b]
-scanrr _ q0 []     =  [q0]
-scanrr f q0 (x:xs) =  f x q : qs
-                      where qs@(q:_) = scanrr f q0 xs 
diff --git a/tests/pos/selfList.hs b/tests/pos/selfList.hs
deleted file mode 100644
--- a/tests/pos/selfList.hs
+++ /dev/null
@@ -1,26 +0,0 @@
-module Foo () where
-
-{-@ LIQUID "--bscope" @-}
-
-import Data.Set (Set(..)) 
-
-{-@ include <selfList.hquals> @-}
-
-{-@ invariant {v0:[{v: a | (Set_mem v (listElts v0))}] | true } @-}
-
-{-@ type IList a  = {v0: [{v:a | (Set_mem v (listElts v0))}] | true } @-}
-
-{-@ moo :: [a] -> IList a @-}
-moo []     = [] 
-moo (_:xs) = xs
-
-goo []     = [] 
-goo (_:xs) = xs
-
-{-@ poo :: IList Int @-}
-poo = goo xs
-  where 
-    xs :: [Int]
-    xs = [2,1,3,2]
-
-
diff --git a/tests/pos/spec0.hs b/tests/pos/spec0.hs
deleted file mode 100644
--- a/tests/pos/spec0.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ assert incr :: x:{v: Int | v >= 0} -> {v: Int | v > x} @-}
-incr   :: Int -> Int
-incr x = x + 1
-
-myabs x = if x >= 0 then incr x else (0 - x)
-
-prop_abs   = let n1 = choose 0 in 
-             liquidAssertB ((myabs n1) >= 0)	
diff --git a/tests/pos/stacks0.hs b/tests/pos/stacks0.hs
deleted file mode 100644
--- a/tests/pos/stacks0.hs
+++ /dev/null
@@ -1,48 +0,0 @@
-module StackSet () where
-
-import qualified Data.Set as S -- (Set(..))
-
-data LL a = Nil | Cons { headC :: a
-                       , tailC :: LL a
-                       }
-
-{-@ data LL a = Nil | Cons { headC :: a
-                           , tailC :: {v: LL a | not (Set_mem headC (elts v)) }
-                           }
-  @-}
-
-{-@ measure elts @-} 
-elts :: (Ord a) => LL a -> S.Set a
-elts (Nil)       = S.empty
-elts (Cons x xs) = S.union (S.singleton x) (elts xs)
-
-{-@ predicate Disjoint X Y = (Set_emp (Set_cap (elts X) (elts Y))) @-}
-{-@ predicate NotIn    X Y = not (Set_mem X (elts Y))              @-}
-
-ll2 = Cons x0 (Cons x1 (Cons x2 Nil))
-  where x0 :: Int
-        x0  = 0
-        x1  = 1
-        x2  = 2
-
-{-@ data Stack a = St { focus  :: a
-                      , up     :: {vu: LL a | (NotIn focus vu) }
-                      , down   :: {vd: LL a | ((NotIn focus vd) && (Disjoint up vd)) }
-                      }
-  @-}
-
-data Stack a = St { focus  :: !a
-                  , up     :: !(LL a)
-                  , down   :: !(LL a)
-                  }
-
-{-@ fresh :: a -> Stack a @-}
-fresh x = St x Nil Nil
-
-{-@ moveUp :: Stack a -> Stack a @-}
-moveUp (St x (Cons y ys) zs) = St y ys (Cons x zs)
-moveUp s                     = s
-
-{-@ moveDn :: Stack a -> Stack a @-}
-moveDn (St x ys (Cons z zs)) = St z (Cons x ys) zs
-moveDn s                     = s
diff --git a/tests/pos/state00.hs b/tests/pos/state00.hs
deleted file mode 100644
--- a/tests/pos/state00.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module StateMonad () where
-
-type State  = Int
-data ST a b = Superb (b -> (a, b)) 
-
-{-@ fresh :: ST {v:Int | v >= 0} {v:Int | v >= 0} @-}
-fresh :: ST Int Int
-fresh = Superb (\n -> (n, n+1))
-
-
diff --git a/tests/pos/stateInvarint.hs b/tests/pos/stateInvarint.hs
deleted file mode 100644
--- a/tests/pos/stateInvarint.hs
+++ /dev/null
@@ -1,43 +0,0 @@
-module StateMonad () where
-
-import Prelude hiding (return, (>>=))
-
-data ST s a = S (s -> (a, s))
-{-@ data ST s a <p :: s -> Bool> 
-     = S { x:: (f:s<p> -> (a, s<p>)) } 
-  @-}
-
-{-@ foo :: (Int, {v:Int|v >=0})@-}
-foo = apply action 0
-
-{-@ action :: ST <{\v -> v>=0 }> Int Int@-}
-action :: ST Int Int
-action
- = act1 `comp` \n1 -> 
-   act2 `comp` \n2 -> 
-   return n1
-
-
-{-@ act1 :: ST <{\v -> v>=0 } > Int Int @-}
-act1 :: ST Int Int
-act1 = S (\n -> (n, n+1))
-
-act2 :: ST Int Int
-act2 = S (\n -> (n, n+9))
-
-{-@ apply :: forall <p :: s -> Bool>. ST <p> s a -> f:s<p> -> (a, s <p>) @-}
-apply :: ST s a -> s -> (a, s)
-apply (S f) x = f x
-
-{-@ return :: forall <p:: s -> Bool>. x:a -> ST <p> s {v:a|v=x} @-}
-return ::  a -> ST s a
-return x = S $ \s -> (x, s)
-
-{-@ comp :: forall < p :: s -> Bool>. ST <p> s a -> (a -> ST <p> s b) -> ST <p> s b @-}
-comp :: ST s a -> (a -> ST s b) -> ST s b
-(S m) `comp` k 
-  = S $ \s -> case (m s) of { (r, new_s) -> 
-              case (k r) of { S k2 -> 
-                (k2 new_s) }}
-
-
diff --git a/tests/pos/string00.hs b/tests/pos/string00.hs
deleted file mode 100644
--- a/tests/pos/string00.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Str0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-foo = "dog"
-
-prop1 = liquidAssertB (0 == 0)	
-prop2 = liquidAssertB (1 /= 0)
diff --git a/tests/pos/tagBinder.hs b/tests/pos/tagBinder.hs
deleted file mode 100644
--- a/tests/pos/tagBinder.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module ListSort () where
-
-data Foo a = F Int a
-
-{-@ data Foo a = F {tag :: Int, f :: a} @-}
-
-foo = F
diff --git a/tests/pos/take.hs b/tests/pos/take.hs
deleted file mode 100644
--- a/tests/pos/take.hs
+++ /dev/null
@@ -1,60 +0,0 @@
-{-@ LIQUID "--no-totality"    @-}
-
-{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP,  NoImplicitPrelude, MagicHash #-}
-{-# OPTIONS_HADDOCK hide #-}
-
-module Take (
-    take0
-  , take
-  ) where
-
-import Data.Maybe
-import GHC.Base 
-import Language.Haskell.Liquid.Prelude (liquidAssert, liquidError, unsafeError) 
-
-
-
-{-@ assert take0  :: n: {v: Int | 0 <= v} -> [a] -> {v:[a] | (len(v) = n)} @-}
-take0 :: Int -> [a] -> [a]
-take0 (I# n#) xs = take_unsafe_UInt0 n# xs
-
-take_unsafe_UInt0 :: Int# -> [a] -> [a]
-take_unsafe_UInt0 0#  _     = []
-take_unsafe_UInt0 n  (x:xs) = x : take_unsafe_UInt0 (n -# 1#) xs
-take_unsafe_UInt0 _   _     = unsafeError "unsafe take"
-
-{-@ assert take  :: n: {v: Int | v >= 0 } -> xs:[a] -> {v:[a] | len v = if len xs < n then (len xs) else n } @-}
-take (I# n#) xs = takeUInt n# xs
--- take (I# n#) xs = take_unsafe_UInt n# xs
-
-takeUInt :: Int# -> [a] -> [a]
-takeUInt n xs
-  | isTrue# (n >=# 0#) =  take_unsafe_UInt n xs
-  | otherwise          =  liquidAssert False []
-
-take_unsafe_UInt :: Int# -> [a] -> [a]
-take_unsafe_UInt 0#  _     = []
-take_unsafe_UInt n ls      =
-  case ls of
-    []     -> []
-    (x:xs) -> x : take_unsafe_UInt (n -# 1#) xs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/pos/term0.hs b/tests/pos/term0.hs
deleted file mode 100644
--- a/tests/pos/term0.hs
+++ /dev/null
@@ -1,33 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-
-module Term0 () where 
-
-import Prelude hiding (sum)
-
-{-@ sum :: Nat -> Nat @-}
-sum   :: Int -> Int
-sum 0 = 0
-sum n = n + sum (n-1)
-
-{-@ fib :: Nat -> Nat @-}
-fib :: Int -> Int 
-fib 0 = 1
-fib 1 = 1 
-fib n = fib (n-1) + fib (n-2)
-
-{-@ sumUp :: Nat -> Nat @-}
-sumUp :: Int -> Int
-sumUp n  = go n 0 0
-  where 
-    go (d :: Int) acc i
-      | i < n     = go (d - 1) (acc + i) (i + 1) 
-      | otherwise = acc
-
-{-@ qualif Diff(v:Int, x:Int, y:Int): v = x - y @-} 
-
-{-@ nonTerm :: Nat -> Nat @-}
-nonTerm :: Int -> Int
-nonTerm n = nonTerm (n+1)
-
-{-@ lazy nonTerm @-}
-
diff --git a/tests/pos/test0.hs b/tests/pos/test0.hs
deleted file mode 100644
--- a/tests/pos/test0.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x = if x > 0 then x else (0 - x)
-
-prop_abs   = let n1 = choose 0 in 
-             liquidAssertB ((myabs n1) >= 0)
diff --git a/tests/pos/test00-int.hs b/tests/pos/test00-int.hs
deleted file mode 100644
--- a/tests/pos/test00-int.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude 
-
-x :: Int
-x = choose 0
-
-prop_abs ::  Bool
-prop_abs = if x > 0 then baz x else False
-
-baz :: Int -> Bool
-baz gooberding = liquidAssertB (gooberding >= 0)
diff --git a/tests/pos/test00.hs b/tests/pos/test00.hs
deleted file mode 100644
--- a/tests/pos/test00.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-
-prop_abs ::  Bool
-prop_abs = if x > 0 then baz x else False
-  where 
-    x    = choose 0
-
-baz gooberding = liquidAssertB (gooberding >= 0)
diff --git a/tests/pos/test00.old.hs b/tests/pos/test00.old.hs
deleted file mode 100644
--- a/tests/pos/test00.old.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x = choose 0
-
-prop_abs = if x `gt` 0 then baz x else False
-
-baz   :: Int -> Bool
-baz z = liquidAssertB (z `geq` 0)
-
diff --git a/tests/pos/test000.hs b/tests/pos/test000.hs
deleted file mode 100644
--- a/tests/pos/test000.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Test0 () where
-
--- import Language.Haskell.Liquid.Prelude
-{-@ toss :: Bool @-}
-toss :: Bool
-toss = (undefined 0) > 10
-
diff --git a/tests/pos/test00b.hs b/tests/pos/test00b.hs
deleted file mode 100644
--- a/tests/pos/test00b.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Test0 () where
-
-import Language.Haskell.Liquid.Prelude
-
-x = choose 0
-
-foo x = x
-
-prop_abs = if x > 0 then baz (foo x) else False
-
-baz ::  (Num a, Ord a) => a -> Bool
-baz z = liquidAssertB (z > 0)
diff --git a/tests/pos/test00c.hs b/tests/pos/test00c.hs
deleted file mode 100644
--- a/tests/pos/test00c.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test00c () where
-
-import Language.Haskell.Liquid.Prelude
-
-getEqs x ys = filter (x ==) ys 
-
-xs :: [Int]
-xs = [1, 2, 3, 4, 5, 6]
-
-prop_abs = map (\z -> liquidAssertB (z >= 0)) ys
-             where ys = getEqs 5 xs
diff --git a/tests/pos/test1.hs b/tests/pos/test1.hs
deleted file mode 100644
--- a/tests/pos/test1.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-module Test1 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x = if x > 0 then x else 0 - x
-
-n = choose 0
-
-prop_absf = liquidAssertB ((myabs n) >= 0)
diff --git a/tests/pos/test2.hs b/tests/pos/test2.hs
deleted file mode 100644
--- a/tests/pos/test2.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Test1 () where
-
-import Language.Haskell.Liquid.Prelude
-
-myabs x = if x > 0 then x else 0 - x
-
-n = choose 0
-
-prop_absf = 
-  let zz = (myabs n) >= 0 in
-  liquidAssertB zz
diff --git a/tests/pos/testRec.hs b/tests/pos/testRec.hs
deleted file mode 100644
--- a/tests/pos/testRec.hs
+++ /dev/null
@@ -1,33 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-
-module TestRec where
-
-import Prelude hiding (foldl)
-
-data L a = N | C { hd :: a
-                 , tl :: L a }
-
-{-@ data L [llen] a = N | C { hd :: a
-                            , tl :: L a }
-  @-}
-
-
-{-@ invariant {v:L a | 0 <= llen v} @-}
-
-{-@ measure llen @-}
-llen :: L a -> Int
-llen N        = 0
-llen (C x xs) = 1 + llen xs
-
-reverse :: L a -> L a
-reverse xs = go N xs
-  where 
-    {-@ go :: acc:_ -> xs:_ -> _ / [llen xs] @-}
-    go :: L a -> L a -> L a 
-    go acc N        = acc
-    go acc (C x xs) = go (C x acc) xs
-
-mapL f N = N
-mapL f (C x xs) = C (f x) (mapL f xs)
-
-
diff --git a/tests/pos/top0.hs b/tests/pos/top0.hs
deleted file mode 100644
--- a/tests/pos/top0.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-module Moo (poop, loop, zoo) where
-
-{-@ invariant {v:Int | v >= 0} @-}
-
-{-@ qualif Sum(v:Int, x: Int, y: Int): v = x + y @-}
-
--- | This should get a TOP type
-poop x = zoo x 
-
--- | This is USED but should ALSO get a TOP type (since exported)
-loop x     = go x 0
-  where 
-    go     :: Int -> Int -> Int 
-    go 0 m = m
-    go n m = go (n-1) (m+1)
-
-zoo     = loop
-
-loop' x     = go x 0
-  where 
-    go     :: Int -> Int -> Int 
-    go 0 m = m
-    go n m = go (n-1) (m+1)
-
--- | This HAS a sig so it should NOT get a TOP type
-{-@ zoo' :: x:Int -> {v:Int | v = x} @-}
-zoo'     = loop'
diff --git a/tests/pos/trans.hs b/tests/pos/trans.hs
deleted file mode 100644
--- a/tests/pos/trans.hs
+++ /dev/null
@@ -1,26 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-module Tx () where
-
-import Language.Haskell.Liquid.Prelude
-
-{- THIS IS A RANDOM COMMENT -}
-
-{-@ foo :: x: Int -> Int @-}
-foo :: Int -> Int
-foo x = x + 1
-
-{-@ transpose :: n:Int
-              -> m:{v:Int | v > 0} 
-              -> {v:[{v:[a] | len(v) = n}] | len(v) = m} 
-              -> {v:[{v:[a] | len(v) = m}] | len(v) = n} 
-  @-}
-transpose :: Int -> Int -> [[a]] -> [[a]]
-transpose 0 _ _              = []
-transpose n m ((x:xs) : xss) = (x : map head xss) : transpose (n - 1) m (xs : map tail xss)
-transpose n m ([] : _)       = liquidError "transpose1" 
-transpose n m []             = liquidError "transpose2"
-
--- NEEDS TAGS: map head xss = [ h | (h:_) <- xss]
--- NEEDS TAGS: map tail xss = [t | (_:t) <- xss]
-
-
diff --git a/tests/pos/transTAG.hs b/tests/pos/transTAG.hs
deleted file mode 100644
--- a/tests/pos/transTAG.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Tx () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ foo :: x: Int -> Int @-}
-foo :: Int -> Int
-foo x = x + 1
-
-{-@ transpose :: n:Int
-              -> m:{v:Int | v > 0} 
-              -> {v:[{v:[a] | len(v) = n}] | len(v) = m} 
-              -> {v:[{v:[a] | len(v) = m}] | len(v) = n} 
-  @-}
-transpose :: Int -> Int -> [[a]] -> [[a]]
-transpose 0 _ _              = []
-transpose n m ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (n - 1) m (xs : [t | (_:t) <- xss])
-transpose n m ([] : _)       = liquidError "transpose1" 
-transpose n m []             = liquidError "transpose2"
-
--- NEEDS TAGS: map head xss = [ h | (h:_) <- xss]
--- NEEDS TAGS: map tail xss = [t | (_:t) <- xss]
-
-
diff --git a/tests/pos/transpose.hs b/tests/pos/transpose.hs
deleted file mode 100644
--- a/tests/pos/transpose.hs
+++ /dev/null
@@ -1,62 +0,0 @@
-{-@ LIQUID "--no-termination" @-}
-{-@ LIQUID "--prune-unsorted" @-}
-{-@ LIQUID "--bscope"         @-}
-
-module Tx (transpose, transpose', transpose'') where
-
-import Language.Haskell.Liquid.Prelude
-
--- | Specifying a matrix
-
-{-@ type Matrix a       = {m0:[{v:[a] | (len v) = (cols m0)}] | true } @-}
-
-{-@ type MatrixCR a C R = {m0:[{v:[a] | (len v) = C}] | (((len m0) = R) && (R > 0 => (cols m0) = C)) } @-}
-
-{-@ measure cols :: [[a]] -> Int
-      cols []   = 0
-      cols (x:xs) = (len x)
-  @-}
-
--- | A Few Simple Examples (which run VERY slowly)
-
-{-@ predicate Dim V C R = (((len V) = R) && ((cols V) = C)) @-}
-
-{-@ mat_3_2 :: {v: Matrix Int | (Dim v 3 2)} @-}
-mat_3_2 :: [[Int]]
-mat_3_2 = [ [1,2,3]
-          , [4,5,6] ]
-
-{-@ mat_2_4 :: {v: Matrix Int | (Dim v 2 4)} @-}
-mat_2_4 :: [[Int]]
-mat_2_4 = [ [1,2]
-          , [3,4]
-          , [5,6]
-          , [7,8] ]
-
--- | Old fashioned transpose with explicit dimensions
-
-{- transpose :: c:Nat
-             -> r:{v:Nat | v > 0}
-             -> {v:[{v:[a] | (len v) = c}] | (len v) = r}
-             -> {v:[{v:[a] | (len v) = r}] | (len v) = c}
-  -}
-
-{-@ transpose :: c:Nat -> r:{v:Nat | v > 0}  -> (MatrixCR a c r) -> (MatrixCR a r c) @-}
-transpose     :: Int -> Int -> [[a]] -> [[a]]
-transpose 0 _ _              = []
-transpose n m ((x:xs) : xss) = (x : map head xss) : transpose (n - 1) m (xs : map tail xss)
-transpose n m ([] : _)       = liquidError "transpose1"
-transpose n m []             = liquidError "transpose2"
-
-
-{-@ transpose' :: m:{v:(Matrix a) | ((len v) > 0)} -> (MatrixCR a (len m) (cols m)) @-}
-transpose' :: [[a]] -> [[a]]
-transpose' ([]:_)         = []
-transpose' ((x:xs) : xss) = (x : map head xss) : transpose' (xs : map tail xss)
-transpose' []             = liquidError "transpose'"
-
--- | A wrapper implementing the explicit transpose using the implicit one
-
-{-@ transpose''     :: c:Nat -> r:{v:Nat | v > 0}  -> (MatrixCR a c r) -> (MatrixCR a r c) @-}
-transpose''         :: Int -> Int -> [[a]] -> [[a]]
-transpose'' n m xss = transpose' xss
diff --git a/tests/pos/tup0.hs b/tests/pos/tup0.hs
deleted file mode 100644
--- a/tests/pos/tup0.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module DepTup0 () where
-
-{-@ type PlusOne = (Int, Int)<{\x v -> v > x}> @-}
-
-{-@ plusOne :: PlusOne @-}
-plusOne :: (Int, Int)
-plusOne = (0, 1)
-
-{-@ plusOnes :: Maybe PlusOne @-}
-plusOnes :: Maybe (Int, Int) 
-plusOnes = Just plusOne -- (0, 1) (5,6), (999,1000)]
diff --git a/tests/pos/tupparse.hs b/tests/pos/tupparse.hs
deleted file mode 100644
--- a/tests/pos/tupparse.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-module Fixme () where
-
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-
-data Vec a = V a deriving (Eq)
-
--- this is verified ...
-{-@ bar :: x:Int 
-        -> y:{v: Int | v = x } 
-        -> Int 
-  @-}
-bar     :: Int -> Int -> Int
-bar x y = liquidAssert (x == y) 0
-
--- and so is this...
-
-{-@ goo :: x:[Int] 
-        -> y:{v: [Int] | v = x } 
-        -> Int 
-  @-}
-goo     :: [Int] -> [Int] -> Int
-goo x y = liquidAssert (x == y) 0
-
-
--- BUT THIS IS NOT!!
-{-@ foo :: x: (Vec Int)
-        -> y:{v: Vec Int | v = x } 
-        -> Int 
-  @-}
-foo     :: Vec Int -> Vec Int -> Int
-foo x y = liquidAssert (x == y) 0
-
-
-
diff --git a/tests/pos/tyExpr.hs b/tests/pos/tyExpr.hs
deleted file mode 100644
--- a/tests/pos/tyExpr.hs
+++ /dev/null
@@ -1,7 +0,0 @@
-module Foo where
-
-{-@ type Range Lo Hi = {v:Int | Lo <= v && v < Hi} @-}
-
-{-@ bow :: Range 0 100 @-}
-bow :: Int
-bow = 12
diff --git a/tests/pos/tyclass0.hs b/tests/pos/tyclass0.hs
deleted file mode 100644
--- a/tests/pos/tyclass0.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Goo (poop) where
-
-class Zog a where
-  zoom :: a -> Int
-
--- Assume the relevant behavior for the method.
-{-@ zoom :: (Zog a) => a -> Nat @-}
-
--- Uses the behavior of `zoom`
-{-@ poop :: (Zog a) => a -> Nat @-}
-poop x = zoom x
diff --git a/tests/pos/tyfam0.hs b/tests/pos/tyfam0.hs
deleted file mode 100644
--- a/tests/pos/tyfam0.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Foo () where
-
-import Control.Monad.Primitive
-
-import Data.Vector.Generic.Mutable
-
-{-@ copyOffset :: (PrimMonad m, MVector v e)
-           => v (PrimState m) e -> v (PrimState m) e -> Int -> Int -> Int -> m ()
-  @-}
-
-copyOffset :: (PrimMonad m, MVector v e)
-           => v (PrimState m) e -> v (PrimState m) e -> Int -> Int -> Int -> m ()
-copyOffset = undefined
-
-{-@ zog :: (m s a) -> Nat @-}
-zog :: (m s a) -> Int
-zog = undefined
diff --git a/tests/pos/tyvar.hs b/tests/pos/tyvar.hs
deleted file mode 100644
--- a/tests/pos/tyvar.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module TyVar () where
-
-{-@ foo :: Eq b => a -> b -> a @-}
-foo :: Eq b => a -> b -> a
-foo = undefined
diff --git a/tests/pos/unusedtyvars.hs b/tests/pos/unusedtyvars.hs
deleted file mode 100644
--- a/tests/pos/unusedtyvars.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Fixme () where
-
-data F a b c = F (Int -> b -> c)
-{- data F a b c = F (x::(Int -> b -> c)) @-}
-
-
-{-@ bar :: F {v:Int| v >= 0} b c @-}
-bar :: F Int b c
-bar = undefined
-
-
-{-@ foo :: F {v:Int| v >= 0} b c  -> Int @-}
-foo :: F Int b c -> Int
-foo = undefined
-
-{-@ hoo :: Int @-}
-hoo = foo bar
diff --git a/tests/pos/vector00.hs b/tests/pos/vector00.hs
deleted file mode 100644
--- a/tests/pos/vector00.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Vec0 () where
-
-import Language.Haskell.Liquid.Prelude
--- import Data.List
-import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
-
-propVec = (vs ! 3) == 3
-  where xs    = [1,2,3,4] :: [Int]
-        vs    = fromList xs
-        
-
diff --git a/tests/pos/vector1.hs b/tests/pos/vector1.hs
deleted file mode 100644
--- a/tests/pos/vector1.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-module Vec1 () where
-
-{-@ LIQUID "--no-termination" @-}
-
-import Language.Haskell.Liquid.Prelude
-import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
-
-for lo hi acc f 
-  | lo < hi   = for (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) {- * (v2!i) -}) +)
-  where n = Data.Vector.length v1
-
-sumSquare v = dotProd v v
-
-total = sumSquare $ Data.Vector.fromList [0..100] -- nums
-range i j = for i j [] (:)
-nums  = range 0 100 -- [0..100]
-
--- prop = liquidAssertB (total >= 0)
diff --git a/tests/pos/vector1a.hs b/tests/pos/vector1a.hs
deleted file mode 100644
--- a/tests/pos/vector1a.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Vec1 () where
-
-import Language.Haskell.Liquid.Prelude
-import Data.Vector hiding (map, concat, zipWith, filter, foldr, foldl, (++))
-
-
-{-@ invariant {v:Int | v >= 0} @-}
-for :: Int -> Int -> a -> (Int -> a -> a) -> a
-for lo hi  = for' (hi-lo) lo hi
-
-for' :: Int -> Int -> Int -> a -> (Int -> a -> a) -> a
-for' d lo hi acc f 
-  | lo < hi   = for' (d-1) (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-dotProd       :: Vector Int -> Vector Int -> Int
-dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
-  where n = Data.Vector.length v1
-
-sumSquare   :: Vector Int -> Int
-sumSquare v = dotProd v v
-
-total = sumSquare $ Data.Vector.fromList [0..100]
diff --git a/tests/pos/vector1b.hs b/tests/pos/vector1b.hs
deleted file mode 100644
--- a/tests/pos/vector1b.hs
+++ /dev/null
@@ -1,19 +0,0 @@
-module Vec1 () where
-
-{-@ LIQUID "--no-termination" @-}
-
-import Language.Haskell.Liquid.Prelude
-import Data.Vector hiding (map, concat, zipWith, filter, foldl, foldr, (++))
-
-for lo hi acc f 
-  | lo < hi   = for (lo + 1) hi (f lo acc) f
-  | otherwise = acc 
-
-dotProd v1 v2 = for 0 n 0 $ \i -> (((v1!i) * (v2!i)) +)
-  where n = Data.Vector.length v1
-
-sumSquare v = dotProd v v
-
-total = sumSquare $ Data.Vector.fromList [0..100] -- nums
-range i j = for i j [] (:)
-nums  = range 0 100 -- [0..100]
diff --git a/tests/pos/vector2.hs b/tests/pos/vector2.hs
deleted file mode 100644
--- a/tests/pos/vector2.hs
+++ /dev/null
@@ -1,70 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-
-module Vec2 (dotProduct, safeLookup) where
-
-import Prelude hiding (length)
-import Data.Vector
-import Language.Haskell.Liquid.Prelude (liquidAssert)
-    
-{-@ predicate Lt X Y      = X < Y                         @-}
-{-@ predicate Ge X Y      = not (Lt X Y)                  @-}
-{-@ predicate InBound I A = ((Ge I 0) && (Lt I (vlen A))) @-}
-
-{-@ invariant {v:Int | v >= 0} @-}
-{-@ unsafeLookup :: vec:Vector a 
-                 -> {v: Int | (0 <= v && v < (vlen vec)) } 
-                 -> a @-}
-unsafeLookup vec i = vec ! i
-
-{-@ unsafeLookup' :: vec:Vector a -> {v: Int | (InBound v vec)} -> a @-}
-unsafeLookup' vec i = vec ! i
-
-safeLookup x i 
-  | 0 <= i && i < length x = Just (x ! i)
-  | otherwise              = Nothing 
-
-{-@ absoluteSum   :: Vector Int -> {v: Int | 0 <= v}  @-}
-absoluteSum       :: Vector Int -> Int 
-absoluteSum vec   = if 0 < n then go n 0 0 else 0
-  where
-    go (d::Int) acc i 
-      | i /= n    = go (d-1) (acc + abz (vec ! i)) (i + 1)
-      | otherwise = acc 
-    n             = length vec
-
-abz n = if 0 <= n then n else (0 - n) 
-
-loop :: Int -> Int -> a -> (Int -> a -> a) -> a 
-loop lo hi base f = go (hi-lo) base lo
-  where
-    {-@ decrease go 1 @-}
-    go (d::Int) acc i     
-      | i /= hi   = go (d-1) (f i acc) (i + 1)
-      | otherwise = acc
-
-incr x = x + 1
-
-zoo = incr 29
-
-{-@ dotProduct :: x:(Vector Int) 
-               -> y:{v: Vector Int | (vlen v) = (vlen x)} 
-               -> Int 
-  @-}
-dotProduct     :: Vector Int -> Vector Int -> Int
-dotProduct x y 
-  | length x == length y
-  = loop 0 (length x) 0 (\i -> (+ (x ! i) * (y ! i))) 
-  | otherwise
-  = error "dotProduct only on equal-sized vectors!"
-
-
-{-@ type SparseVector a N = [({v: Int | (0 <= v && v < N)}, a)] @-}
-
-{-@ sparseDotProduct :: (Num a) => x:(Vector a) -> (SparseVector a {(vlen x)}) -> a @-}
-sparseDotProduct x y  = go 0 y
-  where
-    {-@ decrease go 2 @-}
-    go sum ((i, v) : y') = go (sum + (x ! i) * v) y' 
-    go sum []            = sum
-
-
diff --git a/tests/pos/wrap0.hs b/tests/pos/wrap0.hs
deleted file mode 100644
--- a/tests/pos/wrap0.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Wrap0 () where
-
-import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
-
-data Foo a = F a
-
-type IntFoo = Foo Int
-
-{-@ flibberty :: (Eq a) => a -> Bool @-}
-flibberty x   = prop x (F x)
-prop x (F y)  = liquidAssertB (x == y)
-
-{-@ flibInt :: (Num a, Ord a) => a -> Bool @-}
-flibInt x     = prop1 x (F (x + 1))
-prop1 x (F y) = liquidAssertB (x < y) 
-
-{-@ flibXs :: a -> Bool @-}
-flibXs x     = prop2 (F [x, x, x])
-prop2 (F []) = liquidError "not-the-hippopotamus"
-prop2 (F _ ) = True
diff --git a/tests/pos/wrap1.hs b/tests/pos/wrap1.hs
deleted file mode 100644
--- a/tests/pos/wrap1.hs
+++ /dev/null
@@ -1,33 +0,0 @@
-{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
-
-module Wrap0 () where
-
-
-import Language.Haskell.Liquid.Prelude (liquidError, liquidAssertB)
-import Data.Function (on)
-import Data.Ord (comparing)
-
-data WrapType b a = WrapType {getVect :: b, getVal :: a}
-
-instance Eq (WrapType [Double] a) where
-   (==) = (==) `on` getVect
-
-instance Ord (WrapType [Double] a) where
-    compare = comparing getVect
-
-{-@ assert flibXs :: a -> Bool @-}
-flibXs x              = prop1 (WrapType [x, x, x] x)
-prop1 (WrapType [] _) = liquidError "no!"
-prop1 (WrapType _  _) = True
-
-{-@ assert nflibXs :: Nat -> a -> Bool @-}
-nflibXs n x           = prop2 n (WrapType nxs x)
-                        where nxs = replicate n x 
-
-prop2 :: Int -> WrapType [a] t -> Bool
-prop2 n (WrapType xs _) = liquidAssertB (n == length xs) 
-
-
-
-
-
diff --git a/tests/pos/zipSO.hs b/tests/pos/zipSO.hs
deleted file mode 100644
--- a/tests/pos/zipSO.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-module Blank () where
-
--- From
--- http://stackoverflow.com/questions/17501777/implementing-a-zipper-for-length-indexed-lists/17503667#17503667
-
-import Prelude hiding ((++))
-
-{-@ zipper :: zs:[a] -> [(a, {v:[a] | (len v) = (len zs) - 1})] @-}
-zipper zs          = go [] zs
-  
-{-@ go :: prev:[a] -> rest:[a] -> [(a, {v:[a] | (len v) = (len prev) + (len rest) - 1})] / [len rest]  @-}
-go :: [a] -> [a] -> [(a, [a])]
-go _    []     = []
-go prev (x:xs) = (x, prev ++ xs) : go (prev ++ [x]) xs
-
-{-@ append :: xs:[a] -> ys:[a] -> {v:[a] | (len v) = (len xs) + (len ys)} @-}
-append [] ys     = ys
-append (x:xs) ys = x : append xs ys
-
-(++) = append
diff --git a/tests/pos/zipW.hs b/tests/pos/zipW.hs
deleted file mode 100644
--- a/tests/pos/zipW.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module T () where
-
-import Language.Haskell.Liquid.Prelude
-
-{-@ assert zipW :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len(v) = len(xs)} -> {v : [c] | len(v) = len(xs)} @-}
-zipW :: (a->b->c) -> [a]->[b]->[c]
-zipW f (a:as) (b:bs) = f a b : zipW f as bs
-zipW _ [] []         = []
-zipW _ [] (_:_)      = liquidError "zipWith1"
-zipW _ (_:_) []      = liquidError "zipWith1"
-
-{-@ assert foo :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len(v) = len(xs)} -> {v : [c] | len(v) = len(xs)} @-}
-foo = zipW
-
diff --git a/tests/pos/zipW1.hs b/tests/pos/zipW1.hs
deleted file mode 100644
--- a/tests/pos/zipW1.hs
+++ /dev/null
@@ -1,11 +0,0 @@
-module Import where 
-	
-import Language.Haskell.Liquid.Prelude -- (safeZipWith)
-
-{-@ foo :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len v = len xs} 
-        -> {v : [c] | len v  = len xs} @-}
-foo = safeZipWith
-
-
-{- safeZipWith :: (a -> b -> c) -> xs : [a] -> ys:{v:[b] | len v = len xs} 
-                -> {v : [c] | len v = len xs} @-}
diff --git a/tests/pos/zipW2.hs b/tests/pos/zipW2.hs
deleted file mode 100644
--- a/tests/pos/zipW2.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module ListSort where
-
-
-foo :: [Int] -> [Int]
-foo zs = zipWith (+) zs zs
diff --git a/tests/pos/zipper.hs b/tests/pos/zipper.hs
deleted file mode 100644
--- a/tests/pos/zipper.hs
+++ /dev/null
@@ -1,165 +0,0 @@
-module Zipper (getFocus, getUp, getDown) where
-
-import Prelude hiding (reverse, (++))
-
-import Data.Set
-
-data Stack a = Stack { focus  :: !a        -- focused thing in this set
-                     , up     :: [a]       -- jokers to the left
-                     , down   :: [a] }     -- jokers to the right
-    deriving (Show, Eq)
--- LIQUID     deriving (Show, Read, Eq)
-
--------------------------------------------------------------------------------
------------------------------ Refinements on  Lists ---------------------------
--------------------------------------------------------------------------------
-
--- measures
-
-{-@
-  measure listDup :: forall a. [a] -> (Set a)
-    listDup [] = {v | Set_emp v }
-    listDup (x:xs) = {v | v = if (Set_mem x (listElts xs)) then (Set_cup (Set_sng x) (listDup xs)) else (listDup xs) }
-  @-}
-
--- predicates
-
-{-@ predicate EqElts X Y =
-       ((listElts X) = (listElts Y)) @-}
-
-{-@ predicate SubElts X Y =
-       (Set_sub (listElts X) (listElts Y)) @-}
-
-{-@ predicate UnionElts X Y Z =
-       ((listElts X) = (Set_cup (listElts Y) (listElts Z))) @-}
-
-{-@ predicate ListElt N LS =
-       (Set_mem N (listElts LS)) @-}
-
-{-@ predicate ListUnique LS =
-       (Set_emp (listDup LS)) @-}
-
-{-@ predicate ListDisjoint X Y =
-       (Set_emp (Set_cap (listElts X) (listElts Y))) @-}
-
-
--- types
-
-{-@ type UList a = {v:[a] | (ListUnique v)} @-}
-
-{-@ type UListDif a N = {v:[a] | ((not (ListElt N v)) && (ListUnique v))} @-}
-
-
-
--------------------------------------------------------------------------------
------------------------------ Refinements on Stacks ---------------------------
--------------------------------------------------------------------------------
-
-{-@
-data Stack a = Stack { focus :: a
-                     , up    :: UListDif a focus
-                     , down  :: UListDif a focus }
-@-}
-
-{-@ type UStack a = {v:Stack a | (ListDisjoint (getUp v) (getDown v))}@-}
-
-{-@ measure getFocus @-}
-getFocus :: Stack a -> a
-getFocus (Stack xfocus _ _) = xfocus
-
-{-@ measure getUp @-}
-getUp :: Stack a -> [a]
-getUp (Stack xfocus xup xdown) = xup
-
-{-@ measure getDown @-}
-getDown :: Stack a -> [a]
-getDown (Stack xfocus xup xdown) = xdown
-
-
--------------------------------------------------------------------------------
------------------------------- Functions on Stacks ----------------------------
--------------------------------------------------------------------------------
-
-
-{-@ differentiate :: UList a -> Maybe (UStack a) @-}
-differentiate :: [a] -> Maybe (Stack a)
-differentiate []     = Nothing
-differentiate (x:xs) = Just $ Stack x [] xs
-
-{-@ integrate :: UStack a -> UList a @-}
-integrate :: Stack a -> [a]
-integrate (Stack x l r) = reverse l ++ x : r
-
-{-@ integrate' :: Maybe (UStack a) -> UList a @-}
-integrate' :: Maybe (Stack a) -> [a]
-integrate' = maybe [] integrate
-
-
-{-@ focusUp :: UStack a -> UStack a @-}
-focusUp :: Stack a -> Stack a
-focusUp (Stack t [] rs)     = Stack x xs [] where (x:xs) = reverse (t:rs)
-focusUp (Stack t (l:ls) rs) = Stack l ls (t:rs)
-
-{-@ focusDown :: UStack a -> UStack a @-}
-focusDown :: Stack a -> Stack a
-focusDown = reverseStack . focusUp . reverseStack
-
-{-@ reverseStack :: UStack a -> UStack a @-}
-reverseStack :: Stack a -> Stack a
-reverseStack (Stack t ls rs) = Stack t rs ls
-
-{-@ swapUp :: UStack a -> UStack a @-}
-swapUp :: Stack a -> Stack a
-swapUp  (Stack t (l:ls) rs) = Stack t ls (l:rs)
-swapUp  (Stack t []     rs) = Stack t (reverse  rs) []
-
-{-@ filter :: (a -> Bool) -> UStack a -> Maybe (UStack a) @-}
-filter :: (a -> Bool) -> Stack a -> Maybe (Stack a)
-filter p (Stack f ls rs) = case filterL p (f:rs) of
-    f':rs' -> Just $ Stack f' (filterL p ls) rs'    -- maybe move focus down
-    []     -> case filterL p ls of                  -- filter back up
-                    f':ls' -> Just $ Stack f' ls' [] -- else up
-                    []     -> Nothing
-
-
--------------------------------------------------------------------------------
-------------------------------- Functions on Lists ----------------------------
--------------------------------------------------------------------------------
-
-
-infixr 5 ++
-{-@ Zipper.++ :: xs:(UList a)
-         -> ys:{v: UList a | (ListDisjoint v xs)}
-         -> {v: UList a | (UnionElts v xs ys)}
-  @-}
-(++) :: [a] -> [a] -> [a]
-[] ++ ys = ys
-(x:xs) ++ ys = x: (xs ++ ys)
-
-
-{-@ reverse :: xs:(UList a)
-            -> {v: UList a | (EqElts v xs)}
-  @-}
-reverse :: [a] -> [a]
-reverse = rev []
-
-
-{-@ rev :: acc:(UList a)
-        -> xs:{v: UList a | ListDisjoint acc v }
-        -> {v:UList a | UnionElts v xs acc } / [len xs]
-  @-}
-rev :: [a] -> [a] -> [a]
-rev a []     = a
-rev a (x:xs) = rev (x:a) xs
-
-{-@ filterL :: (a -> Bool) -> xs:(UList a) -> {v:UList a | (SubElts v xs)} @-}
-filterL :: (a -> Bool) -> [a] -> [a]
-filterL p [] = []
-filterL p (x:xs) | p x       = x : filterL p xs
-                 | otherwise = filterL p xs
-
-
--- QUALIFIERS
-{-@ q :: x:a ->  {v:[a] |(not (Set_mem x (listElts v)))} @-}
-q :: a -> [a]
-q = undefined
diff --git a/tests/pos/zipper0.hs b/tests/pos/zipper0.hs
deleted file mode 100644
--- a/tests/pos/zipper0.hs
+++ /dev/null
@@ -1,71 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-module Zipper (getUp, getDown, getFocus) where
-
-import Prelude hiding (reverse)
-
-import Data.Set
-
-data Stack a = Stack { focus  :: !a        -- focused thing in this set
-                     , up     :: [a]       -- jokers to the left
-                     , down   :: [a] }     -- jokers to the right
-
-{-@ type UListDif a N = {v:[a] | ((not (Set_mem N (listElts v))) && (Set_emp (listDup v)))} @-}
-
-{-@
-data Stack a = Stack { focus :: a
-                     , up    :: UListDif a focus
-                     , down  :: UListDif a focus }
-@-}
-
-{-@ measure listDup :: [a] -> (Set a)
-      listDup [] = {v | Set_emp v }
-      listDup (x:xs) = {v | v = if (Set_mem x (listElts xs)) then (Set_cup (Set_sng x) (listDup xs)) else (listDup xs) }
-  @-}
-
-{-@ type UStack a = {v:Stack a |(Set_emp (Set_cap (listElts (getUp v)) (listElts (getDown v))))}@-}
-
-{-@ measure getFocus @-}
-getFocus :: Stack a -> a
-getFocus (Stack xfocus _ _) = xfocus
-
-{-@ measure getUp @-}
-getUp :: Stack a -> [a]
-getUp (Stack xfocus xup xdown) = xup
-
-{-@ measure getDown @-}
-getDown :: Stack a -> [a]
-getDown (Stack xfocus xup xdown) = xdown
-
-
--- QUALIFIERS
-{-@ q :: x:a ->  {v:[a] |(not (Set_mem x (listElts v)))} @-}
-q :: a -> [a]
-q = undefined
-{-@ q1 :: x:a ->  {v:[a] |(Set_mem x (listElts v))} @-}
-q1 :: a -> [a]
-q1 = undefined
-{-@ q0 :: x:a ->  {v:[a] |(Set_emp(listDup v))} @-}
-q0 :: a -> [a]
-q0 = undefined
-
-
-{-@ focusUp :: UStack a -> UStack a @-}
-focusUp :: Stack a -> Stack a
-focusUp (Stack t [] rs)     = Stack xiggety xs [] where (xiggety:xs) = reverse (t:rs)
-focusUp (Stack t (l:ls) rs) = Stack l ls (t:rs)
-
-{-@ focusDown :: UStack a -> UStack a @-}
-focusDown :: Stack a -> Stack a
-focusDown = reverseStack . focusUp . reverseStack
-
--- | reverse a stack: up becomes down and down becomes up.
-{-@ reverseStack :: UStack a -> UStack a @-}
-reverseStack :: Stack a -> Stack a
-reverseStack (Stack t ls rs) = Stack t rs ls
-
-
--- TODO ASSUMES
-{-@ reverse :: {v:[a] | (Set_emp (listDup v))} -> {v:[a]|(Set_emp (listDup v))} @-}
-reverse :: [a] -> [a]
-reverse = undefined
diff --git a/tests/pos/zipper000.hs b/tests/pos/zipper000.hs
deleted file mode 100644
--- a/tests/pos/zipper000.hs
+++ /dev/null
@@ -1,44 +0,0 @@
-{-@ LIQUID "--no-totality" @-}
-
-module Zipper (getUp, getDown) where
-
-import Data.Set
-
-data Stack a = Stack { focus  :: a        -- focused thing in this set
-                     , up     :: [a]       -- jokers to the left
-                     , down   :: [a] }     -- jokers to the right
-
-{-@ type UListDif a N = {v:[a] | not (Set_mem N (listElts v)) } @-}
-
-{-@ data Stack a = Stack 
-      { focus :: a
-      , up    :: UListDif a focus
-      , down  :: UListDif a focus 
-      }
-  @-}
-
-{-@ type UStack a = {v:Stack a | (Set_emp (Set_cap (listElts (getUp v)) (listElts (getDown v))))} @-}
-
-{-@ measure getUp @-}
-getUp :: Stack a -> [a]
-getUp (Stack xfocus xup xdown) = xup
-
-{-@ measure getDown @-}
-getDown :: Stack a -> [a]
-getDown (Stack xfocus xup xdown) = xdown
-
-data Foo a b = J | P a b
-
---------------------------------------------------------------------------------------
-{-@ focusUp :: UStack a -> UStack a @-}
-focusUp :: Stack a -> Stack a
-focusUp (Stack t [] rs) = Stack xiggety xs []
-  where P xiggety xs    = P t rs
-
--- focusUp (Stack t [] rs) = Stack t rs []
-
-
-
-
-
---------------------------------------------------------------------------------------
diff --git a/tests/test.hs b/tests/test.hs
deleted file mode 100644
--- a/tests/test.hs
+++ /dev/null
@@ -1,929 +0,0 @@
-{-# LANGUAGE CPP  #-}
-{-# LANGUAGE DeriveDataTypeable  #-}
-{-# LANGUAGE DoAndIfThenElse     #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE TupleSections #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE OverloadedStrings #-}
-
-module Main where
-
-import Data.Function (on)
-import Control.Applicative
-import qualified Control.Concurrent.STM as STM
-import qualified Control.Monad.State as State
-import Control.Monad.Trans.Class (lift)
-import Control.Monad (when)
-import Data.Char
-import qualified Data.Functor.Compose as Functor
-import qualified Data.IntMap as IntMap
-import qualified Data.Map as Map
-import qualified Data.List as L 
-import Data.Maybe (fromMaybe)
-import Data.Monoid (Sum(..))
-import Data.Proxy
-import Data.String
-import Data.String.Conv
-import Data.Tagged
-import Data.Typeable
--- import Data.List (sort, reverse)
-import qualified Data.Text    as T
-import qualified Data.Text.IO as T
-import Options.Applicative
-import System.Directory
-import System.Environment
-import System.Exit
-import System.FilePath
-import System.IO
-import System.IO.Error
-import System.Process
-import Test.Tasty
--- import Test.Tasty.Golden
-import Test.Tasty.HUnit
-import Test.Tasty.Ingredients.Rerun
-import Test.Tasty.Options
-import Test.Tasty.Runners
-import Test.Tasty.Runners.AntXML
-import Paths_liquidhaskell
-
-import Text.Printf
-
-
-
-testRunner :: Ingredient
-testRunner = rerunningTests
-               [ listingTests
-               , combineReporters myConsoleReporter antXMLRunner
-               , myConsoleReporter
-               ]
-
-myConsoleReporter :: Ingredient
-myConsoleReporter = combineReporters consoleTestReporter loggingTestReporter
-
-main :: IO ()
-main = do unsetEnv "LIQUIDHASKELL_OPTS"
-          -- We don't run tests in depedency order, so having stale
-          -- .liquid/ *.hs.bspec files can causes problems.
-          -- system "rm -r tests/pos/.liquid/"
-          -- system "rm -r tests/neg/.liquid/"
-          run =<< tests
-  where
-    run   = defaultMainWithIngredients [
-                testRunner
-              , includingOptions [ Option (Proxy :: Proxy NumThreads)
-                                 , Option (Proxy :: Proxy LiquidOpts)
-                                 , Option (Proxy :: Proxy LiquidRunner)
-                                 , Option (Proxy :: Proxy SmtSolver) ]
-              ]
-    tests = group "Tests" $ microTests  :
-                            errorTests  : 
-                            macroTests  :
-                            proverTests :
-                           --  goldenTests :
-                            benchTests  : 
-                            []
-                           
-
-    -- tests = group "Tests" [ unitTests  ]
-    -- tests = group "Tests" [ benchTests ]
-    -- tests = group "Tests" [ selfTests  ]
-    -- tests = group "Tests" [ errorTests ]
-
-data SmtSolver = Z3 | CVC4 deriving (Show, Read, Eq, Ord, Typeable)
-
-instance IsOption SmtSolver where
-  defaultValue = Z3
-  parseValue = safeRead . map toUpper
-  optionName = return "smtsolver"
-  optionHelp = return "Use this SMT solver"
-  optionCLParser =
-    option (fmap (read . map toUpper) str)
-      (  long (untag (optionName :: Tagged SmtSolver String))
-      <> help (untag (optionHelp :: Tagged SmtSolver String))
-      )
-
-newtype LiquidOpts = LO String deriving (Show, Read, Eq, Ord, Typeable, IsString)
-
-instance Semigroup LiquidOpts where
-  (LO "") <> y       = y
-  x       <> (LO "") = x
-  (LO x)  <> (LO y)  = LO $ x ++ (' ' : y)
-
-instance Monoid LiquidOpts where
-  mempty = LO ""
-  mappend = (<>)
-
-instance IsOption LiquidOpts where
-  defaultValue = LO ""
-  parseValue = Just . LO
-  optionName = return "liquid-opts"
-  optionHelp = return "Extra options to pass to LiquidHaskell"
-  optionCLParser =
-    option (fmap LO str)
-      (  long (untag (optionName :: Tagged LiquidOpts String))
-      <> help (untag (optionHelp :: Tagged LiquidOpts String))
-      )
-
--- 
--- Controlling the invocation of \"liquid\"
---
--- During the tests we require the executable \"liquid\" to be reachable and in the PATH in order to be
--- able to run the tests. However, \"liquid\" might require to be run with a proper configuration, for
--- example with the correct \"-package-db\" in order to check some files. To do so we can use something like
--- \"stack exec -- liquid\", which would work for Stack but not \"cabal new-*\". To mitigate this, we introduce
--- the \"liquid-runner\" option which can be used to override this choice.
-
-newtype LiquidRunner = LiquidRunner String
-  deriving (Show, Read, Eq, Ord, Typeable, IsString, Semigroup, Monoid)
-
-instance IsOption LiquidRunner where
-  defaultValue = LiquidRunner "stack --silent exec -- liquidhaskell -v0"
-  parseValue = Just . LiquidRunner
-  optionName = return "liquid-runner"
-  optionHelp = return "Specifies the full path or command which will run 'liquid'."
-  optionCLParser =
-    option (fmap LiquidRunner str)
-      (  long (untag (optionName :: Tagged LiquidRunner String))
-      <> help (untag (optionHelp :: Tagged LiquidRunner String))
-      )
-
-errorTests :: IO TestTree
-errorTests = group "Error-Messages"
-  [ 
-    -- errorTest "tests/errors/ExportMeasure0.hs"      2 "Cannot lift `llen` into refinement logic"
-    -- errorTest "tests/errors/ExportReflect0.hs"      2 "Cannot lift `identity` into refinement logic"
-    -- errorTest "tests/errors/ExportMeasure1.hs"      2 "Cannot lift `psnd` into refinement logic"
-    -- , errorTest "tests/errors/ShadowMeasureVar.hs"    2 "Multiple specifications for `shadow`"
-    -- , errorTest "tests/errors/AmbiguousReflect.hs"    2 "Ambiguous specification symbol `mappend`"
-    -- , errorTest "tests/errors/AmbiguousInline.hs"     2 "Ambiguous specification symbol `min`"
-    -- , errorTest "tests/errors/MissingAbsRefArgs.hs"   2 "Illegal type specification for `Fixme.bar`"
-
-    errorTest "tests/errors/ReWrite8.hs"            1 "Could not generate any rewrites from equality"
-  , errorTest "tests/errors/ReWrite7.hs"            1 "Could not generate any rewrites from equality"
-  , errorTest "tests/errors/ReWrite6.hs"            1 "Unable to use ReWrite6.bad as a rewrite because it does not prove an equality"
-  , errorTest "tests/errors/ReWrite5.hs"            1 "parameter \"xs\" contains an inner refinement"
-  , errorTest "tests/errors/ShadowFieldInline.hs"   1 "Multiple specifications for `pig`"
-  , errorTest "tests/errors/ShadowFieldReflect.hs"  1 "Multiple specifications for `pig`"
-  , errorTest "tests/errors/MultiRecSels.hs"        1 "Duplicated definitions for field `left`" 
-  , errorTest "tests/errors/DupFunSigs.hs"          1 "Multiple specifications for `Main.fromWeekDayNum`"
-  , errorTest "tests/errors/DupMeasure.hs"          1 "Multiple specifications for `lenA`"
-  , errorTest "tests/errors/ShadowMeasure.hs"       1 "Multiple specifications for `shadow`"
-  , errorTest "tests/errors/DupData.hs"             1 "Multiple specifications for `OVec`"
-  , errorTest "tests/errors/EmptyData.hs"           1 "one or more fields in the data declaration for `A`"
-  , errorTest "tests/errors/BadGADT.hs"             1 "Specified type does not refine Haskell type for `Main.Nil2`" 
-  , errorTest "tests/errors/TerminationExprSort.hs" 1 "Illegal termination specification for `TerminationExpr.showSep`"
-  , errorTest "tests/errors/TerminationExprNum.hs"  1 "Illegal termination specification for `TerminationExpr.showSep`"
-  , errorTest "tests/errors/TerminationExprUnb.hs"  1 "Illegal termination specification for `go`"
-  , errorTest "tests/errors/UnboundVarInSpec.hs"    1 "Illegal type specification for `Fixme.foo`"
-  , errorTest "tests/errors/UnboundVarInAssume.hs"  1 "Illegal type specification for `Assume.incr`"
-  , errorTest "tests/errors/UnboundCheckVar.hs"     1 "Unknown variable `UnboundCheckVar.ink`"
-  , errorTest "tests/errors/UnboundFunInSpec.hs"    1 "Illegal type specification for `Goo.three`"
-  , errorTest "tests/errors/UnboundFunInSpec1.hs"   1 "Illegal type specification for `Goo.foo`"
-  , errorTest "tests/errors/UnboundFunInSpec2.hs"   1 "Illegal type specification for `Goo.foo`"
-  , errorTest "tests/errors/UnboundVarInLocSig.hs"  1 "Illegal type specification for `bar`" 
-  , errorTest "tests/errors/UnboundVarInReflect.hs" 1 "Illegal type specification for `UnboundVarInReflect.frog`" 
-  , errorTest "tests/errors/Fractional.hs"          1 "Illegal type specification for `Crash.f`"
-  , errorTest "tests/errors/T773.hs"                1 "Illegal type specification for `LiquidR.incr`"
-  , errorTest "tests/errors/T774.hs"                1 "Illegal type specification for `LiquidR.incr`"
-  , errorTest "tests/errors/T1498.hs"               1 "Standalone class method refinement"
-  , errorTest "tests/errors/T1498A.hs"              1 "Bad Data Specification"
-  , errorTest "tests/errors/Inconsistent0.hs"       1 "Specified type does not refine Haskell type for `Ast.id1`" 
-  , errorTest "tests/errors/Inconsistent1.hs"       1 "Specified type does not refine Haskell type for `Boo.incr` (Checked)"
-  , errorTest "tests/errors/Inconsistent2.hs"       1 "Specified type does not refine Haskell type for `Mismatch.foo` (Checked)"
-  , errorTest "tests/errors/BadAliasApp.hs"         1 "Malformed application of type alias `ListN`"
-  , errorTest "tests/errors/BadPragma0.hs"          1 "Illegal pragma"
-  , errorTest "tests/errors/BadPragma1.hs"          1 "Illegal pragma"
-  , errorTest "tests/errors/BadPragma2.hs"          1 "Illegal pragma"
-  , errorTest "tests/errors/BadSyn1.hs"             1 "Malformed application of type alias `Fooz`"
-  , errorTest "tests/errors/BadSyn2.hs"             1 "Malformed application of type alias `Zoo.Foo`"
-  , errorTest "tests/errors/BadSyn3.hs"             1 "Malformed application of type alias `Zoo.Foo`"
-  , errorTest "tests/errors/BadSyn4.hs"             1 "Malformed application of type alias `Foo.Point`"
-  , errorTest "tests/errors/BadAnnotation.hs"       1 "Malformed annotation"
-  , errorTest "tests/errors/BadAnnotation1.hs"      1 "Malformed annotation"
-  , errorTest "tests/errors/CyclicExprAlias0.hs"    1 "Cyclic type alias definition"
-  , errorTest "tests/errors/CyclicExprAlias1.hs"    1 "Cyclic type alias definition" 
-  , errorTest "tests/errors/CyclicExprAlias2.hs"    1 "Cyclic type alias definition"
-  , errorTest "tests/errors/CyclicExprAlias3.hs"    1 "Cyclic type alias definition"
-  , errorTest "tests/errors/DupAlias.hs"            1 "Multiple definitions of Type Alias `BoundedNat`"
-  , errorTest "tests/errors/DupAlias.hs"            1 "Multiple definitions of Pred Alias `Foo`"
-  , errorTest "tests/errors/BadData0.hs"            1 "Unknown type constructor `Zoog`" 
-  , errorTest "tests/errors/BadDataConType.hs"      1 "Illegal type specification for `Boo.fldY`" 
-  , errorTest "tests/errors/BadDataConType1.hs"     1 "Specified type does not refine Haskell type for `Boo.C`" 
-                                                       -- "Illegal type specification for `Boo.fldY`" 
-
-  , errorTest "tests/errors/BadDataConType2.hs"     1 "different numbers of fields for `Boo.C`" 
-  , errorTest "tests/errors/LiftMeasureCase.hs"     1 "Cannot create measure 'Measures.foo': Does not have a case-of at the top-level"
-  , errorTest "tests/errors/HigherOrderBinder.hs"   1 "Illegal type specification for `Main.foo`"
-  , errorTest "tests/errors/HoleCrash1.hs"          1 "Illegal type specification for `ListDemo.t`"
-  , errorTest "tests/errors/HoleCrash2.hs"          1 "Malformed application of type alias `Geq`"
-  , errorTest "tests/errors/HoleCrash3.hs"          1 "Specified type does not refine Haskell type for `ListDemo.countUp`"
-  , errorTest "tests/errors/BadPredApp.hs"          1 "Malformed predicate application"
-  , errorTest "tests/errors/LocalHole.hs"           1 "Illegal type specification for `go`"
-  , errorTest "tests/errors/UnboundAbsRef.hs"       1 "Cannot apply unbound abstract refinement `p`"
-  -- , errorTest "tests/errors/BadQualifier.hs"        2 "Illegal qualifier specification for `Foo`"
-  , errorTest "tests/errors/ParseClass.hs"          1 "Cannot parse specification"
-  , errorTest "tests/errors/ParseBind.hs"           1 "Cannot parse specification"
-  , errorTest "tests/errors/MultiInstMeasures.hs"   1 "Multiple instance measures `sizeOf` for type `GHC.Ptr.Ptr`"
-  , errorTest "tests/errors/BadDataDeclTyVars.hs"   1 "Mismatch in number of type variables for `L`"
-  , errorTest "tests/errors/BadDataCon2.hs"         1 "GHC and Liquid specifications have different numbers of fields for `Boo.Cuthb`"
-  , errorTest "tests/errors/BadSig0.hs"             1 "Illegal type specification for `Zoo.foo`"
-  , errorTest "tests/errors/BadSig1.hs"             1 "Illegal type specification for `Ev.EZ`"
-  , errorTest "tests/errors/BadData1.hs"            1 "Data constructors in refinement do not match original datatype for `EntityField`"
-  , errorTest "tests/errors/BadData2.hs"            1 "Data constructors in refinement do not match original datatype for `Hog`"
-  , errorTest "tests/errors/T1140.hs"               1 "Specified type does not refine Haskell type for `Blank.foo`"
-  , errorTest "tests/errors/InlineSubExp0.hs"       1 "== f B C"
-  , errorTest "tests/errors/InlineSubExp1.hs"       1 "= f B (g A)"
-  , errorTest "tests/errors/EmptySig.hs"            1 "Cannot parse specification"
-  , errorTest "tests/errors/MissingReflect.hs"      1 "Illegal type specification for `Main.empty_foo`" 
-  , errorTest "tests/errors/MissingSizeFun.hs"      1 "Unknown variable `llen2`" 
-  , errorTest "tests/errors/MissingAssume.hs"       1 "Unknown variable `goober`" 
-  , errorTest "tests/errors/HintMismatch.hs"        1 "HINT: Use the hole"
-  , errorTest "tests/errors/ElabLocation.hs"        1 "ElabLocation.hs:13:14-13:15: Error"
-  , errorTest "tests/errors/ErrLocation.hs"         1 "ErrLocation.hs:9:13"
-  , errorTest "tests/errors/ErrLocation2.hs"        1 "ErrLocation2.hs:11:20: error:"
-  , errorTest "tests/errors/frog.hs"                1 "Unbound symbol GHC.Err.undefined"
-  , errorTest "tests/errors/T1708.hs"               1 "Unbound symbol T1708.bool1"
-  , errorTest "tests/errors/SplitSubtype.hs"        1 "| VV > 5}"
-  -- , errorTest "tests/errors/UnknownTyConHole.hs"    2 "HINT: Use the hole" 
-  -- TODO-REBARE ?, errorTest "tests/errors/MissingField1.hs"        2 "Error: Unknown field `goober`" 
-  -- TODO-REBARE ?, errorTest "tests/errors/MissingField2.hs"        2 "Error: Unknown field `fxx`" 
-  ]
-
-macroTests :: IO TestTree
-macroTests = group "Macro"
-   [ testGroup "unit-pos"       <$> dirTests "tests/pos"                            posIgnored        ExitSuccess     (Just " SAFE ") (Just " UNSAFE ")
-   , testGroup "unit-neg"       <$> dirTests "tests/neg"                            negIgnored        (ExitFailure 1) (Just " UNSAFE ") Nothing
-   ] 
-
-{- 
-goldenTests :: IO TestTree
-goldenTests = group "Golden tests"
-   [ pure $ goldenTest "--json output" "tests/golden" "json_output" [LO "--json"]
-   ] 
-
-goldenTest :: TestName -> FilePath -> FilePath -> [LiquidOpts] -> TestTree
-goldenTest testName dir filePrefix testOpts =
-  askOption $ \(smt  :: SmtSolver) -> 
-  askOption $ \(opts :: LiquidOpts) ->
-  askOption $ \(bin  :: LiquidRunner) ->
-    goldenVsString testName
-                   (dir </> filePrefix <> ".golden") 
-                   (toS . snd <$> runLiquidOn smt (mconcat testOpts <> opts) bin dir (filePrefix <> ".hs"))
-
--}
-
-microTests :: IO TestTree
-microTests = group "Micro"
-  [ mkMicroPos "parser-pos"     "tests/parser/pos"
-  , mkMicroPos "basic-pos"      "tests/basic/pos"
-  , mkMicroNeg "basic-neg"      "tests/basic/neg"
-  , mkMicroPos "measure-pos"    "tests/measure/pos"         -- measPosOrder
-  , mkMicroNeg "measure-neg"    "tests/measure/neg"
-  , mkMicroPos "datacon-pos"    "tests/datacon/pos"
-  , mkMicroNeg "datacon-neg"    "tests/datacon/neg"
-  , mkMicroPos "names-pos"      "tests/names/pos"
-  , mkMicroNeg "names-neg"      "tests/names/neg"
-  , mkMicroPos "reflect-pos"    "tests/reflect/pos"
-  , mkMicroNeg "reflect-neg"    "tests/reflect/neg"
-  , mkMicroPos "absref-pos"     "tests/absref/pos"
-  , mkMicroNeg "absref-neg"     "tests/absref/neg"
-  -- , mkMicroPos "import-lib"     "tests/import/lib"      -- NOT disabled; but via CHECK-IMPORTS
-  , mkMicroPos "import-cli"     "tests/import/client"
-  , mkMicroPos "class-pos"      "tests/classes/pos"
-  , mkMicroNeg "class-neg"      "tests/classes/neg"
-  , mkMicroPos "ple-pos"        "tests/ple/pos"
-  , mkMicroNeg "ple-neg"        "tests/ple/neg"
-  , mkMicroPos "rankN-pos"      "tests/RankNTypes/pos"
-  , mkMicroPos "terminate-pos"  "tests/terminate/pos"
-  , mkMicroNeg "terminate-neg"  "tests/terminate/neg"
-  , mkMicroPos "pattern-pos"    "tests/pattern/pos"
-  -- , mkMicroPos "class-laws-pos" "tests/class-laws/pos"
-  -- , mkMicroLaw "class-laws-crash" "tests/class-laws/crash"
-  -- , mkMicroNeg "class-laws-neg"   "tests/class-laws/neg"
-  , mkMicroPos "implicit-pos"   "tests/implicit/pos"
-  , mkMicroNeg "implicit-neg"   "tests/implicit/neg"
-  -- RJ: disabling because broken by adt PR #1068
-  -- , testGroup "gradual/pos"    <$> dirTests "tests/gradual/pos"                    []                ExitSuccess
-  -- , testGroup "gradual/neg"    <$> dirTests "tests/gradual/neg"                    []                (ExitFailure 1)
-  , mkMicroPos "typeclass-pos"  "tests/typeclasses/pos"
-  ]
-  where
-    mkMicroPos name dir = testGroup name <$> dirTests dir [] ExitSuccess     (Just " SAFE ") (Just " UNSAFE ")
-    mkMicroNeg name dir = testGroup name <$> dirTests dir [] (ExitFailure 1) (Just " UNSAFE ") Nothing
-    mkMicroLaw name dir = testGroup name <$> dirTests dir [] (ExitFailure 1) (Just "Law Instance Error") Nothing
-
-
-posIgnored    = [ "mapreduce.hs", "Variance.hs" ]
-gPosIgnored   = ["Intro.hs"]
-gNegIgnored   = ["Interpretations.hs", "Gradual.hs"]
-
-benchTests :: IO TestTree
-benchTests = group "Benchmarks"
-  [ testGroup "cse230"      <$> dirTests   "benchmarks/cse230/src/Week10"         []                        ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "esop"        <$> dirTests  "benchmarks/esop2013-submission"        esopIgnored               ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "vect-algs"   <$> odirTests  "benchmarks/vector-algorithms-0.5.4.2" []            vectOrder   ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "bytestring"  <$> odirTests  "benchmarks/bytestring-0.9.2.1"        bsIgnored     bsOrder     ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "text"        <$> odirTests  "benchmarks/text-0.11.2.3"             textIgnored   textOrder   ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "icfp_pos"    <$> odirTests  "benchmarks/icfp15/pos"                icfpIgnored   icfpOrder   ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "icfp_neg"    <$> odirTests  "benchmarks/icfp15/neg"                icfpIgnored   icfpOrder   (ExitFailure 1) (Just " UNSAFE ") Nothing
-  ]
-
--- AUTO-ORDER _impLibOrder :: Maybe FileOrder 
--- AUTO-ORDER _impLibOrder = Just . mkOrder $ [ "T1102_LibZ.hs", "WrapLibCode.hs", "STLib.hs", "T1102_LibY.hs" ]
--- AUTO-ORDER 
--- AUTO-ORDER _dconPosOrder :: Maybe FileOrder 
--- AUTO-ORDER _dconPosOrder = Just . mkOrder $ [ "Data02Lib.hs" ]
--- AUTO-ORDER 
--- AUTO-ORDER _measPosOrder :: Maybe FileOrder 
--- AUTO-ORDER _measPosOrder = Just . mkOrder $ [ "List00Lib.hs" ]
-
-proverOrder :: Maybe FileOrder 
-proverOrder = Just . mkOrder $ 
-  [ "Proves.hs"
-  , "Helper.hs" 
-  ]
-
-icfpOrder :: Maybe FileOrder 
-icfpOrder = Just . mkOrder $ 
-  [ "RIO.hs" 
-  , "RIO2.hs"
-  , "WhileM.hs" 
-  , "DataBase.hs"
-  ]
-
-vectOrder :: Maybe FileOrder 
-vectOrder = Just . mkOrder $ 
-  [ "Data/Vector/Algorithms/Common.hs"
-  , "Data/Vector/Algorithms/Search.hs"
-  , "Data/Vector/Algorithms/Radix.hs"
-  , "Data/Vector/Algorithms/Termination.hs"
-  , "Data/Vector/Algorithms/Optimal.hs"
-  , "Data/Vector/Algorithms/Insertion.hs"
-  , "Data/Vector/Algorithms/Merge.hs"
-  , "Data/Vector/Algorithms/Heap.hs"
-  , "Data/Vector/Algorithms/Intro.hs"
-  , "Data/Vector/Algorithms/AmericanFlag.hs" 
-  ]  
- 
-bsOrder :: Maybe FileOrder 
-bsOrder = Just . mkOrder $ 
-  [ "Data/ByteString/Internal.hs" 
-  , "Data/ByteString/Lazy/Internal.hs" 
-  , "Data/ByteString/Fusion.hs" 
-  , "Data/ByteString/Fusion.T.hs" 
-  , "Data/ByteString/Unsafe.hs" 
-  , "Data/ByteString.T.hs"
-  , "Data/ByteString.hs"
-  , "Data/ByteString/Lazy.hs"
-  , "Data/ByteString/LazyZip.hs"
-  ]
-
-textOrder :: Maybe FileOrder 
-textOrder = Just . mkOrder $ 
-  [ "Data/Text/Encoding/Utf16.hs"       -- skip
-  , "Data/Text/Unsafe/Base.hs"          -- skip
-  , "Data/Text/UnsafeShift.hs"          -- skip
-  , "Data/Text/Util.hs"
-  , "Data/Text/Fusion/Size.hs"
-  , "Data/Text/Fusion/Internal.hs"      -- skip
-  , "Data/Text/Fusion/CaseMapping.hs"   -- skip
-  , "Data/Text/Fusion/Common.hs"        -- skip
-  , "Data/Text/Array.hs"
-  , "Data/Text/UnsafeChar.hs"
-  , "Data/Text/Internal.hs"
-  , "Data/Text/Search.hs"
-  , "Data/Text/Axioms.hs"               
-  , "Data/Text/Unsafe.hs"
-  , "Data/Text/Private.hs"
-  , "Data/Text/Fusion/Common.hs"
-  , "Data/Text/Fusion.hs"
-  , "Data/Text/Foreign.hs"
-  , "Data/Text.hs"
-  , "Data/Text/Lazy/Internal.hs"
-  , "Data/Text/Lazy/Search.hs"
-  , "Data/Text/Lazy/Fusion.hs"
-  , "Data/Text/Lazy.hs"
-  , "Data/Text/Lazy/Builder.hs"
-  , "Data/Text/Encoding/Fusion.hs"
-  , "Data/Text/Encoding.hs"
-  , "Data/Text/Lazy/Encoding/Fusion.hs"
-  , "Data/Text/Lazy/Encoding.hs"
-  ] 
-  
--- errorTest "tests/errors/ShadowFieldInline.hs"   2 "Error: Multiple specifications for `pig`"
-
-proverTests :: IO TestTree
-proverTests = group "Prover"
-  [ testGroup "foundations"     <$> dirTests  "benchmarks/sf"                ignoreLists                 ExitSuccess    (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "prover_ple_lib"  <$> odirTests "benchmarks/popl18/lib"        []             proverOrder  ExitSuccess    (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "without_ple_pos" <$> odirTests "benchmarks/popl18/nople/pos"  noPleIgnored   proverOrder  ExitSuccess    (Just " SAFE ") (Just " UNSAFE ")
-  , testGroup "without_ple_neg" <$> odirTests "benchmarks/popl18/nople/neg"  noPleIgnored   proverOrder (ExitFailure 1) (Just " UNSAFE ") Nothing
-  , testGroup "with_ple"        <$> odirTests "benchmarks/popl18/ple/pos"    autoIgnored    proverOrder  ExitSuccess    (Just " SAFE ") (Just " UNSAFE ")
-  ]
-
-
-selfTests :: IO TestTree
-selfTests
-  = group "Self" [
-      testGroup "liquid"      <$> dirTests "src"  [] ExitSuccess (Just " SAFE ") (Just " UNSAFE ")
-  ]
-
---------------------------------------------------------------------------------
--- | For each file in `root` check, that we get the given exit `code.`
---------------------------------------------------------------------------------
-dirTests :: FilePath -> [FilePath] -> ExitCode -> Maybe T.Text -> Maybe T.Text -> IO [TestTree]
---------------------------------------------------------------------------------
-dirTests root ignored ecode yesLog noLog = odirTests root ignored Nothing ecode yesLog noLog
-
---------------------------------------------------------------------------------
-odirTests :: FilePath -> [FilePath] -> Maybe FileOrder -> ExitCode -> Maybe T.Text -> Maybe T.Text -> IO [TestTree]
---------------------------------------------------------------------------------
-odirTests root ignored fo ecode yesLog noLog = do
-  files     <- walkDirectory False root
-  -- print (show files)
-  let tests  = sortOrder fo [ rel | f <- files
-                                  , isTest f
-                                  , let rel = makeRelative root f
-                                  , rel `notElem` ignored
-                            ]
-  -- print (show tests)
-  return     $ mkCodeTest ecode yesLog noLog root <$> tests
-
-mkCodeTest :: ExitCode -> Maybe T.Text -> Maybe T.Text -> FilePath -> FilePath -> TestTree
-mkCodeTest code yesLog noLog dir file = mkTest (EC file code yesLog noLog) dir file
-
-isTest   :: FilePath -> Bool
-isTest f =  takeExtension f == ".hs"
-         || takeExtension f == ".lhs"
-
---------------------------------------------------------------------------------
--- | @FileOrder@ is a hack to impose a "build" order on the paths in a given directory
---------------------------------------------------------------------------------
-type FileOrder = Map.Map FilePath Int 
-
-getOrder :: FileOrder -> FilePath -> Int 
-getOrder m f = Map.findWithDefault (1 + Map.size m) f m 
-
--- | Creates an order from a list. Files not in this order will be treated as
--- coming later.
---
-mkOrder :: [FilePath] -> FileOrder 
-mkOrder fs = Map.fromList (zip fs [0..])
-
-defaultFileOrder :: [FilePath] -> [FilePath]
-defaultFileOrder = L.reverse . sortOn stringLower 
-
-sortOrder :: Maybe FileOrder -> [FilePath] -> [FilePath]
-sortOrder Nothing   fs = defaultFileOrder fs 
-sortOrder (Just fo) fs = sortOn (getOrder fo) ordFs ++ defaultFileOrder otherFs 
-  where 
-    (ordFs, otherFs)   = L.partition (`Map.member` fo) fs 
-
-sortOn :: (Ord b) => (a -> b) -> [a] -> [a]
-sortOn f = L.sortBy (compare `on` f)
-
-stringLower :: FilePath -> FilePath 
-stringLower = fmap toLower
-
---------------------------------------------------------------------------------
--- | Check that we get the given `err` text and `ExitFailure status` for the given `path`.
---------------------------------------------------------------------------------
-errorTest :: FilePath -> Int -> T.Text -> IO TestTree
---------------------------------------------------------------------------------
-errorTest path status err = return (mkTest ec dir file)
-  where
-    ec                    = EC file (ExitFailure status) (Just err) Nothing
-    (dir, file)           = splitFileName path
-
---------------------------------------------------------------------------------
-data ExitCheck = EC { ecTest :: FilePath, ecCode :: ExitCode, ecLog :: Maybe T.Text, ecNotLog :: Maybe T.Text }
-                 deriving (Show)
-
-ecAssert :: ExitCheck -> ExitCode -> T.Text -> Assertion
-ecAssert ec (ExitFailure 137) _   =
-  printf "WARNING: possible OOM while testing %s: IGNORING" (ecTest ec)
-
-ecAssert (EC _ code yesLog noLog) c log = do
-  assertEqual ("Wrong exit code; output:\n" <> output) code c
-  if (c == ExitSuccess && T.null log)
-    then do
-      hPutStr stderr "(skipping as apparently already compiled ...) "
-    else do
-      case yesLog of
-        Nothing -> pure ()
-        Just t  -> assertBool ("Did not match message: " <> show (T.unpack t) <> "\n" <> show log) (T.isInfixOf t log)
-      case noLog of
-        Nothing -> pure ()
-        Just t  -> assertBool ("Did match unexpected message: " <> show (T.unpack t) <> "\n" <> output) (not (T.isInfixOf t log))
-  where
-    output = unlines (map ("  > " ++) (lines (T.unpack log)))
-
---------------------------------------------------------------------------------
-mkTest :: ExitCheck -> FilePath -> FilePath -> TestTree
---------------------------------------------------------------------------------
-mkTest ec dir file
-  = askOption $ \(smt :: SmtSolver)   ->
-    askOption $ \(opts :: LiquidOpts) ->
-    askOption $ \(bin  :: LiquidRunner)   -> testCase file $
-      if test `elem` knownToFail smt
-      then do
-        printf "%s is known to fail with %s: SKIPPING" test (show smt)
-        assertEqual "" True True
-      else runLiquidOn smt opts bin dir file >>= uncurry (ecAssert ec)
-  where
-    test = dir </> file
-
-
---------------------------------------------------------------------------------
-runLiquidOn :: SmtSolver 
-            -> LiquidOpts 
-            -> LiquidRunner
-            -> FilePath
-            -> FilePath 
-            -> IO (ExitCode, T.Text)
---------------------------------------------------------------------------------
-runLiquidOn smt opts (LiquidRunner bin) dir file = do
-  absoluteDir <- canonicalizePath dir
-  createDirectoryIfMissing True $ takeDirectory log
-  hSetBuffering stdout NoBuffering
-  withFile log WriteMode $ \h -> do
-    let cmd     = testCmd bin dir file smt $ mappend (extraOptions dir absoluteDir testFileFullPath) (mkLiquidOpt opts)
-    (_,_,_,ph) <- createProcess $ (shell cmd) {std_out = UseHandle h, std_err = UseHandle h}
-    exitCode   <- waitForProcess ph
-    (exitCode,) <$> T.readFile log
-  where
-    testFileFullPath = dir </> file
-    log = "tests/logs/cur" </> testFileFullPath <.> "log"
-
-
-binPath :: FilePath -> IO FilePath
-binPath pkgName = (</> pkgName) <$> getBinDir
-
-knownToFail :: SmtSolver -> [FilePath]
-knownToFail CVC4 = [ "tests/pos/linspace.hs"
-                   , "tests/pos/RealProps.hs"
-                   , "tests/pos/RealProps1.hs"
-                   , "tests/pos/initarray.hs"
-                   , "tests/pos/maps.hs"
-                   , "tests/pos/maps1.hs"
-                   , "tests/neg/maps.hs"
-                   , "tests/pos/Product.hs"
-                   , "tests/pos/Gradual.hs"
-                   , "tests/equationalproofs/pos/MapAppend.hs"
-                   ]
-
-knownToFail Z3   = [ "tests/pos/linspace.hs"
-                   , "tests/equationalproofs/pos/MapAppend.hs"
-                   ]
-
--- | An option (like \"-i\") that also GHC can understand. This newtype is useful to
--- separate \"package-resolution\" options that we can feed to both the plugin /and/
--- the executable with options that are liquidhaskell-specific.
-newtype GhcSuitableOpts = GhcSuitableOpts LiquidOpts deriving (Monoid, Semigroup)
-newtype LiquidOnlyOpts  = LiquidOnlyOpts  LiquidOpts deriving (Monoid, Semigroup)
-
-data ExtraOptions = ExtraOptions { 
-    ghcSuitableOpts :: GhcSuitableOpts
-  , liquidOnlyOpts  :: LiquidOnlyOpts
-  }
-
-mkGhcOpt :: LiquidOpts -> ExtraOptions
-mkGhcOpt o = ExtraOptions (GhcSuitableOpts o) mempty
-
-mkLiquidOpt :: LiquidOpts -> ExtraOptions
-mkLiquidOpt o = ExtraOptions mempty (LiquidOnlyOpts o)
-
-instance Semigroup ExtraOptions where
-    (ExtraOptions o1 o2) <> (ExtraOptions o3 o4) = ExtraOptions (o1 <> o3) (o2 <> o4)
-
-instance Monoid ExtraOptions where
-    mempty  = ExtraOptions mempty mempty
-    mappend = (<>)
-
---------------------------------------------------------------------------------
-extraOptions :: FilePath 
-             -- ^ The current directory /relative/ path.
-             -> FilePath
-             -- ^ The current directory /absolute/ path.
-             -> FilePath 
-             -> ExtraOptions
---------------------------------------------------------------------------------
-extraOptions dir absDir testFileFullPath = mappend (dirOpts dir) (testOpts testFileFullPath)
-  where
-    dirOpts = flip (Map.findWithDefault mempty) $ Map.fromList
-      [ ( "benchmarks/bytestring-0.9.2.1"
-        , mkGhcOpt (LO $ printf "-i%s/include " absDir) <>
-#ifdef USE_NEW_EXECUTABLE
-          mkGhcOpt (LO "-w")
-#else
-          mkLiquidOpt (LO "--ghc-option=-w")
-#endif
-        )
-      , ( "benchmarks/text-0.11.2.3"
-        , mkLiquidOpt "--bscope --no-check-imports " <>
-          mkGhcOpt    (LO $ printf "-i%s/../bytestring-0.9.2.1 " absDir) <>
-          mkGhcOpt    (LO $ printf "-i%s/../bytestring-0.9.2.1/include " absDir) <>
-          mkGhcOpt    (LO $ printf "-i%s/../../include" absDir) <>
-#ifdef USE_NEW_EXECUTABLE
-          mkGhcOpt    (LO "-w")
-#else
-          mkLiquidOpt (LO "--ghc-option=-w")
-#endif
-        )
-      , ( "benchmarks/vector-0.10.0.1"
-        , mkGhcOpt (LO $ printf "-i%s/." absDir)
-        )
-      , ( "tests/import/client"
-        , mkGhcOpt (LO $ printf "-i%s/../lib" absDir)
-        )
-      , ( "benchmarks/popl18/nople/pos"
-        , mkGhcOpt (LO $ printf "-i%s/../../lib" absDir)
-        )
-      , ( "benchmarks/popl18/nople/neg"
-        , mkGhcOpt (LO $ printf "-i%s/../../lib" absDir)
-        )
-      , ( "benchmarks/popl18/ple/pos"
-        , mkGhcOpt (LO $ printf "-i%s/../../lib" absDir)
-        )
-      ]
-    testOpts = flip (Map.findWithDefault mempty) $ Map.fromList
-      [ ( "tests/pos/Class2.hs"
-        , mkGhcOpt (LO $ printf "-i%s/../neg" absDir)
-        )
-      , ( "tests/pos/FFI.hs"
-        , mkGhcOpt (LO $ printf "-i%s/../ffi-include" absDir) <> 
-          mkLiquidOpt "--c-files=../ffi-include/foo.c"
-        )
-      ]
-
----------------------------------------------------------------------------
-testCmd :: FilePath -> FilePath -> FilePath -> SmtSolver -> ExtraOptions -> String
----------------------------------------------------------------------------
-testCmd bin dir file smt (ExtraOptions (GhcSuitableOpts (LO ghcOpts)) (LiquidOnlyOpts (LO liquidOnlyOpts)))
-#ifdef USE_NEW_EXECUTABLE
-  = printf "%s -i. -i%s %s %s %s" bin dir ghcOpts liquidOpts (dir </> file)
-  where
-    liquidOpts = ("--smtsolver=" ++ show smt) <> " " <> liquidOnlyOpts
-#else
-  = printf "cd %s && %s -i . --smtsolver %s %s %s" dir bin (show smt) file (ghcOpts <> " " <> liquidOnlyOpts)
-#endif
-
-ignoreLists :: [FilePath]
-ignoreLists = ["Lists.hs"]       -- TODO: Flaky. Sometimes timeouts in CI after 20 minutes. See #1884
-
-noPleIgnored :: [FilePath]
-noPleIgnored 
-  = "ApplicativeList.hs"         -- TODO-REBARE: TODO BLOWUP but ple version ok
-  : autoIgnored
-
-esopIgnored 
-  = [ "Base0.hs"
-    ]
-
-icfpIgnored :: [FilePath]
-icfpIgnored 
-  = [ "FindRec.hs"
-    , "CopyRec.hs"
-    , "TwiceM.hs"                -- TODO: BLOWUP: using 2.7GB RAM
-    ]
-
-autoIgnored 
-  = "Ackermann.hs" 
-  : proverIgnored
-
-proverIgnored  :: [FilePath]
-proverIgnored 
-  = [ "OverviewListInfix.hs"
-    -- , "Proves.hs"
-    -- , "Helper.hs"
-    , "FunctorReader.hs"      -- NOPROP: TODO: Niki please fix!
-    , "MonadReader.hs"        -- NOPROP: ""
-    , "ApplicativeReader.hs"  -- NOPROP: ""
-    , "FunctorReader.NoExtensionality.hs" -- Name resolution issues
-    -- , "Fibonacci.hs"          -- REFLECT-IMPORTS: TODO: Niki please fix!
-    ]
-
-
-
-hscIgnored :: [FilePath]
-hscIgnored 
-  = [ "HsColour.hs"
-    , "Language/Haskell/HsColour/Classify.hs"      -- eliminate
-    , "Language/Haskell/HsColour/Anchors.hs"       -- eliminate
-    , "Language/Haskell/HsColour/ACSS.hs"          -- eliminate
-    ]
-
-negIgnored :: [FilePath]
-negIgnored 
-  = [ "Lib.hs"
-    , "LibSpec.hs"
-    -- See: https://github.com/ucsd-progsys/liquidhaskell/issues/1677
-    , "QQTySyn2.hs"
-    , "QQTySyn1.hs"
-    , "QQTySig.hs"
-    , "elim-ex-map-3.hs"
-    , "elim-ex-map-2.hs"
-    , "elim-ex-map-1.hs"
-    , "elim-ex-let.hs"
-    , "Variance1.hs"
-    ]
-
-bsIgnored :: [FilePath]
-bsIgnored 
-  = [ "Data/ByteString.T.hs" ]                    -- TODO-REBARE
-
-
-textIgnored :: [FilePath]
-textIgnored 
-  = [ "Setup.lhs"
-    -- , "Data/Text/Axioms.hs"
-    , "Data/Text/Encoding/Error.hs"
-    , "Data/Text/Encoding/Fusion.hs"        -- has nothing in int (compile-spec) but triggers 18 import-builds
-    , "Data/Text/Encoding/Fusion/Common.hs"
-    , "Data/Text/Encoding/Utf16.hs"
-    , "Data/Text/Encoding/Utf32.hs"
-    , "Data/Text/Encoding/Utf8.hs"
-    , "Data/Text/Fusion/CaseMapping.hs"
-    , "Data/Text/IO.hs"
-    , "Data/Text/IO/Internal.hs"
-    , "Data/Text/Lazy/Builder/Functions.hs"
-    , "Data/Text/Lazy/Builder/Int.hs"
-    , "Data/Text/Lazy/Builder/Int/Digits.hs"
-    , "Data/Text/Lazy/Builder/Internal.hs"
-    , "Data/Text/Lazy/Builder/RealFloat.hs"
-    , "Data/Text/Lazy/Builder/RealFloat/Functions.hs"
-    , "Data/Text/Lazy/IO.hs"
-    , "Data/Text/Lazy/Read.hs"
-    , "Data/Text/Read.hs"
-    , "Data/Text/Unsafe/Base.hs"
-    , "Data/Text/UnsafeShift.hs"
-    -- , "Data/Text/Util.hs"
-    , "Data/Text/Fusion-debug.hs"
-    -- , "Data/Text/Encoding.hs"
-    ]
-
-demosIgnored :: [FilePath]
-demosIgnored = [ "Composition.hs"
-               , "Eval.hs"
-               , "Inductive.hs"
-               , "Loop.hs"
-               , "TalkingAboutSets.hs"
-               , "refinements101reax.hs"
-               ]
-
-----------------------------------------------------------------------------------------
--- Generic Helpers
-----------------------------------------------------------------------------------------
-group :: (Monad m) => TestName -> [m TestTree] -> m TestTree
-group n xs = testGroup n <$> sequence xs
-
-gitTimestamp :: IO String
-gitTimestamp = do
-   res <- gitProcess ["show", "--format=\"%ci\"", "--quiet"]
-   return $ filter notNoise res
-
-gitEpochTimestamp :: IO String
-gitEpochTimestamp = do
-   res <- gitProcess ["show", "--format=\"%ct\"", "--quiet"]
-   return $ filter notNoise res
-
-gitHash :: IO String
-gitHash = do
-   res <- gitProcess ["show", "--format=\"%H\"", "--quiet"]
-   return $ filter notNoise res
-
-gitRef :: IO String
-gitRef = do
-   res <- gitProcess ["show", "--format=\"%d\"", "--quiet"]
-   return $ filter notNoise res
-
--- | Calls `git` for info; returns `"plain"` if we are not in a git directory.
-gitProcess :: [String] -> IO String
-gitProcess args = (readProcess "git" args []) `catchIOError` const (return "plain")
-
-notNoise :: Char -> Bool
-notNoise a = a /= '\"' && a /= '\n' && a /= '\r'
-
-headerDelim :: String
-headerDelim = replicate 80 '-'
-
-----------------------------------------------------------------------------------------
-walkDirectory :: Bool -> FilePath -> IO [FilePath]
-----------------------------------------------------------------------------------------
-walkDirectory del root = do 
-  when del (nukeIfThere (root </> ".liquid"))
-  (ds,fs) <- partitionM doesDirectoryExist . candidates =<< (getDirectoryContents root `catchIOError` const (return []))
-  (fs ++) <$> concatMapM (walkDirectory del) ds
-  where
-    candidates fs = [root </> f | f <- fs, not (isExtSeparator (head f))]
-
-nukeIfThere :: FilePath -> IO () 
-nukeIfThere dir = do 
-  ex <- doesDirectoryExist dir 
-  if ex then removeDirectoryRecursive dir else return () 
-
-partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a],[a])
-partitionM f = go [] []
-  where
-    go ls rs []     = return (ls,rs)
-    go ls rs (x:xs) = do b <- f x
-                         if b then go (x:ls) rs xs
-                              else go ls (x:rs) xs
-
--- isDirectory :: FilePath -> IO Bool
--- isDirectory = fmap Posix.isDirectory . Posix.getFileStatus
-
-concatMapM :: Applicative m => (a -> m [b]) -> [a] -> m [b]
-concatMapM _ []     = pure []
-concatMapM f (x:xs) = (++) <$> f x <*> concatMapM f xs
-
--- | Combine two @TestReporter@s into one.
---
--- Runs the reporters in sequence, so it's best to start with the one
--- that will produce incremental output, e.g. 'consoleTestReporter'.
-combineReporters :: Ingredient -> Ingredient -> Ingredient
-combineReporters (TestReporter opts1 run1) (TestReporter opts2 run2)
-  = TestReporter (opts1 ++ opts2) $ \opts tree -> do
-      f1 <- run1 opts tree
-      f2 <- run2 opts tree
-      return $ \smap -> f1 smap >> f2 smap
-combineReporters _ _ = error "combineReporters needs TestReporters"
-
-type Summary = [(String, Double, Bool)]
-
--- this is largely based on ocharles' test runner at
--- https://github.com/ocharles/tasty-ant-xml/blob/master/Test/Tasty/Runners/AntXML.hs#L65
-loggingTestReporter :: Ingredient
-loggingTestReporter = TestReporter [] $ \opts tree -> Just $ \smap -> do
-  let
-    runTest _ testName _ = Traversal $ Functor.Compose $ do
-        i <- State.get
-
-        summary <- lift $ STM.atomically $ do
-          status <- STM.readTVar $
-            fromMaybe (error "Attempted to lookup test by index outside bounds") $
-              IntMap.lookup i smap
-
-          let mkSuccess time = [(testName, time, True)]
-              mkFailure time = [(testName, time, False)]
-
-          case status of
-            -- If the test is done, generate a summary for it
-            Done result
-              | resultSuccessful result
-                  -> pure (mkSuccess (resultTime result))
-              | otherwise
-                  -> pure (mkFailure (resultTime result))
-            -- Otherwise the test has either not been started or is currently
-            -- executing
-            _ -> STM.retry
-
-        Const summary <$ State.modify (+ 1)
-
-    runGroup _ group children = Traversal $ Functor.Compose $ do
-      Const soFar <- Functor.getCompose $ getTraversal children
-      pure $ Const $ map (\(n,t,s) -> (group</>n,t,s)) soFar
-
-    computeFailures :: StatusMap -> IO Int
-    computeFailures = fmap getSum . getApp . foldMap (\var -> Ap $
-      (\r -> Sum $ if resultSuccessful r then 0 else 1) <$> getResultFromTVar var)
-
-    getResultFromTVar :: STM.TVar Status -> IO Result
-    getResultFromTVar var =
-      STM.atomically $ do
-        status <- STM.readTVar var
-        case status of
-          Done r -> return r
-          _ -> STM.retry
-
-  (Const summary, _tests) <-
-     flip State.runStateT 0 $ Functor.getCompose $ getTraversal $
-      foldTestTree
-        trivialFold { foldSingle = runTest, foldGroup = runGroup }
-        opts
-        tree
-
-  return $ \_elapsedTime -> do
-    -- get some semblance of a hostname
-    host <- takeWhile (/='.') . takeWhile (not . isSpace) <$> readProcess "hostname" [] []
-    -- don't use the `time` package, major api differences between ghc 708 and 710
-    time <- head . lines <$> readProcess "date" ["+%Y-%m-%dT%H-%M-%S"] []
-    -- build header
-    ref       <- gitRef
-    timestamp <- gitTimestamp
-    epochTime <- gitEpochTimestamp
-    hash      <- gitHash
-    let hdr = unlines [ref ++ " : " ++ hash,
-                       "Timestamp: " ++ timestamp,
-                       "Epoch Timestamp: " ++ epochTime,
-                       headerDelim,
-                       "test, time(s), result"]
-
-    let dir = "tests" </> "logs" </> host ++ "-" ++ time
-    let smry = "tests" </> "logs" </> "cur" </> "summary.csv"
-    writeFile smry $ unlines
-                   $ hdr
-                   : map (\(n, t, r) -> printf "%s, %0.4f, %s" n t (show r)) summary
-    system $ "cp -r tests/logs/cur " ++ dir
-    (==0) <$> computeFailures smap
