packages feed

haskell-src-exts-util 0.1.0 → 0.2.0

raw patch · 4 files changed

+28/−122 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Language.Haskell.Exts.Util: class Located a where type LocType a where {
- Language.Haskell.Exts.Util: location :: forall f. (Located a, Applicative f) => (LocType a -> f (LocType a)) -> a -> f a
- Language.Haskell.Exts.Util: type family LocType a;
- Language.Haskell.Exts.Util: }
- Language.Haskell.Exts.Util: Vars :: Set (Name s) -> Set (Name s) -> Vars s
+ Language.Haskell.Exts.Util: Vars :: Set (Name ()) -> Set (Name ()) -> Vars
- Language.Haskell.Exts.Util: [bound] :: Vars s -> Set (Name s)
+ Language.Haskell.Exts.Util: [bound] :: Vars -> Set (Name ())
- Language.Haskell.Exts.Util: [free] :: Vars s -> Set (Name s)
+ Language.Haskell.Exts.Util: [free] :: Vars -> Set (Name ())
- Language.Haskell.Exts.Util: allVars :: AllVars a => a -> Vars (LocType a)
+ Language.Haskell.Exts.Util: allVars :: AllVars a => a -> Vars
- Language.Haskell.Exts.Util: class (Located a) => AllVars a
+ Language.Haskell.Exts.Util: class AllVars a
- Language.Haskell.Exts.Util: class (Located a) => FreeVars a
+ Language.Haskell.Exts.Util: class FreeVars a
- Language.Haskell.Exts.Util: data Vars s
+ Language.Haskell.Exts.Util: data Vars
- Language.Haskell.Exts.Util: freeVars :: FreeVars a => a -> Set (Name (LocType a))
+ Language.Haskell.Exts.Util: freeVars :: FreeVars a => a -> Set (Name ())

Files

haskell-src-exts-util.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           haskell-src-exts-util-version:        0.1.0+version:        0.2.0 synopsis:       Helper functions for working with haskell-src-exts trees description:    see README.md category:       language@@ -34,7 +34,6 @@   other-modules:       Language.Haskell.Exts.Bracket       Language.Haskell.Exts.FreeVars-      Language.Haskell.Exts.Located       Language.Haskell.Exts.Util.Internal       Paths_haskell_src_exts_util   default-language: Haskell2010
src/Language/Haskell/Exts/FreeVars.hs view
@@ -18,7 +18,6 @@ import           Data.Set                      (Set) import qualified Data.Set                      as Set import           Language.Haskell.Exts-import           Language.Haskell.Exts.Located import           Prelude  (^+) :: (Data s, Ord s) => Set (Name s) -> Set (Name s) -> Set (Name s)@@ -26,55 +25,59 @@ (^-) :: (Data s, Ord s) => Set (Name s) -> Set (Name s) -> Set (Name s) (^-) = Set.difference -data Vars s = Vars {bound :: Set (Name s), free :: Set (Name s)}+data Vars = Vars {bound :: Set (Name ()), free :: Set (Name ())} -instance (Data s, Ord s) => Monoid (Vars s) where+instance Monoid Vars where     mempty = Vars Set.empty Set.empty     mappend (Vars x1 x2) (Vars y1 y2) = Vars (x1 ^+ y1) (x2 ^+ y2)     mconcat fvs = Vars (Set.unions $ map bound fvs) (Set.unions $ map free fvs) -instance Ord s => Located (Vars s) where-  type LocType (Vars s) = s-  location f (Vars b s)= Vars <$> location f b <*> location f s--class (Located a) => AllVars a where+class AllVars a where     -- | Return the variables, erring on the side of more free variables-    allVars :: a -> Vars (LocType a)+    allVars :: a -> Vars -class (Located a) => FreeVars a where+class FreeVars a where     -- | Return the variables, erring on the side of more free variables-    freeVars :: a -> Set (Name (LocType a))+    freeVars :: a -> Set (Name ()) -freeVars_ :: FreeVars a => a -> Vars (LocType a)+freeVars_ :: (FreeVars a) => a -> Vars freeVars_ = Vars Set.empty . freeVars -inFree :: (AllVars a, FreeVars b, Data s, Ord s, s ~ LocType a, s ~ LocType b) => a -> b -> Set (Name s)+inFree+  :: (AllVars a, FreeVars b)+  => a -> b -> Set (Name ()) inFree a b = free aa ^+ (freeVars b ^- bound aa)     where aa = allVars a -inVars :: (AllVars a, AllVars b, Data s, Ord s, s ~ LocType a, s ~ LocType b) => a -> b -> Vars s+inVars+  :: (AllVars a, AllVars b)+  => a -> b -> Vars inVars a b = Vars (bound aa ^+ bound bb) (free aa ^+ (free bb ^- bound aa))     where aa = allVars a           bb = allVars b -unqualNames :: QName s -> [Name s]-unqualNames (UnQual _ x) = [x]+unqualNames :: QName s -> [Name ()]+unqualNames (UnQual _ x) = [withNoLoc x] unqualNames _            = [] -unqualOp :: QOp s -> [Name s]+unqualOp :: QOp s -> [Name ()] unqualOp (QVarOp _ x) = unqualNames x unqualOp (QConOp _ x) = unqualNames x++withNoLoc x = fmap (const()) x+ instance (Data s, Ord s) => FreeVars (Set (Name s)) where-    freeVars = id+    freeVars = Set.map withNoLoc -instance (Data s, Ord s) => AllVars (Vars s) where+instance AllVars Vars where     allVars = id  instance (Data s, Ord s) => FreeVars (Exp s) where -- never has any bound variables     freeVars (Var _ x) = Set.fromList $ unqualNames x     freeVars (VarQuote l x) = freeVars $ Var l x-    freeVars (SpliceExp _ (IdSplice l x)) = Set.fromList [Ident l x]-    freeVars (InfixApp _ a op b) = freeVars a ^+ Set.fromList (unqualOp op) ^+ freeVars b+    freeVars (SpliceExp _ (IdSplice l x)) = Set.fromList [withNoLoc $ Ident l x]+    freeVars (InfixApp _ a op b) =+      freeVars a ^+ Set.fromList (unqualOp op) ^+ freeVars b     freeVars (LeftSection _ a op) = freeVars a ^+ Set.fromList (unqualOp op)     freeVars (RightSection _ op b) = Set.fromList (unqualOp op) ^+ freeVars b     freeVars (Lambda _ p x) = inFree p x@@ -91,7 +94,7 @@     freeVars = Set.unions . map freeVars  instance (Data s, Ord s) => AllVars (Pat s) where-    allVars (PVar _ x)       = Vars (Set.singleton x) Set.empty+    allVars (PVar _ x)       = Vars (Set.singleton $ withNoLoc x) Set.empty     allVars (PNPlusK l x _)  = allVars (PVar l x)     allVars (PAsPat l n x)   = allVars (PVar l n) `mappend` allVars x     allVars (PWildCard _)    = mempty -- explicitly cannot guess what might be bound here
− src/Language/Haskell/Exts/Located.hs
@@ -1,93 +0,0 @@-{-# LANGUAGE RankNTypes   #-}-{-# LANGUAGE TypeFamilies #-}-module Language.Haskell.Exts.Located-  ( Located(..)-  ) where--import           Data.Set              (Set)-import qualified Data.Set              as Set-import           Language.Haskell.Exts------------------------------------------------------------------------------- | Class of types containing source code locations-class Located a where-  type LocType a--  -- | Traversal providing access to the location details-  location :: forall f . Applicative f => (LocType a -> f (LocType a)) -> a -> f a--instance Located (Alt s) where-  type LocType (Alt s) = s-  location = locationForAnnotatedType--instance Located (Binds s) where-  type LocType (Binds s) = s-  location = locationForAnnotatedType--instance Located (Decl s) where-  type LocType (Decl s) = s-  location = locationForAnnotatedType--instance Located (Exp s) where-  type LocType (Exp s) = s-  location = locationForAnnotatedType--instance Located (IPBind s) where-  type LocType (IPBind s) = s-  location = locationForAnnotatedType--instance Located (Pat s) where-  type LocType (Pat s) = s-  location = locationForAnnotatedType--instance Located (Rhs s) where-  type LocType (Rhs s) = s-  location = locationForAnnotatedType--instance Located (GuardedRhs s) where-  type LocType (GuardedRhs s) = s-  location = locationForAnnotatedType--instance Located (Match s) where-  type LocType (Match s) = s-  location = locationForAnnotatedType--instance Located (Name s) where-  type LocType (Name s) = s-  location = locationForAnnotatedType--instance Located (Stmt s) where-  type LocType (Stmt s) = s-  location = locationForAnnotatedType--instance Located (QOp s) where-  type LocType (QOp s) = s-  location = locationForAnnotatedType--instance Located (QualStmt s) where-  type LocType (QualStmt s) = s-  location = locationForAnnotatedType--instance Located a => Located [a] where-  type LocType [a] = LocType a-  location = traverse.location--instance Located a => Located (Maybe a) where-  type LocType (Maybe a) = LocType a-  location = traverse.location--instance (Located a, Ord a) => Located (Set a) where-  type LocType (Set a) = LocType a-  -- | Valid only if it doesn't remove elements from the 'Set'-  location = traverseSet.location-    where-      traverseSet f s = Set.fromList <$> traverse f (Set.toList s)--instance (Located a, Located b, LocType a ~ LocType b) => Located (a,b) where-  type LocType (a,b) = LocType a-  location f (a,b) = (,) <$> location f a <*> location f b--locationForAnnotatedType-  :: (Functor f, Annotated ast)-  => (t -> f t) -> ast t -> f (ast t)-locationForAnnotatedType f x = (\v -> amap (const v) x) <$> f (ann x)
src/Language/Haskell/Exts/Util.hs view
@@ -1,8 +1,6 @@ module Language.Haskell.Exts.Util-  ( -- * Types annotated with source code locations-    Located(..)-    -- * Free variables of ASTs-  , FreeVars(..)+  ( -- * Free variables of ASTs+    FreeVars(..)   , Vars(..)   , AllVars(..)     -- * Rebracketing of ASTs@@ -16,4 +14,3 @@  import Language.Haskell.Exts.Bracket import Language.Haskell.Exts.FreeVars-import Language.Haskell.Exts.Located