Skip to content

Commit

Permalink
Order quantified variables by occurrence position rather than Ord ins…
Browse files Browse the repository at this point in the history
…tance
  • Loading branch information
glguy committed Aug 11, 2016
1 parent e7e9c1b commit 75938f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Control/Lens/Internal/FieldTH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import Control.Applicative
import Control.Monad
import Language.Haskell.TH.Lens
import Language.Haskell.TH
import Data.Foldable (toList)
import Data.Maybe (isJust,maybeToList)
import Data.List (nub, findIndices)
import Data.Either (partitionEithers)
Expand Down Expand Up @@ -592,16 +591,17 @@ data DefName
-- | Template Haskell wants type variables declared in a forall, so
-- we find all free type variables in a given type and declare them.
quantifyType :: Cxt -> Type -> Type
quantifyType c t = ForallT vs c t
where
vs = map PlainTV (toList (setOf typeVars t))
quantifyType = quantifyType' Set.empty

-- | This function works like 'quantifyType' except that it takes
-- a list of variables to exclude from quantification.
quantifyType' :: Set Name -> Cxt -> Type -> Type
quantifyType' exclude c t = ForallT vs c t
where
vs = map PlainTV (toList (setOf typeVars t Set.\\ exclude))
vs = map PlainTV
$ filter (`Set.notMember` exclude)
$ nub -- stable order
$ toListOf typeVars t


------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion src/Control/Lens/Internal/PrismTH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Control.Lens.Internal.PrismTH
) where

import Control.Applicative
import Control.Lens.Fold
import Control.Lens.Getter
import Control.Lens.Internal.TH
import Control.Lens.Lens
Expand Down Expand Up @@ -190,7 +191,9 @@ stabToType stab@(Stab cx ty s t a b) = ForallT vs cx $
ReviewType -> reviewTypeName `conAppsT` [t,b]

where
vs = map PlainTV (Set.toList (setOf typeVars cx))
vs = map PlainTV
$ nub -- stable order
$ toListOf typeVars cx

stabType :: Stab -> OpticType
stabType (Stab _ o _ _ _ _) = o
Expand Down

0 comments on commit 75938f1

Please sign in to comment.