diff --git a/frege/compiler/Classes.fr b/frege/compiler/Classes.fr index 9f4a8edd..f78a4aad 100644 --- a/frege/compiler/Classes.fr +++ b/frege/compiler/Classes.fr @@ -261,7 +261,7 @@ passC = do mkanno csym mpos osym ssym = do g <- getST i <- uniqid - let newvar = TVar{pos=mpos, var=noClashIdent ("t" ++ show i), kind = KVar} + let newvar = TVar {pos=mpos, var=noClashIdent ("t" ++ show i), kind = KVar} oldvar = ssym.clvar.var thsvar = csym.clvar.var tree1 = TreeMap.insert empty oldvar csym.clvar @@ -749,7 +749,7 @@ tcInstMethod (sc:scs) isym msym = do case msym of SymMeth.V msymv -> changeSym $ SymbolT.V msymv.{typ = msig, anno = true} _ -> pure () - _ -> E.fatal isym.pos $ msgdoc $ "RhoTau expected, got " ++ rhotau.nicer g + other -> E.fatal isym.pos (msgdoc ("RhoTau expected, got " ++ rhotau.nicer g)) Just (SymMeth.V (symv@SymV {typ=sig})) -> do -- isPSigma sig == true E.fatal symv.pos (text (symv.nice g ++ " of " ++ sc.nice g ++ " is not annotated")) -- Some class has a default method that links somewhere else diff --git a/frege/compiler/Kinds.fr b/frege/compiler/Kinds.fr index cce2b53b..b244ae5d 100644 --- a/frege/compiler/Kinds.fr +++ b/frege/compiler/Kinds.fr @@ -122,7 +122,7 @@ kiSigmaX sigma kind = do substSigmaBound (ForAll bound rho) e = ForAll new rho where - new = [ tv.{kind=k} | tv <- bound, k <- lookup tv.var e ] + new = [ tv.{kind=k} | tv ← bound, k ← lookup tv.var e ] kiRhoX :: Rho -> Envs -> Kind -> StG (Rho, Envs, Kind) kiRhoX (RhoT.Tau it) env kind = do @@ -198,9 +198,9 @@ substCtxKind :: TreeMap String (KindT β) -> ContextT β -> ContextT β substCtxKind env it = it.{tau <- substTauKind env} substTauKind :: TreeMap String (KindT β) -> TauT β -> TauT β -substTauKind env (TauT.Var it) = case env.lookup it.var of - Just kind -> TauT.Var it.{kind} - _ -> TauT.Var it +substTauKind env (TauT.Var it) = TauT.Var $ case env.lookup it.var of + Just kind -> it.{kind} + _ -> it substTauKind env (TApp a b) = TApp (substTauKind env a) (substTauKind env b) substTauKind env tau = tau @@ -251,12 +251,12 @@ unifyTauKind names env (TauT.Var tvar) exp case unifyKind tvar.kind exp of Nothing → do g ← getST - E.error tvar.pos (text ("kind error, wildcard `" + E.error tvar.pos (text ("kind error, wildcard `" ++ "` has kind " ++ nicer tvar.kind g ++ ", expected was " ++ nicer exp g)) pure (tvar.kind, env') - Just _ -> pure (tvar.kind, env') + Just _ → pure (tvar.kind, env') unifyTauKind names env (TauT.Var TVar{pos,var,kind}) exp = do g <- getST E.logmsg TRACEK pos (text ("unifyTauKind: " ++ var diff --git a/frege/compiler/Typecheck.fr b/frege/compiler/Typecheck.fr index 860cd546..d0de7601 100644 --- a/frege/compiler/Typecheck.fr +++ b/frege/compiler/Typecheck.fr @@ -180,7 +180,7 @@ pass = do --- e.g. @tc "Int"@ is the @'TCon' 'QName'@ with type constructor for @PreludeBase.Int@ tc :: String -> TCon QName -tc n = TCon{pos=Position.null, name=TName pPreludeBase n} +tc n = TCon {pos=Position.null, name=TName pPreludeBase n} --- @tcTau = TauT.Con . tc@, for abbreviation tcTau :: String -> Tau @@ -370,7 +370,7 @@ checkKind = correctK empty mapM_ (correctK subst) syms ex' <- mapEx false (correctKind subst) ex pure $ Right Let{env, ex = ex', typ = fmap (substSigma $ fmap TauT.Var subst) typ } - correctKind subst x = pure $ Left x.{typ ← fmap (substSigma $ fmap TauT.Var subst)} + correctKind subst x = pure $ Left x.{typ <- fmap (substSigma $ fmap TauT.Var subst)} checkAmbiguous :: Symbol -> Sigma -> StG () checkAmbiguous sym (ForAll bnd r) = do @@ -746,7 +746,7 @@ approxRho :: Expr -> StG Rho approxRho (Lam {ex,pat}) = do sig <- case pat of PAnn{pat, typ} -> return typ - sonst -> ForAll [] . RhoT.Tau . RhoTau [] <$> newMeta2 ("arg", KType) + _ -> ForAll [] . RhoT.Tau . RhoTau [] <$> newMeta2 ("arg", KType) rho <- approxRho ex pure $ RhoT.Fun $ RhoFun [] sig rho approxRho _ = newRhoTyVar ("res", KType) diff --git a/frege/compiler/Utilities.fr b/frege/compiler/Utilities.fr index c214b477..9e182519 100644 --- a/frege/compiler/Utilities.fr +++ b/frege/compiler/Utilities.fr @@ -220,7 +220,7 @@ freeCtxTVars bnd coll cs = fold ctxTVars coll cs freeTauTVars :: [String] -> SigmaEnv t -> TauT t -> SigmaEnv t freeTauTVars bound collected (TauT.Var (tv@TVar{var,kind})) - | isJust (TauT.Var tv).wildTau = coll + | isJust tv.wildTau = coll | var `elem` bound = coll | otherwise = insert var tv coll where @@ -434,13 +434,13 @@ private transSigma1 outer sigma = do case sigma of ForAll bound rho -> do inner ← transBounds sigma.bound - let env = fold (\tm tv -> tm.insertS tv.var tv) outer inner - unshadowedOuter = fold (\tm tv -> tm.delete tv.var) outer inner + let env = fold (\tm tv → tm.insertS tv.var tv) outer inner + unshadowedOuter = fold (\tm tv → tm.delete tv.var) outer inner rho <- transRho env rho let freeTV = freeTVars (keys unshadowedOuter) rho -- same as inner? - innerMap = fold (\tm tv -> tm.insertS tv.var tv) TreeMap.empty inner - newbound = [ maybe tv id (innerMap.lookupS tv.var) | tv <- freeTV ] - constraints rho = case rho of + innerMap = fold (\tm tv → tm.insertS tv.var tv) TreeMap.empty inner + newbound = [ maybe tv id (innerMap.lookupS tv.var) | tv ← freeTV ] + constraints rho = case rho of RhoT.Tau r -> (r.context, RhoT.Tau r.{context=[]}) RhoT.Fun r -> (r.context ++ subctx, RhoT.Fun r.{context=[], rho=subrho}) where (subctx, subrho) = constraints r.rho diff --git a/frege/compiler/common/ImpExp.fr b/frege/compiler/common/ImpExp.fr index abf97c09..04547fba 100644 --- a/frege/compiler/common/ImpExp.fr +++ b/frege/compiler/common/ImpExp.fr @@ -144,7 +144,7 @@ sigmaFromA :: JArray TauA -> JArray Tau -> JArray Rho -> SigmaA -> Sigma sigmaFromA karray tarray rarray SigmaA{bound, kinds, rho} = ForAll (zipWith - (\var kind -> TVar{pos=Position.null, var, kind}) + (\var kind -> TVar{pos=Position.null, var, kind}) bound (map kind kinds)) rarray.[rho] diff --git a/frege/compiler/common/Types.fr b/frege/compiler/common/Types.fr index 14774ca3..40b2c1e5 100644 --- a/frege/compiler/common/Types.fr +++ b/frege/compiler/common/Types.fr @@ -40,9 +40,9 @@ unboundSigmaTvs' g (ForAll{rho}) acc = unboundRhoTvs' g rho acc --- accumulate unbound 'MetaTv's from the components of a 'Rho' unboundRhoTvs' g (RhoT.Fun r) acc = - unboundRhoTvs' g r.rho ( - unboundSigmaTvs' g r.sigma ( - fold (unboundCtxTvs' g) acc r.context)) + unboundRhoTvs' g r.rho $ + unboundSigmaTvs' g r.sigma $ + fold (unboundCtxTvs' g) acc r.context unboundRhoTvs' g (RhoT.Tau r) acc = unboundTauTvs' g r.tau (fold (unboundCtxTvs' g) acc r.context) @@ -231,9 +231,9 @@ substCtx t x = x.{tau <- substTau t} -} tauKind :: Tau -> Kind tauKind app = case app.flat of - TauT.Var TVar{pos, kind, var}:_ -> kind - Meta Flexi{uid, hint, kind}:_ -> kind - other -> KType + TauT.Var TVar{kind}:_ -> kind + Meta Flexi{kind}:_ -> kind + other -> KType --- kindedness of a 'Sigma', based on enclosed 'Tau', see 'tauKind' sigmaKind (ForAll _ rho) = rhoKind rho @@ -280,7 +280,7 @@ rhoKind (RhoT.Tau r) = tauKind r.tau avoidSigma avoid (ForAll tvs rho) = ForAll ntvs (avoidRho (\s -> avoid s || s `elem` new) rho') where - old = map _.var tvs -- old variables + old = map _.var tvs -- old variables bads = filter avoid old -- the variables that need replacement safe s = not (avoid s) && s `notElem` old -- check for a safe name salvage s = head @@ -395,5 +395,5 @@ unifyTau t _ _ = t * which must be a valid substitution of the former (up to contexts). -} sigmaInst :: Sigma -> Sigma -> [Tau] -sigmaInst sigma1 sigma2 = [ s | Just s <- map (TreeMap.lookupS tree) (Sigma.vars sigma1) ] +sigmaInst sigma1 sigma2 = [ s | Just s <- map (TreeMap.lookupS tree) (Sigma.vars sigma1) ] where tree = unifySigma sigma1 sigma2 diff --git a/frege/compiler/common/UnAlias.fr b/frege/compiler/common/UnAlias.fr index 507d4b8d..f2aa81b9 100644 --- a/frege/compiler/common/UnAlias.fr +++ b/frege/compiler/common/UnAlias.fr @@ -95,10 +95,10 @@ unAlias g tau -- substTau env (TFun a b) = TFun (substTau env a) (substTau env b) substTau :: TreeMap String (TauT β) -> TauT β -> TauT β - substTau env (TApp a b) = TApp (substTau env a) (substTau env b) + substTau env (TApp a b) = TApp (substTau env a) (substTau env b) substTau env (TauT.Var TVar{var}) - | Just tau <- lookup var env = tau - substTau env tau = tau + | Just tau <- lookup var env = tau + substTau env tau = tau -- unify t (TFun a b) (TFun c d) = do diff --git a/frege/compiler/gen/java/Common.fr b/frege/compiler/gen/java/Common.fr index 4cc5129c..c0f00cbb 100644 --- a/frege/compiler/gen/java/Common.fr +++ b/frege/compiler/gen/java/Common.fr @@ -448,8 +448,8 @@ unifyJT ta tb subst = case ta of --- type arguments for sigma type targs :: Global -> Sigma -> [JTVar] -targs g = map (\tv -> targ g tv.var tv.kind) . Sigma.bound - +targs g = map (\tv → targ g tv.var tv.kind) . Sigma.bound + --- reconstruct & print Java code tokens reconstruct ∷ [Token] → StIO () reconstruct xs = work xs diff --git a/frege/compiler/gen/java/DataCode.fr b/frege/compiler/gen/java/DataCode.fr index d184874c..56b32619 100644 --- a/frege/compiler/gen/java/DataCode.fr +++ b/frege/compiler/gen/java/DataCode.fr @@ -12,7 +12,7 @@ import Compiler.classes.Nice import Compiler.types.Global import Compiler.types.Symbols import Compiler.types.AbstractJava -import Compiler.types.Types(TVar, pSigma) +import Compiler.types.Types(pSigma) import Compiler.gen.java.VarCode(varCode) import Compiler.gen.java.Match(variantType, conGetter) import Compiler.gen.java.Common @@ -234,7 +234,7 @@ simsalabim g sym jt gvars = JMethod{attr = attrs [JUnchecked, JPublic, JFinal], newtyp = jt.{gargs=map (TArg . _.var) unusedvars} -- just give the type variables different names for the return type, -- as this is an instance method - unusedvars = targs g sym.typ.{bound = zipWith TVar.{var=} + unusedvars = targs g sym.typ.{bound = zipWith _.{var=} sym.typ.bound (filter (`notElem` sym.typ.vars) (allBinders g)) } diff --git a/frege/compiler/gen/java/InstanceCode.fr b/frege/compiler/gen/java/InstanceCode.fr index 5a92d6a0..eb4775d5 100644 --- a/frege/compiler/gen/java/InstanceCode.fr +++ b/frege/compiler/gen/java/InstanceCode.fr @@ -374,8 +374,8 @@ instFun symc symi mname = do let otvs = filter ((`elem` symi.typ.vars) . _.var) cmem.typ.tvars orep = filter (`notElem` (cmem.typ.vars)) (allBinders g) substBound :: TreeMap String (TVar QName) -> [TVar QName] -> [TVar QName] - substBound subst = map $ \tv -> maybe tv _.{kind=tv.kind} (lookup tv.var subst) - subst1 = Map.fromList [ (tv.var, tv.{var=s}) | (s,tv) <- zip orep otvs] + substBound subst xs = map (\tv -> maybe tv _.{kind=tv.kind} (lookup tv.var subst)) xs + subst1 = Map.fromList [ (tv.var, tv.{var=s}) | (s,tv) ← zip orep otvs] typ1 = ForAll (substBound subst1 cmem.typ.bound) (substRho (fmap TauT.Var subst1) cmem.typ.rho) E.logmsg TRACEG symi.pos ( text "(1) renamed type :: " @@ -383,7 +383,7 @@ instFun symc symi mname = do ) let cvar = substTVar subst1 symc.clvar - withoutCVar = filter ((cvar.var !=) . _.var) + withoutCVar = filter ((!=) cvar.var . _.var) E.logmsg TRACEG symi.pos ( text "(2) class var is now " <+> text (nicer cvar g) ) @@ -402,7 +402,7 @@ instFun symc symi mname = do E.logmsg TRACEG symi.pos ( text "(3j) java type of (3) :: " <+> text (show jty3)) - let othertv = head (filter ((!= cvar.var) . _.var) typ3.tvars) + let othertv = head (filter ((!=cvar.var) . _.var) typ3.tvars) instTau0 = (symItau symi).tau instTau = if special then TApp instTau0 (TauT.Var othertv) else instTau0 subst4 = Map.singleton cvar.var instTau diff --git a/frege/compiler/gen/java/MethodCall.fr b/frege/compiler/gen/java/MethodCall.fr index ddf8557d..f7163db6 100644 --- a/frege/compiler/gen/java/MethodCall.fr +++ b/frege/compiler/gen/java/MethodCall.fr @@ -5,7 +5,7 @@ import Data.TreeMap(TreeMap, values) import Data.List(elemBy) import frege.data.Monoid (First) -import frege.compiler.common.Lens (Getting, _Just, preview, view) +import frege.compiler.common.Lens (Getting, _Just, preview) import Compiler.Utilities as U() diff --git a/frege/compiler/grammar/Frege.fr b/frege/compiler/grammar/Frege.fr index fff273aa..6e61bf37 100644 --- a/frege/compiler/grammar/Frege.fr +++ b/frege/compiler/grammar/Frege.fr @@ -6011,12 +6011,12 @@ private reduce226 = liste private reduce227 = \_\(fr,jv,ga)\col\t -> NatDcl {pos=yyline fr, vis=Public, name=fr.value, meth=jv, txs=t, isPure=false, - gargs = ga, + gargs = ga, doc=Nothing} ; private reduce229 = ForAll [] ; -private reduce230 = \_\vs\_\r -> ForAll vs r +private reduce230 = \_\vs\_\r -> ForAll vs r ; private reduce232 = \dot -> do when (Token.value dot != "•") do @@ -6244,7 +6244,7 @@ private reduce297 = private reduce298 = \dat\d\docu\pur\(jt,gargs) -> JavDcl {pos=yyline d, vis=Public, name=Token.value d, jclas=jt, vars=[], defs=[], - gargs, + gargs, isPure = pur, doc=Nothing} @@ -6252,7 +6252,7 @@ private reduce298 = private reduce299 = \dat\d\ds\docu\pur\(jt,gargs) -> JavDcl {pos=yyline d, vis=Public, name=Token.value d, jclas=jt, vars=ds, defs=[], - gargs, + gargs, isPure = pur, doc=Nothing} @@ -6344,7 +6344,7 @@ private reduce340 = \t\i \_\r -> TypDcl {pos=yyline i, private reduce341 = \t\i\vs\_\r -> TypDcl {pos=yyline i, vis=Public, name=Token.value i, - vars=vs, + vars=vs, typ = r, doc=Nothing} ; diff --git a/frege/compiler/grammar/Frege.y b/frege/compiler/grammar/Frege.y index be4965ec..78c1c5a0 100644 --- a/frege/compiler/grammar/Frege.y +++ b/frege/compiler/grammar/Frege.y @@ -819,7 +819,7 @@ impurenativedef: NATIVE methodspec DCOLON sigexs { \_\(fr,jv,ga)\col\t -> NatDcl {pos=yyline fr, vis=Public, name=fr.value, meth=jv, txs=t, isPure=false, - gargs = ga, + gargs = ga, doc=Nothing}} ; @@ -831,7 +831,7 @@ sigma: ; forall: - FORALL dvars mbdot rho { \_\vs\_\r -> ForAll vs r } + FORALL dvars mbdot rho { \_\vs\_\r -> ForAll vs r } ; mbdot: @@ -1103,14 +1103,14 @@ datajavainit: DATA CONID '=' nativepur nativespec { \dat\d\docu\pur\(jt,gargs) -> JavDcl {pos=yyline d, vis=Public, name=Token.value d, jclas=jt, vars=[], defs=[], - gargs, + gargs, isPure = pur, doc=Nothing} } | DATA CONID dvars '=' nativepur nativespec { \dat\d\ds\docu\pur\(jt,gargs) -> JavDcl {pos=yyline d, vis=Public, name=Token.value d, jclas=jt, vars=ds, defs=[], - gargs, + gargs, isPure = pur, doc=Nothing} } @@ -1225,7 +1225,7 @@ typedef: | TYPE CONID dvars '=' sigma { \t\i\vs\_\r -> TypDcl {pos=yyline i, vis=Public, name=Token.value i, - vars=vs, + vars=vs, typ = r, doc=Nothing}} ; diff --git a/frege/compiler/passes/Easy.fr b/frege/compiler/passes/Easy.fr index bfb00722..2fcd1c9c 100644 --- a/frege/compiler/passes/Easy.fr +++ b/frege/compiler/passes/Easy.fr @@ -23,7 +23,6 @@ import frege.compiler.Utilities as U(allourvars, allvars) import frege.compiler.Typecheck as TC(checkRho, substInst, zonkExpr, zonkRigid) import frege.compiler.tc.Util as TCU() import frege.compiler.common.Trans - {-- * In this pass, we make sure that all expressions are in * a form we need for code generation. We say that an expression is, or is not /easy/. @@ -185,8 +184,8 @@ recycle newpos expr rho = do g <- getST expr <- U.copyExpr (Just newpos) empty expr expr <- U.untypeExpr expr - let freevars = U.freeTVars [] rho - tvnames = map _.var freevars + let freevars = U.freeTVars [] rho + tvnames = map _.var freevars (metas, rho) <- TCU.skolemise (ForAll freevars rho) x <- checkRho expr rho -- foreach (zip metas freevars) (uncurry unInst) diff --git a/frege/compiler/passes/Imp.fr b/frege/compiler/passes/Imp.fr index 56342f5e..9ed6f287 100644 --- a/frege/compiler/passes/Imp.fr +++ b/frege/compiler/passes/Imp.fr @@ -700,7 +700,7 @@ preludeBasics = do -- unnamed, undocumented field, strictness and type must be given aField = Field Position.null Nothing Nothing Public vars = map ctos ['a' .. 'z'] - varks = zipWith (\var kind -> TVar{pos=Position.null, var, kind}) vars (repeat KType) + varks = zipWith (\var kind → TVar{pos=Position.null, var, kind}) vars (repeat KType) tvars = map (mvar.{var=}) vars commas = repeat ',' tuple n = "(" ++ packed (take (n-1) commas) ++ ")" diff --git a/frege/compiler/passes/LetUnroll.fr b/frege/compiler/passes/LetUnroll.fr index e79561e5..e0fd1181 100644 --- a/frege/compiler/passes/LetUnroll.fr +++ b/frege/compiler/passes/LetUnroll.fr @@ -203,7 +203,7 @@ unLet (x@Let {env,ex}) -- sym <- globalize sym g <- getST E.logmsg TRACE7 pos (text ("global: " ++ gsym.name.nice g ++ " = " ++ nice ex g)) - let vks = U.freeTVars [] sym.typ.rho + let vks = U.freeTVars [] sym.typ.rho let typ = ForAll vks sym.typ.rho changeST Global.{sub <- SubSt.{ idKind <- insert (KeyTk gsym.pos.first) (Right gsym.name)}} diff --git a/frege/compiler/passes/Transdef.fr b/frege/compiler/passes/Transdef.fr index 6491f424..8478f670 100644 --- a/frege/compiler/passes/Transdef.fr +++ b/frege/compiler/passes/Transdef.fr @@ -359,7 +359,7 @@ transNatDcl env fname (d@NatDcl {pos}) = do avoid = maybeToList phantom ++ objectvars -- type variables that are valid sigvars = filter - ((`notElem` avoid) . _.var) + ((`notElem` avoid) . _.var) (sig.tvars) bound = map _.var sigvars inferred = if nik == NIMethod || nik == NIStatic then sigvars else [] @@ -454,7 +454,7 @@ private refreshType name pos vars sym = do vars <- mapM transTVar vars let !dname = TName g.thisPack name dtcon = TauT.Con TCon{pos, name=dname} - dtau = dtcon.mkapp $ map TauT.Var vars + dtau = dtcon.mkapp $ map TauT.Var vars !dsig = ForAll vars $ RhoT.Tau $ RhoTau [] dtau !kind = foldr KApp KType dsig.kinds :: Kind newsym = sym.{typ=dsig, kind} @@ -600,8 +600,8 @@ transDatDcl env fname (d@DatDcl {pos}) = do let transSigma1 (ForAll [] (RhoT.Tau (RhoTau [] t))) = transTau t transSigma1 s = do -- field types can be sigmas ForAll bound frho <- U.validSigma1 (map _.var bndrs) s - bounds <- U.transBounds bound - let env = fold (\tm tv -> tm.insertS tv.var tv) TreeMap.empty (bounds ++ bndrs) + bounds ← U.transBounds bound + let env = fold (\tm tv → tm.insertS tv.var tv) TreeMap.empty (bounds ++ bndrs) frho <- U.transRho env frho stio (ForAll bounds frho) sigmas <- mapSt (transSigma1 • ConField.typ) d.flds @@ -648,10 +648,10 @@ transJavDcl env fname (d@JavDcl {pos}) = do ) -- fix type arguments that are not generic to kind * ktype t = case t of - TVar{kind=KVar} -> t.{kind=KType} - _ -> t - let typ = sym.typ.{bound <- map ktype} - !kind = foldr KApp KType (map _.kind typ.bound) + TVar{kind=KVar} → t.{kind=KType} + _ → t + let typ = sym.typ.{bound ← map ktype} + !kind = foldr KApp KType (map _.kind typ.bound) let purity = d.isPure || (nativ `elem` pureTypes) changeSym $ SymbolT.T sym.{pur = purity, gargs, typ, kind} foreach d.defs (transdef [] (MName tname)) diff --git a/frege/compiler/tc/Methods.fr b/frege/compiler/tc/Methods.fr index 113bd071..b4c3aa20 100644 --- a/frege/compiler/tc/Methods.fr +++ b/frege/compiler/tc/Methods.fr @@ -417,7 +417,7 @@ sanity (SymbolT.V (symv@SymV{pos, name, typ, nativ = Just item, pur, throwing, o return Nothing _ -> case phantom of Nothing - | TauT.Con _ <- mp = return (Just r) -- Mutable RealWorld xxx + | TauT.Con _ <- mp = return (Just r) -- Mutable RealWorld xxx | otherwise -> do -- use of mutable type in non IO? E.error (getpos tau) ( diff --git a/frege/compiler/tc/Util.fr b/frege/compiler/tc/Util.fr index 26a0cfae..ea48fd32 100644 --- a/frege/compiler/tc/Util.fr +++ b/frege/compiler/tc/Util.fr @@ -43,7 +43,7 @@ package frege.compiler.tc.Util where import frege.Prelude hiding(<+>) -import Data.TreeMap (TreeMap, values, lookup, insert, keys, +import Data.TreeMap (TreeMap, TreeSet, values, lookup, insert, keys, including, union, contains) import Data.List as DL(unique, uniq, sort, elemBy, partition) @@ -219,8 +219,8 @@ subsCheckRR ex ty ety = do - implement rule FUN if one of the types is a RhoFun -} -- matching t1 as RhoTau is redundant, but needed to convince the compiler that these patterns are exhaustive - subsCheckRR' exp (RhoT.Tau t1) (RhoT.Fun (RhoFun _ a2 r2)) = do - (a1,r1) <- unifyFun exp (RhoT.Tau t1) + subsCheckRR' exp (t1@RhoT.Tau _) (RhoT.Fun (RhoFun _ a2 r2)) = do + (a1,r1) <- unifyFun exp t1 subsCheckFun exp a1 r1 a2 r2 subsCheckRR' exp (RhoT.Fun (RhoFun _ a1 r1)) t2 = do (a2,r2) <- unifyFun exp t2 @@ -270,10 +270,10 @@ tauTvs g = keys . getTauTvs g ctxTvs :: Global -> Context -> [MetaTv] ctxTvs g ctx = tauTvs g ctx.tau -getSigmaTvs :: Global -> Sigma -> TreeMap MetaTv () +getSigmaTvs :: Global -> Sigma -> TreeSet MetaTv getSigmaTvs g (ForAll _ rho) = getRhoTvs g rho -getRhoTvs :: Global -> Rho -> TreeMap MetaTv () +getRhoTvs :: Global -> Rho -> TreeSet MetaTv getRhoTvs g (RhoT.Fun (RhoFun cs sig rho)) = let csTvs = map (getCtxTvs g) cs sTvs = getSigmaTvs g sig @@ -284,13 +284,13 @@ getRhoTvs g (RhoT.Tau (RhoTau cs tau)) = let tTvs = getTauTvs g tau in (fold union tTvs csTvs) -getCtxTvs :: Global -> Context -> TreeMap MetaTv () +getCtxTvs :: Global -> Context -> TreeSet MetaTv getCtxTvs g = getTauTvs g . Context.tau -getTauTvs :: Global -> Tau -> TreeMap MetaTv () +getTauTvs :: Global -> Tau -> TreeSet MetaTv getTauTvs g tau = getTauTvsT g TreeMap.empty tau -getTauTvsT :: Global -> TreeMap MetaTv () -> Tau -> TreeMap MetaTv () +getTauTvsT :: Global -> TreeSet MetaTv -> Tau -> TreeSet MetaTv getTauTvsT g t (TApp a b) = let ta = getTauTvsT g t a in getTauTvsT g ta b @@ -347,9 +347,9 @@ instantiate (ForAll ns ty) = do instWildRho :: Rho -> StG Rho instWildRho (RhoT.Fun it) = do context <- mapM instWildCtx it.context - rho <- instWildRho it.rho sigma <- instWildSigma it.sigma - pure $ RhoT.Fun RhoFun{context, rho, sigma} + rho <- instWildRho it.rho + pure $ RhoT.Fun RhoFun{context, sigma, rho} instWildRho (RhoT.Tau it) = do context <- mapM instWildCtx it.context tau <- instWildTau it.tau @@ -674,7 +674,7 @@ quantifiedExcept exc rhos = do -- make sigma for rho with the tvs that appear in that rho mksig ∷ [(String,MetaTv)] → (Rho,[MetaTv]) → StG Sigma mksig bound (rho,tvs) = do - nvz <- forM nv $ \tv -> tv.{kind=} <$> zonkKind tv.kind + nvz ← mapM (\tv → zonkKind tv.kind >>= pure . tv.{kind=}) nv rhoz ← zonkRho rho pure (ForAll nvz rhoz) where nv = [ TVar{pos, kind=MetaTv.kind v, var=n} | (n,v) <- bound, v `elem` tvs] @@ -691,8 +691,8 @@ quantifiedExcept exc rhos = do writeTv tv (TauT.Var TVar{pos, var, kind=KVar}) t' ← mapM zonkTau t writeTv tv (TauT.Var TVar{pos, var, kind=KGen t'}) - other → writeTv tv (TauT.Var TVar{pos, var, kind=tv.kind}) - + _ -> writeTv tv (TauT.Var TVar{pos, var, kind=tv.kind}) + quantify rho = do sigs <- quantified [rho] diff --git a/frege/compiler/types/Global.fr b/frege/compiler/types/Global.fr index 85cec365..b3ede6e4 100644 --- a/frege/compiler/types/Global.fr +++ b/frege/compiler/types/Global.fr @@ -268,9 +268,9 @@ instTSym _ g = fmap assertSymT (g.findit (TName pPreludeBase "->")) --- return type symbol for constructor of tau, if any instTauSym :: Tau -> Global -> Maybe (SymT Global) instTauSym tau g = case tau of - TauT.Con c -> fmap (assertSymT c.name) $ g.findit c.name - TApp a _ -> instTauSym a g - _ -> Nothing + TauT.Con c -> fmap (assertSymT c.name) $ g.findit c.name + TApp a _ -> instTauSym a g + _ -> Nothing where assertSymT _ (SymbolT.T symt) = symt assertSymT name _ = error $ "instTauSym: TCon{name=" ++ show name ++ "} refers to a non-SymT??" diff --git a/frege/compiler/types/Types.fr b/frege/compiler/types/Types.fr index e8e0d5ff..a071b107 100644 --- a/frege/compiler/types/Types.fr +++ b/frege/compiler/types/Types.fr @@ -300,7 +300,12 @@ data RhoFun s = !RhoFun {context::[ContextT s], sigma::SigmaT s, rho::RhoT s} _rho :: Functor f => (RhoT s -> f (RhoT s)) -> RhoFun s -> f (RhoFun s) _rho f r = r.{rho=} <$> f r.rho ---- The rho type for non-functions +{-- + The rho type for (perhaps) non-functions + + Note that a @RhoTau@ may represent functions because @RhoTau.tau@ can represent one. + See 'unTau' and 'tauRho' for conversion between 'RhoFun'. + -} data RhoTau s = !RhoTau {context::[ContextT s], tau::TauT s} where -- _context :: Lens' (RhoTau s) [ContextT s] @@ -387,8 +392,8 @@ instance Positioned (TauT a) where instance Positioned (RhoT a) where is p = "rho type" getpos rho = case rho of - RhoT.Fun RhoFun{sigma,rho} = (c.merge sigma.getpos).merge rho.getpos - RhoT.Tau RhoTau{tau} = c.merge tau.getpos + RhoT.Fun RhoFun{sigma,rho} = (c.merge sigma.getpos).merge rho.getpos + RhoT.Tau RhoTau{tau} = c.merge tau.getpos where c = Position.merges (map Context.getpos rho.context) diff --git a/frege/ide/Utilities.fr b/frege/ide/Utilities.fr index 054fadf4..be637af9 100644 --- a/frege/ide/Utilities.fr +++ b/frege/ide/Utilities.fr @@ -10,7 +10,7 @@ import frege.compiler.passes.Imp as I(getFP) import frege.compiler.tc.Util as TC import frege.compiler.Typecheck as TY hiding(pass, post) -import frege.compiler.common.Lens (preview, view) +import frege.compiler.common.Lens (preview) import Compiler.enums.TokenID(TokenID, defaultInfix) import Compiler.enums.Visibility(Private, Public)