<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yufan Lou</title>
    <description>The latest articles on DEV Community by Yufan Lou (@louy2).</description>
    <link>https://dev.to/louy2</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F260905%2F99f58cb9-896b-4d24-9dd7-19e8a24aec4c.png</url>
      <title>DEV Community: Yufan Lou</title>
      <link>https://dev.to/louy2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/louy2"/>
    <language>en</language>
    <item>
      <title>Don't forget your --release flag when benchmarking</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Mon, 04 Jan 2021 06:52:59 +0000</pubDate>
      <link>https://dev.to/louy2/don-t-forget-your-release-flag-when-benchmarking-2k92</link>
      <guid>https://dev.to/louy2/don-t-forget-your-release-flag-when-benchmarking-2k92</guid>
      <description>&lt;p&gt;Saw this &lt;a href="https://github.com/amitkgupta/nearest_neighbour"&gt;very old post&lt;/a&gt; comparing k-NN algorithm implemented in different languages, and for the love of my life I can't believe Rust runs the thing in over 1 minute.&lt;/p&gt;

&lt;p&gt;So I took the code referred to in the post and ran it. Well it ran in over 40 seconds. I puzzled for an hour, even trying to implement the Go style code in Rust.&lt;/p&gt;

&lt;p&gt;Then I realized I forgot the &lt;code&gt;--release&lt;/code&gt; flag. I append it. It runs in not even a second. &lt;/p&gt;

&lt;p&gt;How I got distracted by this when I was on that old blog for Hindley-Milner is another question.&lt;/p&gt;

</description>
      <category>rust</category>
    </item>
    <item>
      <title>Adventure Migrating to Apple Silicon</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Sun, 29 Nov 2020 18:06:45 +0000</pubDate>
      <link>https://dev.to/louy2/adventure-migrating-to-apple-silicon-2eog</link>
      <guid>https://dev.to/louy2/adventure-migrating-to-apple-silicon-2eog</guid>
      <description>&lt;p&gt;Setting up my Apple Silicon Macbook Pro. It is really snappy! and quiet!&lt;/p&gt;

&lt;p&gt;I chose to jump on the new ship because I am very anxious about battery life and could barely disconnect the charger from my old Macbook Pro. With the new Macbook Pro I was compiling stuff and watching video and after three hours the battery shows 82%. That feels so reassuring.&lt;/p&gt;

&lt;p&gt;Other than that, the biggest reason I am migrating away from my old Macbook Pro is its keyboard problems. I actually prefer the clicky feel and light actuation force I get on the Butterfly keyboard, but I have got several keys shadowing (type twice when pressed once) and my tab key is stuck. The Magic keyboard is heavier, very similar to my old Macbook Air.&lt;/p&gt;

&lt;p&gt;I chose not to migrate my application folder, and decided to reconfigure my zsh environment so I moved my zshrc to a backup file.&lt;/p&gt;

&lt;p&gt;I reinstalled IntelliJ IDEA and it runs nicely enough after translation by Rosetta 2. It feels on par with my Intel Macbook for what small projects I have. The menu highlight lags behind the cursor a bit. I will test it further in the coming days.&lt;/p&gt;

&lt;p&gt;My homebrew installation is migrated and the Intel &lt;code&gt;git&lt;/code&gt; from it worked. That confused me a bit at first. How seamless it feels. I still chooses to unlink it.&lt;/p&gt;

&lt;p&gt;On the other hand, my Intel &lt;code&gt;brew&lt;/code&gt; is prohibited by the devs from installing new programs while they figure out Apple Silicon support. So I set out to follow the &lt;a href="https://github.com/Homebrew/brew/issues/7857#issuecomment-726668719"&gt;community guide&lt;/a&gt; and installing a new homebrew at &lt;code&gt;/opt/homebrew&lt;/code&gt; for Apple Silicon.&lt;/p&gt;

&lt;p&gt;Parallel to that, to recover my &lt;a href="https://starship.rs"&gt;Starship command line prompt&lt;/a&gt; I set out to install Rust. My Intel Rust toolchain is also migrated so when I ran the installation script from &lt;a href="https://rustup.rs"&gt;rustup&lt;/a&gt; it updated my Intel toolchain instead. I set up the &lt;code&gt;PATH&lt;/code&gt; according to its instruction, and installed the Apple Silicon toolchain with &lt;code&gt;rustup toolchain install beta-aarch64&lt;/code&gt;. I set it as default with &lt;code&gt;rustup default beta-aarch64&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Trivia: the architecture of Apple Silicon is called ARM64, but the architecture in the Rust triplet is called AArch64. This difference is a historical artifact from Apple and ARM developing their 64-bit ARM architecture in parallel. Linux initially called this backend ARM64, and Apple did so in-house too, but ARM chose to call it AArch64 (and the 32-bit mode AArch32) when ARM released ARMv8-A. In LLVM, the two backends &lt;a href="https://www.phoronix.com/scan.php?page=news_item&amp;amp;px=MTY5ODk"&gt;merged on 24 May 2014&lt;/a&gt; into a new ARM64 backend.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cargo install starship&lt;/code&gt; gave me an error about wrong architecture regarding &lt;code&gt;libgit2&lt;/code&gt;. I realized it was linking with the Intel &lt;code&gt;libgit2&lt;/code&gt; migrated over, originally installed by my Intel homebrew. I unlinked it and tried again. This time the error is about &lt;code&gt;sysinfo&lt;/code&gt;. A pull request has fixed this issue but it is not released yet, so I use &lt;code&gt;cargo install --git https://github.com/starship/starship.git&lt;/code&gt; instead, and it built successfully.&lt;/p&gt;

&lt;p&gt;Now that starship is in command, I go back to the homebrew installation. I now have Intel &lt;code&gt;brew&lt;/code&gt; at &lt;code&gt;/usr/local/bin/brew&lt;/code&gt; and ARM &lt;code&gt;brew&lt;/code&gt; at &lt;code&gt;/opt/homebrew/bin/brew&lt;/code&gt;. I don't want to mess with my executables but I want to install ARM libraries so I can build against them. So I add &lt;code&gt;/opt/homebrew/bin&lt;/code&gt; to &lt;code&gt;PATH&lt;/code&gt; before &lt;code&gt;/usr/local/bin&lt;/code&gt;. I use &lt;code&gt;/usr/local/bin/brew bundle dump&lt;/code&gt; to dump the list of all installed packages to a &lt;code&gt;Brewfile&lt;/code&gt;. I went into it and added &lt;code&gt;#&lt;/code&gt; to every line to comment them out, and only removed it for lines with &lt;code&gt;lib&lt;/code&gt; in it. Then I &lt;code&gt;/opt/homebrew/bin/brew bundle&lt;/code&gt; to install from the file, and plugged the Macbook in and went to sleep.&lt;/p&gt;

&lt;p&gt;With the relatively small number of libraries I have, I met three libraries failing to install: &lt;code&gt;libbluray&lt;/code&gt;, &lt;code&gt;libsoxr&lt;/code&gt;, and &lt;code&gt;libgcrypt&lt;/code&gt;. &lt;code&gt;libbluray&lt;/code&gt; is blocked on &lt;code&gt;openjdk&lt;/code&gt; failing. &lt;code&gt;libsoxr&lt;/code&gt; and &lt;code&gt;libgcrypt&lt;/code&gt; are listed as working on the &lt;a href="https://github.com/Homebrew/brew/issues/7857"&gt;community guide&lt;/a&gt;, but I see the following error for &lt;code&gt;libsoxr&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Undefined symbols for architecture arm64:
  "_av_get_cpu_flags", referenced from:
      _soxr_create in soxr.c.o
ld: symbol(s) not found for architecture arm64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the following error for &lt;code&gt;libgcrypt&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PASS: bench-slope
SKIP: hashtest-256g
======================================
1 of 27 tests failed
(1 test was not run)
Please report to http://bugs.gnupg.org
======================================
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I later found &lt;a href="https://soffes.blog/homebrew-on-apple-silicon"&gt;Sam's great post&lt;/a&gt; to realized that I need &lt;code&gt;arch -x86_64&lt;/code&gt; prefix to install things with Intel homebrew. I will try this when chance presents.&lt;/p&gt;

</description>
      <category>devjournal</category>
    </item>
    <item>
      <title>How To Exit Press-To-Test on TI Nspire CX (CAS)</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Wed, 14 Oct 2020 11:08:37 +0000</pubDate>
      <link>https://dev.to/louy2/how-to-exit-press-to-test-on-ti-nspire-cx-cas-5d61</link>
      <guid>https://dev.to/louy2/how-to-exit-press-to-test-on-ti-nspire-cx-cas-5d61</guid>
      <description>&lt;p&gt;This how-to is a description of the solution in this &lt;a href="https://www.youtube.com/watch?v=Eoi3PJlLICg"&gt;video&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I don't remember clearly but I think I got this TI-Nspire CX CAS calculator as a gift from my library tutoring job. While I was tinkering with it I got it into the Press-To-Test mode. I thought the "test" means some system self-evaluation stuff, but turns out it means an exam at school or something like SAT. The mode heavily restricts the available features on the calculator as required by testing institutions.&lt;/p&gt;

&lt;p&gt;To get out of it we need to use &lt;a href="https://education.ti.com/en/products/computer-software/ti-nspire-computer-link"&gt;TI-Nspire Computer Link&lt;/a&gt;. TI provides installers for Windows and macOS.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty Note on the calculator, save it as "Exit Test Mode".&lt;/li&gt;
&lt;li&gt;Install TI-Nspire Computer Link on the computer and open it.&lt;/li&gt;
&lt;li&gt;Connect the mini-USB socket on the calculator to a USB socket on the computer.&lt;/li&gt;
&lt;li&gt;Refresh the device list and choose the calculator.&lt;/li&gt;
&lt;li&gt;Drag and drop the "Exit Test Mode" Note file to anywhere on the computer.&lt;/li&gt;
&lt;li&gt;Drag and drop the "Exit Test Mode" Note file from the computer to the "Press-To-Test" folder.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If successful, we should see the "Press-To-Test" folder disappear, and Press-To-Test mode gone.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Usefulness of GPT-3 Deserves The Virality</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Wed, 12 Aug 2020 16:24:39 +0000</pubDate>
      <link>https://dev.to/louy2/the-usefulness-of-gpt-3-deserves-the-virality-261n</link>
      <guid>https://dev.to/louy2/the-usefulness-of-gpt-3-deserves-the-virality-261n</guid>
      <description>&lt;p&gt;This is a comment on Agustin Lebron's &lt;a href="https://marginalrevolution.com/marginalrevolution/2020/07/the-case-against-the-import-of-gpt-3.html"&gt;The case against the import of GPT-3&lt;/a&gt;, as quoted by Tyler Cowen. I know nothing about the two, apart from stumbling upon it when I was looking for Max Woolf's &lt;a href="https://minimaxir.com/2020/07/gpt3-expectations/"&gt;Tempering Expectations for GPT-3 and OpenAI’s API&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Max Woolf's evaluation is very precise and valid, and with which I have to agree. The hype of GPT-3 on Twitter is obviously subject to selection bias. I'd even add survivorship bias on top, which virality always brings. And there are many details, from ethical to legal to economic, to iron out before a commercially successful product using GPT-3 can appear on the market. After all, technology is only one part of any business.&lt;/p&gt;

&lt;p&gt;What I take issue with is Lebron taking Woolf's evaluation one step further, and writes that "we're not replacing front-end devs with attention-layer-stacks anytime soon." I take issue with the thinking that the effect of GPT-3 starts and ends with "replacing front-end devs".&lt;/p&gt;

&lt;p&gt;I take issue with such thinking because of also survivorship bias, but in a different context: the most visible "replacing" happens to the existing surviving workers, while the loss of future workers are much less so. &lt;/p&gt;

&lt;p&gt;To wit, the US has lost 15% of librarian jobs nationwide from 2009-10 to 2015-16, due to a demand for "digital learning specialists" instead. At the center of digital learning is the largest machine learning service deployed: Google. &lt;/p&gt;

&lt;p&gt;There are ample research showing that Google cannot replace librarians entirely. That librarians perform many duties Google cannot. But nonetheless, Google is still replacing librarians in many senses of that word. We no longer need to ask a librarian which is the highest mountain peak of the world. We no longer need to ask a librarian for some nice recipes. &lt;/p&gt;

&lt;p&gt;Librarians use Google, too. Librarians helped develop Google Scholar. However with Google Scholar, we need, or at least the school administrators think that we need, fewer librarians.&lt;/p&gt;

&lt;p&gt;Seeing that GPT-3 is an even smarter model than the one behind Google, and that even Google has displaced librarians, it is inevitable that products based on GPT-3 will similarly displace workers somewhere, to some extent. "Replacing" a whole profession to extinction is indeed rare, as many traditional crafts are still preserved as cultural heritage without economic benefits. Replacing workers, though, is much easier. &lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;a href="http://teacherlibrarian.com/2018/04/11/changing-times-school-librarian-staffing-status/"&gt;Changing Times: School Librarian Staffing Status | Teacher Librarian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://journals.aom.org/doi/abs/10.5465/amj.2012.0201"&gt;“Defining What We Do—All Over Again”: Occupational Identity, Technological Change, and the Librarian/Internet-Search Relationship | Academy of Management Journal&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>machinelearning</category>
      <category>gpt3</category>
      <category>naturallanguageprocessing</category>
    </item>
    <item>
      <title>A Merit of Learning a New Language</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Tue, 28 Jul 2020 06:25:58 +0000</pubDate>
      <link>https://dev.to/louy2/a-merit-of-learning-a-new-language-14n1</link>
      <guid>https://dev.to/louy2/a-merit-of-learning-a-new-language-14n1</guid>
      <description>&lt;p&gt;There are times when I find it hard to express my thinking in a certain way in the new language because I am not familiar enough with it, and I need to find an alternative way. That requires alternative thinking. Sometimes the alternative thinking can be quite a departure from the original, even changing my perspective, sometimes semantically, sometimes genuinely.&lt;/p&gt;

&lt;p&gt;I just really couldn't find a good way to express "that's not what I meant" in Japanese. I resorted to "excuse me for making you misunderstand" instead.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Implementation vs Specification</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Sat, 18 Jul 2020 22:22:42 +0000</pubDate>
      <link>https://dev.to/louy2/implementation-vs-specification-45ck</link>
      <guid>https://dev.to/louy2/implementation-vs-specification-45ck</guid>
      <description>&lt;p&gt;Specification is like a macroeconomics model. It describes the general purpose and trend of the system.&lt;/p&gt;

&lt;p&gt;Implementation is like a microeconomics model. It describes the operation and machinery of the system. &lt;/p&gt;

</description>
      <category>computerscience</category>
    </item>
    <item>
      <title>Three Vim Features</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Sat, 18 Jul 2020 09:56:43 +0000</pubDate>
      <link>https://dev.to/louy2/three-vim-features-185b</link>
      <guid>https://dev.to/louy2/three-vim-features-185b</guid>
      <description>&lt;p&gt;To split a line at pattern:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; :5s/pattern/&amp;lt;c-v&amp;gt;&amp;lt;cr&amp;gt;/g
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;c-v&amp;gt;&lt;/code&gt;, or Ctrl-v, in terminal waits for the next character, and inserts it as a literal (verbatim). So upon pressing &lt;code&gt;&amp;lt;cr&amp;gt;&lt;/code&gt; (carriage return a.k.a enter key), instead of executing the command, the literal carriage return character (would be shown as &lt;code&gt;^M&lt;/code&gt;) is inserted at the cursor, which is then replaced into the file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;^M&lt;/code&gt; is the &lt;a href="https://en.wikipedia.org/wiki/Caret_notation"&gt;caret notation&lt;/a&gt; of carriage return. Other control characters can be similarly inserted with their corresponding key in the caret notation. For example, cancel is &lt;code&gt;^Z&lt;/code&gt;, so to insert it type&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;c-v&amp;gt;&amp;lt;c-z&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To copy the whole file into clipboard:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:%y+&amp;lt;cr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To insert the content of a register, for example, clipboard:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;c-r&amp;gt;+
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>vim</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Sort in Linear Time, But Is It Worthy?</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Tue, 14 Jul 2020 11:22:46 +0000</pubDate>
      <link>https://dev.to/louy2/sort-in-linear-time-but-is-it-worthy-46np</link>
      <guid>https://dev.to/louy2/sort-in-linear-time-but-is-it-worthy-46np</guid>
      <description>&lt;p&gt;I know the fastest sorting algorithm is quicksort. It is even named accordingly. I also know that its time complexity is on average O(nlog(n)). Is there ever a sorting algorithm in linear time?&lt;/p&gt;

&lt;p&gt;Yes, it turns out. It is called radix sort, and it actually predates modern computer. &lt;/p&gt;

&lt;p&gt;What is radix sort? Radix sort is to sort numbers digit by digit. Or sort words letter by letter. It is so named because it uses a buffer of which the size becomes the radix of the sorted numbers. The radix is the number of possible digits in one position. Using a buffer of size 10, you can sort 0 to 9 in one iteration; using a buffer of 256 you can sort 0 to 255 in one iteration. The size is chosen according to memory limits, and in exchange sorting each additional digit takes another iteration.&lt;/p&gt;

&lt;p&gt;Radix sort was THE algorithm used by &lt;a href="https://en.wikipedia.org/wiki/IBM_card_sorter"&gt;IBM card sorters&lt;/a&gt;, which inherited the algorithm from &lt;a href="https://en.wikipedia.org/wiki/Tabulating_machine"&gt;tabulating machines&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;How is radix sort linear? The number of iterations you go through the list to be sorted does not depend on the number of items, but the maximum number of digits or letters of the items, which is often a lot fewer than the number of items. If you know the maximum in advance, like if you know you are sorting 32-bit integers with a radix 2, then your time complexity is at most O(32n), which is indeed linear.&lt;/p&gt;

&lt;p&gt;Linear time is categorized as being faster than n-logarithmic time. But in real world usages, the logarithmic term in n-logarithmic time is often smaller than the constant term in linear time. For the logarithmic term to reach 32, the number of items you are sorting needs to reach 2^32, which is 4 billion. &lt;/p&gt;

&lt;p&gt;With a larger radix, like 256, the constant term of radix sorting for 32-bit integers becomes 4 (=32/log(256)), and to reach that with a logarithmic term the number of items necessary becomes 16. But even above 16 items, when is the improvement in sorting speed worth the additional 1 MB of memory (256 32-bit integers)?&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;All logarithmic above are base 2. &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>Apple Silicon Is Also A Chance To Improve Security</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Thu, 09 Jul 2020 21:18:17 +0000</pubDate>
      <link>https://dev.to/louy2/apple-silicon-is-also-a-chance-to-improve-security-2n0p</link>
      <guid>https://dev.to/louy2/apple-silicon-is-also-a-chance-to-improve-security-2n0p</guid>
      <description>&lt;p&gt;&lt;a href="https://www.microsoft.com/en-us/research/blog/toward-trusted-sensing-for-the-cloud-introducing-project-freta/"&gt;Toward trusted sensing for the cloud: Introducing Project Freta - Microsoft Research&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The fact that sensor evasion is possible at all is surprising to many outsiders to the field of computer security. Anyone who’s visited a retail store understands that it’s a good idea to put the security cameras out of reach—why haven’t we done something similar in the cloud? The answer is a familiar one: backwards compatibility. Our first networked computers didn’t have the silicon real estate to devote to an isolated security sensor. Opportunities for technology companies to break backwards compatibility and “greenfield” redesign with security in mind have appeared only periodically, seen primarily in the mobile and console industries. These redesigns have allowed for increasing hardware separation between the compute plane and the security plane&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Apple changing Macs to Apple silicon presents a similar opportunity to break backwards compatibility and redesign the security architecture. They kind of tried it with the T2 co-processor, but the complete transition may lead to a something more. How the isolation (lock-down) in macOS has been progressing up to Catalina might have also been in preparation for this, and Big Sur might be closer to iOS in more ways than the UI. I look forward to all the analyses that might come out from Objective-See.&lt;/p&gt;

&lt;p&gt;I suppose some people get annoyed at the degree of lock-down Apple has been introducing. Personally, I've locked down my Linux instances even more. I just don't have the expertise and time to figure out how to lock it down without impairing the user experience too much, and I am glad Apple has been at it all this time. &lt;/p&gt;

</description>
      <category>security</category>
      <category>microsoft</category>
      <category>apple</category>
    </item>
    <item>
      <title>Today I Learned Program and Coprogram</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Thu, 09 Jul 2020 09:13:04 +0000</pubDate>
      <link>https://dev.to/louy2/today-i-learned-program-and-coprogram-210d</link>
      <guid>https://dev.to/louy2/today-i-learned-program-and-coprogram-210d</guid>
      <description>&lt;p&gt;&lt;a href="https://patternsinfp.wordpress.com/2018/11/21/how-to-design-co-programs/"&gt;How to design co-programs | Patterns in Functional Programming&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the tail of the last random thought I realized data transformations are reinterpretations of constructors. That turns out to be a very established pattern in program design. Implicit in my thought was that constructors means constructors of the input. Like any established pattern, it has a dual. Enter coprogram, which are reinterpretations of constructors of the output.&lt;/p&gt;

&lt;p&gt;The motivating example of &lt;code&gt;zip&lt;/code&gt; is quite impressive. &lt;code&gt;zip&lt;/code&gt; takes two lists and transform them into one list of pairs, pairing corresponding elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The conventional way of defining &lt;code&gt;zip&lt;/code&gt; is case analysis on the input, as shown in the Haskell Prelude.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt;     &lt;span class="n"&gt;_bs&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt;
&lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="n"&gt;_as&lt;/span&gt;    &lt;span class="kt"&gt;[]&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt;
&lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;bs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="n"&gt;as&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What if we case analyze the output instead? Instead of asking "what is the output when input is empty", what if we ask "what is the input when output is empty"?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="n"&gt;as&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
    &lt;span class="kr"&gt;if&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt; &lt;span class="n"&gt;as&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt; &lt;span class="kr"&gt;then&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt;
    &lt;span class="kr"&gt;else&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;zip&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This concept adds a very welcome stepping stone between structural recursion and divide-and-conquer.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>theory</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Today I Learned (Not) Reflection</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Thu, 09 Jul 2020 06:32:11 +0000</pubDate>
      <link>https://dev.to/louy2/today-i-learned-not-reflection-2g4g</link>
      <guid>https://dev.to/louy2/today-i-learned-not-reflection-2g4g</guid>
      <description>&lt;p&gt;&lt;a href="https://queuea9.wordpress.com/2020/04/01/an-intuition-for-reflection/" rel="noopener noreferrer"&gt;An intuition for reflection | QA9&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This reflection is not the one for metaprogramming, but the property that if you fold a piece of data with its constructors, you get back the piece of data itself. In terms of list in Haskell, with constructors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="kt"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and a folding function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;foldr&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The property of reflection is then defined as this equation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;foldr&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another "Today I Learned" quote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is known (although I am not sure where you can find this in a paper) that if you have parametricity and reflection, you can derive induction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7xkaln7idtsupylkcthg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7xkaln7idtsupylkcthg.gif" alt="A man feeling mindblown"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Especially revelatory quotes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With induction, we are trying to summarize an infinite number of cases in some finite way. This finite way is with the constructors for the datatype.&lt;/p&gt;

&lt;p&gt;not taking constructors and datatypes for granted, we might ask: but how do you know you correctly summarized that infinite set of values using your functions you call constructors&lt;/p&gt;

&lt;p&gt;My intuition about reflection is that it contributes an essential property towards knowing you have the correct summary of your infinite set of data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A philosophical quote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All it does is go through the list and interpret cons as cons, nil as nil.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Data transformation is all about reinterpreting the constructors of data.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>math</category>
    </item>
    <item>
      <title>(Ok) Tagless Final in Rust</title>
      <dc:creator>Yufan Lou</dc:creator>
      <pubDate>Fri, 03 Jul 2020 08:50:51 +0000</pubDate>
      <link>https://dev.to/louy2/ok-tagless-final-in-rust-1aff</link>
      <guid>https://dev.to/louy2/ok-tagless-final-in-rust-1aff</guid>
      <description>&lt;p&gt;Rust nightly has Higher-Kinded Type! 🔥&lt;/p&gt;

&lt;p&gt;OMG I still don't know what use this has but damn it felt magical.&lt;/p&gt;

&lt;p&gt;Props to whoever in the compiler team working on this.&lt;/p&gt;

&lt;p&gt;You actually have to mark the output type correctly as &lt;code&gt;L::Repr&amp;lt;bool&amp;gt;&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;If you pass a &lt;code&gt;L::int(1)&lt;/code&gt; to &lt;code&gt;L::add&lt;/code&gt; it's a compile time error and the compiler tells you that &lt;code&gt;i64&lt;/code&gt; doesn't match &lt;code&gt;bool&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Gosh. Awesome. Amazing.&lt;/p&gt;

&lt;p&gt;Now let's hope this won't tank the compilation time too much. 😛&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![allow(dead_code)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_snake_case)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(incomplete_features)]&lt;/span&gt;

&lt;span class="nd"&gt;#![feature(generic_associated_types)]&lt;/span&gt;

&lt;span class="cm"&gt;/*
let b (bv:bool) env = bv
let int (iv:int) env = iv
let and b1 b2 env = b1 &amp;amp; b2
*/&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;O&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Box&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;dyn&lt;/span&gt; &lt;span class="nf"&gt;FnOnce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;O&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;trait&lt;/span&gt; &lt;span class="n"&gt;Lang&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;core&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;marker&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PhantomData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PhantomData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;'static&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Copy&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Lang&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;move&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="mi"&gt;_&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;bv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;move&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="mi"&gt;_&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;move&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nf"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;Lang&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;P&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bv&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} &amp;amp; {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;prog1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;L&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Repr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; 
    &lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Lang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nn"&gt;L&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;L&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nn"&gt;L&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// fn prog_with_error&amp;lt;L&amp;gt;() -&amp;gt; L::Repr&amp;lt;bool&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;// where&lt;/span&gt;
&lt;span class="c"&gt;//     L: Lang,&lt;/span&gt;
&lt;span class="c"&gt;// {&lt;/span&gt;
&lt;span class="c"&gt;//     L::and(L::int(3), L::b(true))&lt;/span&gt;
&lt;span class="c"&gt;// }&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;test1_p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;prog1&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;P&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test1_p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;test1_b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;prog1&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()(());&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test1_b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// TODO: De Brujin Indices&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>rust</category>
      <category>functional</category>
      <category>edsl</category>
    </item>
  </channel>
</rss>
