typelet 0.1.2 → 0.1.3
raw patch · 4 files changed
+56/−18 lines, 4 filesdep ~basedep ~ghc-tcplugin-api
Dependency ranges changed: base, ghc-tcplugin-api
Files
- CHANGELOG.md +5/−1
- src/TypeLet/Plugin/NameResolution.hs +8/−11
- src/TypeLet/UserAPI.hs +39/−2
- typelet.cabal +4/−4
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for typelet +## 0.1.3 -- 2023-03-06++* Support ghc 9.4+ ## 0.1.2 -- 2022-07-22 * Add `constructLet` (#112)@@ -8,6 +12,6 @@ * Move to `ghc-tcplugin-api` 0.7 -## 0.1.0.0 -- 2021-12-17 +## 0.1.0.0 -- 2021-12-17 * First version.
src/TypeLet/Plugin/NameResolution.hs view
@@ -22,21 +22,18 @@ resolveNames :: TcPluginM 'Init ResolvedNames resolveNames = do- m <- do r <- findImportedModule typeletMod (OtherPkg typeletUnitId)- case r of- Found _ m -> return m- _otherwise -> panic $ "Could not find "- ++ showSDocUnsafe (ppr typeletMod)+ pkgQual <- resolveImport typeletMod (Just $ fsLit "typelet")+ modl <- do res <- findImportedModule typeletMod pkgQual+ case res of+ Found _ m -> return m+ _otherwise -> panic $ "resolveNames: could not find "+ ++ showSDocUnsafe (ppr typeletMod) -- Constraints handled by the plugin - clsEqual <- tcLookupClass =<< lookupOrig m (mkTcOcc "Equal")- clsLet <- tcLookupClass =<< lookupOrig m (mkTcOcc "Let")-+ clsEqual <- tcLookupClass =<< lookupOrig modl (mkTcOcc "Equal")+ clsLet <- tcLookupClass =<< lookupOrig modl (mkTcOcc "Let") return ResolvedNames{..} where typeletMod :: ModuleName typeletMod = mkModuleName "TypeLet.UserAPI"-- typeletUnitId :: UnitId- typeletUnitId = stringToUnitId "typelet"
src/TypeLet/UserAPI.hs view
@@ -20,6 +20,9 @@ import Data.Proxy import Unsafe.Coerce (unsafeCoerce) +-- $setup+-- >>> :set -fplugin=TypeLet+ {------------------------------------------------------------------------------- Main classes -------------------------------------------------------------------------------}@@ -50,8 +53,34 @@ -- @Let@ constraints of the right shape. When @Let@ constraints are introduced -- manually, the plugin will report a type error if ----- * The left-hand side is not a skolem type variable+-- * The left-hand side is not a type variable+--+-- >>> let aux :: Let Int Int => () ; aux = castEqual () in aux+-- ...+-- ...Let with non-variable LHS...+-- ...+--+-- >>> :{+-- \(x :: a) ->+-- let+-- y :: Let a Int => a+-- y = castEqual (1 :: Int)+-- in y+-- :}+-- ...+-- ...Let with non-variable LHS...+-- ...+-- -- * The set of let-bindings in scope are cyclic.+--+-- >>> :{+-- let cycle :: (Let a b, Let b a) => (a, b) -> (a, b)+-- cycle (a, b) = (castEqual b, castEqual a)+-- in cycle ('a', 'b')+-- :}+-- ...+-- ...Cycle in type-level let bindings: a := b, b := a+-- ... instance Let a a -- | (Nominal) type equality, up to type-level let@@ -69,7 +98,15 @@ -- | Type-safe cast, using 'Equal' as the notion of equality ----- See comments for 'Equal'.+-- See discussion of 'Equal' for additional information.+--+-- Note: without additional 'Let' constraints in scope, 'Equal' constraints+-- simply resolve to unification constraints:+--+-- >>> (castEqual :: Int -> Bool) 1+-- ...+-- ...Couldn't match...Int...Bool...+-- ... castEqual :: Equal a b => a -> b -- Implementation note: marking this as NOINLINE in an attempt to make sure that -- @unsafeCoerce@ does not escape the scope of the evidence for @Equal@ (which,
typelet.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 build-type: Simple name: typelet-version: 0.1.2+version: 0.1.3 synopsis: Plugin to faciliate type-level let description: For a certain class of programs, type-level let is essential in order to be able to write these programs in such a way@@ -17,7 +17,7 @@ copyright: Well-Typed LLP, Juspay Technologies Pvt Ltd category: Plugin extra-source-files: CHANGELOG.md-tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.2+tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.7 || ==9.4.4 source-repository head type: git@@ -34,8 +34,8 @@ TypeLet.Plugin.NameResolution TypeLet.Plugin.Substitution build-depends:- base >= 4.13 && < 4.17- , ghc-tcplugin-api >= 0.8 && < 0.9+ base >= 4.13 && < 4.18+ , ghc-tcplugin-api >= 0.10 && < 0.11 -- whichever versions are bundled with ghc: , containers