Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate ways to reduce Sto clutter #52

Open
mhuesch opened this issue Aug 21, 2021 · 0 comments
Open

investigate ways to reduce Sto clutter #52

mhuesch opened this issue Aug 21, 2021 · 0 comments

Comments

@mhuesch
Copy link
Contributor

mhuesch commented Aug 21, 2021

an example of troublesome-looking Sto output:

        924 : CellThunk(Ev { _: VClosure(Name("x"), App(App(Prim(Add), Lit(LInt(1))), Var(Name("acc"))), {Name("_1"): VRef(0), Name("acc"): VRef(923), Name("foldl"): VRef(3)}) })
        925 : CellThunk(UnevExpr { expr: App(Prim(Head), Var(Name("xs"))), env: {Name("_1"): VRef(0), Name("acc"): VRef(118), Name("f"): VRef(116), Name("foldl"): VRef(2), Name("xs"): VRef(120)} })
        926 : CellRedirect(VRef(110))
        927 : CellThunk(Ev { _: VClosure(Name("x"), App(App(Prim(Add), Lit(LInt(1))), Var(Name("acc"))), {Name("_1"): VRef(0), Name("acc"): VRef(926), Name("foldl"): VRef(3)}) })
        928 : CellThunk(UnevExpr { expr: App(Prim(Head), Var(Name("xs"))), env: {Name("_1"): VRef(0), Name("acc"): VRef(110), Name("f"): VRef(108), Name("foldl"): VRef(2), Name("xs"): VRef(112)} })
        929 : CellRedirect(VRef(102))
        930 : CellThunk(Ev { _: VClosure(Name("x"), App(App(Prim(Add), Lit(LInt(1))), Var(Name("acc"))), {Name("_1"): VRef(0), Name("acc"): VRef(929), Name("foldl"): VRef(3)}) })
        931 : CellThunk(UnevExpr { expr: App(Prim(Head), Var(Name("xs"))), env: {Name("_1"): VRef(0), Name("acc"): VRef(102), Name("f"): VRef(100), Name("foldl"): VRef(2), Name("xs"): VRef(104)} })
        932 : CellRedirect(VRef(95))
        933 : CellThunk(Ev { _: VClosure(Name("x"), App(App(Prim(Add), Lit(LInt(1))), Var(Name("acc"))), {Name("_1"): VRef(0), Name("acc"): VRef(932), Name("foldl"): VRef(3)}) })
        934 : CellThunk(UnevExpr { expr: App(Prim(Head), Var(Name("xs"))), env: {Name("_1"): VRef(0), Name("acc"): VRef(95), Name("f"): VRef(93), Name("foldl"): VRef(2), Name("xs"): VRef(97)} })
        935 : CellRedirect(VRef(87))
        936 : CellThunk(Ev { _: VClosure(Name("x"), App(App(Prim(Add), Lit(LInt(1))), Var(Name("acc"))), {Name("_1"): VRef(0), Name("acc"): VRef(935), Name("foldl"): VRef(3)}) })
        937 : CellThunk(UnevExpr { expr: App(Prim(Head), Var(Name("xs"))), env: {Name("_1"): VRef(0), Name("acc"): VRef(87), Name("f"): VRef(85), Name("foldl"): VRef(2), Name("xs"): VRef(89)} })

we see a lot of duplication and (most concerning to me), it appears as though currying-by-default means we cannot strip down the env of a closure.

this comes from a length computation across a large list:

defn foldl
 (fix (lam [foldl]
   (lam [f acc xs]
     (if (null xs)
       acc
       (foldl
         f
         (f acc (head xs))
         (tail xs)))))))

(defn length (foldl (lam [acc x] (+ 1 acc)) 0))

if we had an uncurried language, we'd be able to see that (lam [acc x] (+ 1 acc)) has no free variables and therefore doesn't need an environment. instead, because we are currying, that represents two lambdas, and the variable is "free" inside the body of the inner lambda, because it was bound by the outer (or maybe I have the order switched up).

this makes me think that currying-by-default is worth reconsidering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant