Jekyll2023-11-18T18:03:46-05:00https://unfooling.com/unfooling.com/feed.xmlUnfoolingWriting about computers and other beautiful and worthwhile things.Andrew Chenandrewchen14250@email.com13 week Mech Interp Study Journal2023-10-28T12:00:00-04:002023-10-28T12:00:00-04:00https://unfooling.com/unfooling.com/13-week-mech-interp-study<h3 id="foreword">Foreword</h3>
<!-- Cross all history, we might just be living in the most anticipatory time. Billions of neurons, organized as subgraphs and circuitries, firing millions of "AI will revolutionize..."s everyday. But most of us, even those that happen to study computer science, and even those that happen to study artificial intelligence, seems to not grasp the gravity of the moment. Indeed, so much happened so quickly that perhaps, our circuitries have overfitted on the irregular progression of science.
I read my first alignment paper this week, and it has reignited my once diminished passion for AI and machine learning. Though my future occupation in formal verifications does not have too much correspondance to AI yet, I have, as a scientist, a moral responsibility to understand this field fully. Of course, as an undergrad who's writing his thesis on LLMs -->
<p>Mech Interp is super cool! I’m gonna set aside 13 weeks to study it. In these 13 weeks, I plan to master basic ML math, master transformers, read a couple mech interp papers in depth, and hopefully carry out some small-scaled, original mech interp exploration.</p>
<p>Note, this is a direct mirror of my personal log in my Obsidian vault, and some formatting might not be appropriate (I will format everything at the end).</p>
<h3 id="timeline">Timeline</h3>
<p><strong>Target</strong>: 10/28/2023 to 1/26/2023 (end of my winter break)</p>
<h3 id="undated-day-1">Undated Day 1</h3>
<ul>
<li>Read some basic definitions of <em>Linear Algebra Done Right</em>.
<h3 id="undated-day-2">Undated Day 2</h3>
</li>
<li>Finished <em>Linear Algebra Done Right</em> Chapter 1. Re-learnt subspaces, sums of subspaces, direct sums.</li>
<li>Looking ahead, to solidfy my linear algebra for MI, I should master Chapter 1-3, 5-6, and 7d. More importantly, I need to spend some time everyday in finding connections of the niche linear algebra techniques are used for ML.</li>
<li>I found one such connection today (querying ChatGPT): Gradients should be initialized with orthonormal matrices in order to preserve the magnitude of gradients.</li>
</ul>
<h3 id="day-1">Day 1</h3>
<ul class="task-list">
<li>Read <em>Linear Algebra Done Right</em> Chapter 2 up until the last definition. I think basis and theorems regarding bases drilled in the definition of linear independence and span.</li>
<li>Tomorrow, I just want to finish up the definition, do a few problems. Then, I want to skim some high-level material on why bases matters for machine learning; in particular, I hear a lot about “orthonormal” bases in ML, when and why do they come up?</li>
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />Why bases matter for machine learning - high level view. 📅 2023-10-28 ✅ 2023-10-28</li>
</ul>
<h3 id="day-2">Day 2</h3>
<ul>
<li>Yesterday i assigned the “why bases matters” task, I have a high-level answer: To address the curse of dimensionality and other dimension related issues. Keywords are privileged, non-privileged bases, PCA, SVD.
<ul>
<li>Resources: https://harrisonpim.com/blog/privileged-vs-non-privileged-bases-in-machine-learning</li>
</ul>
</li>
</ul>
<h3 id="day-3">Day 3</h3>
<p>Skipped</p>
<h3 id="day-4">Day 4</h3>
<ul>
<li>Did 15 exercises for [[Chapter 2]]. I didn’t try too hard, I looked at the solution if I can’t solve in 5 mins.</li>
</ul>
<h3 id="day-5">Day 5</h3>
<p>Skipped</p>
<h3 id="day-6">Day 6</h3>
<p>Skipped</p>
<h3 id="day-7-11-03-2023">Day 7 (11-03-2023)</h3>
<p>Wrote MLP forward stuff.</p>
<p>Watched this great <a href="https://www.youtube.com/watch?v=Gey9CG6R6w8">video</a> by WhyML on Skip connection and residual blocks.</p>
<ul class="task-list">
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />Review Batch Normaliztaion, Optimizers, Regularization, Gradient Clipping, Weight Constraints, Weight Normalization, Layer Normalization 📅 2023-11-04 ✅ 2023-11-09</li>
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />What is Skip Connections and Residual Blocks? 📅 2023-11-03 ✅ 2023-11-04</li>
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />Understand the gradients that are taken. 📅 2023-11-12 ✅ 2023-11-15</li>
</ul>
<h3 id="day-8-11-04-2023">Day 8 (11-04-2023)</h3>
<p>Studied backpropagation. I used multiple resources: The original sparse encoder article, some random article by ML-dawn, and Brilliant Wiki. But, when I revisited 3b1b’s video, that’s the one that made it all click. Tomorrow, I plan to rewatch the video and take a lot of notes.</p>
<h3 id="day-9-11-05-2023">Day 9 (11-05-2023)</h3>
<p>Rewatched 3b1b’s video and I think all the formulae individually makes sense. Tomorrow, I’ll try to</p>
<ul>
<li>Derive the gradients from scratch</li>
<li>If I get them right, give a shot at drawing derivative diagrams for a MLP</li>
<li>Implement backprop in MLP.</li>
</ul>
<h3 id="day-10-18-11-06-2023-to-11-14-2023">Day 10-18 (11-06-2023 to 11-14-2023)</h3>
<p>Skipped. Not gonna lie, played a little too much minesweeper.</p>
<h3 id="day-19">Day 19</h3>
<ul>
<li>Deleted my online minesweeper account. Started 2 weeks ago and sunk 35 hours into it, no good, those hours will now be redirected to mech interp.</li>
<li>Watched Neel Nanda’s <a href="https://www.youtube.com/watch?v=bZvPLRZx-V8">MI and Math</a> talk and annotated it. The slides are <a href="https://docs.google.com/presentation/d/1hQHsWcoxtBQKj4mTgFtMA9KgDjkyAcjEWjxDwXq5EPg/edit#slide=id.g24176faf163_0_225">here</a></li>
<li>40 mins into ML street talk episode with Neel Nanda. Take aways:
<ul>
<li>A biologist’s getting hands dirty view might be more appropriate than a mathematician’s view. A good quality of a mech interp researcher is someone who can <em>handle</em> a surprise.</li>
</ul>
</li>
</ul>
<p>My goals this week is to start understanding transformers well, read this paper, and get a sense of the other techniques I gotta study (dimensionality reduction, Fourier transform even?).</p>
<p><strong>Idea</strong>: Analyze transformers that implement simple regexes / text manipulation patterns?</p>
<h3 id="day-20">Day 20</h3>
<ul>
<li>Read the <a href="https://jalammar.github.io/visualizing-neural-machine-translation-mechanics-of-seq2seq-models-with-attention/">Attention</a> blog post, it is a prior of the <a href="https://jalammar.github.io/illustrated-transformer/">Illustrated Transformers</a> guide.</li>
</ul>
<p>Some knowledge tasks.</p>
<ul class="task-list">
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />Understand: What is the Curse of Dimensionality? 📅 2023-11-17</li>
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />Master PCA 📅 2023-11-19</li>
</ul>
<p>Inspired by Neel’s talks yesterday, I will run a mech interp notebook this week to get a feel of the tools.</p>
<ul class="task-list">
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />Run, completely, one mech interp notebook 📅 2023-11-17</li>
</ul>Andrew Chenandrewchen14250@email.comForeword <!– Cross all history, we might just be living in the most anticipatory time. Billions of neurons, organized as subgraphs and circuitries, firing millions of “AI will revolutionize…”s everyday. But most of us, even those that happen to study computer science, and even those that happen to study artificial intelligence, seems to not grasp the gravity of the moment. Indeed, so much happened so quickly that perhaps, our circuitries have overfitted on the irregular progression of science.October Proses • 十月的随笔2023-10-11T12:00:00-04:002023-10-11T12:00:00-04:00https://unfooling.com/unfooling.com/october-proses<h3 id="壹--角度">壹 • 角度</h3>
<p>生处的坐标,位置不同,头扬的角度不同,思考的事情也必然不同。躺在一只肥猪下看天空,小猪似乎也变成了天蓬元帅。
我写中文时,就容易变得文艺。在搞科研时,只有在户外才引入潮水一般涌来的思路。
通常来讲,文言是文言,数学是数学。可是,哲学家们似乎非常喜欢在黑板上谈心。他们用着 “first principle” 的借口轰炸着
由艺术,由生命而生的伦理。</p>
<p>依我见,伦理不是哲学应所侵犯的领域。伦理是生命,是苦难,是我们哭泣的理由,是人情味。这种味道,还是不要过多去”taxonomize”的好。</p>
<p>您读我刚才写着的时候可能脑海里闪过一些画面:呆板,毫无勃起力的哲学家,数学家,挂个老老的眼镜,低着头,慢吞吞得在黑板上画着圆圈。假若您的确思其画面,那么抱歉,您入了我写这一段篇的圈套。搞纯理论的数学家也可以让我们的生命细胞脉动。</p>
<h3 id="所有的一切推着我们前进">所有的一切推着我们前进</h3>
<p>昨天重返了《功夫熊猫1》。其中有一场景十分有趣。</p>
<p><strong>乌龟师傅</strong>:</p>
<blockquote>
<p>人违逆不了命运。</p>
</blockquote>
<p><strong>浣熊师傅</strong>:</p>
<blockquote>
<p>[猛踹了大树] 但,我可控制桃子什么时候掉落,也可控制它在哪里生长。</p>
</blockquote>
<p><strong>乌龟师傅</strong>:</p>
<blockquote>
<p>对,但无论怎样,一颗桃核总会繁衍一棵桃树。</p>
</blockquote>
<p>记得美国脱口秀之王George Carlin说过,气候维护者们总是声称,全球变暖破坏了地球。瞎搞,以前陨石撞地球时对于地球来说不过是挠个痒。其实,我们只是怕气候变暖搞糟了人类。所以,虽然可能有一天,人类会停止繁衍与前进。但这个宇宙永远不会,滴答滴答,微生物又在另一个星球上诞生了。</p>
<h3 id="中文是抽象的">中文是抽象的</h3>
<p>我其实总觉得,我们的中文是抽象的。举个例子,道德经说的“一生二,二生三,三生万物”,似乎概括了数学里“induction”的这个概念。这一点我得留至十一月去多想想。</p>
<h3 id="论madman">论“Madman”</h3>
<p>十一月再说吧。</p>Andrew Chenandrewchen14250@email.com壹 • 角度 生处的坐标,位置不同,头扬的角度不同,思考的事情也必然不同。躺在一只肥猪下看天空,小猪似乎也变成了天蓬元帅。 我写中文时,就容易变得文艺。在搞科研时,只有在户外才引入潮水一般涌来的思路。 通常来讲,文言是文言,数学是数学。可是,哲学家们似乎非常喜欢在黑板上谈心。他们用着 “first principle” 的借口轰炸着 由艺术,由生命而生的伦理。Reflecting on my 2022 tech opinions2023-08-05T12:05:00-04:002023-08-05T12:05:00-04:00https://unfooling.com/unfooling.com/reflecting-on-my-2022-tech-opinions<p>Last August, I gave 6 tech <a href="https://unfooling.com/6-tech-opinions-i-formed-during-my-year-long-internship/">opinions</a>. I reflect on those now —</p>
<blockquote>
<p>Reading the source code is more responsible and often faster than asking the author, given that you understand the source’s architecture. This echoes item 1 in Matt’s <a href="https://matt-rickard.com/reflections-on-10-000-hours-of-programming">reflection</a>.</p>
</blockquote>
<p>I would like to update this — My new thought is that whether to ask should be based primary on the inherent beauty of the source. If you’re reading a spaghetti game engine to figure out some minute detail, might as well ask the author since they didn’t publish code that was worth your time. Remember, an idiot admires complexity while a genius admires simplicity.</p>
<blockquote>
<p>Don’t force dumber code in the fear of others not understanding. Example: Paul Graham on <a href="http://www.paulgraham.com/avg.html">Why Lisp?</a>. Writing hard (but simple) code makes you smarter and inspires code reviewers. Here’s a good article on <a href="https://rpeszek.github.io/posts/2022-08-30-code-cognitiveload.html">hard vs easy, complex vs simple</a>.</p>
</blockquote>
<p>I would like to elaborate — When I wrote this, I was relatively new to Haskell, enticed by every single language extension and believed everyone else should be equally passionate as me. But, should you really use dependent types for the sake of it? There’s no clear answer — it depends on your team structure (# seniors vs. # juniors, average tenure) and purpose (research, academics). For a well-written essay on this matter, see this <a href="https://www.parsonsmatt.org/2019/12/26/write_junior_code.html">plea</a> for simple Haskell.</p>
<blockquote>
<p>If you lack knowledge in an established research area (e.g., database, OS, etc), the best way to catch up is to read a textbook.</p>
</blockquote>
<p>Oh yea, 100%, read things that people spent years working on. Textbooks and papers often fill this criteria while most blogs don’t.</p>
<blockquote>
<p>The quality of a software correlates with how much internal information it has on its documentation. Of course, some software must reveal its internals. However, I find myself revealing unnecessary internal information when I am unable to articulate the usages.</p>
</blockquote>
<p>This opinion provides a great question: Did I leak internals because the design of my interface is not abstract enough (the surface area approaches the volume, as what Bartosz Milewski would say)? I continue to use this question on my own projects.</p>
<blockquote>
<p>9 pregnant women can’t give birth to a baby in one month (from <a href="https://www.wikiwand.com/en/The_Mythical_Man-Month">The Mythical Man Month</a>). I now understand how true this. Conversely, project managers must decide on this balance, and that’s why tech PMs should have tech backgrounds.</p>
</blockquote>
<p>Mostly, but I don’t think PMs necessarily need tech backgrounds as long as they understand the complexities of software construction.</p>
<blockquote>
<p>And the most important tech opinion: Tech is created by people and for people, so <strong>people > tech</strong>. Software engineering sits in between computer science and social science. My experience at ClearBlade was enjoyable: People at my work were nice and acknowledged each other’s doing, my CTO reminded me to take vacations, and the list goes on.</p>
</blockquote>
<p>Of the people, for the people, by the people.</p>Andrew Chenandrewchen14250@email.comLast August, I gave 6 tech opinions. I reflect on those now —Programming Languages Journal2023-06-28T12:00:00-04:002023-06-28T12:00:00-04:00https://unfooling.com/unfooling.com/pl-journal<h3 id="foreword">Foreword</h3>
<p>I have come to a point in my Haskell journey where I should start learning about other programming languages (PL) fields. Towards the end of my <a href="https://unfooling.com/fp-journal/">FP journal</a>, I started diving into Category Theory and formal verifications, endeavours that shouldn’t be documented in a “FP Journal”. As such, I’ve decided to start a PL journal, documenting all of my PL ventures. Unlike the previous journal, I do not plan to elaborate on the concepts I made sense of, as these elaborations often turn into word rambles in the moment.</p>
<h2 id="june">June</h2>
<p><strong>28th</strong></p>
<p>Understanding the relationships between LTL (Linear Temporal Logic), Haskell, model-checkers, and proof assistants. Conclusion: TLA+ (model checker) can be used to model LTL statements and verify them. There exists LTL libraries in Haskell but they appear to be more data modelling purposes.</p>
<p><strong>29th</strong></p>
<ul>
<li>Chris (from work) sent me two papers:
<ul>
<li><a href="https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/papers/RV.pdf">Runtime Verification for LTL and TLTL</a></li>
<li><a href="https://www.cs.rice.edu/~vardi/papers/vol1000.pdf">Alternating Automata and Program Verification</a>
These papers supposedly describe how LTL statements can really be translated (down?) to a FSM (Finite State Machine). From there, any language can be used to implement this FSM (since a simple FSM is just a <code class="language-plaintext highlighter-rouge">while</code> loop + <code class="language-plaintext highlighter-rouge">switch</code> statements).
I will zoom in on these tomorrow.</li>
</ul>
</li>
<li>Watched a video on <a href="https://www.youtube.com/watch?v=FqDHSIpWJRw&t=331s&ab_channel=Serokell">linear logic</a>. Everyday I’m hearing 5 new jargons, at the end of this week I ought to layout a taxonomy of the topics.</li>
</ul>
<h2 id="july">July</h2>
<p><strong>1st to 14th</strong></p>
<ul>
<li>Read the first 10 pages of the Lamport’s TLA <a href="https://lamport.azurewebsites.net/pubs/lamport-actions.pdf">paper</a> that covers TLA motivation and semantics.</li>
<li>Watched the <a href="https://www.youtube.com/watch?v=VHWEldcSx14&list=PLhZdSWbNhIbCQKxUta0VrDGg3gLguedIh&index=1&ab_channel=songsong">first lecture</a> of RWTH Aachen University’s Model Checking course.</li>
<li>Talked to ChatGPT a lot to derive a taxonomy of formal verifications technique. Lectures do better jobs covering these types of information though — ChatGPT don’t really come up with memorable sayings.</li>
<li>Came across <a href="https://www.youtube.com/watch?v=FqDHSIpWJRw&t=14s&ab_channel=Serokell">Linear Types</a>, didn’t understand much.</li>
<li>Submitted my first paper ever (it’s on program analysis) to SCAM’23! I can reveal more if it gets accepted.</li>
<li>Read the intro of Pierce’s <a href="https://softwarefoundations.cis.upenn.edu/lf-current/Basics.html">Software Foundations</a>.</li>
<li>Read the first two chapter of Pierce’s TAPL — currently, I don’t find type theory as interesting as formal verifications. Though, I do believe that enjoyment is a linear combinations of the interestingness of the topic’s pure abstractions, the topic’s applicability, and one’s current understanding of the field. When it comes to type theory, I don’t have any of these.</li>
</ul>
<p><strong>15th to 19th</strong></p>
<ul>
<li>Read the docs of the <code class="language-plaintext highlighter-rouge">servant</code> library thoroughly: It’s the first library I encountered that uses <code class="language-plaintext highlighter-rouge">DataKinds</code>.</li>
<li>Read up on the expression problem (encountered through <code class="language-plaintext highlighter-rouge">servant</code>’s paper). Supposedly, Object Algebras of OOP or advanced Haskell type features can address it.</li>
<li>Going back to reading Milewski’s Category Theory for Programmers because I should be knowing what Kelsili Arrow and natural transformations are at this point.
<ul>
<li>Finished Chapter 3. Interesting idea: Think of functions in their uncurried form more. If I think of <code class="language-plaintext highlighter-rouge">mappend</code> as <code class="language-plaintext highlighter-rouge">m -> (m -> m)</code>, I can see it as a mapping between an element of a monoid set to a function acting on that set!</li>
</ul>
</li>
</ul>
<p><strong>Week 4</strong></p>
<ul>
<li>Listened to two episodes of the Haskell Interlude podcast: One with Gabriella Gonzalez, and one with Graham Hutton. Professor Hutton’s honesty and passion was, simply put, inspiring. The also-inspiring Gabriella mentioned two interesting things I’ll look into: Monad Reader and Dhall.</li>
<li>Listened to Conal Elliot talking about <a href="https://www.typetheoryforall.com/2022/05/09/17-The-Lost-Elegance-of-Computation-(Conal-Elliott).html">the lost elegance of computation</a>. Unique and poignant philosophy, inspired by Conal’s passion, I ought to read John Backus’s famou 1977 Turing award <a href="https://dl.acm.org/doi/pdf/10.1145/359576.359579">lecture</a> and read into FRP.</li>
<li>Read Monad Reader issue <a href="https://themonadreader.files.wordpress.com/2011/10/issue19.pdf">19</a>; learned about the <code class="language-plaintext highlighter-rouge">Coroutine</code> monad; I was able to use <code class="language-plaintext highlighter-rouge">Iteratee</code> and <code class="language-plaintext highlighter-rouge">Generator</code> to successfully implement a basic sketch of a program for work.</li>
</ul>
<h2 id="august">August</h2>
<p><strong>Week 1</strong></p>
<ul>
<li>Spent a weekend in FRP via Heinrich’s <a href="https://github.com/HeinrichApfelmus/frp-guides">guide</a>. Big idea: <code class="language-plaintext highlighter-rouge">Behaviors</code> are continous and <code class="language-plaintext highlighter-rouge">Events</code> are discrete, but, they can be easily composed and transformed to one another.</li>
<li>React-banana uses <code class="language-plaintext highlighter-rouge">MonadMoment</code>, which is also a <code class="language-plaintext highlighter-rouge">MonadFix</code>. I tried reading <a href="https://elvishjerricco.github.io/2017/08/22/monadfix-is-time-travel.html">MonadFix is Time Travel</a>. I only partially understood what’s going on even with after reading another <a href="https://www.parsonsmatt.org/2016/10/26/grokking_fix.html">article</a> because I lack a complete understanding of laziness, thunks, and <code class="language-plaintext highlighter-rouge">seq</code>, so, I started reading Haskell wikibook’s laziness <a href="https://en.wikibooks.org/wiki/Haskell/Laziness">article</a>.</li>
</ul>
<p><strong>Week 2</strong></p>
<ul>
<li>Finished my internship at TwoSix technologies, looking forward in returning as a formal methods researcher next summer!</li>
<li>Coming across the following for the first time: Refinement types, cubic type theory, the K framework.</li>
<li>I want to dedicate my time fully to reading 2 materials: Software Foundations (SF) and the Milewski’s Category Theory handbook, until school begins.</li>
<li>Finished the Basics chapter of SF’s Logical Foundations (LF) book. Good old functional programming!</li>
<li>Read Chapter 5-8 of the category theory book. I need to spend some time to gather more examples…</li>
</ul>Andrew Chenandrewchen14250@email.comForewordHow the Turn Tables2022-12-20T06:49:35-05:002022-12-20T06:49:35-05:00https://unfooling.com/unfooling.com/how-the-turn-tables<p>Mini life update: I’m almost done with the fall semester of my junior year; I’m still searching for internships; I’m beginning to do research with the <a href="https://www.cs.wm.edu/semeru/">SEMERU</a> group this spring! According to its lead and my academic advisor, Professor Poshyvanyk, SEMERU is the first group to apply deep neural models in code generation tasks. So, exciting things ahead!</p>
<p>Now, my team and I built an incomplete yet functioning call graph generator, and I’m thinking about how to best visualize it. Obviously, <code class="language-plaintext highlighter-rouge">d3.js</code> is my go-to choice, after all, I used to make <a href="https://www.youtube.com/watch?v=y2-sgZh49dQ&ab_channel=AndrewChen">youtube videos</a> on them. But, I needed a little refresher, so I surfed the web and found <a href="https://observablehq.com/@martinascharrer/d3-force-directed-graph-with-small-circles-around-nodes">this</a>:</p>
<figure class="kg-card kg-image-card"><img src=" __GHOST_URL__ /content/images/2022/12/Screenshot-from-2022-12-20-01-35-39.png" class="kg-image" alt="" loading="lazy" width="714" height="336" srcset=" __GHOST_URL__ /content/images/size/w600/2022/12/Screenshot-from-2022-12-20-01-35-39.png 600w, __GHOST_URL__ /content/images/2022/12/Screenshot-from-2022-12-20-01-35-39.png 714w" /></figure>
<p>How the tables have turned!</p>
<p>Here’s a forced, independent takeaway: The essence of studying smart in higher education begins with recognizing that not all knowledge are worth the same. First, abstract and intuitive knowledge are more valuable, which we should focus on absorbing. Second, a general, breadth-first mindset pays the dividends long-term. Additionally, knowing just the existence and bare minimum of a wide range of concepts can do you a lot of good.</p>
<p>Just as weightlifters prioritize multi-joined, compound movements (deadlift, squat, benchpress), we too shall focus on the multi-faceted CS areas in our studies (algorithms, programming language theory and features, OS principles, etc). Things like specific visualization library, though addicting to experiment with, might deviate us from learning essential CS knowledge.</p>
<p>P.S., “<a href="https://www.urbandictionary.com/define.php?term=How%20the%20turn%20tables">How the turn tables</a>” is a memorable saying from the American show, <em>The Office.</em></p>Andrew Chenandrewchen14250@email.comMini life update: I’m almost done with the fall semester of my junior year; I’m still searching for internships; I’m beginning to do research with the SEMERU group this spring! According to its lead and my academic advisor, Professor Poshyvanyk, SEMERU is the first group to apply deep neural models in code generation tasks. So, exciting things ahead!Abundance and Scarcity2022-11-20T05:38:29-05:002022-11-20T05:38:29-05:00https://unfooling.com/unfooling.com/abundance-and-scarcity<p>Update: I was ignorant when I first wrote this — I couldn’t even name a handful of mathematical insights derived this century (but there are plenty). I should’ve instead explored why ancient mathematicians <strong>appeared</strong> smarter. I think this appearance is mainly due to the fact that they picked up low-hanging and foundational fruits. These attributes, in conjunction with time, made more modern people aware of their work, thus contributing to the illusory truth effect.</p>
<p>Below lies the original blog:
***
Opinion: Ancient mathematicians are smarter. </p>
<p>But, the Mesopotamians, or ancient Greeks, or Renaissance-undergoing Prussians weren’t just genetically smart: What’re some fundamental principles that fostered such an intellectual environment?</p>
<ol>
<li>Totally Diminishing Marginal Utility</li>
</ol>
<p>Marginal utility, an Econ jargon, is the satisfaction derived from consuming a product. Diminishing marginal utility observes marginal utilities over all products consumed, and rules that <code class="language-plaintext highlighter-rouge">Consuming the (N+1)th item derives less pleasure than consuming the Nth</code>.</p>
<p>But, I’m afraid, due to the abundance of information, ALL marginal utilities on academic materials have decreased: <code class="language-plaintext highlighter-rouge">Consuming Euler's Elements of Algebra in the 2000s derives less pleasure than consuming it in the 1600s</code>.</p>
<p>The consequence of abundance is the lost of scarcity, the lost of the human nature to care for vulnerable, precious things.</p>
<ol>
<li>Diminishing Focus</li>
</ol>
<p>Neil Postman wrote that whole <code class="language-plaintext highlighter-rouge">Amusing Ourselves to Death</code> book that I remember reading in high school for actually, self-help purposes. However, what he observed in 1985 about the dangers of TV and media must’ve tripled by today. His main theory was that television reduces important things to mere entertainment, therefore diluting focus and purpose.</p>
<ol>
<li>Less Purpose</li>
</ol>
<p>On the note of less purpose: Mathematicians were really smart during war times. Alan Turing and his colleagues recruited through crossword puzzle contests cracked the enigma, and the whole space race thing was another level of spectacle (Oh gosh, spectacle, did I just reduce the space race to mere entertainment?).</p>
<p>Although us contemporary folks can still find purpose without war and religion, those purposes were embedded in our systems and simple to follow. Today, we are out of luck, our lives are comparably easier, which ironically makes living a purposeful life harder.</p>Andrew Chenandrewchen14250@email.comUpdate: I was ignorant when I first wrote this — I couldn’t even name a handful of mathematical insights derived this century (but there are plenty). I should’ve instead explored why ancient mathematicians appeared smarter. I think this appearance is mainly due to the fact that they picked up low-hanging and foundational fruits. These attributes, in conjunction with time, made more modern people aware of their work, thus contributing to the illusory truth effect.Analyzing my 11k bash commands2022-10-29T15:48:59-04:002022-10-29T15:48:59-04:00https://unfooling.com/unfooling.com/analyzing-my-11k-bash-commands<p><code class="language-plaintext highlighter-rouge">history | wc</code> informs me that I’ve typed exactly <strong>11005</strong> bash commands for the 278 days I’ve used Ubuntu (<code class="language-plaintext highlighter-rouge">ls -lt /var/log/installer</code>). However, I only expanded my <code class="language-plaintext highlighter-rouge">history</code> storage about 3 months ago, so I’ve probably lost out on 60% of the commands I’ve ever typed.</p>
<p>Still, I’m intrigued to investigate what commands have I been writing, so I set out to write some scripts to find out. I hypothesize the front runners to be <code class="language-plaintext highlighter-rouge">cd</code>, <code class="language-plaintext highlighter-rouge">ls</code>, and <code class="language-plaintext highlighter-rouge">docker</code>.</p>
<h3 id="top-10-commands-executed">Top 10 commands executed</h3>
<p>I wrote the following script:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">Counter</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">" __main__"</span><span class="p">:</span>
<span class="n">history_path</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="s">""</span><span class="p">,</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s">"~"</span><span class="p">),</span> <span class="s">".bash_history"</span><span class="p">)</span>
<span class="n">raw_history</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">history_path</span><span class="p">,</span> <span class="s">'r'</span><span class="p">).</span><span class="n">read</span><span class="p">().</span><span class="n">splitlines</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">nonEmpty</span><span class="p">(</span><span class="nb">str</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span>
<span class="k">def</span> <span class="nf">isSegmentEnvVar</span><span class="p">(</span><span class="n">segment</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="k">return</span> <span class="s">'='</span> <span class="ow">in</span> <span class="n">segment</span>
<span class="k">def</span> <span class="nf">isSegmentDate</span><span class="p">(</span><span class="n">segment</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="k">return</span> <span class="n">segment</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">isnumeric</span><span class="p">()</span>
<span class="c1"># remove blank lines and dates and env varibales
</span> <span class="n">history</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">row</span><span class="p">:</span> <span class="s">' '</span><span class="p">.</span><span class="n">join</span><span class="p">(</span>
<span class="n">dropwhile</span><span class="p">(</span><span class="k">lambda</span> <span class="n">segment</span><span class="p">:</span> <span class="n">isSegmentDate</span><span class="p">(</span><span class="n">segment</span><span class="p">)</span> <span class="ow">or</span> <span class="n">isSegmentEnvVar</span><span class="p">(</span><span class="n">segment</span><span class="p">),</span> <span class="n">row</span><span class="p">.</span><span class="n">split</span><span class="p">())),</span> <span class="n">raw_history</span>
<span class="p">))</span>
<span class="n">history</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">nonEmpty</span><span class="p">,</span> <span class="n">history</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">top_n_command_name</span><span class="p">(</span><span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">command_names</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">row</span><span class="p">:</span> <span class="n">row</span><span class="p">.</span><span class="n">split</span><span class="p">(</span><span class="s">" "</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="n">history</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Counter</span><span class="p">(</span><span class="n">command_names</span><span class="p">).</span><span class="n">most_common</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">top_n_command_name</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span>
</code></pre></div></div>
<p>Results:</p>
<!--kg-card-begin: markdown-->
<table>
<thead>
<tr>
<th>Command</th>
<th>Times Executed</th>
</tr>
</thead>
<tbody>
<tr>
<td>cd</td>
<td>1522</td>
</tr>
<tr>
<td>ls</td>
<td>1446</td>
</tr>
<tr>
<td>npm</td>
<td>725</td>
</tr>
<tr>
<td>sudo</td>
<td>684</td>
</tr>
<tr>
<td>python3</td>
<td>588</td>
</tr>
<tr>
<td>git</td>
<td>513</td>
</tr>
<tr>
<td>cb-dev-kit</td>
<td>449</td>
</tr>
<tr>
<td>cb-cli</td>
<td>444</td>
</tr>
<tr>
<td>code</td>
<td>396</td>
</tr>
<tr>
<td>node</td>
<td>296</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown-->
<p><code class="language-plaintext highlighter-rouge">isSegmentEnvVar</code> serves to remove the leading environment variables (e.g, <code class="language-plaintext highlighter-rouge">ENV1=hello python3 driver.py</code>).</p>
<p><code class="language-plaintext highlighter-rouge">isSegmentDate</code> serves to remove the <a href="https://www.cherryservers.com/blog/a-complete-guide-to-linux-bash-history#add-date-and-timestamps-to-bash-history-output">leading date</a> information that might appear in a standard history entry.</p>
<p>Looks like I use a lot of node and python. Interesting, I would’ve thought that I’ve used more <code class="language-plaintext highlighter-rouge">gcc</code> than the other two.</p>
<h3 id="10-most-frequent-commands-with-2-keywords">10 most frequent commands with 2 keywords</h3>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="k">def</span> <span class="nf">top_n_k_keyword</span><span class="p">(</span><span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">k</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">keywords_list</span> <span class="o">=</span> <span class="p">[</span><span class="s">' '</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="n">row</span><span class="p">.</span><span class="n">split</span><span class="p">()[:</span><span class="n">k</span><span class="p">])</span>
<span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">history</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">row</span><span class="p">.</span><span class="n">split</span><span class="p">())</span> <span class="o">>=</span> <span class="n">k</span><span class="p">]</span>
<span class="k">return</span> <span class="n">Counter</span><span class="p">(</span><span class="n">keywords_list</span><span class="p">).</span><span class="n">most_common</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">top_n_k_keyword</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
</code></pre></div></div>
<!--kg-card-begin: markdown-->
<table>
<thead>
<tr>
<th>Command</th>
<th>Times Executed</th>
</tr>
</thead>
<tbody>
<tr>
<td>cd ..</td>
<td>324</td>
</tr>
<tr>
<td>code .</td>
<td>142</td>
</tr>
<tr>
<td>npm start</td>
<td>74</td>
</tr>
<tr>
<td>cd packages/server/</td>
<td>71</td>
</tr>
<tr>
<td>ls -R</td>
<td>44</td>
</tr>
<tr>
<td>cb-cli init</td>
<td>43</td>
</tr>
<tr>
<td>cd ../..</td>
<td>42</td>
</tr>
<tr>
<td>stack build</td>
<td>39</td>
</tr>
<tr>
<td>cb-dev-kit generate</td>
<td>38</td>
</tr>
<tr>
<td>git push</td>
<td>37</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown-->
<h3 id="my-full-script-with-3-more-options">My full script with 3 more options</h3>
<p><a href="https://github.com/BlastWind/unfooling-blog-snippets/tree/main/bash-history-analysis">Link</a>
I designed 3 more options:</p>
<ul>
<li>Shortest N commands</li>
<li>Longest N commands</li>
<li>N most frequent full commands</li>
</ul>
<p>Run the script I linked above with no arguments to get some default output.</p>Andrew Chenandrewchen14250@email.comhistory | wc informs me that I’ve typed exactly 11005 bash commands for the 278 days I’ve used Ubuntu (ls -lt /var/log/installer). However, I only expanded my history storage about 3 months ago, so I’ve probably lost out on 60% of the commands I’ve ever typed.Art must be2022-10-27T03:16:25-04:002022-10-27T03:16:25-04:00https://unfooling.com/unfooling.com/art-must-be<p>Free flowing. Ready to burst, a 40-week old fetus clenches at the bars imprisoning it. The moment the thesaurus is consulted for a needless change in subtlety, the art is lost. You can’t time manage art, art can’t be controlled. It must be one of the highest feeling, the acme of existence, instilled of god-ness.</p>
<p>I had the pleasure of partaking in an university sculpting class. My results was okay but my experience was to be envied. Subscribed to art, it commanded me to chisel, saw, scrape, sand its amorphous thoughts into reality. It commanded me in irregular hours, when my body was tired but my mind alert. </p>
<p>I had the pleasure of writing in my confined, dark themed, markdown editor. The ratio of my prose attempts to publishes is 5:1 because the moment I hesitate, the beauty begins to rot, which I recycle.</p>
<p>Art must be opinionated. No one loves a lonely man. But some love a opinionated, cigar smoking, sad man. Those men call themselves existentialists, I think they would relinquish that title if a real pretty and soulful girl fell in love with them.</p>
<p>Art must be cringe. Some will never believe in an art form, and that someone is not wrong. But you must believe in your art.</p>Andrew Chenandrewchen14250@email.comFree flowing. Ready to burst, a 40-week old fetus clenches at the bars imprisoning it. The moment the thesaurus is consulted for a needless change in subtlety, the art is lost. You can’t time manage art, art can’t be controlled. It must be one of the highest feeling, the acme of existence, instilled of god-ness.Functional Programming Journal2022-09-06T14:29:26-04:002022-09-06T14:29:26-04:00https://unfooling.com/unfooling.com/fp-journal<h3 id="foreword">Foreword</h3>
<blockquote>
<p>It is not only the violin that shapes the violinist, we are all shaped by the tools we train ourselves to use, and in this respect programming languages have a devious influence: they shape our thinking habits. - Dijkstra</p>
</blockquote>
<p>At the time of writing this foreword (9/6/2022), I have functionally programmed ~200 hrs (mainly, regurgitating and practicing <a href="https://github.com/MostlyAdequate/mostly-adequate-guide">this</a>). I love it, it’s a challenge, it makes me think clearer and feel more powerful. Two months ago, I started dabbing in Haskell a bit and am 10 chapters into <a href="https://haskellbook.com/">this</a>. As Euclid deemed that “there is no loyal road to geometry”, the modern FP wizards deem that there is “no loyal road to FP”. But, I still want to serve this community with my personal learning notes. Perhaps you, my reader, will stumble upon this journal years after my initial post, and at least find some comfort in that there are others after the same destination, who followed through and prevailed (hopefully).</p>
<p>I want to maintain the entire journal in this single post. I shall debrief daily, but I’ll compile the debriefs each month so that this place doesn’t get too cluttered.</p>
<p>Edit (11/28/2022): I am not going to compile the journals at the end of each month. I think a compilation will dull the sentiments of the journal! However, to avoid clutter, I’ll open up a new journal post every few months.</p>
<h3 id="september-2022">September 2022</h3>
<p><strong>6th</strong></p>
<p><code class="language-plaintext highlighter-rouge">foldr, foldl, fold'</code>: foldr can short circuit. foldr, foldl are lazy, stack overflow prone. foldl’ is strict (opposite of lazy), hangs in infinite loop because no stack overflow.</p>
<p>7th</p>
<p>HPFFP pg. 590-642: Interesting <code class="language-plaintext highlighter-rouge">Product</code>, <code class="language-plaintext highlighter-rouge">Sum</code> types (<code class="language-plaintext highlighter-rouge">data Sum a b = First a | Second b</code>). First time coming across kinds, cardinality (despite being familiar with sum and product type).</p>
<p>8th</p>
<p>HPFFP pg. 643-681: Function type is the exponent operator (in regards to sum and product types). Higher kinded types are similar to higher order functions. Lists are polymorphic.</p>
<p>9th</p>
<p>First half of <a href="http://learnyouahaskell.com/input-and-output">Input and Output</a>. Solved 5 basic codeforces problems according to this <a href="https://github.com/anurudhp/CPHaskell">list</a> left. Biggest lesson from doing these exercises: Type can be inferenced using knowledge of the next function invoked, this is how <code class="language-plaintext highlighter-rouge">read</code> can be written to not use explicit casts; <code class="language-plaintext highlighter-rouge">interact $</code>.</p>
<p>10th</p>
<p>HPFFP pg. 681-690. Started studying binary trees, yet to comprehend <a href="https://riptutorial.com/haskell/example/2556/an-instance-of-foldable-for-a-binary-tree">Foldable instance for Tree</a> implementation:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> foldr f acc Leaf = acc
foldr f acc (Node l x r) = foldr f (f x (foldr f acc r)) l
</code></pre></div></div>
<p>Tomorrow I want to understand everything in the previously attached linked deeply.</p>
<p>11th</p>
<p>Understood yesterday’s snippet: To fold a tree, recursively fold its left subtree with the accumulator value being the result of the input function applied to the current root node’s value and the result of folding the right subtree.</p>
<p>Started doing HPFFP Ch.11 exercises, stuck on Ciphers problem. Watched 90 minutes of <a href="https://www.youtube.com/watch?v=N9RUqGYuGfw">this</a>: How a custom Parser type (which has instances for Functors and Applicatives) can parse json (also the topic of HPFFP Ch.24). I’ll refrain from finishing the entire video, need to build up to understanding everything.</p>
<p>12th</p>
<p>Used <code class="language-plaintext highlighter-rouge">zipWith</code> to iterate two Foldables at once to complete the cipher (thanks to my python knowledge); Learned <code class="language-plaintext highlighter-rouge">as-patterns</code> to bind original variable while pattern matching it.</p>
<p>14th</p>
<p>HPFFP Ch.15 reading. Types can have more than one monoidal operation.</p>
<p>15th</p>
<p>HPFFP Ch.13 reading and exercises: Built hangman!</p>
<p>16th</p>
<p>Read almost all of HPFFP Ch.14 on testing, still internalizing <code class="language-plaintext highlighter-rouge">Arbitrary</code> and <code class="language-plaintext highlighter-rouge">Gen</code>. Solved code forces 2A in haskell, used <code class="language-plaintext highlighter-rouge">Data.Map</code> for the first time.</p>
<p>16-27th: Busy with other stuff. Read half of the chapter on Functors.</p>
<p>28th: Lisp s-expressions. Stumbled upon this because I’m working on a call graph generator which uses tree-sitter, a parser with a query language formatted with s-expressions.</p>
<h3 id="october-2022">October 2022</h3>
<p>5th: Q1 - Q4 of <a href="https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems">99 problems</a>. Ignore first argument in function application by using const. Ignore second argument with a <code class="language-plaintext highlighter-rouge">const . (+1)</code>. So damn cool.</p>
<p>6th: Went back to <code class="language-plaintext highlighter-rouge">foldr, foldl, fold'</code>. I learned that <code class="language-plaintext highlighter-rouge">seq</code> can be used to enforce strictness in the lazy realm of haskell.</p>
<p>15th: <code class="language-plaintext highlighter-rouge">(fmap . fmap)</code> penetrates the value of the second Functor. More can be chained. I was able to trace the type of this expression, but man, I don’t have much intuition of it.</p>
<p>16th: Finished HPFFP Functor Chapter. Instead of pattern matching on <code class="language-plaintext highlighter-rouge">Just</code> and <code class="language-plaintext highlighter-rouge">Nothing</code>, just use a single <code class="language-plaintext highlighter-rouge">fmap</code>! Understand functors more, like why <code class="language-plaintext highlighter-rouge">fmap</code> only hits the second argument in <code class="language-plaintext highlighter-rouge">Either</code>, tuples, etc.</p>
<p>17th: HPFFP p.1052-p.1067. Obtained basics of <code class="language-plaintext highlighter-rouge">Applicative</code>. It was tough writing the pedagogical <code class="language-plaintext highlighter-rouge">Applicative</code> instance for <code class="language-plaintext highlighter-rouge">Constant x</code> , had to look up both how to write <code class="language-plaintext highlighter-rouge">pure</code> and <code class="language-plaintext highlighter-rouge"><*></code>, it all makes sense now though.</p>
<p>18th-22nd: HPFFP p.1067-1206 (currently on Monad exercises). Built a simple <a href="https://github.com/BlastWind/hic-hac-hoe">tic tac toe</a>. Internalized <code class="language-plaintext highlighter-rouge"><$></code>, <code class="language-plaintext highlighter-rouge"><*></code>, <code class="language-plaintext highlighter-rouge">>>=</code>. I need, however, a deep understanding of “algebras that aren’t other algebras”. In other words, concrete examples of say, Applicative instances that aren’t Monad instances.</p>
<p>28th: Read over how to use quickcheck in HPFFP again, did some Monad exercises.</p>
<p>29th: HPFFP p.1212-1258: Learned to build a URL shortener! Also TIL <code class="language-plaintext highlighter-rouge">replicateM 5 [1,2,3]</code>effectively generates all length 5 permutations with elements from <code class="language-plaintext highlighter-rouge">[1,2,3]</code>. This is because <code class="language-plaintext highlighter-rouge">replicateM</code> performs the monad 5 times, and list monads combine on mappend.</p>
<p>30th-31st: HPFFP Ch20 Foldable and Ch21 Traversable (p.1259-1314). Fun and easy.</p>
<h3 id="november-2022">November 2022</h3>
<p>1st: HPFFP Ch22 Reader Monad. Tbh, this <a href="https://engineering.dollarshaveclub.com/the-reader-monad-example-motivation-542c54ccfaa8#77ff">article</a> offered a great explanation. There is, more to the reader monad than resolving “prop drilling” (term used by the ReactJS community), but it is one of its greater uses.</p>
<p>2nd: I found that similar to how <code class="language-plaintext highlighter-rouge">fmap . fmap</code> targets a value beneath nested functors, <code class="language-plaintext highlighter-rouge">foldMap . foldMap</code> targets a value beneath nested <code class="language-plaintext highlighter-rouge">foldables</code>. The concept might be understood quicker if one were to just write <code class="language-plaintext highlighter-rouge">fmap (fmap f)</code> and <code class="language-plaintext highlighter-rouge">foldMap (foldMap f)</code> though. The <code class="language-plaintext highlighter-rouge">(.)</code> syntax, while terse, doesn’t imply nestedness. However, I’m but a novice, I think stronger readers can understand quickly that <code class="language-plaintext highlighter-rouge">fmap</code> can be seen as <code class="language-plaintext highlighter-rouge">(a->b) -> (f a -> f b)</code>, so the second <code class="language-plaintext highlighter-rouge">fmap</code> of <code class="language-plaintext highlighter-rouge">(fmap . fmap)</code> is the function the first <code class="language-plaintext highlighter-rouge">fmap</code> accepts, which is functorial <code class="language-plaintext highlighter-rouge">(f a -> f b)</code>.</p>
<p>3rd: HPFFP Ch 25 and partial Ch 26. I’m getting a hang of monad transformers thanks to <a href="https://stackoverflow.com/questions/32579133/simplest-non-trivial-monad-transformer-example-for-dummies-iomaybe">this</a>. What I understand is that <code class="language-plaintext highlighter-rouge">MaybeT</code> <code class="language-plaintext highlighter-rouge">return Nothing</code> in its <code class="language-plaintext highlighter-rouge">>>=</code> when the first part’s nested Maybe is indeed a <code class="language-plaintext highlighter-rouge">Nothing</code>. What I still need are more examples. It seems like <code class="language-plaintext highlighter-rouge">MaybeT</code>, in the stackoverflow example, solves the staircase problem because the Maybe-ness is embedded in the <code class="language-plaintext highlighter-rouge">>>=</code>, and thus embedded between the lines of a <code class="language-plaintext highlighter-rouge">do</code> block. This prevents the need to pattern match on <code class="language-plaintext highlighter-rouge">Maybe</code>, and thus prevents the staircase problem.</p>
<p>4th: Watch this little <a href="https://www.youtube.com/watch?v=A-qGGag3Mt8">gem</a> on how IO is defined using the state monad. Haven’t understood everything about it yet. I also traced through a state monad in this <a href="https://www.youtube.com/watch?v=DaU6BAV7Z94&t=1215s">video</a>, also still trying to understand it.</p>
<p>5th-9th: Went through the <a href="https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State#Accessing_the_State">Turnstile State example</a>. In addition to the essence of state, I also dabbled in <code class="language-plaintext highlighter-rouge">foldM</code>, <code class="language-plaintext highlighter-rouge">mapM</code>, <code class="language-plaintext highlighter-rouge">filterM</code>, and <code class="language-plaintext highlighter-rouge">sequence</code>.</p>
<p>11th: Wrote the instance for the monad transformers <code class="language-plaintext highlighter-rouge">ReaderT</code> and <code class="language-plaintext highlighter-rouge">StateT</code>. Turns out, I can’t write an <code class="language-plaintext highlighter-rouge">Applicative</code> for <code class="language-plaintext highlighter-rouge">StateT</code> unless the inner higher typed variable is a <code class="language-plaintext highlighter-rouge">Monad</code>. This is because, to get from <code class="language-plaintext highlighter-rouge">s -> m (s, a->b)</code> and <code class="language-plaintext highlighter-rouge">s -> m(s, a)</code> to <code class="language-plaintext highlighter-rouge">s -> m(s, b)</code>, I can apply the <code class="language-plaintext highlighter-rouge">s</code> to the first expression to get <code class="language-plaintext highlighter-rouge">m (s, a->b)</code> , but then, to get the <code class="language-plaintext highlighter-rouge">s</code> out of this expression in order to apply it to the second expression, <code class="language-plaintext highlighter-rouge">m</code> must be a Monad.</p>
<p>12th-13th: More on monad transformers, read through the MonadTrans section in HPFFP but didn’t really internalize much, so I plan to read <a href="https://en.wikibooks.org/wiki/Haskell/Monad_transformers">this</a>.</p>
<p>14th: The reason we do <code class="language-plaintext highlighter-rouge">MaybeT $ do ...</code> when defining the monad instance for <code class="language-plaintext highlighter-rouge">MaybeT</code> is that <code class="language-plaintext highlighter-rouge">do</code> must be in the other monad, <code class="language-plaintext highlighter-rouge">m</code>’s context, and not in <code class="language-plaintext highlighter-rouge">MaybeT m</code>’s (because it <code class="language-plaintext highlighter-rouge">MaybeT</code> monad is yet to be defined). “There is no magic formula to create a transformer version of a monad; the form depends on what makes sense in the context of its non-transformer type.” We can write liftM with the bind or do notation.</p>
<p>15th: Read this little <a href="http://matija.me/2020/11/05/haskell-monad-transformers-intro/">piece</a> on monad transformers. Now reading FP Complete’s <a href="https://www.fpcomplete.com/haskell/tutorial/monad-transformers/">piece</a> on it. The <code class="language-plaintext highlighter-rouge">foldTerminate</code> function utilizing Either monad is something I haven’t seen before. I’m going to carefully trace through and unwrap it tomorrow.</p>
<p>18th: Read the <code class="language-plaintext highlighter-rouge">StateEither</code> example of FP Complete’s piece of monad transformers.</p>
<p>19th: I am getting a hang on monad transformers. The <code class="language-plaintext highlighter-rouge">StateEither</code>’s <code class="language-plaintext highlighter-rouge">Applicative</code> and <code class="language-plaintext highlighter-rouge">Monad</code> instances required no explicit usage of <code class="language-plaintext highlighter-rouge">State</code> functions, it just uses <code class="language-plaintext highlighter-rouge">return</code> and <code class="language-plaintext highlighter-rouge">>>=</code>, which all monads have. So really, many monads can wrap <code class="language-plaintext highlighter-rouge">Either</code>.</p>
<p>21st: Summary of the FP Complete’s article so far:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>step 1: Observe that we can write foldTerminate whose fold f returns EitherWe can then write sumTillNegative, with negative case returning (Left acc)
step 2: Avoid explicitly patterning matching on Either by using Either's monad and do notation.
step 3: Notice that fold can be implemented with the State monad. So, foldTerminate can be implementedwith a State monad whose outputs were Either.
step 4: We make a StateEither type and write the algebra instances; we write the helper methods
step 5: We notice that it is possible to write the algebra instances with methods that all monads have (>>=, return).
step 6: We make EitherT and write algebra instances and an MonadTrans instance for it; we write the helper methods
step 7: The helper methods, like modify, do not need to be defined on Either. So we write modifyM that uses the polymorphic lift.
</code></pre></div></div>
<p>22nd: Exercise #1 on the FP Complete article</p>
<p>23rd: Took me 2 hrs to write this for the article’s Exercise #2:</p>
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">foldTerminateM</span> <span class="o">::</span> <span class="kt">Monad</span> <span class="n">m</span><span class="o">=></span> <span class="p">(</span><span class="n">b</span> <span class="o">-></span> <span class="n">a</span> <span class="o">-></span> <span class="n">m</span><span class="p">(</span><span class="kt">Either</span> <span class="n">b</span> <span class="n">b</span><span class="p">))</span> <span class="o">-></span> <span class="n">b</span> <span class="o">-></span> <span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="o">-></span> <span class="n">m</span> <span class="n">b</span>
<span class="n">foldTerminateM</span> <span class="n">f</span> <span class="n">accum</span> <span class="p">(</span><span class="n">x</span><span class="o">:</span><span class="n">xs</span><span class="p">)</span> <span class="o">=</span> <span class="n">fmap</span> <span class="p">(</span><span class="n">either</span> <span class="n">id</span> <span class="n">id</span><span class="p">)</span> <span class="o">$</span> <span class="n">runExceptT</span> <span class="o">$</span> <span class="kr">do</span>
<span class="n">b</span> <span class="o"><-</span> <span class="kt">ExceptT</span> <span class="o">$</span> <span class="n">f</span> <span class="n">accum</span> <span class="n">x</span>
<span class="n">lift</span> <span class="o">$</span> <span class="n">foldTerminateM</span> <span class="n">f</span> <span class="n">b</span> <span class="n">xs</span>
<span class="n">foldTerminateM</span> <span class="n">f</span> <span class="n">accum</span> <span class="kt">[]</span> <span class="o">=</span> <span class="n">return</span> <span class="n">accum</span>
</code></pre></div></div>
<p>I was getting confused at first tackling this problem since I was <strong>using the wrong “lifting action”</strong>. Specifically, I was doing <code class="language-plaintext highlighter-rouge">return $ foldTerminateM f b xs</code> instead of <code class="language-plaintext highlighter-rouge">lift $ foldTerminateM f b xs</code>.</p>
<p>26th: Exercise 3. Going to take a detour to study <a href="https://www.fpcomplete.com/haskell/tutorial/lens/">Lenses</a> since exercise 4 depends on it.</p>
<p>28th: 20 minutes into SJP on <a href="https://www.youtube.com/watch?v=k-QwBL9Dia0">Lenses</a>, implemented my own Bad Lens example.</p>
<p>29th: I decided to read some real Haskell code, think I’ve been in the ivory tower for too long! To start, I’m reading <a href="https://github.com/8Gitbrix/2048Haskell">2048 written in Haskell</a> with the TUI library <a href="https://github.com/jtdaugherty/brick">bricks</a>. Two nuggets I learned thus far: 1) Use <code class="language-plaintext highlighter-rouge">forkIO</code> to start a background thread. 2) Use <code class="language-plaintext highlighter-rouge">uncurry</code> to apply a tuple as the first two args to a function. Overall, it’s very surprising how easy it is to write 2048 with Haskell in a framework. <code class="language-plaintext highlighter-rouge">bricks</code> allows for a very declarative style of programming, where you predefined all your event handlers and drawing functions in one <code class="language-plaintext highlighter-rouge">App</code> object. When I’m experienced enough, I will read <code class="language-plaintext highlighter-rouge">bricks</code>.</p>
<p>30th: Started working on a tic-tac-toe clone, which I affectionately named <code class="language-plaintext highlighter-rouge">hic-hac-hoe</code>. I am using <code class="language-plaintext highlighter-rouge">bricks</code>, so this is TUI, and so I envision users moving around the highlight block with the arrow keys, pressing <code class="language-plaintext highlighter-rouge">enter</code> to make a move. I have already implemented a dummy cell with text “highlight”, that moves around in the tic-tac-toe grid on arrow key inputs. The code is very similar to the 2048 haskell clone.</p>
<h3 id="december-2022">December 2022</h3>
<p>1st, 2nd:</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src=" __GHOST_URL__ /content/images/2022/12/demo.gif" class="kg-image" alt="" loading="lazy" width="600" height="338" srcset=" __GHOST_URL__ /content/images/2022/12/demo.gif 600w" /><figcaption>Done!</figcaption></figure>
<p>3rd: I started looking around for networking libraries. The author of <code class="language-plaintext highlighter-rouge">bricks</code> recommended <code class="language-plaintext highlighter-rouge">zeromq-haskell</code> to me, so I probably will look a lot into it, but it doesn’t have much documentations since it is a binding.</p>
<p>4th: I browsed for multiplayer haskell games. Unfortunately, most of them use web server frameworks like <code class="language-plaintext highlighter-rouge">Yesod</code>, <code class="language-plaintext highlighter-rouge">scotty</code>. which I don’t need since I just need some simple messaging relaying. I am going to follow haskell wiki’s <code class="language-plaintext highlighter-rouge">Network.Socket</code> only “<a href="https://wiki.haskell.org/Implement_a_chat_server">implement a chat server</a>” tutorial first, and then maybe dig into <code class="language-plaintext highlighter-rouge">zeromq</code> if I think I need more.</p>
<p>5th: I took a detour and did a thought experiment on how to model a call graph generator application in Haskell. I got stuck, so I <a href="https://softwareengineering.stackexchange.com/questions/442688/haskell-data-modeling-an-internal-app-that-interfaces-with-a-3rd-party-library">asked</a>. Also, I do not plan to study much Haskell in the coming 2 weeks. I have finals and research papers to read! During the winter break, however, I plan to basically Haskell every waking hour and also start working through <a href="https://www.cis.upenn.edu/~bcpierce/tapl/">TAPL</a>.</p>
<p>14th: I haven’t touched FP in the last 10 days due to finals. However, I have learned in the last 10 days that becoming acquainted with PL jargons serves me better in the longer run than working through something specific like TAPL. So, during my winter break, I’ll instead work with <a href="https://www.cs.rochester.edu/~scott/pragmatics/">PLP</a> (Programming Language Pragmatics), which is, actually, the current textbook of my PL class.</p>
<p>25th: Merry Christmas! I began digging into <code class="language-plaintext highlighter-rouge">vty</code>, a <code class="language-plaintext highlighter-rouge">ncurses</code> alternative written in Haskell. <code class="language-plaintext highlighter-rouge">vty</code> is a precursor of <code class="language-plaintext highlighter-rouge">brick</code>, which I plan to dig into in the future.</p>
<h3 id="february-2023">February 2023</h3>
<p>7th, 8th: I’ve taken a huge break from FP due to school but now I’m back. I began digging into the Parsec library and learned the basics of Parsec via this <a href="https://book.realworldhaskell.org/read/using-parsec.html">article</a>. Since I eventually want to produce a code-base-deep-dive video on Parsec, I am reading earlier papers on Monadic Parser Combinators to gain a thorough understanding. I am 10 pages into Hutton’s <a href="https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf">work</a>. The most important improvement that Parsec since made is better error handling and performance.</p>
<h3 id="apr-2023">Apr 2023</h3>
<p>From Feb 8th to Apr 2nd:</p>
<ul>
<li>Read <a href="https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.168.4008&rep=rep1&type=pdf">A History of Haskell: being lazy with class</a></li>
<li>Read <a href="https://www.cs.nott.ac.uk/~pszgmh/123.pdf">It’s Easy As 1, 2, 3</a>
<ul>
<li>Inspired me to read the Semantic Algebras chapter of <a href="https://www.google.com/search?q=schmidt+denotational+semantics&oq=schimdt+denotational+semantics&aqs=chrome..69i57j33i10i160j33i299.6393j0j7&sourceid=chrome&ie=UTF-8&si=AMnBZoGh_HM3J_-U1hyC2-ep11yDw5aKTM8ASg3cFDT_bpkmN-nz5Mys77G29AQiHAXdbAd7TklX5aUP33W1kspyQShjpUO0COnYw2TFvAFB9cDkpqyU_igPXLp5DmM54gWv62A3829WebxaSMHIzi44AILQgKHgUcLtdgjqSa_Gtpqc0NXnW-3Z1XETi1Y3HKkzrB5rNFE4&ictx=1&ved=2ahUKEwjZuOfJsYz-AhVbE1kFHcvoC78QnZMFegQIWRAC">Denotational Semantics, A Methodology for Language Development</a></li>
</ul>
</li>
<li>For my undergrad research on <em>Interpreting Language Models for Functional Programming</em>, I defined a taxonomy for Haskell (mapping Haskell grammar rules to general categories, e.g., <code class="language-plaintext highlighter-rouge">algebraic data types</code> belongs to the category <code class="language-plaintext highlighter-rouge">type system</code>). In defining this taxonomy, I came across many Haskell extensions that was complex for me to organize. Thankfully, I discovered <a href="https://thinkingwithtypes.com/">Thinking with Types, Type-Level Programming in Haskell</a>. I am only one chapter in, but I plan to finish this book.</li>
</ul>
<p>Apr 3rd: A few pages of Thinking in Types (I abbreviate as TiT from now).
Fully applied (saturated) TypeClasses always end in <code class="language-plaintext highlighter-rouge">Constraint</code>, this single fact seems to be the missing piece for me to internalize the non-extended Haskell’s type system. Previously, I learned from <code class="language-plaintext highlighter-rouge">HPFFP</code> that
a type constructor like <code class="language-plaintext highlighter-rouge">Maybe</code> has kind <code class="language-plaintext highlighter-rouge">* -> *</code>, but I think I never
remembered these stuff well because I didn’t internalize where TypeClasses fit in the whole scheme.</p>
<p>May 8th: Sorry! Another big skip. I didn’t do much last month. Today, I reread
TiT Chapter 1, took notes, and did the exercises. The big idea I learned is that the Curry-Howard correspondence/isomorphism allows us to analyze mathematical theorems through the lens of functional programming. We get surprising results, for example, somehow, the power of power rule corresponds to currying.</p>
<p>May 9th: Reread TiT Ch2.1 and 2.2. This time around, I’ve cleared up many concepts, for example</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">(->)</code> is higher kind</li>
<li>Exact difference between <code class="language-plaintext highlighter-rouge">TYPE</code> (<code class="language-plaintext highlighter-rouge">*</code>) and type
As last time, I got stuck when reading the admin token example. But I did more digging into the example and learned:</li>
<li><code class="language-plaintext highlighter-rouge">Proxy</code> is a type constructor whose only type variable is poly-kinded. That’s how it’s able to pass any type around.</li>
<li>One usage of <code class="language-plaintext highlighter-rouge">forall</code> is to allow for type variables to show up in data constructors but not in their type constructors.
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kr">data</span> <span class="kt">Worker</span> <span class="n">x</span> <span class="n">y</span> <span class="o">=</span> <span class="n">forall</span> <span class="n">b</span><span class="o">.</span> <span class="kt">Buffer</span> <span class="n">b</span> <span class="o">=></span> <span class="kt">Worker</span> <span class="p">{</span> <span class="n">buffer</span> <span class="o">::</span> <span class="n">b</span><span class="p">,</span> <span class="n">input</span> <span class="o">::</span> <span class="n">x</span><span class="p">,</span> <span class="n">output</span> <span class="o">::</span> <span class="n">y</span><span class="p">}</span>
</code></pre></div> </div>
</li>
<li>Scoped Type Variables allow free variables to be re-used in the scope of a function.
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">mkpair</span> <span class="o">::</span> <span class="n">forall</span> <span class="n">a</span> <span class="n">b</span><span class="o">.</span> <span class="n">a</span> <span class="o">-></span> <span class="n">b</span> <span class="o">-></span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">mkpair</span> <span class="n">aa</span> <span class="n">bb</span> <span class="o">=</span> <span class="p">(</span><span class="n">ida</span> <span class="n">aa</span><span class="p">,</span> <span class="n">bb</span><span class="p">)</span>
<span class="kr">where</span>
<span class="c1">-- ida :: b -> b would error!</span>
<span class="n">ida</span> <span class="o">::</span> <span class="n">a</span> <span class="o">-></span> <span class="n">a</span> <span class="c1">-- Refers to "a" in the type signature.</span>
<span class="n">ida</span> <span class="o">=</span> <span class="n">id</span>
</code></pre></div> </div>
<p>Yet, I still don’t understand the admin token example. I checked out TiT’s source repo and it didn’t have that part filled in. However, I did find more code around the TicTacToe example in Ch1 that taught me a few more things. I’ll skip this example for now.</p>
</li>
</ul>
<p>May 10th: Finishes TiT Ch2. Learned about how lists and tuples behave in type-level programming. I don’t have the intuition down, but I kept querying <code class="language-plaintext highlighter-rouge">GHCi</code> to
get practice. Here’re some of my queries and results:</p>
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">:</span><span class="n">set</span> <span class="o">-</span><span class="kt">XDataKinds</span>
<span class="o">></span> <span class="o">:</span><span class="n">t</span> <span class="kt">[]</span>
<span class="kt">[]</span> <span class="o">::</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span>
<span class="o">></span> <span class="o">:</span><span class="n">k</span> <span class="kt">[]</span>
<span class="kt">[]</span> <span class="o">::</span> <span class="o">*</span> <span class="o">-></span> <span class="o">*</span>
<span class="o">></span> <span class="o">:</span><span class="n">k</span> <span class="p">[</span><span class="kt">Bool</span><span class="p">]</span>
<span class="p">[</span><span class="kt">Bool</span><span class="p">]</span> <span class="o">::</span> <span class="o">*</span>
<span class="o">></span> <span class="o">:</span><span class="n">k</span> <span class="n">'</span><span class="kt">[]</span>
<span class="n">'</span><span class="kt">[]</span> <span class="o">::</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span>
<span class="o">></span> <span class="o">:</span><span class="n">t</span> <span class="n">'</span><span class="kt">[]</span> <span class="c1">-- throws error.</span>
<span class="o">></span> <span class="o">:</span><span class="n">k</span> <span class="n">'</span><span class="p">[</span> <span class="kt">Bool</span> <span class="p">]</span>
<span class="n">'</span><span class="p">[</span> <span class="kt">Bool</span> <span class="p">]</span> <span class="o">::</span> <span class="p">[</span><span class="o">*</span><span class="p">]</span>
<span class="o">></span> <span class="o">:</span><span class="n">k</span> <span class="n">'</span><span class="p">[</span> <span class="kt">'True</span> <span class="p">]</span>
<span class="n">'</span><span class="p">[</span> <span class="kt">'True</span> <span class="p">]</span> <span class="o">::</span> <span class="p">[</span><span class="kt">Bool</span><span class="p">]</span>
</code></pre></div></div>
<p>I stumbled half an hour into Ch3, couldn’t understand much. This textbook is not beginner friendly.</p>
<p>May 11th: Finished TiT Ch3-Ch4.2. Confused about the following two statements from the Ch3, they seem conflicting with each other.
1) Variance is a property of a type in relation to one of its type constructors.
2) The variance of a type <code class="language-plaintext highlighter-rouge">T a</code> with respect to its type variable <code class="language-plaintext highlighter-rouge">a</code> is …
By the definition of 1), it seems off to say 2). I skip this for now.
Coolest thing I learned is the positive/negative positioning trick to quickly determine a type’s variance.</p>
<p>Then, I read the FPComplete’s <a href="https://www.fpcomplete.com/blog/2016/11/covariance-contravariance/">Covariance and Contravariance</a> article and learned the mappings between Haskell typeclasses and variance
(e.g., <code class="language-plaintext highlighter-rouge">Profunctor</code> is a bifunctor where the first argument is contravariant and the second argument is covariant).</p>
<p>Onto Ch4 —</p>
<ul>
<li>I filled in a knowledge gap of <code class="language-plaintext highlighter-rouge">forall</code> from before. I knew that <code class="language-plaintext highlighter-rouge">forall</code> can be applied in ADT declaration. But when there’re applied to functions, they moreso expand the type variables’ scope to the entire function (in conjunction with <code class="language-plaintext highlighter-rouge">XScopedTypeVariables</code>).</li>
<li><code class="language-plaintext highlighter-rouge">XTypeApplications</code> allow us to apply types to polymorphic functions in the same way we can apply value arguments to functions.</li>
</ul>
<p>May 12th: Finished TiT Ch4.3-Ch5. Learned about how to write a heterogeneous list and that the GADTs syntax is just syntactic sugar upon type equalities. So, I challenged myself to write <code class="language-plaintext highlighter-rouge">HList</code> with the latter:</p>
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kr">data</span> <span class="kt">HList</span> <span class="p">(</span><span class="n">xs</span> <span class="o">::</span> <span class="p">[</span><span class="kt">Type</span><span class="p">])</span>
<span class="o">=</span> <span class="kt">HNil</span>
<span class="o">|</span> <span class="n">forall</span> <span class="n">t</span> <span class="n">ts</span><span class="o">.</span> <span class="p">(</span><span class="n">xs</span> <span class="o">~</span> <span class="p">(</span><span class="n">t</span> <span class="n">'</span><span class="o">:</span> <span class="n">ts</span><span class="p">))</span> <span class="o">=></span> <span class="n">t</span> <span class="p">(</span><span class="o">:#</span><span class="p">)</span> <span class="kt">HList</span> <span class="n">ts</span>
</code></pre></div></div>
<p>This allows for functions like</p>
<div class="language-haskell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">showBool</span> <span class="o">::</span> <span class="kt">HList</span> <span class="n">'</span><span class="p">[</span><span class="n">_1</span><span class="p">,</span> <span class="kt">Bool</span><span class="p">,</span> <span class="n">_2</span><span class="p">]</span> <span class="o">-></span> <span class="kt">String</span>
</code></pre></div></div>
<p>Afterwards, I wrote the <code class="language-plaintext highlighter-rouge">Eq</code>, <code class="language-plaintext highlighter-rouge">Show</code>, and <code class="language-plaintext highlighter-rouge">Ord</code> instances for <code class="language-plaintext highlighter-rouge">HList</code> because GHC can’t derive GADTs instances well. To do this efficiently, I also learned to write the closed type family <code class="language-plaintext highlighter-rouge">All</code> to fold <code class="language-plaintext highlighter-rouge">[TYPE]</code> into a <code class="language-plaintext highlighter-rouge">CONSTRAINT</code>.</p>
<p>May 13th: Finished TiT Ch6-Ch6.3.</p>
<p>Biggest takeaway: Universally quantified type variables are instantiated at the call site while existentially quantified type variables can be instantiated in the function definition. With existentially quantified type variables, we can take in a truly polymorphic functions, and then instantiate it if needed.</p>
<p>May 18th: TiT Ch6.3</p>
<p>6.4 started talking about the Continuation Monad. I’m can’t figure
out the essence despite knowing how to write the instances. I looked for other sources, finally landing on <a href="(https://www.haskellforall.com/2012/12/the-continuation-monad.html)">this</a>. The author suggests that to understand a Monad’s purpose, I must study what its <em>Kleisli arrows</em> do, something I don’t know much about.</p>
<p>So starting tomorrow, I’ll take a detour from TiT and into <a href="https://www.youtube.com/watch?v=i9CU4CuHADQ">Category Theory 3.2: Kleisli category</a> and the lectures before it. Then, I’ll finish the article, and then back to TiT.</p>
<p>May 19th: Category Theory Playlist 1.1-2.1</p>
<p>I dulged in 2 hours of Category Theory lecture today.</p>
<p>Bartosz Milewski is an excellent lecturer. I absorbed more about the epistemology of Category Theory and Physics more than Category Theory itself. I grasped the axioms of a category, understood an example category pertaining to programming, studied the category of sets, and learned about some relationships between sets and categories (isomorphism corresponds to function invertibility).</p>
<p>I wonder if the power of type level programming follows:</p>
<p>If I have a def that does:</p>
<p>def false(): return False</p>
<p>The return type can only be annotated as “Bool”, even though we know it can ever be only False.</p>Andrew Chenandrewchen14250@email.comHeyo!Improve Code Reading with Software?2022-09-04T01:58:45-04:002022-09-04T01:58:45-04:00https://unfooling.com/unfooling.com/improve-code-reading-with-software<p>A quick search of “software to help read code” led me to the download links of different IDEs. Interesting. While there are thousands of books that teaches how to read books, among the millions of software, there doesn’t seem to be many that helps with reading software.</p>
<p>Let’s brainstorm some features for such a tool:</p>
<ul>
<li>Code Focus: Select a few lines of code to focus, this will fade away all variables and functions that have nothing to do with the selected code. If branching occurs in the selection, use our tool to quickly denote the truth values of the logical expressions in order to focus on the right flow.</li>
</ul>
<p>Interlude: Why do we read FOSS? I read FOSS to learn how to write similar software, intricate design choices and architecture, and hidden nuggets. Here is an <a href="https://github.com/JimLiu/recoil-paint/blob/master/src/recoil/defaults.js">example</a> of a hidden nugget: JS code can modify global variables (<code class="language-plaintext highlighter-rouge">gId</code>) of another file. Although I have wrote something similar to this in C, this is still eye-opening in JS, and textbooks/manuals rarely provide examples as specific as you will find in real code.</p>
<ul>
<li>Auto commenting the code patterns detected.</li>
</ul>
<p>Now, onto intricate design choices and architecture. I don’t know how our tool can deduce a software’s “macroarchitecture” (where its components exists on a computer, how do its moving parts communicate with each other, etc). However, our tool can certainly detect code patterns: For example, our tool might tag a class as “Singleton” when it detects a private constructor. <strong>Furthermore, while copilot translates idea -> code, our tool can probably utilize the inverse: code -> idea</strong> , and auto comment the idea.</p>
<p>(Update Sep 4)</p>
<ul>
<li>Tutorial mode.</li>
</ul>
<p>If our software becomes a standard way of browsing code, we can enforce special tutorial annotation comments that software authors write to provide a tutorial mode” for new readers. For example, authors can give functions a certain <code class="language-plaintext highlighter-rouge">@tutorial-item-order-1</code>.</p>
<p>So, the flow looks something like this: Readers realize that the software is compliant with our tool’s tutorial mode -> They begin the tutorial -> A code slideshow begins, moving forward in the slides jumps to the next piece of code the authors annotated.</p>
<ul>
<li>Special annotations for a sea of possibilities</li>
</ul>
<p>If our software becomes a standard way of browsing code, we can enforce special annotation comments that software authors write to provide a better experience for code readers. For example, one annotation could be <code class="language-plaintext highlighter-rouge">@hack</code>. Readers can browse all interesting hacks and gotchas in a slideshow format. Furthermore, <code class="language-plaintext highlighter-rouge">hacks</code> might be tinted in red for emphasis.</p>
<p>Another annotation I thought about is <code class="language-plaintext highlighter-rouge">@tutorial-item-order</code>. The authors can provide this annotation for code to be browsed in a guided, sequential order in a tutorial mode. I have personally commented my repos this way for the ease of new readers to better follow the code flow.</p>
<p>At last, I think such a software should be packaged as a vscode extension.</p>Andrew Chenandrewchen14250@email.comA quick search of “software to help read code” led me to the download links of different IDEs. Interesting. While there are thousands of books that teaches how to read books, among the millions of software, there doesn’t seem to be many that helps with reading software.