Add two new helper instances for Has

This commit is contained in:
John Wiegley 2018-04-30 14:55:10 -05:00
parent 3b738e3aa3
commit a735d3ffb6
2 changed files with 6 additions and 4 deletions

View file

@ -15,7 +15,6 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
@ -72,9 +71,6 @@ newtype Reducer m a = Reducer
MonadReader (Maybe FilePath, Scopes (Reducer m) NExprLoc),
MonadState (HashMap FilePath NExprLoc))
instance Has (Maybe FilePath, Scopes m v) (Scopes m v) where
hasLens f (x, y) = (x,) <$> f y
-- gatherNames :: NExprLoc -> HashSet VarName
-- gatherNames = cata $ \case
-- NSym_ _ var -> S.singleton var

View file

@ -108,6 +108,12 @@ class Has a b where
instance Has a a where
hasLens f = f
instance Has (a, b) a where
hasLens f (x, y) = (, y) <$> f x
instance Has (a, b) b where
hasLens f (x, y) = (x,) <$> f y
toEncodingSorted :: A.Value -> A.Encoding
toEncodingSorted = \case
A.Object m ->