Skip to content

Commit

Permalink
Remove TauT.traverseApp, traverseTVar and headTCon
Browse files Browse the repository at this point in the history
I added them because I thought they would be useful, but they weren't.
  • Loading branch information
matil019 committed Nov 8, 2019
1 parent 4279cb5 commit f688cda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
5 changes: 3 additions & 2 deletions frege/compiler/Kinds.fr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Compiler.types.Global as G
import Compiler.common.Errors as E()
import Compiler.common.SymbolTable
import Compiler.common.Types as T(unifySigma, substSigma)
import Compiler.common.Lens (preview, set, view)

import Compiler.classes.Nice
import Compiler.instances.Nicer
Expand Down Expand Up @@ -436,4 +435,6 @@ rhoTCons set (rho@RhoFun{}) = rhoTCons sigset rho.rho where
rhoTCons set (rho@RhoTau{}) = tauTCons set rho.tau

--- find all 'QName's that denote types in a 'Tau' type
tauTCons set = maybe set (\c -> set `including` c.name) . preview TauT.headTCon
tauTCons set (TauT.Con c) = set `including` c.name
tauTCons set (TApp a b) = tauTCons (tauTCons set a) b
tauTCons set _ = set
7 changes: 5 additions & 2 deletions frege/compiler/common/Types.fr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Compiler.types.QNames (QName)
import Compiler.types.Positions (Position, getpos)
import Compiler.common.Binders
import frege.compiler.classes.Nice(Nice)
import frege.compiler.common.Lens(over)

--- tell if the 'SigmaT' represents a function type.
isFun (ForAll _ rho) g = isRhoFun rho g
Expand Down Expand Up @@ -292,7 +291,11 @@ rnTVar tree t = case lookup t.var tree of
Nothing -> t

rnTau :: TreeMap String String -> Tau -> Tau
rnTau tree = over TauT.traverseTVar (rnTVar tree)
rnTau tree (TApp a b) = TApp (rnTau tree a) (rnTau tree b)
rnTau _ (t@TauT.Con _) = t
rnTau tree (TauT.Var v) = TauT.Var $ rnTVar tree v
rnTau _ (t@TSig _) = t
rnTau _ (t@Meta _) = t

rnKind :: TreeMap String String Kind Kind
rnKind tree (KGen ts) = KGen (map (rnTau tree) ts)
Expand Down
34 changes: 0 additions & 34 deletions frege/compiler/types/Types.fr
Original file line number Diff line number Diff line change
Expand Up @@ -227,40 +227,6 @@ data TauT s =
_pos _ (t@(TSig _)) = pure t
_pos _ (t@(Meta _)) = pure t

{--
@traverseApp review\' preview\' f t@ traverses over 'TApp' and apply a transformation @f@.
@traverseApp@ uses @preview\'@ to choose an element to apply @f@, and @review\'@ to convert it back.
Elements that @preview\'@ returns @Nothing@ are left unchanged.
The arguments should satisfy the following law:
> maybe t review' (preview' t) == t
If we had @Prism@, @traverseApp@ is isomorphic to @:: Prism (TauT s) a -> Traversal' (TauT s) a@.
-}
-- traverseApp :: (a -> TauT s) -> (TauT s -> Maybe a) -> Traversal' (TauT s) a
traverseApp :: Applicative f => (a -> TauT s) -> (TauT s -> Maybe a) -> (a -> f a) -> TauT s -> f (TauT s)
traverseApp review' preview' f = go
where
go (TApp a b) = TApp <$> go a <*> go b
go t = case preview' t of
Just a -> review' <$> f a
Nothing -> pure t
--- Traverse over 'TVar's in 'TauT.Var' or recursively in case of 'TApp'
-- traverseTVar :: Traversal' (TauT s) (TVar s)
traverseTVar :: Applicative f => (TVar s -> f (TVar s)) -> TauT s -> f (TauT s)
traverseTVar = traverseApp Var (preview _Var)
{--
Access a bare 'TCon' or one in the head of a possibly nested 'TApp'.
For example,
> over TauT.headTCon f tau == case tau.flat of { (TauT.Con h:t) -> TauT.Con (f h):t; other -> other; }
-}
-- headTCon :: Traversal' (TauT s) (TCon s)
headTCon :: Applicative f => (TCon s -> f (TCon s)) -> TauT s -> f (TauT s)
headTCon f (Con c) = Con <$> f c
headTCon f (TApp a b) = (\a' -> TApp a' b) <$> headTCon f a
headTCon _ t = pure t

unkindVar :: String -> TauT a -> TauT a
unkindVar s (TauT.Var v) | s == v.var = TauT.Var v.{kind=KVar}
Expand Down

0 comments on commit f688cda

Please sign in to comment.