summaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
Diffstat (limited to '2024')
-rw-r--r--2024/01/08/OCaml-News-2024-1/index.html19
-rw-r--r--2024/01/18/OCaml-News-2024-2/index.html40
-rw-r--r--2024/01/22/Rescript-React-Native/index.html5
-rw-r--r--2024/01/23/G-Machine/index.html4
-rw-r--r--2024/01/23/二〇二四年一月二十三日/index.html5
-rw-r--r--2024/01/23/慢性肺源性心脏病/index.html50
-rw-r--r--2024/01/25/急诊与灾难医学-烧伤/index.html42
-rw-r--r--2024/02/07/二〇二四年二月七日/index.html12
-rw-r--r--2024/02/26/OCaml-News-2024-3/index.html135
-rw-r--r--2024/03/22/二〇二四年三月二十二日/index.html12
-rw-r--r--2024/04/08/二〇二四年四月八日/index.html6
-rw-r--r--2024/05/07/二〇二四年五月七日/index.html18
-rw-r--r--2024/05/16/二〇二四年五月十六日/index.html5
-rw-r--r--2024/05/20/Rescript-genType-import-问题/index.html15
-rw-r--r--2024/06/06/NET-AOT-下的-F-命令行参数解析库选择/index.html9
-rw-r--r--2024/06/27/OCaml-News-2024-5/index.html94
-rw-r--r--2024/06/27/二〇二四年六月二十七日/index.html6
-rw-r--r--2024/07/01/OCaml-News-2024-4/index.html162
-rw-r--r--2024/07/09/神经系统重点/index.html156
-rw-r--r--2024/07/23/OCaml-News-2024-6/index.html130
-rw-r--r--2024/08/02/二〇二四年八月一日/index.html5
-rw-r--r--2024/09/12/Functional-Reactive-Programming-in-F/index.html37
-rw-r--r--2024/09/15/Advanced-C-binding-using-ocaml-ctypes-and-dune/index.html56
-rw-r--r--2024/09/15/肩周炎和肩袖损伤的区别/index.html15
-rw-r--r--2024/09/27/Turborepo-简述/index.html129
-rw-r--r--2024/10/06/Obsidian-Vault-的-obsidian-目录中的各文件作用/index.html27
-rw-r--r--2024/10/18/10-Tips-for-Productive-FSharp-Scripting/index.html56
-rw-r--r--2024/10/18/Building-custom-fibers-library-in-FSharp/index.html95
-rw-r--r--2024/10/18/Dealing-with-complex-dependency-injection-in-FSharp/index.html51
-rw-r--r--2024/11/15/西柚对药物的影响/index.html3
-rw-r--r--2024/11/26/如何管理用户界面中的危险操作/index.html30
-rw-r--r--2024/12/15/OCaml-News-2024-7/index.html213
-rw-r--r--2024/12/18/二〇二四年十二月十八日/index.html11
33 files changed, 975 insertions, 678 deletions
diff --git a/2024/01/08/OCaml-News-2024-1/index.html b/2024/01/08/OCaml-News-2024-1/index.html
index 7dda21b9..6f9d1b9a 100644
--- a/2024/01/08/OCaml-News-2024-1/index.html
+++ b/2024/01/08/OCaml-News-2024-1/index.html
@@ -192,7 +192,8 @@
</div>
</div>
<div class="post-content">
- <h2 id="News"><a href="#News" class="headerlink" title="News"></a>News</h2><ul>
+ <h2 id="News"><a class="header-anchor" href="#News">¶</a>News</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://tarides.com/blog/2023-12-20-ocaml-survey-developers-perception-interest-and-perceived-barriers/">OCaml Survey: Developers’ Perception, Interest, and Perceived Barriers</a></li>
<li><a target="_blank" rel="noopener" href="https://tarides.com/blog/2023-12-29-announcing-the-orchide-project-powering-satellite-innovation/">Announcing the ORCHIDE Project: Powering Satellite Innovation</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/pull/12885">Dynarrays, unboxed (with local dummies) #12885</a></li>
@@ -203,13 +204,15 @@
<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/pull/1802">Make the character set for OCaml source code officially UTF-8. #1802</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/pull/12719">Add thread local storage #12719</a></li>
</ul>
-<h2 id="Videos"><a href="#Videos" class="headerlink" title="Videos"></a>Videos</h2><ul>
+<h2 id="Videos"><a class="header-anchor" href="#Videos">¶</a>Videos</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=zG7JejHlQoM">“Melange: The next frontier in type-safe web development” by Dillon Mulroy - RVAJS 2023</a></li>
<li><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=R-XJzUrP7bQ">Trying out OCaml TUI framework Mint Tea!</a></li>
<li><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=XyDbG9FGR1o">A TUI chat in OCaml 🐫</a></li>
<li>[Building a Game Engine… with OCaml ?! [Part 1]](<a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=1XpUaTnssQE">https://www.youtube.com/watch?v=1XpUaTnssQE</a></li>
</ul>
-<h2 id="Blogs"><a href="#Blogs" class="headerlink" title="Blogs"></a>Blogs</h2><ul>
+<h2 id="Blogs"><a class="header-anchor" href="#Blogs">¶</a>Blogs</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://sancho.dev/blog/whats-possible-with-melange">What’s possible with Melange</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/access-inferred-types/13805">Access inferred types</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/using-menhir-to-parse-into-idiomatic-js-typescript-structures/13809">Using Menhir to parse into idiomatic JS (TypeScript) structures</a></li>
@@ -219,7 +222,8 @@
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-to-express-koka-home-page-example/13748">How to express Koka home page example?</a></li>
<li><a target="_blank" rel="noopener" href="https://practicalocaml.com/parsing-with-binary-string-pattern-matching/">Parsing with Binary String Pattern Matching</a></li>
</ul>
-<h2 id="Highlighted-Projects"><a href="#Highlighted-Projects" class="headerlink" title="Highlighted Projects"></a>Highlighted Projects</h2><ul>
+<h2 id="Highlighted-Projects"><a class="header-anchor" href="#Highlighted-Projects">¶</a>Highlighted Projects</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://github.com/backtracking/grid">grid: A tiny library for two-dimensional arrays</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/leostera/minttea">A fun little TUI framework for OCaml</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/terrateamio/ocaml-ts-mode">ocaml-ts-mode: Ocaml mode for emacs using treesitter</a></li>
@@ -232,11 +236,12 @@
<li><a target="_blank" rel="noopener" href="https://github.com/leostera/colors">colors: A pure OCaml library for manipulating colors in different color spaces.</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/nationalarchives/miiify">miilfy: A web annotation server built with the same principles as Git</a></li>
</ul>
-<h2 id="New-Releases"><a href="#New-Releases" class="headerlink" title="New Releases"></a>New Releases</h2><ul>
+<h2 id="New-Releases"><a class="header-anchor" href="#New-Releases">¶</a>New Releases</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://github.com/leostera/riot">Roit v0.0.7: An actor-model multi-core scheduler for OCaml 5 🐫</a></li>
-<li><a target="_blank" rel="noopener" href="https://github.com/leostera/castore">CAStore: A portable pure OCaml CA Store, with no dependencies, inspired by Elixir’s <a target="_blank" rel="noopener" href="https://github.com/elixir-mint/castore">:castore</a>.</a></li>
+<li>[CAStore: A portable pure OCaml CA Store, with no dependencies, inspired by Elixir’s <a target="_blank" rel="noopener" href="https://github.com/elixir-mint/castore">:castore</a>.](<a target="_blank" rel="noopener" href="https://github.com/leostera/castore">https://github.com/leostera/castore</a>)</li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/learn-ocaml-1-0-approaching-call-for-testers/13621">Lean-OCaml 1.0: A Web Application for Learning OCaml</a></li>
-<li><a target="_blank" rel="noopener" href="https://erratique.ch/software/cmarkit">cmarkit 0.3.0” CommonMark parser and renderer for OCaml</a></li>
+<li><a target="_blank" rel="noopener" href="https://erratique.ch/software/cmarkit">cmarkit 0.3.0&quot; CommonMark parser and renderer for OCaml</a></li>
<li><a target="_blank" rel="noopener" href="https://ocaml.org/p/dream-html/latest">dream-html 2.0.0: A library for generating HTML</a></li>
<li><a target="_blank" rel="noopener" href="https://git.frama-c.com/pub/caisar/">Caisar: A platform under active development at CEA LIST, aiming to provide a wide range of features to characterize the safety and robustness of artificial intelligence based software.</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/jserot/rfsm">RFSM 2.0: A toolset for describing and simulating StateChart-like state diagrams.</a></li>
diff --git a/2024/01/18/OCaml-News-2024-2/index.html b/2024/01/18/OCaml-News-2024-2/index.html
index c93ecc1d..aeabc58f 100644
--- a/2024/01/18/OCaml-News-2024-2/index.html
+++ b/2024/01/18/OCaml-News-2024-2/index.html
@@ -192,16 +192,18 @@
</div>
</div>
<div class="post-content">
- <h2 id="News"><a href="#News" class="headerlink" title="News"></a>News</h2><ul>
+ <h2 id="News"><a class="header-anchor" href="#News">¶</a>News</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-preview-play-with-project-wide-occurrences-for-ocaml/13814">[ANN][PREVIEW] Play with project-wide occurrences for OCaml!</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/dune/pull/8784">[Dune]: Add link flags ocamlmklib when using ctypes stubs. #8784</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-software-foundation-january-2024-update/13828">OCaml Software Foundation: January 2024 update</a></li>
<li>[Apprendre à programmer avec OCaml](Apprendre à programmer avec OCaml)</li>
-<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/call-for-speakers-for-the-2024-carolina-code-conference-is-open-until-april-15th/13827"><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/call-for-speakers-for-the-2024-carolina-code-conference-is-open-until-april-15th/13827">Call for Speakers for the 2024 Carolina Code Conference is open until April 15th</a></a></li>
+<li>[<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/call-for-speakers-for-the-2024-carolina-code-conference-is-open-until-april-15th/13827">Call for Speakers for the 2024 Carolina Code Conference is open until April 15th</a>](<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/call-for-speakers-for-the-2024-carolina-code-conference-is-open-until-april-15th/13827">https://discuss.ocaml.org/t/call-for-speakers-for-the-2024-carolina-code-conference-is-open-until-april-15th/13827</a>)</li>
<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/discussions/11924">[OCaml]: feature request: better errors #11924</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocsigen-summary-of-recent-releases/13817">Ocsigen: summary of recent releases</a></li>
</ul>
-<h2 id="Discussion"><a href="#Discussion" class="headerlink" title="Discussion"></a>Discussion</h2><ul>
+<h2 id="Discussion"><a class="header-anchor" href="#Discussion">¶</a>Discussion</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/benchmark-between-open-addressing-and-closed-addressing-hashtbl/13882">Benchmark between open-addressing and closed-addressing hashtbl</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/examples-of-caqti-infix/13878">Examples of Caqti infix?</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/why-can-t-i-create-a-project-with-non-ascii-characters/13865">Why can’t I create a project with non-ASCII characters? </a></li>
@@ -211,20 +213,23 @@
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/partially-apply-function-accepting-multiple-modules-and-keep-polymorphic-types/13823">Partially apply function accepting multiple modules and keep polymorphic types</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/printing-unicode-characters-on-different-platforms/13813">Printing Unicode Characters on Different Platforms</a></li>
</ul>
-<h2 id="Videos"><a href="#Videos" class="headerlink" title="Videos"></a>Videos</h2><ul>
+<h2 id="Videos"><a class="header-anchor" href="#Videos">¶</a>Videos</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/iQNqZzA8gVmd4RQaycAwx4">Verifying an Effect-Based Cooperative Concurrency Scheduler in Iris by Adrian Dapprich</a></li>
</ul>
-<h2 id="Blogs"><a href="#Blogs" class="headerlink" title="Blogs"></a>Blogs</h2><ul>
+<h2 id="Blogs"><a class="header-anchor" href="#Blogs">¶</a>Blogs</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/advice-for-combining-multiple-monads/10409">Advice for combining multiple monads</a></li>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/writing-ctypes-bindings-to-system-shared-libraries-for-bytecode-targets-via-the-dune-ctypes-stanza/13844">Writing ctypes bindings to system shared libraries for bytecode targets via the dune ctypes stanza</a></li>
</ul>
-<h2 id="Highlighted-Projects"><a href="#Highlighted-Projects" class="headerlink" title="Highlighted Projects"></a>Highlighted Projects</h2><ul>
+<h2 id="Highlighted-Projects"><a class="header-anchor" href="#Highlighted-Projects">¶</a>Highlighted Projects</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://github.com/johnyob/grace">Grace: A fancy diagnostics library that allows your compilers to exit with grace</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/thierry-martinez/metapp">meta-pp: Meta-preprocessor for OCaml</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/stedolan/ppx_stage">ppx_stage: Staged metaprogramming in stock OCaml</a></li>
-<li><a target="_blank" rel="noopener" href="https://erratique.ch/software/cmarkit">Cmarkit is an <a target="_blank" rel="noopener" href="http://ocaml.org/">OCaml</a> libary for parsing the <a target="_blank" rel="noopener" href="https://spec.commonmark.org/">CommonMark</a> specification.</a></li>
-<li><a target="_blank" rel="noopener" href="https://erratique.ch/software/brr">Brr is a toolkit for programming browsers in <a target="_blank" rel="noopener" href="http://ocaml.org/">OCaml</a> with the <a target="_blank" rel="noopener" href="http://ocsigen.org/js_of_ocaml/">js_of_ocaml</a> compiler. It provides:</a></li>
-<li><a target="_blank" rel="noopener" href="https://erratique.ch/software/zipc">Zipc is an in-memory <a target="_blank" rel="noopener" href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT">ZIP</a> archive and <a target="_blank" rel="noopener" href="https://www.rfc-editor.org/rfc/rfc1951">deflate</a> compression codec for <a target="_blank" rel="noopener" href="http://ocaml.org/">OCaml</a>.</a></li>
+<li>[Cmarkit is an <a target="_blank" rel="noopener" href="http://ocaml.org">OCaml</a> libary for parsing the <a target="_blank" rel="noopener" href="https://spec.commonmark.org/">CommonMark</a> specification.](<a target="_blank" rel="noopener" href="https://erratique.ch/software/cmarkit">https://erratique.ch/software/cmarkit</a>)</li>
+<li>[Brr is a toolkit for programming browsers in <a target="_blank" rel="noopener" href="http://ocaml.org">OCaml</a> with the <a target="_blank" rel="noopener" href="http://ocsigen.org/js_of_ocaml/">js_of_ocaml</a> compiler. It provides:](<a target="_blank" rel="noopener" href="https://erratique.ch/software/brr">https://erratique.ch/software/brr</a>)</li>
+<li>[Zipc is an in-memory <a target="_blank" rel="noopener" href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT">ZIP</a> archive and <a target="_blank" rel="noopener" href="https://www.rfc-editor.org/rfc/rfc1951">deflate</a> compression codec for <a target="_blank" rel="noopener" href="http://ocaml.org">OCaml</a>.](<a target="_blank" rel="noopener" href="https://erratique.ch/software/zipc">https://erratique.ch/software/zipc</a>)</li>
<li><a target="_blank" rel="noopener" href="https://github.com/lukstafi/ocaml-gccjit">ocaml-gccjit: OCaml bindings for libgccjit</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/whitequark/ocaml-m17n">ocaml-m17n: Multilingualization for the OCaml source code</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/hackwaly/ocamlearlybird">ocamlearlybird: OCaml debug adapter</a></li>
@@ -232,21 +237,26 @@
<li><a target="_blank" rel="noopener" href="https://github.com/mattjbray/ocaml-decoders">ocaml-decoders: Elm-inspired decoders for Ocaml</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/OCamlPro/ez_toml">ez_toml: A library to parse and print TOML files</a></li>
</ul>
-<h2 id="New-Releases"><a href="#New-Releases" class="headerlink" title="New Releases"></a>New Releases</h2><ul>
-<li><a target="_blank" rel="noopener" href="http://cambium.inria.fr/~fpottier/oma/doc/oma/Oma/index.html">Oma: OCaml implementation of ‘Two Simplified Algorithms for Maintaining Order in a List’</a><ul>
+<h2 id="New-Releases"><a class="header-anchor" href="#New-Releases">¶</a>New Releases</h2>
+<ul>
+<li><a target="_blank" rel="noopener" href="http://cambium.inria.fr/~fpottier/oma/doc/oma/Oma/index.html">Oma: OCaml implementation of ‘Two Simplified Algorithms for Maintaining Order in a List’</a>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-first-release-of-oma/13845">[ANN] First release of oma</a></li>
<li><a target="_blank" rel="noopener" href="https://erikdemaine.org/papers/DietzSleator_ESA2002/paper.pdf">Two Simplified Algorithms for Maintaining Order in a List</a></li>
</ul>
</li>
-<li><a target="_blank" rel="noopener" href="https://github.com/hackwaly/ocamlearlybird">ocamlearlybird: v1.3.0</a><ul>
-<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-ocamlearlybird-just-got-ability-to-inspect-opaque-abstract-values/13852">[ANN] Ocamlearlybird just got ability to inspect opaque&#x2F;abstract values</a></li>
+<li><a target="_blank" rel="noopener" href="https://github.com/hackwaly/ocamlearlybird">ocamlearlybird: v1.3.0</a>
+<ul>
+<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-ocamlearlybird-just-got-ability-to-inspect-opaque-abstract-values/13852">[ANN] Ocamlearlybird just got ability to inspect opaque/abstract values</a></li>
</ul>
</li>
-<li><a target="_blank" rel="noopener" href="https://github.com/Axot017/validate">validate: OCaml Data Validation library</a><ul>
+<li><a target="_blank" rel="noopener" href="https://github.com/Axot017/validate">validate: OCaml Data Validation library</a>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-validate-a-new-library-for-data-validation/13861">[ANN] Validate - A New Library for Data Validation</a></li>
</ul>
</li>
-<li><a target="_blank" rel="noopener" href="https://github.com/gborough/sarif">sarif v2.1.0: Static Analysis Results Interchange Format (SARIF) For OCaml</a><ul>
+<li><a target="_blank" rel="noopener" href="https://github.com/gborough/sarif">sarif v2.1.0: Static Analysis Results Interchange Format (SARIF) For OCaml</a>
+<ul>
<li><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-sarif-0-1-0-static-analysis-results-interchange-format-sarif-for-ocaml/13821">[ANN] sarif 0.1.0 - Static Analysis Results Interchange Format (SARIF) For OCaml</a></li>
</ul>
</li>
diff --git a/2024/01/22/Rescript-React-Native/index.html b/2024/01/22/Rescript-React-Native/index.html
index 9fb50113..7e0b1d15 100644
--- a/2024/01/22/Rescript-React-Native/index.html
+++ b/2024/01/22/Rescript-React-Native/index.html
@@ -194,7 +194,7 @@
<div class="post-content">
<p>Rescript 对 React Native 的支持还算可以,但如今的 RN 已经是 Expo 的 RN 了,所以仍然有些落后,在这个 template 中,我测试了 rescript + rescript-react-native + expo + nativewind 的组合,可以跑起来:</p>
<ul>
-<li><a target="_blank" rel="noopener" href="https://github.com/muqiuhan/rescript-react-native-expo-nativewind-template">muqiuhan&#x2F;rescript-react-native-expo-nativewind-template</a></li>
+<li><a target="_blank" rel="noopener" href="https://github.com/muqiuhan/rescript-react-native-expo-nativewind-template">muqiuhan/rescript-react-native-expo-nativewind-template</a></li>
</ul>
<p>其中有两个问题,一是 <a target="_blank" rel="noopener" href="https://github.com/rescript-bindings/expo">rescript-expo</a> 对 rescript v11 的兼容性,我通过简单的注释让其通过编译:</p>
<ul>
@@ -202,13 +202,10 @@
</ul>
<p>二是对于 nativewind 的支持,编写的 binding 非常丑陋:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">type default_style = &#123;</span><br><span class="line"> className?: string,</span><br><span class="line"> children?: React.element,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@module(&quot;nativewind&quot;)</span><br><span class="line">external styled: React.component&lt;&#x27;a&gt; =&gt; React.component&lt;default_style&gt; = &quot;styled&quot;</span><br><span class="line"></span><br><span class="line">module StyledText = &#123;</span><br><span class="line"> let make = styled(ReactNative.Text.make)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">module StyledView = &#123;</span><br><span class="line"> let make = styled(ReactNative.View.make)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">module StyledImage = &#123;</span><br><span class="line"> type props = &#123;</span><br><span class="line"> source?: string,</span><br><span class="line"> ...default_style,</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> @module(&quot;nativewind&quot;)</span><br><span class="line"> external styled: React.component&lt;&#x27;a&gt; =&gt; React.component&lt;props&gt; = &quot;styled&quot;</span><br><span class="line"></span><br><span class="line"> let make: React.component&lt;props&gt; = styled(ReactNative.Image.make)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
<p>而这似乎并没有好的解决方案,理想中的实现应该是:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">module Styled = (Component: &#123;</span><br><span class="line"> type params // or type params = &#x27;a</span><br><span class="line"> let make: React.component&lt;props&gt;</span><br><span class="line">&#125;) =&gt; &#123;</span><br><span class="line"> type props = &#123;</span><br><span class="line"> ...Component.props, // This can&#x27;t work as it is not defined as record</span><br><span class="line"> className?: string</span><br><span class="line"> &#125;</span><br><span class="line"> @module(&quot;nativewind&quot;)</span><br><span class="line"> external styled: React.component&lt;Component.props&gt; =&gt; React.component&lt;props&gt; = &quot;styled&quot;</span><br><span class="line"></span><br><span class="line"> let make: React.component&lt;props&gt; = styled(Component.make)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
<p>或者退一步:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">type styledProps = &#123;</span><br><span class="line"> className?: string,</span><br><span class="line"> // ...</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@module(&quot;nativewind&quot;)</span><br><span class="line"> external styled: React.component&lt;&#x27;a&gt; =&gt; React.component&lt;&#x27;b&gt; = &quot;styled&quot;</span><br><span class="line"></span><br><span class="line">module StyledText = &#123;</span><br><span class="line"> type props = &#123;</span><br><span class="line"> ...ReactNative.Text.props,</span><br><span class="line"> ...styledProps</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> let make: React.component&lt;props&gt; = styled(ReactNative.Text.make)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
<p>但这在当前的 rescript 中,根本无法实现。</p>
<p>详细的讨论看这个帖子:</p>
<ul>
diff --git a/2024/01/23/G-Machine/index.html b/2024/01/23/G-Machine/index.html
index d79bbc9c..03cfbc41 100644
--- a/2024/01/23/G-Machine/index.html
+++ b/2024/01/23/G-Machine/index.html
@@ -195,12 +195,12 @@
<ul>
<li><a target="_blank" rel="noopener" href="https://link.springer.com/chapter/10.1007/3-540-15975-4_50">The G-machine: A fast, graph-reduction evaluator</a></li>
</ul>
-<p>G-Machine 是一种通过图规约来对函数式语言程序求值的抽象架构。<br>与组合子规约不同,组合子规约的control是从表达式图本身动态导出的,而G-Machine是由通过编译Application表达式导出的指令序列指定的。</p>
+<p>G-Machine 是一种通过图规约来对函数式语言程序求值的抽象架构。<br>
+与组合子规约不同,组合子规约的control是从表达式图本身动态导出的,而G-Machine是由通过编译Application表达式导出的指令序列指定的。</p>
<hr>
<p>FP的程序基本上都可以用一个表达式的图表示,图计算机就是对这个图求值的机器,总的说来对图的求值是一个不停合并图上的节点生产新节点的过程。</p>
<p>例如:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> x = <span class="number">2</span> + <span class="number">3</span> <span class="keyword">in</span> </span><br><span class="line"> x * x</span><br></pre></td></tr></table></figure>
-
<p>先计算出5,然后创建一个新的节点 <code>5 * 5</code>,然后再对这个节点求值,于是求值过程中就产生了很多临时的节点,这些中间节点也被叫做是 spine,求值过程是沿着 spine 进行的。</p>
<p>但是这样就产生了很多额外的开销,lambda lifting 里提到:可以把程序里,很多捕捉了外围绑定的闭包函数中的这些绑定,转换成函数的参数,从而消除闭包,得到的这个函数就可以自由脱离作用域,被静态的编译到机器码里。这些被 float out 的函数也叫 supercombinator.</p>
<p>在上面的代码中,如果不创建新的节点,顺序计算完了第一个 <code>x</code>,第二个 <code>x</code> 还会再被算一遍。</p>
diff --git a/2024/01/23/二〇二四年一月二十三日/index.html b/2024/01/23/二〇二四年一月二十三日/index.html
index 6870afd5..a5326ed3 100644
--- a/2024/01/23/二〇二四年一月二十三日/index.html
+++ b/2024/01/23/二〇二四年一月二十三日/index.html
@@ -186,12 +186,13 @@
<div class="post-content">
<p>有人在桥上并肩走过,孩子们举着风车大笑着跑开,热乎乎的米糕新鲜出炉,香气混着夜风传去老远。</p>
<p>桥上是喧闹繁杂的尘世万千,桥下是静谧安宁的人间留恋。</p>
-<p>我有时候会无法控制的想,如果这一切都是梦,一觉醒来又回到了那暗无天日的日子……但转瞬即否定这个答案———那我会重新走到今天。</p>
+<p>我有时候会无法控制的想,如果这一切都是梦,一觉醒来又回到了那暗无天日的日子…但转瞬即否定这个答案———那我会重新走到今天。</p>
<p>寒风拂过我的侧脸,把碎发拂去耳后。</p>
<p>如果你也只剩活着了。</p>
<p>就像一条小鱼,在这一方小世界中摆尾流浪,海波荡漾了许多年,也飘出去那么远。</p>
<p>这么些年的煎熬时光或许将你沉寂,或许掀起了惊涛骇浪,吞噬你的理智与晴空,令你彻底疯狂。</p>
-<p>直到海浪卷起鱼群,波及到每一个地方,<br>直到风平浪静,晴空如洗。</p>
+<p>直到海浪卷起鱼群,波及到每一个地方,<br>
+直到风平浪静,晴空如洗。</p>
<hr>
<p>但几个小时之后,天际黎明乍现的那一瞬,会有一只无形的大手,将最后一层青灰色的夜幕轻轻抹去。</p>
<p>晨光会从海平线迤逦而来,洒向鳞次栉比的高楼和错综复杂的街道。码头,树木,楼房,电线杆。</p>
diff --git a/2024/01/23/慢性肺源性心脏病/index.html b/2024/01/23/慢性肺源性心脏病/index.html
index 192e45ce..2abdcd00 100644
--- a/2024/01/23/慢性肺源性心脏病/index.html
+++ b/2024/01/23/慢性肺源性心脏病/index.html
@@ -192,21 +192,27 @@
</div>
</div>
<div class="post-content">
- <p>肺源性心脏病(cor pulmonale)简称肺心病, 指由于支气管-肺组织, 胸廓或肺血管病变引起肺血管阻力增加, 产生肺动脉高压,继而右心室结构和&#x2F;或功能改变的疾病.<br>根据起病缓急和病程长短, 可分为急性肺心病和慢性肺心病两类, 急性肺心病常见于急性大面积肺栓塞,这里主要讲慢性肺心病.</p>
+ <p>肺源性心脏病(cor pulmonale)简称肺心病, 指由于支气管-肺组织, 胸廓或肺血管病变引起肺血管阻力增加, 产生肺动脉高压,继而右心室结构和/或功能改变的疾病.<br>
+根据起病缓急和病程长短, 可分为急性肺心病和慢性肺心病两类, 急性肺心病常见于急性大面积肺栓塞,这里主要讲慢性肺心病.</p>
<p>慢性肺心病是常见的呼吸系统疾病.患病率存在地区差异, 北方地区高于南方地区,农村高于城市.患病率随年龄增高而增加, 吸烟者比不吸烟者患病率明显增多, 男女无明显差异.</p>
<p>冬春季节和气候骤变时, 易出现急性发作.</p>
-<h2 id="病因与发病机制"><a href="#病因与发病机制" class="headerlink" title="病因与发病机制"></a>病因与发病机制</h2><h3 id="病因"><a href="#病因" class="headerlink" title="病因"></a>病因</h3><ol>
+<h2 id="病因与发病机制"><a class="header-anchor" href="#病因与发病机制">¶</a>病因与发病机制</h2>
+<h3 id="病因"><a class="header-anchor" href="#病因">¶</a>病因</h3>
+<ol>
<li>支气管, 肺疾病: 最多见为COPD, 占80%~90%, 其次为哮喘, 支气管扩张症, 肺结核, 间质性肺疾病等.</li>
<li>胸廓运动障碍性疾病: 较少见, 严重胸廓或脊椎畸形以及神经肌肉疾患均可引起胸廓活动受限, 肺受压, 支气管扭曲或变形, 气道引流不畅,肺部反复感染,并发肺气肿或纤维化,最终引起慢性肺心病.</li>
<li>肺血管疾病: 特发性或慢性栓塞性肺动脉高压, 肺小动脉炎均可起肺血管阻力增加, 肺动脉压升高和右心室负荷加重,发展为慢性肺心病.</li>
<li>其他: 原发性肺泡通气不足及先天性口咽畸形, 睡眠呼吸暂停低通气综合征等均可产生低氧血症, 引起肺血管收缩, 导致肺动脉高压, 发展为慢性肺心病.</li>
</ol>
-<h3 id="发病机制"><a href="#发病机制" class="headerlink" title="发病机制"></a>发病机制</h3><blockquote>
+<h3 id="发病机制"><a class="header-anchor" href="#发病机制">¶</a>发病机制</h3>
+<blockquote>
<p>肺动脉高压的形成: 不同疾病所致肺动脉高压的机制不完全一样, 这里记录低氧性肺动脉高压, 尤其COPD所致肺动脉高压的机制.</p>
</blockquote>
<ol>
-<li>肺血管阻力增加的功能性因素: 肺血管收缩在低氧性肺动脉高压的发生中起着关键作用.缺氧, 高碳酸血症和呼吸性酸中毒导致肺血管收缩, 痉挛, 其中缺氧是肺动脉高压形成最重要的因素.缺氧时收缩血管的活性物质增多,使肺血管收缩, 血管阻力增加.缺氧使肺血管平滑肌细胞膜对 <code>Ca2+</code> 的通透性增加, 直接使肺血管平滑肌收缩.另外, 高碳酸血症时,『产生增多,使血管对缺氧的敏感<br>性增强, 致肺动脉压增高.</li>
-<li>肺血管阻力增加的解剖学因素: 解剖学因素系指肺血管解剖结构的变化, 形成肺循环血流动力学障碍.主要原因有:<ol>
+<li>肺血管阻力增加的功能性因素: 肺血管收缩在低氧性肺动脉高压的发生中起着关键作用.缺氧, 高碳酸血症和呼吸性酸中毒导致肺血管收缩, 痉挛, 其中缺氧是肺动脉高压形成最重要的因素.缺氧时收缩血管的活性物质增多,使肺血管收缩, 血管阻力增加.缺氧使肺血管平滑肌细胞膜对 <code>Ca2+</code> 的通透性增加, 直接使肺血管平滑肌收缩.另外, 高碳酸血症时,『产生增多,使血管对缺氧的敏感<br>
+性增强, 致肺动脉压增高.</li>
+<li>肺血管阻力增加的解剖学因素: 解剖学因素系指肺血管解剖结构的变化, 形成肺循环血流动力学障碍.主要原因有:
+<ol>
<li>长期反复发作的COPD及支气管周围炎,可累及邻近肺小动脉, 引起血管炎, 使肺血管阻力增加, 产生肺动脉高压.</li>
<li>肺气肿导致肺泡内压增高, 压迫肺泡毛细血管, 造成管腔狭窄或闭塞.肺泡壁破裂造成毛细血管网的毁损, 当肺泡毛细血管床减损超过70%时肺循环阻力增大.</li>
<li>肺血管重构:慢性缺氧使肺血管收缩, 管壁张力增高.缺氧时肺内产生多种生长因子,可直接刺激管壁平滑肌细胞, 内膜弹力纤维及胶原纤维增生.</li>
@@ -217,43 +223,55 @@
<li>心脏病变和心力衰竭:肺循环阻力增加导致肺动脉高压, 右心发挥代偿作用, 以克服肺动脉压升高的阻力而发生右心室肥厚.随着病情进展, 肺动脉压持续升高, 右心失代偿而致右心衰竭.</li>
<li>其他重要器官的损害:缺氧和高碳酸血症可导致重要器官如脑, 肝, 肾, 胃肠及内分泌系统, 血液系统等发生病理改变, 引起多脏器的功能损害.</li>
</ol>
-<h2 id="临床表现"><a href="#临床表现" class="headerlink" title="临床表现"></a>临床表现</h2><h1 id="肺-心功能代偿期"><a href="#肺-心功能代偿期" class="headerlink" title="肺, 心功能代偿期"></a>肺, 心功能代偿期</h1><ol>
+<h2 id="临床表现"><a class="header-anchor" href="#临床表现">¶</a>临床表现</h2>
+<h1>肺, 心功能代偿期</h1>
+<ol>
<li>症状:C0PD病人可有咳嗽, 咳痰, 气促, 活动后可有心悸, 呼吸困难, 乏力和劳动耐力下降,少有胸痛或咯血.</li>
<li>体征:原发肺脏疾病体征, 可有不同程度的发维和肺气肿体征,可见肺动脉高压和右室扩大的体征.</li>
</ol>
-<h2 id="肺-心功能失代偿期"><a href="#肺-心功能失代偿期" class="headerlink" title="肺, 心功能失代偿期"></a>肺, 心功能失代偿期</h2><ol>
-<li>呼吸衰竭<ul>
+<h2 id="肺-心功能失代偿期"><a class="header-anchor" href="#肺-心功能失代偿期">¶</a>肺, 心功能失代偿期</h2>
+<ol>
+<li>呼吸衰竭
+<ul>
<li>症状:呼吸困难加重, 夜间为甚, 常有头痛, 失眠, 食欲下降, 白天嗜睡, 甚至出现表情淡漠, 神志恍惚, 澹妄等肺性脑病的表现.</li>
<li>体征:明显发维, 球结膜充血, 水肿, 严重时可有视网膜血管, 视盘水肿等颅内压升高的表现.腱反射减弱或消失, 出现病理反射.因高碳酸血症可出现周围血管扩张的表现, 如皮肤潮红, 多汗.</li>
</ul>
</li>
-<li>右心衰竭<ul>
+<li>右心衰竭
+<ul>
<li>症状:明显气促, 心悸, 食欲缺乏, 腹胀, 恶心等.</li>
<li>体征:发绡明显, 颈静脉怒张, 心率增快, 可出现心律失常, 剑突下可闻及收缩期杂音, 甚至出现舒张期杂音.肝大并有压痛,肝颈静脉回流征阳性, 下肢水肿,重者可有腹水.</li>
</ul>
</li>
<li>并发症: 肺性脑病, 电解质及酸碱平衡紊乱, 心律失常, 休克, 消化道出血和弥散性血管内凝血等.</li>
</ol>
-<h2 id="实验室及其他检查"><a href="#实验室及其他检查" class="headerlink" title="实验室及其他检查"></a>实验室及其他检查</h2><ol>
+<h2 id="实验室及其他检查"><a class="header-anchor" href="#实验室及其他检查">¶</a>实验室及其他检查</h2>
+<ol>
<li>胸部X线检查: 除肺, 胸基础疾病及急性肺部感染的特征外, 尚有肺动脉高压征象.</li>
-<li>心电图检查: 心电图对慢性肺心病的诊断阳性率为60. 1%〜88. 2%.主要表现有电轴右偏,<br>肺性P波.</li>
+<li>心电图检查: 心电图对慢性肺心病的诊断阳性率为60. 1%〜88. 2%.主要表现有电轴右偏,<br>
+肺性P波.</li>
<li>超声心动图检查: 超声心动图诊断慢性肺心病的阳性率为60.6%〜87.0%.</li>
<li>动脉血气分析: 可出现低氧血症,甚至呼吸衰竭或合并高碳酸血症.</li>
<li>血液检查: 红细胞及血红蛋白可升高, 全血及血浆黏度可增加, 心功能不全时可伴有肾功能或肝功能异常.</li>
<li>其他: 早期或缓解期病人可行肺功能检查.痰细菌学检查可指导抗生素的选用.</li>
</ol>
-<h2 id="治疗要点"><a href="#治疗要点" class="headerlink" title="治疗要点"></a>治疗要点</h2><h3 id="肺-心功能代偿期-1"><a href="#肺-心功能代偿期-1" class="headerlink" title="肺, 心功能代偿期"></a>肺, 心功能代偿期</h3><p>可采用综合治疗措施, 延缓基础疾病进展, 增强病人的免疫功能,预防感染,减少或避免急性加重, 加强康复锻炼和营养,必要时长期家庭氧疗或家庭无创呼吸机治疗等.</p>
-<h3 id="肺-心功能失代偿期-1"><a href="#肺-心功能失代偿期-1" class="headerlink" title="肺, 心功能失代偿期"></a>肺, 心功能失代偿期</h3><p>治疗原则为积极控制感染, 保持呼吸道通畅,改善呼吸功能, 纠正缺氧和二氧化碳潴留, 控制呼吸衰竭和心力衰竭, 处理并发症.</p>
+<h2 id="治疗要点"><a class="header-anchor" href="#治疗要点">¶</a>治疗要点</h2>
+<h3 id="肺-心功能代偿期"><a class="header-anchor" href="#肺-心功能代偿期">¶</a>肺, 心功能代偿期</h3>
+<p>可采用综合治疗措施, 延缓基础疾病进展, 增强病人的免疫功能,预防感染,减少或避免急性加重, 加强康复锻炼和营养,必要时长期家庭氧疗或家庭无创呼吸机治疗等.</p>
+<h3 id="肺-心功能失代偿期-v2"><a class="header-anchor" href="#肺-心功能失代偿期-v2">¶</a>肺, 心功能失代偿期</h3>
+<p>治疗原则为积极控制感染, 保持呼吸道通畅,改善呼吸功能, 纠正缺氧和二氧化碳潴留, 控制呼吸衰竭和心力衰竭, 处理并发症.</p>
<ol>
<li>控制感染:参考痰培养及药敏试验选择抗生素.没有培养结果时, 根据感染的环境及痰涂片结果选用抗生素.常用青霉素类, 氨基糖甘类, 喳诺酮类或头抱菌素类药物.注意继发真菌感染的可能.</li>
<li>控制呼吸衰竭:使用支气管舒张药和祛痰药, 吸痰, 通畅呼吸道, 改善通气功能.合理氧疗.需要时给予无创正压通气或气管插管有创正压通气治疗.详见本章第十四节“呼吸衰竭”的治疗.</li>
-<li>控制心力衰竭:慢性肺心病病人一般经积极控制感染, 改善呼吸功能, 纠正缺氧和二氧化碳潴留后, 心力衰竭便能得到改善,病人尿量增多, 水肿消退, 不需常规使用利尿药和正性肌力药.但病情较重或对上述治疗无效的病人, 可适当选用利尿药, 正性肌力药或扩血管药物.<ol>
+<li>控制心力衰竭:慢性肺心病病人一般经积极控制感染, 改善呼吸功能, 纠正缺氧和二氧化碳潴留后, 心力衰竭便能得到改善,病人尿量增多, 水肿消退, 不需常规使用利尿药和正性肌力药.但病情较重或对上述治疗无效的病人, 可适当选用利尿药, 正性肌力药或扩血管药物.
+<ol>
<li>利尿药:具有消除水肿, 减少血容量, 减轻右心前负荷的作用.原则上选用作用温和的利尿药, 联合保钾利尿药,宜短期, 小剂量使用.如氢氯廛嗪25mg,每天1〜3次;联用螺内酯20〜40mg,每天1〜2次.应用利尿药易出现低钾, 低氯性碱中毒, 痰液黏稠不易排痰和血液浓缩,应注意预防.</li>
-<li>正性肌力药:由于慢性缺氧和感染,慢性肺心病病人对洋地黄类药物耐受性低, 容易中毒, 出现心律失常.原则上选用作用快, 排泄快的洋地黄类药物, 小剂量(常规剂量的1&#x2F;2或2&#x2F;3量)静脉给药.用药前注意纠正缺氧, 防治低钾血症, 以免发生药物毒性反应.</li>
+<li>正性肌力药:由于慢性缺氧和感染,慢性肺心病病人对洋地黄类药物耐受性低, 容易中毒, 出现心律失常.原则上选用作用快, 排泄快的洋地黄类药物, 小剂量(常规剂量的1/2或2/3量)静脉给药.用药前注意纠正缺氧, 防治低钾血症, 以免发生药物毒性反应.</li>
</ol>
</li>
</ol>
-<h2 id="健康指导"><a href="#健康指导" class="headerlink" title="健康指导"></a>健康指导</h2><ol>
+<h2 id="健康指导"><a class="header-anchor" href="#健康指导">¶</a>健康指导</h2>
+<ol>
<li>疾病预防指导: 由于慢性肺心病是各种原发肺胸疾病晚期的并发症, 应对高危人群进行宣传教育, 劝导戒烟, 积极防治COPD等慢性支气管肺疾病, 以降低发病率.</li>
<li>疾病知识指导: 使病人和家属了解疾病发生, 发展过程, 减少反复发作的次数.积极防治原发病, 避免和防治各种可能导致病情急性加重的诱因, 坚持家庭氧疗等.加强饮食营养, 以保证机体康复的需要.病情缓解期应根据肺, 心功能及体力情况进行适当的体育锻炼和呼吸功能锻炼如散步, 气功, 太极拳, 腹式呼吸, 缩唇呼吸等, 改善呼吸功能,提高机体免疫功能.</li>
<li>病情监测指导: 告知病人及家属病情变化的征象, 如体温升高, 呼吸困难加重, 咳嗽剧烈, 咳痰不畅, 尿量减少, 水肿明显或发现病人神志淡漠, 嗜睡, 躁动, 口唇发纳加重等,均提示病情变化或加重,需及时就诊.</li>
diff --git a/2024/01/25/急诊与灾难医学-烧伤/index.html b/2024/01/25/急诊与灾难医学-烧伤/index.html
index f9372bad..4f68f670 100644
--- a/2024/01/25/急诊与灾难医学-烧伤/index.html
+++ b/2024/01/25/急诊与灾难医学-烧伤/index.html
@@ -193,8 +193,10 @@
</div>
<div class="post-content">
<p>烧伤,烫伤是一个很常见的急诊意外损伤,这里科普一下相关的知识。</p>
-<h2 id="临床特点"><a href="#临床特点" class="headerlink" title="临床特点"></a>临床特点</h2><p>烧伤组织出现变性坏死,体液渗出引起组织水肿,变性,小面积的浅度烧伤,体液渗出有限,经过代偿之后不会影响身体的有效循环血量,大面积或者深度的烧伤,会因为大量渗出,休克,感染等病理变化导致并发脓毒症和多器官功能衰竭。</p>
-<h3 id="烧伤面积判断"><a href="#烧伤面积判断" class="headerlink" title="烧伤面积判断"></a>烧伤面积判断</h3><p>首先我们要估算烧伤的面积,也就是判断皮肤烧伤区占人体表面积的百分比,最常用的是九分法和手掌法,前者用于大面积烧伤,后者用于小面积烧伤。</p>
+<h2 id="临床特点"><a class="header-anchor" href="#临床特点">¶</a>临床特点</h2>
+<p>烧伤组织出现变性坏死,体液渗出引起组织水肿,变性,小面积的浅度烧伤,体液渗出有限,经过代偿之后不会影响身体的有效循环血量,大面积或者深度的烧伤,会因为大量渗出,休克,感染等病理变化导致并发脓毒症和多器官功能衰竭。</p>
+<h3 id="烧伤面积判断"><a class="header-anchor" href="#烧伤面积判断">¶</a>烧伤面积判断</h3>
+<p>首先我们要估算烧伤的面积,也就是判断皮肤烧伤区占人体表面积的百分比,最常用的是九分法和手掌法,前者用于大面积烧伤,后者用于小面积烧伤。</p>
<ul>
<li>手掌法:病人的五个手指并拢后,手掌的面积估算为 1% 体表面积。</li>
<li>九分法:</li>
@@ -207,7 +209,8 @@
<th>小儿各部位面积(%)</th>
</tr>
</thead>
-<tbody><tr>
+<tbody>
+<tr>
<td>头额</td>
<td><code>9x1=9 (发部3,面部3,颈部3)</code></td>
<td><code>9 + (12-年龄) </code></td>
@@ -227,8 +230,10 @@
<td><code>9x5+1=45 (双臀5, 双大腿21, 双小腿13, 双足7)</code></td>
<td><code>46-(12-年龄)</code></td>
</tr>
-</tbody></table>
-<h3 id="烧伤深度判断"><a href="#烧伤深度判断" class="headerlink" title="烧伤深度判断"></a>烧伤深度判断</h3><p>三度四分法:</p>
+</tbody>
+</table>
+<h3 id="烧伤深度判断"><a class="header-anchor" href="#烧伤深度判断">¶</a>烧伤深度判断</h3>
+<p>三度四分法:</p>
<ul>
<li>I 度:仅伤及表皮浅层</li>
<li>浅 II 度:伤及表皮的生发层与真皮乳头层</li>
@@ -245,7 +250,8 @@
<th>预后</th>
</tr>
</thead>
-<tbody><tr>
+<tbody>
+<tr>
<td>I</td>
<td>粉红或红色</td>
<td>干燥</td>
@@ -273,7 +279,8 @@
<td>无感觉</td>
<td>需切痂皮,植皮,皮瓣移植或截肢</td>
</tr>
-</tbody></table>
+</tbody>
+</table>
<p>根据以上的参考,可以把伤情分为四类:</p>
<ol>
<li>轻度烧伤:总面积 9% 以下的 II 度烧伤</li>
@@ -284,24 +291,32 @@
<hr>
<p><strong>根据烧伤病史和临床表现,要注意包括对烧伤严重程度的判断,烧伤原因的鉴别,需要排除电和化学烧伤</strong></p>
<hr>
-<h2 id="急诊处理"><a href="#急诊处理" class="headerlink" title="急诊处理"></a>急诊处理</h2><h3 id="现场急救"><a href="#现场急救" class="headerlink" title="现场急救"></a>现场急救</h3><ol>
+<h2 id="急诊处理"><a class="header-anchor" href="#急诊处理">¶</a>急诊处理</h2>
+<h3 id="现场急救"><a class="header-anchor" href="#现场急救">¶</a>现场急救</h3>
+<ol>
<li>迅速脱离热源,褪去衣物,不可粗暴剥脱。在现场可用干净敷料或布织物保护伤处,立即送医</li>
-<li>初步判断伤情,如有大出血,窒息,开放性气胸,严重中毒,立即组织抢救<blockquote>
-<p>烧伤常伴呼吸道受烟雾,热力灼伤<br>切记注意有无呼吸道吸入性损伤,保持呼吸通畅,<strong>必要时切开气管</strong><br>出现心脏骤停,确认环境安全后,迅速心肺复苏</p>
+<li>初步判断伤情,如有大出血,窒息,开放性气胸,严重中毒,立即组织抢救
+<blockquote>
+<p>烧伤常伴呼吸道受烟雾,热力灼伤<br>
+切记注意有无呼吸道吸入性损伤,保持呼吸通畅,<strong>必要时切开气管</strong><br>
+出现心脏骤停,确认环境安全后,迅速心肺复苏</p>
</blockquote>
</li>
<li>轻度烧伤,特别是四肢烧伤,立即用冷水连续冲洗或浸泡</li>
<li>大面积烧伤,立即建立静脉通道,予以补液,抗休克治疗</li>
<li>转运伤员就近原则,严重烧伤早期,<strong>切忌长途转运</strong></li>
</ol>
-<h3 id="急诊治疗"><a href="#急诊治疗" class="headerlink" title="急诊治疗"></a>急诊治疗</h3><h4 id="轻度烧伤"><a href="#轻度烧伤" class="headerlink" title="轻度烧伤"></a>轻度烧伤</h4><blockquote>
+<h3 id="急诊治疗"><a class="header-anchor" href="#急诊治疗">¶</a>急诊治疗</h3>
+<h4 id="轻度烧伤"><a class="header-anchor" href="#轻度烧伤">¶</a>轻度烧伤</h4>
+<blockquote>
<p>处理创面,<strong>小心</strong> 剔净创面周围毛发,清洁健康皮肤,去除异物。</p>
</blockquote>
<ul>
<li>I 度创面无需处理,外敷清凉药物即可</li>
<li>浅 II 度,如果水疱完整,不要动它,如果水疱很大,用消毒空针去抽水疱液,然后消毒包扎,如果水疱已经撕破,用无菌纱布,油性敷料包扎。创面无感染无需经常换药,面颈部和会阴部烧伤可以予以暴露,关节部位 II~III 度必须用夹板固定关节,按需用止痛镇静药物,酌情使用破伤风抗毒素。</li>
</ul>
-<h1 id="中度及以上烧伤立刻运送至有烧伤专科的医院"><a href="#中度及以上烧伤立刻运送至有烧伤专科的医院" class="headerlink" title="中度及以上烧伤立刻运送至有烧伤专科的医院"></a>中度及以上烧伤立刻运送至有烧伤专科的医院</h1><p>处理要点:</p>
+<h1>中度及以上烧伤立刻运送至有烧伤专科的医院</h1>
+<p>处理要点:</p>
<ol>
<li>吸氧,呼吸支持,建立输液通道,留置尿管,观察每小时尿量,比重,pH,有无血红蛋白尿,肌红蛋白尿。</li>
<li>估算烧伤面积,深度</li>
@@ -313,7 +328,8 @@
<li>肠内肠外营养支持,尽量肠内营养</li>
<li>减少瘢痕,挛缩,进行功能康复</li>
</ol>
-<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
+<h2 id="参考"><a class="header-anchor" href="#参考">¶</a>参考</h2>
+<ul>
<li>《外科护理学【第六版】》</li>
<li>《烧伤外科学分册》</li>
<li>《急诊与灾难医学【第三版】》</li>
diff --git a/2024/02/07/二〇二四年二月七日/index.html b/2024/02/07/二〇二四年二月七日/index.html
index b601f715..a25045ef 100644
--- a/2024/02/07/二〇二四年二月七日/index.html
+++ b/2024/02/07/二〇二四年二月七日/index.html
@@ -184,9 +184,15 @@
</div>
</div>
<div class="post-content">
- <p>瀑布的水逆流而上,<br>蒲公英种子从远处飘回,聚成伞的模样,<br>太阳从西边升起,落向东方。</p>
-<p>子弹退回枪膛,<br>运动员回到起跑线上,<br>我交回录取通知书,忘了十年寒窗。</p>
-<p>厨房里飘来饭菜的香,<br>你把我的卷子签好名字,<br>关掉电视,帮我把书包背上。</p>
+ <p>瀑布的水逆流而上,<br>
+蒲公英种子从远处飘回,聚成伞的模样,<br>
+太阳从西边升起,落向东方。</p>
+<p>子弹退回枪膛,<br>
+运动员回到起跑线上,<br>
+我交回录取通知书,忘了十年寒窗。</p>
+<p>厨房里飘来饭菜的香,<br>
+你把我的卷子签好名字,<br>
+关掉电视,帮我把书包背上。</p>
<p>你还在我身旁。</p>
<hr>
<p>功利性主义总会引导我们思考结局,可生活本质上就是一场旅途。</p>
diff --git a/2024/02/26/OCaml-News-2024-3/index.html b/2024/02/26/OCaml-News-2024-3/index.html
index 4c44f48a..22dc4af2 100644
--- a/2024/02/26/OCaml-News-2024-3/index.html
+++ b/2024/02/26/OCaml-News-2024-3/index.html
@@ -192,99 +192,144 @@
</div>
</div>
<div class="post-content">
- <h2 id=""><a href="#" class="headerlink" title=""></a></h2><p>o-新鲜事儿</p>
+ <h2 id=""><a class="header-anchor" href="#">¶</a></h2>
+<p>o-新鲜事儿</p>
<ul>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-5-1-0-released/13021">OCaml 5.1.0 released</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-5-1-0-released/13021">OCaml 5.1.0 released</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-dune-3-14/14096">[ANN] dune 3.14</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-dune-3-14/14096">[ANN] dune 3.14</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://ocaml.codes/search/">code search</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://ocaml.codes/search/">code search</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-ocaml-codes-code-search-for-opam-packages/14092">[ANN] ocaml.codes, code search for OPAM packages</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-ocaml-codes-code-search-for-opam-packages/14092">[ANN] ocaml.codes, code search for OPAM packages</a></p>
</li>
-<li><p>用 livegrep 基于 opam 包的源码做的代码搜索,还挺方便的。</p>
+<li>
+<p>用 livegrep 基于 opam 包的源码做的代码搜索,还挺方便的。</p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://melange.re/blog/posts/announcing-melange-3">Announcing Melange 3</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://melange.re/blog/posts/announcing-melange-3">Announcing Melange 3</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-melange-3-0/14102">[ANN] Melange 3.0</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-melange-3-0/14102">[ANN] Melange 3.0</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/learn-ocaml-1-0-is-out/14100">Learn-OCaml 1.0 is out!</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/learn-ocaml-1-0-is-out/14100">Learn-OCaml 1.0 is out!</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://ocaml-sf.org/learn-ocaml-public/">https://ocaml-sf.org/learn-ocaml-public/</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://ocaml-sf.org/learn-ocaml-public/">https://ocaml-sf.org/learn-ocaml-public/</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/owlbarn/owl">GitHub - owlbarn&#x2F;owl: Owl - OCaml Scientific Computing @ http://ocaml.xyz</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/owlbarn/owl">GitHub - owlbarn/owl: Owl - OCaml Scientific Computing @ http://ocaml.xyz</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/owl-project-concluding/14117">Owl project concluding</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/owl-project-concluding/14117">Owl project concluding</a></p>
</li>
-<li><p>经过八年的维护,Owl项目即将终止</p>
+<li>
+<p>经过八年的维护,Owl项目即将终止</p>
</li>
</ul>
-<h2 id="-1"><a href="#-1" class="headerlink" title=""></a></h2><p>o-视频</p>
+<h2 id="-v2"><a class="header-anchor" href="#-v2">¶</a></h2>
+<p>o-视频</p>
<ul>
-<li><p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=jvQ7fj9LlVA">Inferring Locality in OCaml | OCaml Unboxed</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=jvQ7fj9LlVA">Inferring Locality in OCaml | OCaml Unboxed</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=AGu4AO5zO8o">OCaml Locals Save Allocations | OCaml Unboxed</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=AGu4AO5zO8o">OCaml Locals Save Allocations | OCaml Unboxed</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/qQzb94X9WM7zLif7FynPyN">Ocsigen: Developing Web and mobile applications in OCaml – Jérôme Vouillon &amp; Vincent Balat</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/qQzb94X9WM7zLif7FynPyN">Ocsigen: Developing Web and mobile applications in OCaml – Jérôme Vouillon &amp; Vincent Balat</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/iQNqZzA8gVmd4RQaycAwx4">Verifying an Effect-Based Cooperative Concurrency Scheduler in Iris by Adrian Dapprich</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/iQNqZzA8gVmd4RQaycAwx4">Verifying an Effect-Based Cooperative Concurrency Scheduler in Iris by Adrian Dapprich</a></p>
</li>
</ul>
-<h2 id="-2"><a href="#-2" class="headerlink" title=""></a></h2><p>o-博客 &#x2F; 文章 &#x2F; 帖子</p>
+<h2 id="-v3"><a class="header-anchor" href="#-v3">¶</a></h2>
+<p>o-博客 / 文章 / 帖子</p>
<ul>
-<li><p><a target="_blank" rel="noopener" href="https://priver.dev/blog/dbcaml/dbcaml/">Introducing DBCaml, Database toolkit for OCaml</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://priver.dev/blog/dbcaml/dbcaml/">Introducing DBCaml, Database toolkit for OCaml</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://priver.dev/blog/dbcaml/building-a-connnection-pool/">Building a Connnection Pool for DBCaml on top of riot</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://priver.dev/blog/dbcaml/building-a-connnection-pool/">Building a Connnection Pool for DBCaml on top of riot</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml/">Generating static and portable executables with OCaml</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml/">Generating static and portable executables with OCaml</a></p>
</li>
-<li><p>OCaml编译器没有内置生成静态可移植可执行文件的特性,这里提到了一些技巧</p>
+<li>
+<p>OCaml编译器没有内置生成静态可移植可执行文件的特性,这里提到了一些技巧</p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/analog-of-promise-any-for-multicore-ocaml/14145">Analog of Promise.any() for Multicore OCaml</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/analog-of-promise-any-for-multicore-ocaml/14145">Analog of Promise.any() for Multicore OCaml</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/printf-vs-format/14130">Printf vs. Format?</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/printf-vs-format/14130">Printf vs. Format?</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-to-represent-tuples-in-ast/14095">How to represent tuples in AST?</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-to-represent-tuples-in-ast/14095">How to represent tuples in AST?</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-do-i-pass-an-unsigned-char-an-array-of-bytes-representing-binary-data-from-c-to-ocaml/14074">How do I pass an unsigned char * (an array of bytes representing binary data) from C to OCaml?</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-do-i-pass-an-unsigned-char-an-array-of-bytes-representing-binary-data-from-c-to-ocaml/14074">How do I pass an unsigned char * (an array of bytes representing binary data) from C to OCaml?</a></p>
</li>
</ul>
-<h2 id="-3"><a href="#-3" class="headerlink" title=""></a></h2><p>o-未来</p>
+<h2 id="-v4"><a class="header-anchor" href="#-v4">¶</a></h2>
+<p>o-未来</p>
<ul>
-<li><p><a target="_blank" rel="noopener" href="https://docs.google.com/forms/d/e/1FAIpQLSe1U_5KanTeKt1h9t5vjYohYXepXDhPCru4tsms4OcI5k0Fkw/viewform?pli=1">How do we want to present OCaml to the World on OCaml.org?</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://docs.google.com/forms/d/e/1FAIpQLSe1U_5KanTeKt1h9t5vjYohYXepXDhPCru4tsms4OcI5k0Fkw/viewform?pli=1">How do we want to present OCaml to the World on OCaml.org?</a></p>
</li>
-<li><p>一个问卷,用于更好的改进 <a target="_blank" rel="noopener" href="http://ocaml.org/">ocaml.org</a> 有关学术和工业应用板块的内容。</p>
+<li>
+<p>一个问卷,用于更好的改进 <a target="_blank" rel="noopener" href="http://ocaml.org/">ocaml.org</a> 有关学术和工业应用板块的内容。</p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/feedback-help-wanted-upcoming-ocaml-org-cookbook-feature/14127">Feedback &#x2F; Help Wanted: Upcoming OCaml.org Cookbook Feature</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/feedback-help-wanted-upcoming-ocaml-org-cookbook-feature/14127">Feedback / Help Wanted: Upcoming OCaml.org Cookbook Feature</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="http://ocaml.org/">ocaml.org</a> 准备上线一个cookbook页面,放一些如何用OCaml的生态解决常见需求的资源</p>
+<li>
+<p><a target="_blank" rel="noopener" href="http://ocaml.org/">ocaml.org</a> 准备上线一个cookbook页面,放一些如何用OCaml的生态解决常见需求的资源</p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/state-of-compaction-in-ocaml-5/14121/1">State of compaction in OCaml 5?</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/state-of-compaction-in-ocaml-5/14121/1">State of compaction in OCaml 5?</a></p>
</li>
-<li><p>OCaml 5.2 的 compact heap 会将未使用的内存返回给操作系统。在 OCaml 5 的 GC 中,小于 128byte 的块用大小隔离池进行管理,比如有一个池,处理大小为 3byte 的分配,另一个池处理大小为 4byte 的分配等等,这样的池在每个Domain里都有。用这个方法分配速度很快,因为不用找合适的内存间隙了,只要找正确的池大小就行。</p>
+<li>
+<p>OCaml 5.2 的 compact heap 会将未使用的内存返回给操作系统。在 OCaml 5 的 GC 中,小于 128byte 的块用大小隔离池进行管理,比如有一个池,处理大小为 3byte 的分配,另一个池处理大小为 4byte 的分配等等,这样的池在每个Domain里都有。用这个方法分配速度很快,因为不用找合适的内存间隙了,只要找正确的池大小就行。</p>
</li>
</ul>
-<h2 id="-4"><a href="#-4" class="headerlink" title=""></a></h2><p>o-值得被注意的项目</p>
+<h2 id="-v5"><a class="header-anchor" href="#-v5">¶</a></h2>
+<p>o-值得被注意的项目</p>
<ul>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/mbarbin/vcs">GitHub - mbarbin&#x2F;vcs: A versatile OCaml library for Git interaction</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/mbarbin/vcs">GitHub - mbarbin/vcs: A versatile OCaml library for Git interaction</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/a-versatile-ocaml-library-for-git-interaction-seeking-community-feedback/14155">A Versatile OCaml Library for Git Interaction - Seeking Community Feedback</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/a-versatile-ocaml-library-for-git-interaction-seeking-community-feedback/14155">A Versatile OCaml Library for Git Interaction - Seeking Community Feedback</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/dbcaml/dbcaml">GitHub - dbcaml&#x2F;dbcaml: DBCaml is a database library for OCaml</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/dbcaml/dbcaml">GitHub - dbcaml/dbcaml: DBCaml is a database library for OCaml</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/dbcaml-a-new-database-toolkit-built-on-riot/14150">DBcaml, a new database toolkit built on Riot</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/dbcaml-a-new-database-toolkit-built-on-riot/14150">DBcaml, a new database toolkit built on Riot</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/c-cube/fuseau">GitHub - c-cube&#x2F;fuseau: [alpha] lightweight fiber library for OCaml 5</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/c-cube/fuseau">GitHub - c-cube/fuseau: [alpha] lightweight fiber library for OCaml 5</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-fuseau-0-1/14157">[ANN] fuseau 0.1</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-fuseau-0-1/14157">[ANN] fuseau 0.1</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/issuu/ocaml-protoc-plugin">GitHub - issuu&#x2F;ocaml-protoc-plugin: ocaml-protoc-plugin</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/issuu/ocaml-protoc-plugin">GitHub - issuu/ocaml-protoc-plugin: ocaml-protoc-plugin</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/taking-over-maintanence-of-a-stale-project/14156">Taking over maintanence of a stale project</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/taking-over-maintanence-of-a-stale-project/14156">Taking over maintanence of a stale project</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://github.com/darrenldl/docfd">GitHub - darrenldl&#x2F;docfd: TUI multiline fuzzy document finder</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://github.com/darrenldl/docfd">GitHub - darrenldl/docfd: TUI multiline fuzzy document finder</a></p>
</li>
-<li><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-docfd-tui-multiline-fuzzy-document-finder-2-2-0/14109/1">[ANN] Docfd: TUI multiline fuzzy document finder 2.2.0</a></p>
+<li>
+<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-docfd-tui-multiline-fuzzy-document-finder-2-2-0/14109/1">[ANN] Docfd: TUI multiline fuzzy document finder 2.2.0</a></p>
</li>
</ul>
diff --git a/2024/03/22/二〇二四年三月二十二日/index.html b/2024/03/22/二〇二四年三月二十二日/index.html
index 9f9b451e..c0f0a672 100644
--- a/2024/03/22/二〇二四年三月二十二日/index.html
+++ b/2024/03/22/二〇二四年三月二十二日/index.html
@@ -184,12 +184,18 @@
</div>
</div>
<div class="post-content">
- <p>毛毛在人群中牵着我,却很难融入人群,我在林中面对着毛毛,树木的思想却千姿百态地向我涌来。<br>它说,它要将灵魂撕裂,让它暴露在最灼热的阳光下灼烧,要让风刺进来,硬生生扯开一道口子,要让原有的赤色消失殆尽,只留下一堆松散的灰色颗粒,任雨打浮萍。</p>
-<p>毛毛和我看到了宇宙熵增,和我见到了熙攘的街道,现在变成了我耳边的风声。<br>是啊,是啊,你不再身陷囹圄,自由不再是攀在高墙上爬山虎的叶子,不再是吹进风间的花粉,不再是藏躲进阴暗土地里的水,不再是破碎割手的杯子片块。<br>但是这个世界还是越来越美了,我独自一人,却很自在,别无所求,只想被阳光晒透,被狂风穿过。渴望成熟,要准备好死去,也准备好重生。</p>
+ <p>毛毛在人群中牵着我,却很难融入人群,我在林中面对着毛毛,树木的思想却千姿百态地向我涌来。<br>
+它说,它要将灵魂撕裂,让它暴露在最灼热的阳光下灼烧,要让风刺进来,硬生生扯开一道口子,要让原有的赤色消失殆尽,只留下一堆松散的灰色颗粒,任雨打浮萍。</p>
+<p>毛毛和我看到了宇宙熵增,和我见到了熙攘的街道,现在变成了我耳边的风声。<br>
+是啊,是啊,你不再身陷囹圄,自由不再是攀在高墙上爬山虎的叶子,不再是吹进风间的花粉,不再是藏躲进阴暗土地里的水,不再是破碎割手的杯子片块。<br>
+但是这个世界还是越来越美了,我独自一人,却很自在,别无所求,只想被阳光晒透,被狂风穿过。渴望成熟,要准备好死去,也准备好重生。</p>
<hr>
<p>小土堆上长出了狗尾巴草,当我靠近时,狗尾巴草会向我轻轻晃动,就像它小时候向我跑来时那样,不同的是,当我向前跑的时候,背后没有一个小小的身影再追过来了,但当我回望小土堆,狗尾巴草依然在摇晃,就像当初给予我回应那样。</p>
<hr>
-<p>狗儿要听狗儿歌,<br>毛毛下雨要回家,<br>小狗小狗画梅花,<br>直走就是我们家。</p>
+<p>狗儿要听狗儿歌,<br>
+毛毛下雨要回家,<br>
+小狗小狗画梅花,<br>
+直走就是我们家。</p>
</div>
diff --git a/2024/04/08/二〇二四年四月八日/index.html b/2024/04/08/二〇二四年四月八日/index.html
index 74a86016..cbcf68be 100644
--- a/2024/04/08/二〇二四年四月八日/index.html
+++ b/2024/04/08/二〇二四年四月八日/index.html
@@ -184,7 +184,11 @@
</div>
</div>
<div class="post-content">
- <p>我不预设和任何人事物共度一生,<br>就自然的生活,<br>命运把我带到哪里就到哪里,<br>有缘的话,我会在世界中看见你,<br>无缘的话,我会看见你在世界中。</p>
+ <p>我不预设和任何人事物共度一生,<br>
+就自然的生活,<br>
+命运把我带到哪里就到哪里,<br>
+有缘的话,我会在世界中看见你,<br>
+无缘的话,我会看见你在世界中。</p>
<p>我为人们的开心而开心,诚恳,真诚的请求看到这里的人们每天都要笑一笑哦,你们真的真的对我很重要。</p>
</div>
diff --git a/2024/05/07/二〇二四年五月七日/index.html b/2024/05/07/二〇二四年五月七日/index.html
index e241a2f3..ef899859 100644
--- a/2024/05/07/二〇二四年五月七日/index.html
+++ b/2024/05/07/二〇二四年五月七日/index.html
@@ -184,9 +184,23 @@
</div>
</div>
<div class="post-content">
- <p>我在写信<br>寄给羊水<br>信里提到<br>宇宙称呼它为灰<br>我们叫地球<br>还提到<br>风车不能骑<br>但是石头可以打水漂<br>你呀<br>到时别忘了<br>用小小的哭声款待我</p>
+ <p>我在写信<br>
+寄给羊水<br>
+信里提到<br>
+宇宙称呼它为灰<br>
+我们叫地球<br>
+还提到<br>
+风车不能骑<br>
+但是石头可以打水漂<br>
+你呀<br>
+到时别忘了<br>
+用小小的哭声款待我</p>
<hr>
-<p>我们应该坐在一起发呆<br>发很久的呆<br>然后我说人类好无聊啊<br>这个地球完蛋了<br>你点点头</p>
+<p>我们应该坐在一起发呆<br>
+发很久的呆<br>
+然后我说人类好无聊啊<br>
+这个地球完蛋了<br>
+你点点头</p>
</div>
diff --git a/2024/05/16/二〇二四年五月十六日/index.html b/2024/05/16/二〇二四年五月十六日/index.html
index 4abe50cf..25ef30a4 100644
--- a/2024/05/16/二〇二四年五月十六日/index.html
+++ b/2024/05/16/二〇二四年五月十六日/index.html
@@ -190,10 +190,11 @@
<p>多尝试点事情吧,试得越多,就能越快判断出自己是不是这块料。如果是,很好;如果不是,过,下一个。在这期间不要有任何心态波澜,行就是行,不行就是不行。反正不是非行不可。</p>
<p>人自信不是样样精通、事事皆成,凡事都做得比别人更好;自信是一个高级陷阱,仰赖自信的人终有一日会崩塌于自信的毁灭。</p>
<p>用生命力来取代往日的自信心,用绝对强大的权力意志来取代往日相对成功的小胜小利。</p>
-<p>不放弃的理由不是因为自信,而是因为知道这事必须得干&#x2F;行得通;放弃的理由也不是因为不自信,而是因为知道这事不能去干&#x2F;行不通。</p>
+<p>不放弃的理由不是因为自信,而是因为知道这事必须得干/行得通;放弃的理由也不是因为不自信,而是因为知道这事不能去干/行不通。</p>
<p>而一旦在理性和感性层面都认为必须办成某件事,那就不顾一切去办成。哪怕绕再多的路,要办的事就是要办。</p>
<p>当不再局限于自信或自卑,而是立足于实事求是去布局和行动,一切都会变得更加清晰明了。若想成事,首先要花时间去搞明白自己的长处与短板,然后学会在面对具体事项之际快速判断自己行不行、是不是非做不可、要做的话又有几分把握、失败了要如何应对、要不要改变其中某些变量再多试几次。</p>
-<p>当有了一个目标,需要的不是豪言壮志,不是任何心理建设,而是尽快上手去做。<br>做一件事,无关心态,只要去做就是了。发挥最大的主观能动性,遇到问题就解决,碰到障碍就破开,需要帮助就求助。别因为所谓的自信就盲目冒进,也别因为所谓的自卑就胆小退缩,那俩玩意都不存在。</p>
+<p>当有了一个目标,需要的不是豪言壮志,不是任何心理建设,而是尽快上手去做。<br>
+做一件事,无关心态,只要去做就是了。发挥最大的主观能动性,遇到问题就解决,碰到障碍就破开,需要帮助就求助。别因为所谓的自信就盲目冒进,也别因为所谓的自卑就胆小退缩,那俩玩意都不存在。</p>
<p>尊重事情本身的客观发展规律,什么样的人匹配什么样的事,什么样的条件匹配什么样的理想。别把心态想得太重要,更别花太多时间精力去建设心态,客观规律不会因为心态就发生奇迹般地转变。</p>
<p>你最好趁早学会尊重客观规律。</p>
diff --git a/2024/05/20/Rescript-genType-import-问题/index.html b/2024/05/20/Rescript-genType-import-问题/index.html
index 060d77b2..607c75e2 100644
--- a/2024/05/20/Rescript-genType-import-问题/index.html
+++ b/2024/05/20/Rescript-genType-import-问题/index.html
@@ -194,20 +194,19 @@
<div class="post-content">
<p>Rescript 11 之后,<code>@genType</code> 被合并进编译器,无需任何依赖就能使用,当在 Rescript 中 <code>@genType</code> 了使用某些 Rescript built-in 的基本类型时,可能会生成有问题的 <code>import</code> 相关代码,例如:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">@genType</span><br><span class="line">module LoginResponse = &#123;</span><br><span class="line"> let status = response =&gt; &#123;</span><br><span class="line"> response</span><br><span class="line"> -&gt;Js.Json.decodeObject</span><br><span class="line"> -&gt;Option.flatMap(response =&gt; &#123;</span><br><span class="line"> response-&gt;Js_dict.get(&quot;status&quot;)</span><br><span class="line"> &#125;)</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
<p><code>status</code> 函数具有 <code>Js.Json.t =&gt; option&lt;Js.Json.t&gt;</code> 类型,那么在生成的 TypeScript 文件中,会出现这样的 import:</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="keyword">type</span> &#123; <span class="title class_">Json</span>_t <span class="keyword">as</span> <span class="title class_">Js</span>_Json_t &#125; <span class="keyword">from</span> <span class="string">&quot;./Js.gen.tsx&quot;</span></span><br></pre></td></tr></table></figure>
-
<p>而 <code>Js.gen.tsx</code> 这个文件是不存在的,解决方案是使用 <code>@genType</code> 的 <code>shim</code>:</p>
<ul>
-<li><p>在 <code>rescript.json</code> 中的 <code>gentypeconfig</code> 中添加 <code>shim</code> 配置:</p>
+<li>在 <code>rescript.json</code> 中的 <code>gentypeconfig</code> 中添加 <code>shim</code> 配置:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="attr">&quot;gentypeconfig&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">...</span><br><span class="line"> <span class="attr">&quot;shims&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;Js&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Js&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">...</span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure>
-</li>
-<li><p>然后新建 <code>Js.shim.ts</code>:</p>
+<ul>
+<li>然后新建 <code>Js.shim.ts</code>:</li>
+</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> <span class="title class_">Json</span>_t = <span class="built_in">unknown</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> t = <span class="built_in">unknown</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> <span class="title class_">Exn</span>_t = <span class="title class_">Error</span>;</span><br></pre></td></tr></table></figure>
-</li>
-<li><p>删除原来由 <code>@genType</code> 生成的 TypeScript 文件并重新生成</p>
-</li>
+<ul>
+<li>删除原来由 <code>@genType</code> 生成的 TypeScript 文件并重新生成</li>
</ul>
<p>现在生成的 TypeScript 文件将会从 <code>Js.shim.ts</code> import 类型:</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="keyword">type</span> &#123;<span class="title class_">Json</span>_t <span class="keyword">as</span> <span class="title class_">Js</span>_Json_t&#125; <span class="keyword">from</span> <span class="string">&#x27;../../src/model/Js.shim.ts&#x27;</span>;</span><br></pre></td></tr></table></figure>
diff --git a/2024/06/06/NET-AOT-下的-F-命令行参数解析库选择/index.html b/2024/06/06/NET-AOT-下的-F-命令行参数解析库选择/index.html
index 68a607bf..1c605526 100644
--- a/2024/06/06/NET-AOT-下的-F-命令行参数解析库选择/index.html
+++ b/2024/06/06/NET-AOT-下的-F-命令行参数解析库选择/index.html
@@ -192,9 +192,12 @@
</div>
</div>
<div class="post-content">
- <p>Argu 不支持 AOT,不过用 F# 的话可以看整个 .NET 的生态,我看了一下 C# 的 CommandLineParser:<br><a target="_blank" rel="noopener" href="https://github.com/commandlineparser">https://github.com/commandlineparser</a></p>
-<p>在这个 PR 中支持了 Native AOT<br><a target="_blank" rel="noopener" href="https://github.com/commandlineparser/commandline/pull/913">https://github.com/commandlineparser/commandline/pull/913</a></p>
-<p>除此之外,还有一个更加精巧的 F# 库可以用,只有两百多行:<br><a target="_blank" rel="noopener" href="https://github.com/B2R2-org/FsOptParse/">https://github.com/B2R2-org/FsOptParse/</a></p>
+ <p>Argu 不支持 AOT,不过用 F# 的话可以看整个 .NET 的生态,我看了一下 C# 的 CommandLineParser:<br>
+<a target="_blank" rel="noopener" href="https://github.com/commandlineparser">https://github.com/commandlineparser</a></p>
+<p>在这个 PR 中支持了 Native AOT<br>
+<a target="_blank" rel="noopener" href="https://github.com/commandlineparser/commandline/pull/913">https://github.com/commandlineparser/commandline/pull/913</a></p>
+<p>除此之外,还有一个更加精巧的 F# 库可以用,只有两百多行:<br>
+<a target="_blank" rel="noopener" href="https://github.com/B2R2-org/FsOptParse/">https://github.com/B2R2-org/FsOptParse/</a></p>
<p>AOT 后的大小很可观,并且支持 full trim.</p>
<p>用例:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">(** defines a state to pass to the option parser *)</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">opts</span> <span class="operator">=</span></span><br><span class="line"> &#123;</span><br><span class="line"> optX <span class="operator">:</span> <span class="type">int</span>;</span><br><span class="line"> optY <span class="operator">:</span> <span class="type">bool</span>;</span><br><span class="line"> optZ <span class="operator">:</span> <span class="type">string</span>;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">(** default option state *)</span></span><br><span class="line"><span class="keyword">let</span> defaultOpts <span class="operator">=</span></span><br><span class="line"> &#123;</span><br><span class="line"> optX <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"> optY <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line"> optZ <span class="operator">=</span> <span class="string">&quot;&quot;</span>;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">(*</span></span><br><span class="line"><span class="comment"> An example command line specification, which is a list of Options.</span></span><br><span class="line"><span class="comment"> Each Option describes a command line option (switch) that is specified with</span></span><br><span class="line"><span class="comment"> either a short (a single-dash option) or long option (a double-dash option).</span></span><br><span class="line"><span class="comment">*)</span></span><br><span class="line"><span class="keyword">let</span> spec <span class="operator">=</span></span><br><span class="line"> [</span><br><span class="line"> <span class="comment">(* This option can be specified with -x &lt;NUM&gt;. There is an extra argument to</span></span><br><span class="line"><span class="comment"> specify a value in integer. *)</span></span><br><span class="line"> Option (<span class="comment">(* description of the option *)</span></span><br><span class="line"> descr<span class="operator">=</span><span class="string">&quot;this is a testing param X&quot;</span>,</span><br><span class="line"> <span class="comment">(* how many extra argument must be provided by a user? *)</span></span><br><span class="line"> extra<span class="operator">=</span><span class="number">1</span>,</span><br><span class="line"> <span class="comment">(* callback sets up the option and returns it *)</span></span><br><span class="line"> callback<span class="operator">=</span>(<span class="keyword">fun</span> opts arg <span class="operator">-&gt;</span> &#123;opts <span class="keyword">with</span> optX<span class="operator">=</span>(int) arg.[<span class="number">0</span>]&#125;),</span><br><span class="line"> <span class="comment">(* use a short option style -x *)</span></span><br><span class="line"> short<span class="operator">=</span><span class="string">&quot;-x&quot;</span></span><br><span class="line"> );</span><br><span class="line"></span><br><span class="line"> <span class="comment">(* This option can be specified with -y. There is no extra argument. This</span></span><br><span class="line"><span class="comment"> option just sets a flag, optY. *)</span></span><br><span class="line"> Option (<span class="comment">(* description of the option *)</span></span><br><span class="line"> descr<span class="operator">=</span><span class="string">&quot;this is a testing param Y&quot;</span>,</span><br><span class="line"> <span class="comment">(* set the option to be true *)</span></span><br><span class="line"> callback<span class="operator">=</span>(<span class="keyword">fun</span> opts _ <span class="operator">-&gt;</span> &#123;opts <span class="keyword">with</span> optY<span class="operator">=</span><span class="literal">true</span>&#125;),</span><br><span class="line"> <span class="comment">(* use a short option style (-y) *)</span></span><br><span class="line"> short<span class="operator">=</span><span class="string">&quot;-y&quot;</span>,</span><br><span class="line"> <span class="comment">(* also use a long option style (--yoohoo) *)</span></span><br><span class="line"> long<span class="operator">=</span><span class="string">&quot;--yoohoo&quot;</span></span><br><span class="line"> );</span><br><span class="line"></span><br><span class="line"> <span class="comment">(* A dummy option to pretty-print the usage *)</span></span><br><span class="line"> Option (<span class="comment">(* description of the option *)</span></span><br><span class="line"> descr<span class="operator">=</span><span class="string">&quot;&quot;</span>,</span><br><span class="line"> dummy<span class="operator">=</span><span class="literal">true</span></span><br><span class="line"> );</span><br><span class="line"> Option (<span class="comment">(* description of the option *)</span></span><br><span class="line"> descr<span class="operator">=</span><span class="string">&quot;[Required Options]&quot;</span>,</span><br><span class="line"> descrColor<span class="operator">=</span>System.ConsoleColor.DarkCyan,</span><br><span class="line"> dummy<span class="operator">=</span><span class="literal">true</span></span><br><span class="line"> );</span><br><span class="line"></span><br><span class="line"> <span class="comment">(* The third option is a required option. In other words, option parsing</span></span><br><span class="line"><span class="comment"> will raise an exception if this option is not given by a user. This</span></span><br><span class="line"><span class="comment"> option takes in an additional integer argument, and set it to the global</span></span><br><span class="line"><span class="comment"> variable z. *)</span></span><br><span class="line"> Option (<span class="comment">(* description of the option *)</span></span><br><span class="line"> descr<span class="operator">=</span><span class="string">&quot;required parameter &lt;STRING&gt; with an integer option&quot;</span>,</span><br><span class="line"> <span class="comment">(* callback to set the optZ value *)</span></span><br><span class="line"> callback<span class="operator">=</span>(<span class="keyword">fun</span> opts arg <span class="operator">-&gt;</span> &#123;opts <span class="keyword">with</span> optZ<span class="operator">=</span>arg.[<span class="number">0</span>]&#125;),</span><br><span class="line"> <span class="comment">(* specifying this is a required option *)</span></span><br><span class="line"> required<span class="operator">=</span><span class="literal">true</span>,</span><br><span class="line"> <span class="comment">(* one additional argument to specify an integer value *)</span></span><br><span class="line"> extra<span class="operator">=</span><span class="number">1</span>,</span><br><span class="line"> <span class="comment">(* use only a long option style *)</span></span><br><span class="line"> long<span class="operator">=</span><span class="string">&quot;--req&quot;</span></span><br><span class="line"> );</span><br><span class="line"> ]</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> _ <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> prog <span class="operator">=</span> <span class="string">&quot;opttest.fsx&quot;</span></span><br><span class="line"> <span class="keyword">let</span> args <span class="operator">=</span> System.Environment.GetCommandLineArgs ()</span><br><span class="line"> <span class="keyword">let</span> usageGetter () <span class="operator">=</span> <span class="string">&quot;[Usage]\n %p %o&quot;</span></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> <span class="keyword">let</span> left, opts <span class="operator">=</span> optParse spec usageGetter prog args defaultOpts</span><br><span class="line"> <span class="built_in">printfn</span> <span class="string">&quot;Rest args: %A, x: %d, y: %b, z: %s&quot;</span></span><br><span class="line"> left opts.optX opts.optY opts.optZ</span><br><span class="line"> <span class="number">0</span></span><br><span class="line"> <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> SpecErr msg <span class="operator">-&gt;</span></span><br><span class="line"> <span class="built_in">eprintfn</span> <span class="string">&quot;Invalid spec: %s&quot;</span> msg</span><br><span class="line"> exit <span class="number">1</span></span><br><span class="line"> <span class="operator">|</span> RuntimeErr msg <span class="operator">-&gt;</span></span><br><span class="line"> <span class="built_in">eprintfn</span> <span class="string">&quot;Invalid args given by user: %s&quot;</span> msg</span><br><span class="line"> usagePrint spec prog usageGetter (<span class="keyword">fun</span> () <span class="operator">-&gt;</span> exit <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
diff --git a/2024/06/27/OCaml-News-2024-5/index.html b/2024/06/27/OCaml-News-2024-5/index.html
index 198d695e..6b45e5ad 100644
--- a/2024/06/27/OCaml-News-2024-5/index.html
+++ b/2024/06/27/OCaml-News-2024-5/index.html
@@ -192,58 +192,70 @@
</div>
</div>
<div class="post-content">
- <h2 id="语言的发展"><a href="#语言的发展" class="headerlink" title="语言的发展"></a>语言的发展</h2><ul>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097: This PR proposes to add immutable arrays to OCaml.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13199">Support running native debuggers in ocamltest #13199</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13152">The Pattern-Matching Bug: fix totality information by gasche · Pull Request #13152 · ocaml&#x2F;ocaml</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/11974%23discussion_r1621832545">Add loongarch architecture support #11974</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13101">Add Stdlib.todo #13101</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-26-enhancing-the-ocaml-org-community-page-boosting-ux-and-ui-based-on-user-research/">Enhancing the OCaml.org Community Page: Boosting UX and UI Based on User Research.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-22-launching-the-first-class-windows-project/">Launching the First-Class Windows Project</a>.</li>
+ <h2 id="语言的发展"><a class="header-anchor" href="#语言的发展">¶</a>语言的发展</h2>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097: This PR proposes to add immutable arrays to OCaml.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13199">Support running native debuggers in ocamltest #13199</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13152">The Pattern-Matching Bug: fix totality information by gasche · Pull Request #13152 · ocaml/ocaml</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/11974%23discussion_r1621832545">Add loongarch architecture support #11974</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13101">Add Stdlib.todo #13101</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-06-26-enhancing-the-ocaml-org-community-page-boosting-ux-and-ui-based-on-user-research/">Enhancing the OCaml.org Community Page: Boosting UX and UI Based on User Research.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-05-22-launching-the-first-class-windows-project/">Launching the First-Class Windows Project</a>.</li>
</ul>
-<h2 id="新消息"><a href="#新消息" class="headerlink" title="新消息"></a>新消息</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847">[ANN] Project wide occurrences in Merlin and LSP</a>.</p>
+<h2 id="新消息"><a class="header-anchor" href="#新消息">¶</a>新消息</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847">[ANN] Project wide occurrences in Merlin and LSP</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-opam-2-2-0-rc1-release/14842">[ANN] opam 2.2.0 rc1 release</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-opam-2-2-0-rc1-release/14842">[ANN] opam 2.2.0 rc1 release</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-first-release-of-baby/14840">[ANN] First release of baby</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-first-release-of-baby/14840">[ANN] First release of baby</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">baby</a> is an OCaml library that offers several implementations of balanced binary search trees.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/fpottier/baby">baby</a> is an OCaml library that offers several implementations of balanced binary search trees.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-preview-of-stripe-client-and-mock-server-dkstdrestapis/14841">[ANN] Preview of Stripe client and mock server - DkStdRestApis</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-preview-of-stripe-client-and-mock-server-dkstdrestapis/14841">[ANN] Preview of Stripe client and mock server - DkStdRestApis</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-caisar-release-2-0-a-platform-for-characterizing-ai-safety-and-robustness/14831">[ANN] CAISAR release 2.0, a platform for characterizing AI safety and robustness</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-caisar-release-2-0-a-platform-for-characterizing-ai-safety-and-robustness/14831">[ANN] CAISAR release 2.0, a platform for characterizing AI safety and robustness</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-forester-4-1/14800">[ANN] Forester 4.1</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-forester-4-1/14800">[ANN] Forester 4.1</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808">[ANN] dream-html &amp; pure-html 3.5.2</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808">[ANN] dream-html &amp; pure-html 3.5.2</a></p>
</li>
</ul>
-<h2 id="有价值的文章"><a href="#有价值的文章" class="headerlink" title="有价值的文章"></a>有价值的文章</h2><ul>
-<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-19-keeping-up-with-the-compiler-how-we-help-maintain-the-ocaml-language/">Keeping Up With the Compiler: How we Help Maintain the OCaml Language</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/10995">Explain mapping between OCaml memory model and C.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://xavierleroy.org/CdF/2023-2024/index.html">Control structures – Xavier Leroy</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://dev.to/chshersh/8-months-of-ocaml-after-8-years-of-haskell-in-production-h96">8 months of OCaml after 8 years of Haskell in production</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://hypirion.com/musings/getting-ocaml-through-the-eye-of-a-needle">Getting OCaml Through the Eye of a Needle</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-05-secure-from-the-ground-up-introducing-the-fides-project-combining-risc-v-and-mirageos/">Secure From the Ground Up: Introducing the FIDES Project Combining RISC-V and MirageOS.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/">Effective ML Through Merlin’s Destruct Command.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://blog.osau.re/articles/reproducible.html">Dinosaure’s website - Reproducibility!</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/experiments-in-jitting/14853">Experiments in JITting</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/how-to-write-an-efficient-cp-r-clone-with-eio/14848">How to write an efficient ‘cp -R’ clone with Eio?</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/generating-infix-extension-nodes-with-ppxlib/14833">Generating infix extension nodes with Ppxlib</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/this-made-my-day-float-to-string-and-string-of-float-without-loss-of-precision/14825">This made my day (float to string and string of float without loss of precision)</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/help-with-cryptic-dependency-cycle-compile-errors-using-dune-build/14864">Help with cryptic dependency cycle compile errors using <code>dune build</code></a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/why-does-relaxed-value-restriction-treat-function-types-differently/14802">Why does relaxed value restriction treat function types differently?</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/binding-existentials-in-a-non-uniform-gadt/14809">Binding existentials in a non-uniform GADT</a>.</li>
+<h2 id="有价值的文章"><a class="header-anchor" href="#有价值的文章">¶</a>有价值的文章</h2>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-06-19-keeping-up-with-the-compiler-how-we-help-maintain-the-ocaml-language/">Keeping Up With the Compiler: How we Help Maintain the OCaml Language</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/10995">Explain mapping between OCaml memory model and C.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//xavierleroy.org/CdF/2023-2024/index.html">Control structures – Xavier Leroy</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//dev.to/chshersh/8-months-of-ocaml-after-8-years-of-haskell-in-production-h96">8 months of OCaml after 8 years of Haskell in production</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//hypirion.com/musings/getting-ocaml-through-the-eye-of-a-needle">Getting OCaml Through the Eye of a Needle</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-06-05-secure-from-the-ground-up-introducing-the-fides-project-combining-risc-v-and-mirageos/">Secure From the Ground Up: Introducing the FIDES Project Combining RISC-V and MirageOS.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/">Effective ML Through Merlin’s Destruct Command.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//blog.osau.re/articles/reproducible.html">Dinosaure’s website - Reproducibility!</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/experiments-in-jitting/14853">Experiments in JITting</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/how-to-write-an-efficient-cp-r-clone-with-eio/14848">How to write an efficient ‘cp -R’ clone with Eio?</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/generating-infix-extension-nodes-with-ppxlib/14833">Generating infix extension nodes with Ppxlib</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/this-made-my-day-float-to-string-and-string-of-float-without-loss-of-precision/14825">This made my day (float to string and string of float without loss of precision)</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/help-with-cryptic-dependency-cycle-compile-errors-using-dune-build/14864">Help with cryptic dependency cycle compile errors using <code>dune build</code></a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/why-does-relaxed-value-restriction-treat-function-types-differently/14802">Why does relaxed value restriction treat function types differently?</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/binding-existentials-in-a-non-uniform-gadt/14809">Binding existentials in a non-uniform GADT</a>.</li>
</ul>
-<h2 id="有趣的项目"><a href="#有趣的项目" class="headerlink" title="有趣的项目"></a>有趣的项目</h2><ul>
-<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/ocaml-index/latest">ocaml-index 1.0 (latest) · OCaml Package: A tool that indexes value usages from cmt files</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/fileutils/latest">fileutils 0.6.4 (latest) · OCaml Package: API to manipulate files (POSIX like) and filenames.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/pure-html/latest">pure-html 3.5.2 (latest) · OCaml Package</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">GitHub - fpottier&#x2F;baby: A balanced binary search tree library for OCaml</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/akabe/ocaml-jupyter">GitHub - akabe&#x2F;ocaml-jupyter: An OCaml kernel for Jupyter (IPython) notebook</a>.</li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/robur-coop/orb">Github - robur-coop&#x2F;orb: check opam package reproductibility.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/dscheck%23motivation">Github - ocaml-multicore&#x2F;dscheck: Experimental model checker for testing concurrent algorithms.</a></li>
+<h2 id="有趣的项目"><a class="header-anchor" href="#有趣的项目">¶</a>有趣的项目</h2>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//ocaml.org/p/ocaml-index/latest">ocaml-index 1.0 (latest) · OCaml Package: A tool that indexes value usages from cmt files</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//ocaml.org/p/fileutils/latest">fileutils 0.6.4 (latest) · OCaml Package: API to manipulate files (POSIX like) and filenames.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//ocaml.org/p/pure-html/latest">pure-html 3.5.2 (latest) · OCaml Package</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/fpottier/baby">GitHub - fpottier/baby: A balanced binary search tree library for OCaml</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/akabe/ocaml-jupyter">GitHub - akabe/ocaml-jupyter: An OCaml kernel for Jupyter (IPython) notebook</a>.</li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/robur-coop/orb">Github - robur-coop/orb: check opam package reproductibility.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-multicore/dscheck%23motivation">Github - ocaml-multicore/dscheck: Experimental model checker for testing concurrent algorithms.</a></li>
</ul>
</div>
diff --git a/2024/06/27/二〇二四年六月二十七日/index.html b/2024/06/27/二〇二四年六月二十七日/index.html
index ebfa85b1..903b3aaf 100644
--- a/2024/06/27/二〇二四年六月二十七日/index.html
+++ b/2024/06/27/二〇二四年六月二十七日/index.html
@@ -184,7 +184,11 @@
</div>
</div>
<div class="post-content">
- <p>钟摆晃荡 走出时间,<br>面包屑洒了一地 变成星空,<br>玻璃杯留下的牛奶唇印、折射出极光,<br>​狂犬症发病具有潜伏期,<br>宇宙说它也会倦怠、凋落,</p>
+ <p>钟摆晃荡 走出时间,<br>
+面包屑洒了一地 变成星空,<br>
+玻璃杯留下的牛奶唇印、折射出极光,<br>
+​狂犬症发病具有潜伏期,<br>
+宇宙说它也会倦怠、凋落,</p>
<p>身后伟岸的森林倒下了,我最大的遗失是没有了后悔的权利,我的忽视酿成了天地两别再无可相见的结局。</p>
<p>我的眼睛面积一定小于湖,我也很少哭,你若坐在我面前,就像站在湖边,细细的雾水就扯着地连着天。</p>
<blockquote>
diff --git a/2024/07/01/OCaml-News-2024-4/index.html b/2024/07/01/OCaml-News-2024-4/index.html
index 432ce7e8..bf6aabf1 100644
--- a/2024/07/01/OCaml-News-2024-4/index.html
+++ b/2024/07/01/OCaml-News-2024-4/index.html
@@ -192,115 +192,167 @@
</div>
</div>
<div class="post-content">
- <h2 id="那么接下来"><a href="#那么接下来" class="headerlink" title="那么接下来"></a>那么接下来</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/first-beta-release-for-ocaml-5-2-0/14356">First beta release for OCaml 5.2.0</a>.</p>
+ <h2 id="那么接下来"><a class="header-anchor" href="#那么接下来">¶</a>那么接下来</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/first-beta-release-for-ocaml-5-2-0/14356">First beta release for OCaml 5.2.0</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12876">#12876</a> 和 <a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12915">#12915</a> 提供了 ThreadSanitizer 对 Power 和 s390x 上的 Linux 支持。</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12876">#12876</a> 和 <a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12915">#12915</a> 提供了 ThreadSanitizer 对 Power 和 s390x 上的 Linux 支持。</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12677">#12677</a> 和 <a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12889">#12889</a> 实现了 <code>Domain.DLS</code> 的线程安全。</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12677">#12677</a> 和 <a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12889">#12889</a> 实现了 <code>Domain.DLS</code> 的线程安全。</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12924">#12924</a> 和 <a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/issues/12930">#12930</a> 提到了一个类型系统的错误和其修复方式(merged):</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12924">#12924</a> 和 <a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/issues/12930">#12930</a> 提到了一个类型系统的错误和其修复方式(merged):</p>
</li>
</ul>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="keyword">type</span> <span class="type">S</span> = <span class="keyword">sig</span></span><br><span class="line"> <span class="keyword">type</span> t [@@immediate]</span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> t = (<span class="keyword">module</span> <span class="type">S</span> <span class="keyword">with</span> <span class="keyword">type</span> t = <span class="built_in">int</span>)</span><br><span class="line"> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span><br><span class="line"><span class="comment">(*</span></span><br><span class="line"><span class="comment">Error: In this with constraint, the new definition of t</span></span><br><span class="line"><span class="comment"> does not match its original definition in the constrained signature:</span></span><br><span class="line"><span class="comment"> Type declarations do not match:</span></span><br><span class="line"><span class="comment"> type t</span></span><br><span class="line"><span class="comment"> is not included in</span></span><br><span class="line"><span class="comment"> type t [@@immediate]</span></span><br><span class="line"><span class="comment"> The first is not an immediate type.</span></span><br><span class="line"><span class="comment">*)</span></span><br></pre></td></tr></table></figure>
-
<ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-4-14-2-released/14308">OCaml 4.14.2 released</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-4-14-2-released/14308">OCaml 4.14.2 released</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/owl-project-restructured/14226">Owl project restructured</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/owl-project-restructured/14226">Owl project restructured</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/your-feedback-needed-on-ocaml-home-page-wireframe/14366">Your Feedback Needed on OCaml Home Page Wireframe!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/your-feedback-needed-on-ocaml-home-page-wireframe/14366">Your Feedback Needed on OCaml Home Page Wireframe!</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/shape-with-us-the-new-ocaml-org-community-area/14322">Shape with us the New OCaml.org Community Area!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/shape-with-us-the-new-ocaml-org-community-area/14322">Shape with us the New OCaml.org Community Area!</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-platform-newsletter-february-2024/14361">OCaml Platform Newsletter: February 2024</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-platform-newsletter-february-2024/14361">OCaml Platform Newsletter: February 2024</a>.</p>
</li>
-<li><p>其中值得注意的是:<a href="https://link.zhihu.com/?target=https://ocaml.org/docs/platform-roadmap%23w4-build-a-project">探索 dune 和包管理的集成</a> 和 <a href="https://link.zhihu.com/?target=https://ocaml.org/docs/platform-roadmap%23w5-manage-dependencies">opam 2.2 的 Windows Native support</a>.</p>
+<li>
+<p>其中值得注意的是:<a href="https://link.zhihu.com/?target=https%3A//ocaml.org/docs/platform-roadmap%23w4-build-a-project">探索 dune 和包管理的集成</a> 和 <a href="https://link.zhihu.com/?target=https%3A//ocaml.org/docs/platform-roadmap%23w5-manage-dependencies">opam 2.2 的 Windows Native support</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-workshop-2024-at-icfp-announcement-and-call-for-proposals/14371">OCaml Workshop 2024 at ICFP – announcement and call for proposals</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-workshop-2024-at-icfp-announcement-and-call-for-proposals/14371">OCaml Workshop 2024 at ICFP – announcement and call for proposals</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/volunteers-for-icfp-2024-artifact-evaluation-committee-aec/14355">Volunteers for ICFP 2024 Artifact Evaluation Committee (AEC)</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/volunteers-for-icfp-2024-artifact-evaluation-committee-aec/14355">Volunteers for ICFP 2024 Artifact Evaluation Committee (AEC)</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/odoc-3-0-planning/14360">Odoc 3.0 planning</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/odoc-3-0-planning/14360">Odoc 3.0 planning</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/opam-repository-updated-documentation-retirement-and-call-for-maintainers/14325">Opam-repository: Updated documentation, retirement and call for maintainers</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/opam-repository-updated-documentation-retirement-and-call-for-maintainers/14325">Opam-repository: Updated documentation, retirement and call for maintainers</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/u/kit-ty-kate">kit-ty-kate</a> 退休啦。</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/u/kit-ty-kate">kit-ty-kate</a> 退休啦。</p>
</li>
</ul>
-<h2 id="论文"><a href="#论文" class="headerlink" title="论文"></a>论文</h2><ul>
-<li><a href="https://link.zhihu.com/?target=https://jcheminf.biomedcentral.com/articles/10.1186/s13321-019-0332-0">Chemoinformatics and structural bioinformatics in OCaml</a>.</li>
+<h2 id="论文"><a class="header-anchor" href="#论文">¶</a>论文</h2>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//jcheminf.biomedcentral.com/articles/10.1186/s13321-019-0332-0">Chemoinformatics and structural bioinformatics in OCaml</a>.</li>
</ul>
-<h2 id="帖子-文章"><a href="#帖子-文章" class="headerlink" title="帖子&#x2F;文章"></a>帖子&#x2F;文章</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-for-building-shared-libraries-how-are-the-ergonomics-and-performance/14352">OCaml for building shared libraries: how are the ergonomics and performance?</a></p>
+<h2 id="帖子-文章"><a class="header-anchor" href="#帖子-文章">¶</a>帖子/文章</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-for-building-shared-libraries-how-are-the-ergonomics-and-performance/14352">OCaml for building shared libraries: how are the ergonomics and performance?</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://mccd.space/posts/awk-with-kakoune/">Using Awk in Kakoune to Generate SQL Types for OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//mccd.space/posts/awk-with-kakoune/">Using Awk in Kakoune to Generate SQL Types for OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-03-20-eio-1-0-release-introducing-a-new-effects-based-i-o-library-for-ocaml/">Eio 1.0 Release: Introducing a new Effects-Based I&#x2F;O Library for OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//tarides.com/blog/2024-03-20-eio-1-0-release-introducing-a-new-effects-based-i-o-library-for-ocaml/">Eio 1.0 Release: Introducing a new Effects-Based I/O Library for OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/blog-the-flambda2-snippets-by-ocamlpro/14331">[BLOG] The Flambda2 Snippets, by OCamlPro</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/blog-the-flambda2-snippets-by-ocamlpro/14331">[BLOG] The Flambda2 Snippets, by OCamlPro</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://ocamlpro.com/blog/2024_03_18_the_flambda2_snippets_0/">The Flambda2 Snippets, Episode 0</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//ocamlpro.com/blog/2024_03_18_the_flambda2_snippets_0/">The Flambda2 Snippets, Episode 0</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://ocamlpro.com/blog/2024_03_19_the_flambda2_snippets_1/">CPS Representation and Foundational Design Decisions in Flambda2</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//ocamlpro.com/blog/2024_03_19_the_flambda2_snippets_1/">CPS Representation and Foundational Design Decisions in Flambda2</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/monadic-library-for-eio-capabilities/14202">Monadic Library for Eio Capabilities?</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/monadic-library-for-eio-capabilities/14202">Monadic Library for Eio Capabilities?</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/is-there-any-consensus-on-which-type-to-unify-on-for-errors-in-result-types-whats-your-preference/14304">Is there any consensus on which type to unify on for errors in result types? What’s your preference?</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/is-there-any-consensus-on-which-type-to-unify-on-for-errors-in-result-types-whats-your-preference/14304">Is there any consensus on which type to unify on for errors in result types? What’s your preference?</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/create-opam-switch-specifying-custom-c-compiler/14276">Create opam switch specifying custom C compiler</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/create-opam-switch-specifying-custom-c-compiler/14276">Create opam switch specifying custom C compiler</a>.</p>
</li>
</ul>
-<h2 id="视频"><a href="#视频" class="headerlink" title="视频"></a>视频</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://watch.ocaml.org/w/b7sv1LQSVZQH6trf4xpwFX">Outreachy Presentations for the December 2023 Round</a>.</p>
+<h2 id="视频"><a class="header-anchor" href="#视频">¶</a>视频</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//watch.ocaml.org/w/b7sv1LQSVZQH6trf4xpwFX">Outreachy Presentations for the December 2023 Round</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=IxQ586TS8Gw">Taking Erlang to OCaml 5 (with Leandro Ostera)</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DIxQ586TS8Gw">Taking Erlang to OCaml 5 (with Leandro Ostera)</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=LwD3GxsY-pc">OCaml Unboxed: An Exploration of Jane Street’s Experiments with OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DLwD3GxsY-pc">OCaml Unboxed: An Exploration of Jane Street’s Experiments with OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=TxuLrsQZprE">OCaml for Fun &amp; Profit: An Experience Report • Tim McGilchrist • YOW! 2023</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DTxuLrsQZprE">OCaml for Fun &amp; Profit: An Experience Report • Tim McGilchrist • YOW! 2023</a>.</p>
</li>
</ul>
-<h2 id="值得注意的项目"><a href="#值得注意的项目" class="headerlink" title="值得注意的项目"></a>值得注意的项目</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/eio/releases/tag/v1.0">Eio 1.0: Effects-based direct-style IO for multicore OCaml</a>.</p>
+<h2 id="值得注意的项目"><a class="header-anchor" href="#值得注意的项目">¶</a>值得注意的项目</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-multicore/eio/releases/tag/v1.0">Eio 1.0: Effects-based direct-style IO for multicore OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/icfp-2023-eio-tutorial">icfp-2023-eio-tutorial: This tutorial covers how to convert an OCaml 4 program using Lwt for concurrency to use OCaml 5 and Eio.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-multicore/icfp-2023-eio-tutorial">icfp-2023-eio-tutorial: This tutorial covers how to convert an OCaml 4 program using Lwt for concurrency to use OCaml 5 and Eio.</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://erratique.ch/software/down">Down: An unintrusive user experience upgrade for the OCaml toplevel system (REPL).</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//erratique.ch/software/down">Down: An unintrusive user experience upgrade for the OCaml toplevel system (REPL).</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/zshipko/ocaml-rs">ocaml-rs: OCaml extensions in Rust</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/zshipko/ocaml-rs">ocaml-rs: OCaml extensions in Rust</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/eio-trace">eio-trace: Trace visualisation tool for Eio programs</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-multicore/eio-trace">eio-trace: Trace visualisation tool for Eio programs</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dkcoder-0-1-0/14327">[ANN] DkCoder 0.1.0: A transparently installed OCaml 4.14 environment with one API: run a script.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-dkcoder-0-1-0/14327">[ANN] DkCoder 0.1.0: A transparently installed OCaml 4.14 environment with one API: run a script.</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/darrenldl/docfd/releases/tag/3.0.0">[ANN] Docfd 3.0.0: TUI multiline fuzzy document finder</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/darrenldl/docfd/releases/tag/3.0.0">[ANN] Docfd 3.0.0: TUI multiline fuzzy document finder</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-ocaml-windows-5-1-1/14268">[ANN] Ocaml-windows 5.1.1</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-ocaml-windows-5-1-1/14268">[ANN] Ocaml-windows 5.1.1</a>.</p>
</li>
-<li><p>这里指的是 <a href="https://link.zhihu.com/?target=https://github.com/ocaml-cross/opam-cross-windows">opam-cross-windows</a> 支持 5.1.1 了,不是 Windows 支持。</p>
+<li>
+<p>这里指的是 <a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-cross/opam-cross-windows">opam-cross-windows</a> 支持 5.1.1 了,不是 Windows 支持。</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ml-in-barcelona/quickjs.ml">[ANN] Bindings to QuickJS</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ml-in-barcelona/quickjs.ml">[ANN] Bindings to QuickJS</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/lukstafi/ppx_minidebug">[ANN] ppx_minidebug 1.3.0: toward a logging framework</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/lukstafi/ppx_minidebug">[ANN] ppx_minidebug 1.3.0: toward a logging framework</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/c-cube/ocaml-iostream/releases/tag/v0.2">[ANN] iostream 0.2</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/c-cube/ocaml-iostream/releases/tag/v0.2">[ANN] iostream 0.2</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocsigen/js_of_ocaml/releases/tag/5.7.1">[ANN] Js_of_ocaml 5.7</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocsigen/js_of_ocaml/releases/tag/5.7.1">[ANN] Js_of_ocaml 5.7</a>.</p>
</li>
</ul>
-<h2 id="有趣的项目"><a href="#有趣的项目" class="headerlink" title="有趣的项目"></a>有趣的项目</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/pdonadeo/ocaml-lua">ocaml-lua: Lua bindings for OCaml</a>.</p>
+<h2 id="有趣的项目"><a class="header-anchor" href="#有趣的项目">¶</a>有趣的项目</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/pdonadeo/ocaml-lua">ocaml-lua: Lua bindings for OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/LexiFi/csml">csml: High-level bindings between .Net and OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/LexiFi/csml">csml: High-level bindings between .Net and OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/LexiFi/landmarks">landmarks: A Simple Profiling Library for OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/LexiFi/landmarks">landmarks: A Simple Profiling Library for OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://erratique.ch/software/ttweetnacl">Ttweetnacl: An OCaml module providing thin bindings to the TweetNaCl cryptographic library.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//erratique.ch/software/ttweetnacl">Ttweetnacl: An OCaml module providing thin bindings to the TweetNaCl cryptographic library.</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/xavierleroy/cryptokit">cryptokit: A library of cryptographic primitives (ciphers, hashes, etc) for OCaml</a>.</p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/xavierleroy/cryptokit">cryptokit: A library of cryptographic primitives (ciphers, hashes, etc) for OCaml</a>.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/gridbugs/llama">llama: A library for building software-defined modular synthesizers in a declarative style.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/gridbugs/llama">llama: A library for building software-defined modular synthesizers in a declarative style.</a></p>
</li>
</ul>
diff --git a/2024/07/09/神经系统重点/index.html b/2024/07/09/神经系统重点/index.html
index fa92d155..82368925 100644
--- a/2024/07/09/神经系统重点/index.html
+++ b/2024/07/09/神经系统重点/index.html
@@ -193,25 +193,30 @@
</div>
<div class="post-content">
<ol>
-<li><p>十二对脑神经的顺序(一嗅二视三动眼,四滑五叉六外展,七面八听九舌咽,迷副舌下神经全):嗅神经、视神经、动眼神经、滑车神经、三叉神经、展神经、面神经、位听神经、舌咽神经、迷走神经、副神经和舌下神经。 </p>
+<li>
+<p>十二对脑神经的顺序(一嗅二视三动眼,四滑五叉六外展,七面八听九舌咽,迷副舌下神经全):嗅神经、视神经、动眼神经、滑车神经、三叉神经、展神经、面神经、位听神经、舌咽神经、迷走神经、副神经和舌下神经。</p>
</li>
-<li><p>脑干病变的特点:交叉性瘫痪、意识障碍、去大脑僵直、定位体征、脊髓。 </p>
+<li>
+<p>脑干病变的特点:交叉性瘫痪、意识障碍、去大脑僵直、定位体征、脊髓。</p>
</li>
-<li><p>瞳孔直径约为3-4mm,一般认为瞳孔直径<2mm为瞳孔缩小,>5mm为瞳孔散大。 </p>
+<li>
+<p>瞳孔直径约为3-4mm,一般认为瞳孔直径<2mm为瞳孔缩小,>5mm为瞳孔散大。</p>
</li>
-<li><p>正常脑脊液压力:80-180mmH2O。 </p>
+<li>
+<p>正常脑脊液压力:80-180mmH2O。</p>
</li>
-<li><p>意识障碍包括:</p>
+<li>
+<p>意识障碍包括:</p>
<ul>
-<li>嗜睡:是最轻的意识障碍,是一种病理性倦睡,患者陷入持续的睡眠状态,可被唤醒,并能正确回答和做出各种反应,但当刺激去除后很快又再入睡。 </li>
-<li>昏睡:较嗜睡重,持续处于睡眠状态,强刺激方能唤醒,应答不切题。 </li>
+<li>嗜睡:是最轻的意识障碍,是一种病理性倦睡,患者陷入持续的睡眠状态,可被唤醒,并能正确回答和做出各种反应,但当刺激去除后很快又再入睡。</li>
+<li>昏睡:较嗜睡重,持续处于睡眠状态,强刺激方能唤醒,应答不切题。</li>
<li>浅昏迷:对针刺和压眶由痛苦表情及躲避反应,无语言应答,各种反射无明显改变。</li>
<li>深昏迷:意识全部丧失,强刺激也不能引起反应,肢体常呈弛缓状失。偶有深反射亢进与病理反射出现。机体仅能维持呼吸与血循环功能。</li>
<li>意识模糊:较嗜睡为深的一种意识障碍,表现为定向障碍,思维和语言不连贯,可有和幻觉、躁动不安、谵语或精神错乱。</li>
</ul>
-<p> </p>
</li>
-<li><p>运动障碍的护理诊断:有失用综合征的危险的护理措施:</p>
+<li>
+<p>运动障碍的护理诊断:有失用综合征的危险的护理措施:</p>
<ul>
<li>早期康复干预:重视患侧刺激、保持良好的肢体位臵、体位变换(翻身)、床上运动训练(Bobath握手、桥式运动)</li>
<li>恢复期运动训练</li>
@@ -219,25 +224,29 @@
</ul>
<blockquote>
<ul>
-<li>急性炎症性脱髓鞘性多神经根病的临床表现中感觉障碍呈手套袜子样分布。    </li>
+<li>急性炎症性脱髓鞘性多神经根病的临床表现中感觉障碍呈手套袜子样分布。</li>
<li>重要特点是蛋白-细胞分离现象。</li>
</ul>
</blockquote>
</li>
-<li><p>脑血管疾病的分类</p>
+<li>
+<p>脑血管疾病的分类</p>
<ul>
<li>依据症状持续时间:短暂性脑缺血发作、脑卒中。</li>
<li>依据病理性质:缺血性卒中、出血性卒中。</li>
<li>依据发病急缓:急性脑血管疾病、慢性脑血管疾病。</li>
</ul>
</li>
-<li><p>定义: 短暂性脑缺血发作(TIA):局造性脑缺血导致突发短暂的可逆性神经功能障碍。</p>
+<li>
+<p>定义: 短暂性脑缺血发作(TIA):局造性脑缺血导致突发短暂的可逆性神经功能障碍。</p>
</li>
-<li><p>脑血栓形成(脑血管病中最常见)</p>
+<li>
+<p>脑血栓形成(脑血管病中最常见)</p>
+<ul>
+<li>病因:最常见的病因是脑动脉粥样硬化,其次为脑动脉炎。高血压、高脂血症、糖尿病是加速脑血管硬化进展的重要因素。</li>
+<li>检查:头颅CT:24小时后CT可见相应部位低密度影像。</li>
+<li>急性期治疗:
<ul>
-<li>病因:最常见的病因是脑动脉粥样硬化,其次为脑动脉炎。高血压、高脂血症、糖尿病是加速脑血管硬化进展的重要因素。    </li>
-<li>检查:头颅CT:24小时后CT可见相应部位低密度影像。   </li>
-<li>急性期治疗:<ul>
<li>早期溶栓:在发病后6小时以内进行溶栓。</li>
<li>调整血压:急性期应维持病人血压于较平时稍高水平,血压过高(收缩压>220mmHg或舒张压>120mmHg)。</li>
<li>抗血小板聚集。</li>
@@ -248,73 +257,80 @@
<li>外科治疗:开颅降压术。</li>
<li>早期康复治疗。</li>
</ul>
-<p>  </p>
</li>
-<li>用药护理:<ul>
+<li>用药护理:
+<ul>
<li>溶栓和抗凝药物:严格掌握药物剂量,监测BT、PT、 APTT,观察有无黑便、牙龈出血、皮肤瘀点瘀斑等出血表现;观察有无并发颅内出血;观察有无栓子脱落所致其他部位栓塞的表现。</li>
<li>甘露醇:监测尿量及尿液颜色;有无头痛、呕吐、意识障碍等低颅压综合征的表现。</li>
</ul>
-<p>  </p>
</li>
-<li>饮食护理:<ul>
+<li>饮食护理:
+<ul>
<li>体位选择:能坐者坐位进食,头略前屈,不能坐起者将床头摇起30°,头下垫枕头部前屈。</li>
<li>食物选择:食物柔软、密度与性状均一;不易松散有一定黏度;能够变形;不易粘在黏膜上。</li>
<li>吞咽方法选择:空吞咽和吞咽食物交替进行;侧方吞咽:吞咽时头侧向健侧肩部;点头样吞咽。</li>
-<li>不能吞咽的病人给予鼻饲饮食。 <blockquote>
+<li>不能吞咽的病人给予鼻饲饮食。
+<blockquote>
<p>防止窒息:进食前应注意休息;保持进餐环境的安静、舒适;减少进餐时环境中分散注意力的干扰因素。</p>
</blockquote>
</li>
</ul>
</li>
</ul>
-<p> </p>
</li>
-<li><p>脑栓塞的病因:根据栓子来源可分为心源性、非心源性和来源不明性。心源性为最常见的原因,其中一半以上病人有风湿性心脏病二尖瓣狭窄合并心房颤动。</p>
+<li>
+<p>脑栓塞的病因:根据栓子来源可分为心源性、非心源性和来源不明性。心源性为最常见的原因,其中一半以上病人有风湿性心脏病二尖瓣狭窄合并心房颤动。</p>
</li>
-<li><p>脑出血临床特点:</p>
+<li>
+<p>脑出血临床特点:</p>
<ul>
<li>多见于50岁以上有高血压病史者,男性较女性多见,冬季发病率较高。</li>
<li>体力活动或情绪激动时发病,多无前驱症状。</li>
<li>起病较急,症状于数分钟至数小时达高峰。</li>
<li>有肢体瘫痪、失语等局灶定位症状和剧烈头痛、喷射性呕吐、意识障碍等全脑症状。</li>
-<li>发病时血压明显升高。(“三偏征”对侧偏瘫、偏身感觉障碍和同向性偏盲)。    <blockquote>
-<p>头颅CT:确诊脑出血的首选检查方法,发病后即刻出现边界清楚的高密度影像。    </p>
+<li>发病时血压明显升高。(“三偏征”对侧偏瘫、偏身感觉障碍和同向性偏盲)。</li>
+</ul>
+<blockquote>
+<p>头颅CT:确诊脑出血的首选检查方法,发病后即刻出现边界清楚的高密度影像。</p>
<p>治疗要点:治疗原则是脱水降颅压、调整血压、防止继续出血、减轻血肿所致继发性损害、促进神经功&gt; 能恢复、加强护理防治并发症。</p>
<ul>
-<li>一般治疗:卧床休息,密切观察生命体征,保持呼吸道通畅,吸氧,保持肢体的功能位,鼻饲,预防感染,维持水、电解质平衡等。 </li>
+<li>一般治疗:卧床休息,密切观察生命体征,保持呼吸道通畅,吸氧,保持肢体的功能位,鼻饲,预防感染,维持水、电解质平衡等。</li>
<li>脱水降颅压:目的是控制脑水肿,药物:20%甘露醇。</li>
-<li>调控血压:血压≥200&#x2F;110mmHg时,可采取降压治疗,给予硫酸镁等。</li>
+<li>调控血压:血压≥200/110mmHg时,可采取降压治疗,给予硫酸镁等。</li>
<li>止血和凝血治疗。</li>
-<li>外科治疗:壳核出血量>30ml,小脑或丘脑出血>10ml(6)康复治疗。 </li>
+<li>外科治疗:壳核出血量>30ml,小脑或丘脑出血>10ml(6)康复治疗。</li>
<li>休息与安全:绝对卧床休息2~4周,抬高床头15~30度,减轻脑水肿。</li>
</ul>
</blockquote>
</li>
-</ul>
-<p> </p>
-</li>
-<li><p>帕金森病的临床表现:</p>
+<li>
+<p>帕金森病的临床表现:</p>
<ul>
<li>静止性震颤:多从一侧开始,类似“搓丸”样动作,静止时明显震颤,动作时减轻,精神紧张时加重,入睡后消失。</li>
<li>肌强直:“铅管样强直”、“齿轮样强直”。</li>
-<li>运动迟缓:“小写症”“面具脸”。 </li>
+<li>运动迟缓:“小写症”“面具脸”。</li>
<li>姿势步态异常:“慌张步态”。</li>
</ul>
</li>
-<li><p>癫痫持续状态在给氧、防护的从速制止发作,首先给地西泮10~20mg静脉注射,注射速度不超过每分钟2mg,以免抑制呼吸,在监测血压同时静脉滴入苯妥英钠以控制发作。 </p>
+<li>
+<p>癫痫持续状态在给氧、防护的从速制止发作,首先给地西泮10~20mg静脉注射,注射速度不超过每分钟2mg,以免抑制呼吸,在监测血压同时静脉滴入苯妥英钠以控制发作。</p>
</li>
-<li><p>癫痫的护理诊断:</p>
+<li>
+<p>癫痫的护理诊断:</p>
<ul>
<li>防窒息</li>
<li>防受伤:活动状态时发作,陪伴者应立即将病人缓慢臵于平卧位,防止外伤,抽搐肢体不可用力按压,以免造成骨折或关节脱位。</li>
</ul>
</li>
-<li><p>重症肌无力的临床特点:</p>
+<li>
+<p>重症肌无力的临床特点:</p>
<ul>
-<li>是一种与胸腺异常有关的自身免疫性疾病。 </li>
-<li>最先表现为一侧眼睑下垂。 </li>
+<li>是一种与胸腺异常有关的自身免疫性疾病。</li>
+<li>最先表现为一侧眼睑下垂。</li>
<li>肌无力呈进行性发展逐渐累及其他肌肉。</li>
-<li>症状晨轻暮重、活动后重,休息后轻。 <blockquote>
+<li>症状晨轻暮重、活动后重,休息后轻。</li>
+</ul>
+<blockquote>
<p>实验室检查:</p>
<ul>
<li>疲劳试验(Jolly试验):嘱病人用力眨眼30次后眼裂明显变小或两臂持续平举后出现上臂下垂。</li>
@@ -322,50 +338,64 @@
</ul>
</blockquote>
</li>
-</ul>
-<p> </p>
-</li>
-<li><p>腰椎穿刺术后护理嘱病人去枕平卧4~6小时,不可抬高头部,观察有无并发症,如头痛、腰背痛、脑疝、感染。 </p>
+<li>
+<p>腰椎穿刺术后护理嘱病人去枕平卧4~6小时,不可抬高头部,观察有无并发症,如头痛、腰背痛、脑疝、感染。</p>
</li>
-<li><p>意识障碍按程度可分为嗜睡、昏睡、浅昏迷、中昏迷、深昏迷。  </p>
+<li>
+<p>意识障碍按程度可分为嗜睡、昏睡、浅昏迷、中昏迷、深昏迷。</p>
</li>
-<li><p>脑出血病人急性期治疗的主要原则是防止再出血、控制脑水肿、减低颅内压、维持生命功能、防治并发症。  </p>
+<li>
+<p>脑出血病人急性期治疗的主要原则是防止再出血、控制脑水肿、减低颅内压、维持生命功能、防治并发症。</p>
</li>
-<li><p>根据癫痫发作的临床表现和脑电图特点,可将癫痫分为部分性发作、全面性发作、不能分类的癫痫发作3大类。  </p>
+<li>
+<p>根据癫痫发作的临床表现和脑电图特点,可将癫痫分为部分性发作、全面性发作、不能分类的癫痫发作3大类。</p>
<blockquote>
-<p>癫痫全面性强直–阵挛发作过程可分为强直期、阵挛期、痉挛后三期。  </p>
+<p>癫痫全面性强直–阵挛发作过程可分为强直期、阵挛期、痉挛后三期。</p>
</blockquote>
</li>
-<li><p>诊断癫痫最有价值的检查是脑电图。  </p>
+<li>
+<p>诊断癫痫最有价值的检查是脑电图。</p>
</li>
-<li><p>脑动脉粥样硬化是脑血栓形成最常见的病因。  </p>
+<li>
+<p>脑动脉粥样硬化是脑血栓形成最常见的病因。</p>
</li>
-<li><p>蛛网膜下腔出血病人应绝对卧床4-6周周,避免用力排便情绪激动等。 </p>
+<li>
+<p>蛛网膜下腔出血病人应绝对卧床4-6周周,避免用力排便情绪激动等。</p>
</li>
-<li><p>三偏症指偏瘫,偏盲,偏麻(偏身感觉障碍)。  </p>
+<li>
+<p>三偏症指偏瘫,偏盲,偏麻(偏身感觉障碍)。</p>
</li>
-<li><p>吉兰——巴雷的主要危险是呼吸麻痹。  </p>
+<li>
+<p>吉兰——巴雷的主要危险是呼吸麻痹。</p>
</li>
-<li><p>脑血管发病最重要的危险因素是高血压,心脏病,糖尿病,TIA。 </p>
+<li>
+<p>脑血管发病最重要的危险因素是高血压,心脏病,糖尿病,TIA。</p>
</li>
-<li><p>TIA指脑缺血症状24小时内可以完全恢复。  </p>
+<li>
+<p>TIA指脑缺血症状24小时内可以完全恢复。</p>
</li>
-<li><p>早期溶栓指发病6小时内进行溶栓处理。  </p>
+<li>
+<p>早期溶栓指发病6小时内进行溶栓处理。</p>
</li>
-<li><p>脑组织中豆纹动脉动脉最容易出血。  </p>
+<li>
+<p>脑组织中豆纹动脉动脉最容易出血。</p>
</li>
-<li><p>一般20%甘露醇200ml静脉滴注30分钟分钟内滴完。输入甘露醇后4小时内尿量少于200毫升ml要慎用或停用。  </p>
+<li>
+<p>一般20%甘露醇200ml静脉滴注30分钟分钟内滴完。输入甘露醇后4小时内尿量少于200毫升ml要慎用或停用。</p>
</li>
-<li><p>蛛网膜下腔出血的特征性体征是脑膜刺激征,特征性实验室检查是脑脊液检查。  </p>
+<li>
+<p>蛛网膜下腔出血的特征性体征是脑膜刺激征,特征性实验室检查是脑脊液检查。</p>
</li>
-<li><p>脑血栓形成常在安静时发病,脑出血常在活动及情绪激动时发病。 </p>
+<li>
+<p>脑血栓形成常在安静时发病,脑出血常在活动及情绪激动时发病。</p>
</li>
-<li><p>简述癫痫持续状态的护理要点:(1)迅速控制发作(安定10~20mg静脉慢推)(2)用床挡,专人守护,必要时用约束带(3)移开周围物品(4)立即取下假牙、垫牙,保护皮肤,不用力按压病人(5)解开衣领,头偏一侧,保持气道通畅(6)观察生命体征、神志。 </p>
+<li>
+<p>简述癫痫持续状态的护理要点:(1)迅速控制发作(安定10~20mg静脉慢推)(2)用床挡,专人守护,必要时用约束带(3)移开周围物品(4)立即取下假牙、垫牙,保护皮肤,不用力按压病人(5)解开衣领,头偏一侧,保持气道通畅(6)观察生命体征、神志。</p>
</li>
-<li><p>名词解释:短暂性脑缺血发作、癫痫、癫痫持续状态、帕金森病。</p>
+<li>
+<p>名词解释:短暂性脑缺血发作、癫痫、癫痫持续状态、帕金森病。</p>
</li>
</ol>
-<p>  </p>
</div>
diff --git a/2024/07/23/OCaml-News-2024-6/index.html b/2024/07/23/OCaml-News-2024-6/index.html
index 45e38913..8947726f 100644
--- a/2024/07/23/OCaml-News-2024-6/index.html
+++ b/2024/07/23/OCaml-News-2024-6/index.html
@@ -193,91 +193,133 @@
</div>
<div class="post-content">
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> ^o3</span><br><span class="line">~/\_/\_|)</span><br><span class="line">|/=_=\|</span><br><span class="line">&quot; &quot;</span><br></pre></td></tr></table></figure>
-
-<h2 id="语言的发展"><a href="#语言的发展" class="headerlink" title="语言的发展"></a>语言的发展</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13275">Modular explicits #13275</a></p>
+<h2 id="语言的发展"><a class="header-anchor" href="#语言的发展">¶</a>语言的发展</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13275">Modular explicits #13275</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12828">Add short syntax for dependent functor types #12828</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12828">Add short syntax for dependent functor types #12828</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13310">Add Pair module to standard library #13310</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13310">Add Pair module to standard library #13310</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13272">Allow maximum number of domains to be specified as a OCAMLRUNPARAM parameter #13272</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13272">Allow maximum number of domains to be specified as a OCAMLRUNPARAM parameter #13272</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13161">Restore native armv7 support for NetBSD 10.0 #13161</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13161">Restore native armv7 support for NetBSD 10.0 #13161</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12309">Add effect syntax #12309</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12309">Add effect syntax #12309</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12114">Add ThreadSanitizer support #12114</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12114">Add ThreadSanitizer support #12114</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13195">A new abstract data type of enumerations in Set.Make(Ord).Enum #13195</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13195">A new abstract data type of enumerations in Set.Make(Ord).Enum #13195</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12871">Stdlib priority queues #12871</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12871">Stdlib priority queues #12871</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/9080">Aliasing &#x3D;&#x3D; and !&#x3D; with explicit names #9080</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/9080">Aliasing == and != with explicit names #9080</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12964">Memory cleanup at exit #12964</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12964">Memory cleanup at exit #12964</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13169">A document type for error messages #13169</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13169">A document type for error messages #13169</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13318">Fix GC alarm regression #13318</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13318">Fix GC alarm regression #13318</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13326">Implement O_APPEND on windows #13326</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13326">Implement O_APPEND on windows #13326</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13296">Add missing functions from Array to Dynarray #13296</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13296">Add missing functions from Array to Dynarray #13296</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12182%23discussion_r1678134261">Improve the type clash error message #12182</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12182%23discussion_r1678134261">Improve the type clash error message #12182</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/12298">Emphasize that Bigarray.int refers to the OCaml int type, and not the C int type #12298</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/12298">Emphasize that Bigarray.int refers to the OCaml int type, and not the C int type #12298</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/effects-with-lwt-a-dead-end-for-now/15002">Effects with Lwt, a dead end for now?</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/effects-with-lwt-a-dead-end-for-now/15002">Effects with Lwt, a dead end for now?</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/changes-in-handling-of-gc-parameters-and-alarms-in-5-2-0/14986">Changes in handling of Gc parameters and alarms in 5.2.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/changes-in-handling-of-gc-parameters-and-alarms-in-5-2-0/14986">Changes in handling of Gc parameters and alarms in 5.2.0</a></p>
</li>
</ul>
-<h2 id="新消息"><a href="#新消息" class="headerlink" title="新消息"></a>新消息</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-mopsa-1-0-modular-open-platform-for-static-analysis/15013">[ANN] Mopsa 1.0 – Modular Open Platform for Static Analysis</a></p>
+<h2 id="新消息"><a class="header-anchor" href="#新消息">¶</a>新消息</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-mopsa-1-0-modular-open-platform-for-static-analysis/15013">[ANN] Mopsa 1.0 – Modular Open Platform for Static Analysis</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-a-small-extension-of-bigarray-genarray-adding-iteration-mapping-and-folding/15005">[ANN] A small extension of Bigarray.Genarray adding iteration, mapping and folding</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-a-small-extension-of-bigarray-genarray-adding-iteration-mapping-and-folding/15005">[ANN] A small extension of Bigarray.Genarray adding iteration, mapping and folding</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-cudajit-bindings-to-the-cuda-and-nvrtc-libraries/15010">[ANN] cudajit: Bindings to the <code>cuda</code> and <code>nvrtc</code> libraries</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-cudajit-bindings-to-the-cuda-and-nvrtc-libraries/15010">[ANN] cudajit: Bindings to the <code>cuda</code> and <code>nvrtc</code> libraries</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-ocaml-lsp-1-18-0/14952">[ANN] OCaml LSP 1.18.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-ocaml-lsp-1-18-0/14952">[ANN] OCaml LSP 1.18.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-ortac-0-3-0-dynamic-formal-verification-made-easy/14936">[ANN] Ortac 0.3.0 Dynamic formal verification made easy</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-ortac-0-3-0-dynamic-formal-verification-made-easy/14936">[ANN] Ortac 0.3.0 Dynamic formal verification made easy</a></p>
</li>
</ul>
-<h2 id="有价值的文章"><a href="#有价值的文章" class="headerlink" title="有价值的文章"></a>有价值的文章</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://hal.sorbonne-universite.fr/hal-02890500v1/document">Combinations of Reusable Abstract Domains for a Multilingual Static Analyzer</a></p>
+<h2 id="有价值的文章"><a class="header-anchor" href="#有价值的文章">¶</a>有价值的文章</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//hal.sorbonne-universite.fr/hal-02890500v1/document">Combinations of Reusable Abstract Domains for a Multilingual Static Analyzer</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://fizzixnerd.com/blog/2024-07-21-fixing-living/">Fighting Mutation with Mutation in Living</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//fizzixnerd.com/blog/2024-07-21-fixing-living/">Fighting Mutation with Mutation in Living</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/type-system-and-polymorphic-lets/14990">Type system and polymorphic let’s</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/type-system-and-polymorphic-lets/14990">Type system and polymorphic let’s</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/using-docusaurus-to-document-an-ocaml-project/13359">Using Docusaurus to document an OCaml project</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/using-docusaurus-to-document-an-ocaml-project/13359">Using Docusaurus to document an OCaml project</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/exploring-the-docusaurus-odoc-combo/15012">Exploring the Docusaurus+Odoc combo</a><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/type-system-and-polymorphic-lets/14990">Type system and polymorphic let’s</a><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/exploring-the-docusaurus-odoc-combo/15012">Exploring the Docusaurus+Odoc combo</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/exploring-the-docusaurus-odoc-combo/15012">Exploring the Docusaurus+Odoc combo</a><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/type-system-and-polymorphic-lets/14990">Type system and polymorphic let’s</a><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/exploring-the-docusaurus-odoc-combo/15012">Exploring the Docusaurus+Odoc combo</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://fizzixnerd.com/blog/2024-07-11-a-possibly-safer-interface-to-the-ctypes-ffi/">A (Possibly) Safer Interface to the Ctypes FFI</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//fizzixnerd.com/blog/2024-07-11-a-possibly-safer-interface-to-the-ctypes-ffi/">A (Possibly) Safer Interface to the Ctypes FFI</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://fizzixnerd.com/blog/2024-07-09-ocaml-ffi-sharp-edges-and-how-to-avoid-them/">OCaml FFI Sharp Edges – and How to Avoid them!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//fizzixnerd.com/blog/2024-07-09-ocaml-ffi-sharp-edges-and-how-to-avoid-them/">OCaml FFI Sharp Edges – and How to Avoid them!</a></p>
</li>
</ul>
-<h2 id="有趣的项目"><a href="#有趣的项目" class="headerlink" title="有趣的项目"></a>有趣的项目</h2><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://ocaml.libvirt.org/">ocaml-libvirt OCaml bindings for libvirt</a></p>
+<h2 id="有趣的项目"><a class="header-anchor" href="#有趣的项目">¶</a>有趣的项目</h2>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//ocaml.libvirt.org/">ocaml-libvirt OCaml bindings for libvirt</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://gitlab.com/mopsa/mopsa-analyzer/">Gitlab - MOPSA&#x2F;MOPSA analyzer: stands for Modular and Open Platform for Static Analysis.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//gitlab.com/mopsa/mopsa-analyzer/">Gitlab - MOPSA/MOPSA analyzer: stands for Modular and Open Platform for Static Analysis.</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/Heyji2/GenArrayIter">GitHub - Heyji2&#x2F;GenArrayIter: Adding iteration, mapping and folding to the ocaml BigArray.Genarrays module which provides arrays of arbitrary dimensions</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/Heyji2/GenArrayIter">GitHub - Heyji2/GenArrayIter: Adding iteration, mapping and folding to the ocaml BigArray.Genarrays module which provides arrays of arbitrary dimensions</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/mbarbin/bopkit">GitHub - mbarbin&#x2F;bopkit: An educational project for digital circuits programming</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/mbarbin/bopkit">GitHub - mbarbin/bopkit: An educational project for digital circuits programming</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/dx3mod/rpmfile">GitHub - dx3mod&#x2F;rpmfile: A library for reading metadata from RPM packages.</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/dx3mod/rpmfile">GitHub - dx3mod/rpmfile: A library for reading metadata from RPM packages.</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/gildor478/ocaml-fileutils">Github - gildor478&#x2F;ocaml-fileutils: OCaml API to manipulate real files (POSIX like) and filenames</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/gildor478/ocaml-fileutils">Github - gildor478/ocaml-fileutils: OCaml API to manipulate real files (POSIX like) and filenames</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/NathanReb/ocaml-api-watch">Github - NathanReb&#x2F;ocaml-api-watch: Libraries and tools to keep watch on you OCaml lib’s API changes</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/NathanReb/ocaml-api-watch">Github - NathanReb/ocaml-api-watch: Libraries and tools to keep watch on you OCaml lib’s API changes</a></p>
</li>
</ul>
diff --git a/2024/08/02/二〇二四年八月一日/index.html b/2024/08/02/二〇二四年八月一日/index.html
index 7f00eb97..6ec0fefe 100644
--- a/2024/08/02/二〇二四年八月一日/index.html
+++ b/2024/08/02/二〇二四年八月一日/index.html
@@ -184,7 +184,10 @@
</div>
</div>
<div class="post-content">
- <p>阿公烧烟成老瘾,<br>阿公饮酒会面红,<br>他说日子要开心,<br>他说人生要尽兴。</p>
+ <p>阿公烧烟成老瘾,<br>
+阿公饮酒会面红,<br>
+他说日子要开心,<br>
+他说人生要尽兴。</p>
</div>
diff --git a/2024/09/12/Functional-Reactive-Programming-in-F/index.html b/2024/09/12/Functional-Reactive-Programming-in-F/index.html
index 94586aea..b1bc57f8 100644
--- a/2024/09/12/Functional-Reactive-Programming-in-F/index.html
+++ b/2024/09/12/Functional-Reactive-Programming-in-F/index.html
@@ -209,7 +209,8 @@
<p>We saw in the previous post on message queues that one of the advantages of that approach was that the requests were “serialized” making it conceptually easier to deal with.</p>
<p>There is a similar approach that can be used with events. The idea is to turn a series of events into an “event stream”. Event streams then become quite like IEnumerables, and so the obvious next step is to treat them in much the the same way that LINQ handles collections, so that they can be filtered, mapped, split and combined.</p>
<p>F# has built in support for this model, as well as for the more traditional approach.</p>
-<h2 id="A-simple-event-stream"><a href="#A-simple-event-stream" class="headerlink" title="A simple event stream"></a>A simple event stream</h2><p>Let’s start with a simple example to compare the two approaches. We’ll implement the classic event handler approach first.</p>
+<h2 id="A-simple-event-stream"><a class="header-anchor" href="#A-simple-event-stream">¶</a>A simple event stream</h2>
+<p>Let’s start with a simple example to compare the two approaches. We’ll implement the classic event handler approach first.</p>
<p>First, we define a utility function that will:</p>
<ul>
<li>create a timer</li>
@@ -218,60 +219,47 @@
</ul>
<p>Here’s the code:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">open</span> System</span><br><span class="line"><span class="keyword">open</span> System.Threading</span><br><span class="line"></span><br><span class="line"><span class="comment">/// create a timer and register an event handler,</span></span><br><span class="line"><span class="comment">/// then run the timer for five seconds</span></span><br><span class="line"><span class="keyword">let</span> createTimer timerInterval eventHandler <span class="operator">=</span></span><br><span class="line"> <span class="comment">// setup a timer</span></span><br><span class="line"> <span class="keyword">let</span> timer <span class="operator">=</span> <span class="keyword">new</span> System.Timers.Timer(float timerInterval)</span><br><span class="line"> timer.AutoReset <span class="operator">&lt;-</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// add an event handler</span></span><br><span class="line"> timer.Elapsed.Add eventHandler</span><br><span class="line"></span><br><span class="line"> <span class="comment">// return an async task</span></span><br><span class="line"> <span class="keyword">async</span> &#123;</span><br><span class="line"> <span class="comment">// start timer...</span></span><br><span class="line"> timer.Start()</span><br><span class="line"> <span class="comment">// ...run for five seconds...</span></span><br><span class="line"> <span class="keyword">do!</span> Async.Sleep <span class="number">5000</span></span><br><span class="line"> <span class="comment">// ... and stop</span></span><br><span class="line"> timer.Stop()</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
-
<p>Now test it interactively:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create a handler. The event args are ignored</span></span><br><span class="line"><span class="keyword">let</span> basicHandler _ <span class="operator">=</span> <span class="built_in">printfn</span> <span class="string">&quot;tick %A&quot;</span> DateTime.Now</span><br><span class="line"></span><br><span class="line"><span class="comment">// register the handler</span></span><br><span class="line"><span class="keyword">let</span> basicTimer1 <span class="operator">=</span> createTimer <span class="number">1000</span> basicHandler</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the task now</span></span><br><span class="line">Async.RunSynchronously basicTimer1</span><br></pre></td></tr></table></figure>
-
<p>Now let’s create a similar utility method to create a timer, but this time it will return an “observable” as well, which is the stream of events.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> createTimerAndObservable timerInterval <span class="operator">=</span></span><br><span class="line"> <span class="comment">// setup a timer</span></span><br><span class="line"> <span class="keyword">let</span> timer <span class="operator">=</span> <span class="keyword">new</span> System.Timers.Timer(float timerInterval)</span><br><span class="line"> timer.AutoReset <span class="operator">&lt;-</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// events are automatically IObservable</span></span><br><span class="line"> <span class="keyword">let</span> observable <span class="operator">=</span> timer.Elapsed</span><br><span class="line"></span><br><span class="line"> <span class="comment">// return an async task</span></span><br><span class="line"> <span class="keyword">let</span> task <span class="operator">=</span> <span class="keyword">async</span> &#123;</span><br><span class="line"> timer.Start()</span><br><span class="line"> <span class="keyword">do!</span> Async.Sleep <span class="number">5000</span></span><br><span class="line"> timer.Stop()</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// return a async task and the observable</span></span><br><span class="line"> (task,observable)</span><br></pre></td></tr></table></figure>
-
<p>And again test it interactively:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create the timer and the corresponding observable</span></span><br><span class="line"><span class="keyword">let</span> basicTimer2 , timerEventStream <span class="operator">=</span> createTimerAndObservable <span class="number">1000</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// register that every time something happens on the</span></span><br><span class="line"><span class="comment">// event stream, print the time.</span></span><br><span class="line">timerEventStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;tick %A&quot;</span> DateTime.Now)</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the task now</span></span><br><span class="line">Async.RunSynchronously basicTimer2</span><br></pre></td></tr></table></figure>
-
<p>The difference is that instead of registering a handler directly with an event, we are “subscribing” to an event stream. Subtly different, and important.</p>
-<h2 id="Counting-events"><a href="#Counting-events" class="headerlink" title="Counting events"></a>Counting events</h2><p>In this next example, we’ll have a slightly more complex requirement:</p>
+<h2 id="Counting-events"><a class="header-anchor" href="#Counting-events">¶</a>Counting events</h2>
+<p>In this next example, we’ll have a slightly more complex requirement:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Create a timer that ticks every 500ms.</span><br><span class="line">At each tick, print the number of ticks so far and the current time.</span><br></pre></td></tr></table></figure>
-
<p>To do this in a classic imperative way, we would probably create a class with a mutable counter, as below:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">ImperativeTimerCount</span>() <span class="operator">=</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> count <span class="operator">=</span> <span class="number">0</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// the event handler. The event args are ignored</span></span><br><span class="line"> <span class="keyword">member</span> this.handleEvent _ <span class="operator">=</span></span><br><span class="line"> count <span class="operator">&lt;-</span> count <span class="operator">+</span> <span class="number">1</span></span><br><span class="line"> <span class="built_in">printfn</span> <span class="string">&quot;timer ticked with count %i&quot;</span> count</span><br></pre></td></tr></table></figure>
-
<p>We can reuse the utility functions we created earlier to test it:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create a handler class</span></span><br><span class="line"><span class="keyword">let</span> handler <span class="operator">=</span> <span class="keyword">new</span> ImperativeTimerCount()</span><br><span class="line"></span><br><span class="line"><span class="comment">// register the handler method</span></span><br><span class="line"><span class="keyword">let</span> timerCount1 <span class="operator">=</span> createTimer <span class="number">500</span> handler.handleEvent</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the task now</span></span><br><span class="line">Async.RunSynchronously timerCount1</span><br></pre></td></tr></table></figure>
-
<p>Let’s see how we would do this same thing in a functional way:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create the timer and the corresponding observable</span></span><br><span class="line"><span class="keyword">let</span> timerCount2, timerEventStream <span class="operator">=</span> createTimerAndObservable <span class="number">500</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// set up the transformations on the event stream</span></span><br><span class="line">timerEventStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.scan (<span class="keyword">fun</span> count _ <span class="operator">-&gt;</span> count <span class="operator">+</span> <span class="number">1</span>) <span class="number">0</span></span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> count <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;timer ticked with count %i&quot;</span> count)</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the task now</span></span><br><span class="line">Async.RunSynchronously timerCount2</span><br></pre></td></tr></table></figure>
-
<p>Here we see how you can build up layers of event transformations, just as you do with list transformations in LINQ.</p>
<p>The first transformation is <code>scan</code>, which accumulates state for each event. It is roughly equivalent to the <code>List.fold</code> function that we have seen used with lists. In this case, the accumulated state is just a counter.</p>
<p>And then, for each event, the count is printed out.</p>
<p>Note that in this functional approach, we didn’t have any mutable state, and we didn’t need to create any special classes.</p>
-<h2 id="Merging-multiple-event-streams"><a href="#Merging-multiple-event-streams" class="headerlink" title="Merging multiple event streams"></a>Merging multiple event streams</h2><p>For a final example, we’ll look at merging multiple event streams.</p>
+<h2 id="Merging-multiple-event-streams"><a class="header-anchor" href="#Merging-multiple-event-streams">¶</a>Merging multiple event streams</h2>
+<p>For a final example, we’ll look at merging multiple event streams.</p>
<p>Let’s make a requirement based on the well-known “FizzBuzz” problem:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Create two timers, called &#x27;3&#x27; and &#x27;5&#x27;. The &#x27;3&#x27; timer ticks every 300ms and the &#x27;5&#x27; timer ticks</span><br><span class="line">every 500ms.</span><br><span class="line"></span><br><span class="line">Handle the events as follows:</span><br><span class="line">a) for all events, print the id of the time and the time</span><br><span class="line">b) when a tick is simultaneous with a previous tick, print &#x27;FizzBuzz&#x27;</span><br><span class="line">otherwise:</span><br><span class="line">c) when the &#x27;3&#x27; timer ticks on its own, print &#x27;Fizz&#x27;</span><br><span class="line">d) when the &#x27;5&#x27; timer ticks on its own, print &#x27;Buzz&#x27;</span><br></pre></td></tr></table></figure>
-
<p>First let’s create some code that both implementations can use.</p>
<p>We’ll want a generic event type that captures the timer id and the time of the tick.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">FizzBuzzEvent</span> <span class="operator">=</span> &#123;label<span class="operator">:</span><span class="type">int</span>; time<span class="operator">:</span> DateTime&#125;</span><br></pre></td></tr></table></figure>
-
<p>And then we need a utility function to see if two events are simultaneous. We’ll be generous and allow a time difference of up to 50ms.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> areSimultaneous (earlierEvent,laterEvent) <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> &#123;label<span class="operator">=</span>_;time<span class="operator">=</span>t1&#125; <span class="operator">=</span> earlierEvent</span><br><span class="line"> <span class="keyword">let</span> &#123;label<span class="operator">=</span>_;time<span class="operator">=</span>t2&#125; <span class="operator">=</span> laterEvent</span><br><span class="line"> t2.Subtract(t1).Milliseconds <span class="operator">&lt;</span> <span class="number">50</span></span><br></pre></td></tr></table></figure>
-
<p>In the imperative design, we’ll need to keep track of the previous event, so we can compare them. And we’ll need special case code for the first time, when the previous event doesn’t exist</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">ImperativeFizzBuzzHandler</span>() <span class="operator">=</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> previousEvent<span class="operator">:</span> FizzBuzzEvent <span class="type">option</span> <span class="operator">=</span> <span class="literal">None</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> printEvent thisEvent <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> &#123;label<span class="operator">=</span><span class="built_in">id</span>; time<span class="operator">=</span>t&#125; <span class="operator">=</span> thisEvent</span><br><span class="line"> <span class="built_in">printf</span> <span class="string">&quot;[%i] %i.%03i &quot;</span> <span class="built_in">id</span> t.Second t.Millisecond</span><br><span class="line"> <span class="keyword">let</span> simultaneous <span class="operator">=</span> previousEvent.IsSome <span class="operator">&amp;&amp;</span> areSimultaneous (previousEvent.Value,thisEvent)</span><br><span class="line"> <span class="keyword">if</span> simultaneous <span class="keyword">then</span> <span class="built_in">printfn</span> <span class="string">&quot;FizzBuzz&quot;</span></span><br><span class="line"> <span class="keyword">elif</span> <span class="built_in">id</span> <span class="operator">=</span> <span class="number">3</span> <span class="keyword">then</span> <span class="built_in">printfn</span> <span class="string">&quot;Fizz&quot;</span></span><br><span class="line"> <span class="keyword">elif</span> <span class="built_in">id</span> <span class="operator">=</span> <span class="number">5</span> <span class="keyword">then</span> <span class="built_in">printfn</span> <span class="string">&quot;Buzz&quot;</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">member</span> this.handleEvent3 eventArgs <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> event <span class="operator">=</span> &#123;label<span class="operator">=</span><span class="number">3</span>; time<span class="operator">=</span>DateTime.Now&#125;</span><br><span class="line"> printEvent event</span><br><span class="line"> previousEvent <span class="operator">&lt;-</span> <span class="literal">Some</span> event</span><br><span class="line"></span><br><span class="line"> <span class="keyword">member</span> this.handleEvent5 eventArgs <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> event <span class="operator">=</span> &#123;label<span class="operator">=</span><span class="number">5</span>; time<span class="operator">=</span>DateTime.Now&#125;</span><br><span class="line"> printEvent event</span><br><span class="line"> previousEvent <span class="operator">&lt;-</span> <span class="literal">Some</span> event</span><br></pre></td></tr></table></figure>
-
<p>Now the code is beginning to get ugly fast! Already we have mutable state, complex conditional logic, and special cases, just for such a simple requirement.</p>
<p>Let’s test it:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create the class</span></span><br><span class="line"><span class="keyword">let</span> handler <span class="operator">=</span> <span class="keyword">new</span> ImperativeFizzBuzzHandler()</span><br><span class="line"></span><br><span class="line"><span class="comment">// create the two timers and register the two handlers</span></span><br><span class="line"><span class="keyword">let</span> timer3 <span class="operator">=</span> createTimer <span class="number">300</span> handler.handleEvent3</span><br><span class="line"><span class="keyword">let</span> timer5 <span class="operator">=</span> createTimer <span class="number">500</span> handler.handleEvent5</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the two timers at the same time</span></span><br><span class="line">[timer3;timer5]</span><br><span class="line"><span class="operator">|&gt;</span> Async.Parallel</span><br><span class="line"><span class="operator">|&gt;</span> Async.RunSynchronously</span><br></pre></td></tr></table></figure>
-
<p>It does work, but are you sure the code is not buggy? Are you likely to accidentally break something if you change it?</p>
<p>The problem with this imperative code is that it has a lot of noise that obscures the the requirements.</p>
<p>Can the functional version do better? Let’s see!</p>
<p>First, we create <em>two</em> event streams, one for each timer:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> timer3, timerEventStream3 <span class="operator">=</span> createTimerAndObservable <span class="number">300</span></span><br><span class="line"><span class="keyword">let</span> timer5, timerEventStream5 <span class="operator">=</span> createTimerAndObservable <span class="number">500</span></span><br></pre></td></tr></table></figure>
-
<p>Next, we convert each event on the “raw” event streams into our FizzBuzz event type:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// convert the time events into FizzBuzz events with the appropriate id</span></span><br><span class="line"><span class="keyword">let</span> eventStream3 <span class="operator">=</span></span><br><span class="line"> timerEventStream3</span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> &#123;label<span class="operator">=</span><span class="number">3</span>; time<span class="operator">=</span>DateTime.Now&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> eventStream5 <span class="operator">=</span></span><br><span class="line"> timerEventStream5</span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> &#123;label<span class="operator">=</span><span class="number">5</span>; time<span class="operator">=</span>DateTime.Now&#125;)</span><br></pre></td></tr></table></figure>
-
<p>Now, to see if two events are simultaneous, we need to compare them from the two different streams somehow.</p>
<p>It’s actually easier than it sounds, because we can:</p>
<ul>
@@ -282,26 +270,21 @@
</ul>
<p>Here’s the actual code to do this:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// combine the two streams</span></span><br><span class="line"><span class="keyword">let</span> combinedStream <span class="operator">=</span></span><br><span class="line"> Observable.merge eventStream3 eventStream5</span><br><span class="line"></span><br><span class="line"><span class="comment">// make pairs of events</span></span><br><span class="line"><span class="keyword">let</span> pairwiseStream <span class="operator">=</span></span><br><span class="line"> combinedStream <span class="operator">|&gt;</span> Observable.pairwise</span><br><span class="line"></span><br><span class="line"><span class="comment">// split the stream based on whether the pairs are simultaneous</span></span><br><span class="line"><span class="keyword">let</span> simultaneousStream, nonSimultaneousStream <span class="operator">=</span></span><br><span class="line"> pairwiseStream <span class="operator">|&gt;</span> Observable.partition areSimultaneous</span><br></pre></td></tr></table></figure>
-
<p>Finally, we can split the <code>nonSimultaneousStream</code> again, based on the event id:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// split the non-simultaneous stream based on the id</span></span><br><span class="line"><span class="keyword">let</span> fizzStream, buzzStream <span class="operator">=</span></span><br><span class="line"> nonSimultaneousStream</span><br><span class="line"> <span class="comment">// convert pair of events to the first event</span></span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> (ev1,_) <span class="operator">-&gt;</span> ev1)</span><br><span class="line"> <span class="comment">// split on whether the event id is three</span></span><br><span class="line"> <span class="operator">|&gt;</span> Observable.partition (<span class="keyword">fun</span> &#123;label<span class="operator">=</span><span class="built_in">id</span>&#125; <span class="operator">-&gt;</span> <span class="built_in">id</span><span class="operator">=</span><span class="number">3</span>)</span><br></pre></td></tr></table></figure>
-
<p>Let’s review so far. We have started with the two original event streams and from them created four new ones:</p>
<ul>
<li><code>combinedStream</code> contains all the events</li>
<li><code>simultaneousStream</code> contains only the simultaneous events</li>
-<li><code>fizzStream</code> contains only the non-simultaneous events with id&#x3D;3</li>
-<li><code>buzzStream</code> contains only the non-simultaneous events with id&#x3D;5</li>
+<li><code>fizzStream</code> contains only the non-simultaneous events with id=3</li>
+<li><code>buzzStream</code> contains only the non-simultaneous events with id=5</li>
</ul>
<p>Now all we need to do is attach behavior to each stream:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//print events from the combinedStream</span></span><br><span class="line">combinedStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> &#123;label<span class="operator">=</span><span class="built_in">id</span>;time<span class="operator">=</span>t&#125; <span class="operator">-&gt;</span></span><br><span class="line"> <span class="built_in">printf</span> <span class="string">&quot;[%i] %i.%03i &quot;</span> <span class="built_in">id</span> t.Second t.Millisecond)</span><br><span class="line"></span><br><span class="line"><span class="comment">//print events from the simultaneous stream</span></span><br><span class="line">simultaneousStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;FizzBuzz&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">//print events from the nonSimultaneous streams</span></span><br><span class="line">fizzStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;Fizz&quot;</span>)</span><br><span class="line"></span><br><span class="line">buzzStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;Buzz&quot;</span>)</span><br></pre></td></tr></table></figure>
-
<p>Let’s test it:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// run the two timers at the same time</span></span><br><span class="line">[timer3;timer5]</span><br><span class="line"><span class="operator">|&gt;</span> Async.Parallel</span><br><span class="line"><span class="operator">|&gt;</span> Async.RunSynchronously</span><br></pre></td></tr></table></figure>
-
<p>Here’s all the code in one complete set:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// create the event streams and raw observables</span></span><br><span class="line"><span class="keyword">let</span> timer3, timerEventStream3 <span class="operator">=</span> createTimerAndObservable <span class="number">300</span></span><br><span class="line"><span class="keyword">let</span> timer5, timerEventStream5 <span class="operator">=</span> createTimerAndObservable <span class="number">500</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// convert the time events into FizzBuzz events with the appropriate id</span></span><br><span class="line"><span class="keyword">let</span> eventStream3 <span class="operator">=</span> timerEventStream3</span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> &#123;label<span class="operator">=</span><span class="number">3</span>; time<span class="operator">=</span>DateTime.Now&#125;)</span><br><span class="line"><span class="keyword">let</span> eventStream5 <span class="operator">=</span> timerEventStream5</span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> &#123;label<span class="operator">=</span><span class="number">5</span>; time<span class="operator">=</span>DateTime.Now&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// combine the two streams</span></span><br><span class="line"><span class="keyword">let</span> combinedStream <span class="operator">=</span></span><br><span class="line"> Observable.merge eventStream3 eventStream5</span><br><span class="line"></span><br><span class="line"><span class="comment">// make pairs of events</span></span><br><span class="line"><span class="keyword">let</span> pairwiseStream <span class="operator">=</span></span><br><span class="line"> combinedStream <span class="operator">|&gt;</span> Observable.pairwise</span><br><span class="line"></span><br><span class="line"><span class="comment">// split the stream based on whether the pairs are simultaneous</span></span><br><span class="line"><span class="keyword">let</span> simultaneousStream, nonSimultaneousStream <span class="operator">=</span></span><br><span class="line"> pairwiseStream <span class="operator">|&gt;</span> Observable.partition areSimultaneous</span><br><span class="line"></span><br><span class="line"><span class="comment">// split the non-simultaneous stream based on the id</span></span><br><span class="line"><span class="keyword">let</span> fizzStream, buzzStream <span class="operator">=</span></span><br><span class="line"> nonSimultaneousStream</span><br><span class="line"> <span class="comment">// convert pair of events to the first event</span></span><br><span class="line"> <span class="operator">|&gt;</span> Observable.map (<span class="keyword">fun</span> (ev1,_) <span class="operator">-&gt;</span> ev1)</span><br><span class="line"> <span class="comment">// split on whether the event id is three</span></span><br><span class="line"> <span class="operator">|&gt;</span> Observable.partition (<span class="keyword">fun</span> &#123;label<span class="operator">=</span><span class="built_in">id</span>&#125; <span class="operator">-&gt;</span> <span class="built_in">id</span><span class="operator">=</span><span class="number">3</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">//print events from the combinedStream</span></span><br><span class="line">combinedStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> &#123;label<span class="operator">=</span><span class="built_in">id</span>;time<span class="operator">=</span>t&#125; <span class="operator">-&gt;</span></span><br><span class="line"> <span class="built_in">printf</span> <span class="string">&quot;[%i] %i.%03i &quot;</span> <span class="built_in">id</span> t.Second t.Millisecond)</span><br><span class="line"></span><br><span class="line"><span class="comment">//print events from the simultaneous stream</span></span><br><span class="line">simultaneousStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;FizzBuzz&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">//print events from the nonSimultaneous streams</span></span><br><span class="line">fizzStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;Fizz&quot;</span>)</span><br><span class="line"></span><br><span class="line">buzzStream</span><br><span class="line"><span class="operator">|&gt;</span> Observable.subscribe (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> <span class="built_in">printfn</span> <span class="string">&quot;Buzz&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// run the two timers at the same time</span></span><br><span class="line">[timer3;timer5]</span><br><span class="line"><span class="operator">|&gt;</span> Async.Parallel</span><br><span class="line"><span class="operator">|&gt;</span> Async.RunSynchronously</span><br></pre></td></tr></table></figure>
-
<p>The code might seem a bit long winded, but this kind of incremental, step-wise approach is very clear and self-documenting.</p>
<p>Some of the benefits of this style are:</p>
<ul>
@@ -311,9 +294,9 @@
<li>It is easy to debug. For example, I could easily “tap” the output of the <code>simultaneousStream</code> to see if it contains what I think it contains:</li>
</ul>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// debugging code</span></span><br><span class="line"><span class="comment">//simultaneousStream |&gt; Observable.subscribe (fun e -&gt; printfn &quot;sim %A&quot; e)</span></span><br><span class="line"><span class="comment">//nonSimultaneousStream |&gt; Observable.subscribe (fun e -&gt; printfn &quot;non-sim %A&quot; e)</span></span><br></pre></td></tr></table></figure>
-
<p>This would be much harder in the imperative version.</p>
-<h2 id="Summary"><a href="#Summary" class="headerlink" title="Summary"></a>Summary</h2><p>Functional Reactive Programming (known as FRP) is a big topic, and we’ve only just touched on it here. I hope this introduction has given you a glimpse of the usefulness of this way of doing things.</p>
+<h2 id="Summary"><a class="header-anchor" href="#Summary">¶</a>Summary</h2>
+<p>Functional Reactive Programming (known as FRP) is a big topic, and we’ve only just touched on it here. I hope this introduction has given you a glimpse of the usefulness of this way of doing things.</p>
<p>If you want to learn more, see the documentation for the F# <a target="_blank" rel="noopener" href="https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ee370313%28v=vs.100%29?redirectedfrom=MSDN">Observable module</a>, which has the basic transformations used above. And there is also the <a target="_blank" rel="noopener" href="https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242985%28v=vs.103%29">Reactive Extensions (Rx)</a> library which shipped as part of .NET 4. That contains many other additional transformations.</p>
</div>
diff --git a/2024/09/15/Advanced-C-binding-using-ocaml-ctypes-and-dune/index.html b/2024/09/15/Advanced-C-binding-using-ocaml-ctypes-and-dune/index.html
index 9f8963b8..a825fda7 100644
--- a/2024/09/15/Advanced-C-binding-using-ocaml-ctypes-and-dune/index.html
+++ b/2024/09/15/Advanced-C-binding-using-ocaml-ctypes-and-dune/index.html
@@ -200,21 +200,26 @@
<div class="post-content">
<p>I was working on a OCaml binding for <a target="_blank" rel="noopener" href="https://github.com/Haivision/srt">libsrt</a> last summer, to add support for SRT real-time input and output to <a target="_blank" rel="noopener" href="https://github.com/savonet/liquidsoap">liquidsoap</a>, and came across the need to access the <code>[sys/socket.h](https://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html)</code> C API.</p>
<p>I had already decided to use the very elegant <code>[ocaml-ctypes](https://github.com/ocamllabs/ocaml-ctypes)</code> module for the SRT binding so I went with it and created a <code>[ocaml-sys-socket](https://github.com/toots/ocaml-sys-socket)</code> module using it as well. It was a very interesting experience that I would like to describe here!</p>
-<h1 id="ocaml-ctypes"><a href="#ocaml-ctypes" class="headerlink" title="ocaml-ctypes"></a>ocaml-ctypes</h1><p>The idea behind OCaml ctypes is to create a binding against a C library without having to write C code, or as least as possible. The most straight-forward way of using it is via <code>[libffi](https://github.com/libffi/libffi)</code> , providing access to dynamically-loaded libraries.</p>
+<h1>ocaml-ctypes</h1>
+<p>The idea behind OCaml ctypes is to create a binding against a C library without having to write C code, or as least as possible. The most straight-forward way of using it is via <code>[libffi](https://github.com/libffi/libffi)</code> , providing access to dynamically-loaded libraries.</p>
<p>The second way of using it is by letting the module generate the basic C stubs required to build and link against a shared library. This is the mode that we’re going to use here. In this mode, the programmer has to describe the C headers of the library they intent to bind to using dedicated OCaml modules, operators and types. From that description, ocaml-ctypes is able to generate the required glue for the binding.</p>
<p>One advantage of using ocaml-ctypes is that the created bindings make as few assumptions as possible about the <a target="_blank" rel="noopener" href="https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html">OCaml C interfacing API</a>. This is pretty nice, in particular since the <a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml">OCaml compiler</a> is moving pretty quickly these days (which is awesome!) and also if, perhaps one day, <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/ocaml-multicore">support for multi-core</a> is added to the compiler, which will undoubtedly change the C interface API quite a bit.</p>
-<h1 id="dune"><a href="#dune" class="headerlink" title="dune"></a>dune</h1><p><code>[dune](https://github.com/ocaml/dune)</code> (formally <code>jbuilder</code> ) is a build system for OCaml projects that has recently raised to much popularity, particularly due to its tight integration with the rest of the OCaml ecosystem, such as <code>[ocamlfind](http://projects.camlcity.org/projects/findlib.html)</code> and <code>[opam](https://opam.ocaml.org/)</code> .</p>
+<h1>dune</h1>
+<p><code>[dune](https://github.com/ocaml/dune)</code> (formally <code>jbuilder</code> ) is a build system for OCaml projects that has recently raised to much popularity, particularly due to its tight integration with the rest of the OCaml ecosystem, such as <code>[ocamlfind](http://projects.camlcity.org/projects/findlib.html)</code> and <code>[opam](https://opam.ocaml.org/)</code> .</p>
<p>My personal motto in programming in general is that <em>“Simple things should be simple, but complex things should be possible”</em>. <code>dune</code> certainly does not fit into that category but, rather, makes some complex things extremely easy to setup. It’s the kind of tool that will make your life incredibly easier when what you intent to do fits well within their workflow but might not be easy to bend to some very specific niche use. We will see one such case below.</p>
<p>At any rate, it’s been an amazing experience getting to learn how to use <code>dune</code> and the resulting code and build system is remarkably short and elegant, yet very powerful.</p>
-<h1 id="socket-h"><a href="#socket-h" class="headerlink" title="socket.h"></a>socket.h</h1><p><code>socket.h</code> is the Unix header that describes the C API to various socket operations, IP version 4 and 6 as well as unix file sockets. There is also a windows API mimicking it, which makes most code using it easily portable to windows.</p>
+<h1>socket.h</h1>
+<p><code>socket.h</code> is the Unix header that describes the C API to various socket operations, IP version 4 and 6 as well as unix file sockets. There is also a windows API mimicking it, which makes most code using it easily portable to windows.</p>
<p>Most network-based C libraries refer to <code>socket.h</code> to describe the type of socket that can be used with their API so it’s an important entry point for a lot of network operations and one that would be nice to support as generically as possible in OCaml.</p>
<p>The catch, though, is that, most likely for historical reasons¹, the <a target="_blank" rel="noopener" href="https://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html">POSIX specifications</a> only <em>partially</em> defines some of the required data structures and types, which makes it possible to write C code using them but does not give enough information to write C bindings without having to use the compiler to parse the actual system-specific headers of the running host.</p>
<p>For instance, here’s how the <code>sockaddr</code> structure is specified:</p>
-<p>The <em>&lt;sys&#x2F;socket.h&gt;</em> header defines the sockaddr structure that includes at least the following members:sa_family_t sa_family address family<br>char sa_data[] socket address (variable-length data)</p>
+<p>The <em>&lt;sys/socket.h&gt;</em> header defines the sockaddr structure that includes at least the following members:sa_family_t sa_family address family<br>
+char sa_data[] socket address (variable-length data)</p>
<p>Likewise, here’s what is specified about the size of the <code>socklen_t</code> data type:</p>
-<p><em>&lt;sys&#x2F;socket.h&gt;</em> makes available a type, socklen_t, which is an unsigned opaque integral type of length of at least 32 bits.</p>
+<p><em>&lt;sys/socket.h&gt;</em> makes available a type, socklen_t, which is an unsigned opaque integral type of length of at least 32 bits.</p>
<p>Thus, in order to know the exact offset of <code>sa_family</code> inside the <code>sockaddr</code> structure or the actual size of a <code>socklen_t</code> integer, one has to include the OS-specific header, parse its definitions for that specific OS and, only then, is it possible to compute that offset or data size. Let’s see how it’s done in our binding now!</p>
-<h1 id="Putting-it-together"><a href="#Putting-it-together" class="headerlink" title="Putting it together"></a>Putting it together</h1><p>The C binding requires 4 separate passes:</p>
+<h1>Putting it together</h1>
+<p>The C binding requires 4 separate passes:</p>
<ul>
<li>The <code>[constants](https://github.com/toots/ocaml-sys-socket/tree/master/src/sys-socket/constants)</code> pass, which computes and exports some specific constant and data sizes, computed from the C headers</li>
<li>The <code>[types](https://github.com/toots/ocaml-sys-socket/tree/master/src/sys-socket/types)</code> pass, which, given the system-specific constants and sizes exported in the previous phase, defines the actual C data structure bindings.</li>
@@ -222,73 +227,62 @@
<li>Finally, the <a target="_blank" rel="noopener" href="https://github.com/toots/ocaml-sys-socket/blob/master/src/sys-socket/sys_socket.mli">last pass</a> does a cleanup of the <code>stubs</code> pass to export a relevant and OCaml- (and <code>ocaml-ctypes</code>) specific public API that is to be used by users of the module.</li>
</ul>
<p><code>dune</code> makes each of these steps fairly easy to integrate into the next one, defining compilation elements and binaries to build before moving to the next pass.</p>
-<h2 id="Constants-pass"><a href="#Constants-pass" class="headerlink" title="Constants pass"></a>Constants pass</h2><p>During that pass, we compute and export all required C values defined in the headers. We also add our own constants, which give us the sizes that the POSIX specifications leave up to the OS. Here’s the OCaml code for it:</p>
+<h2 id="Constants-pass"><a class="header-anchor" href="#Constants-pass">¶</a>Constants pass</h2>
+<p>During that pass, we compute and export all required C values defined in the headers. We also add our own constants, which give us the sizes that the POSIX specifications leave up to the OS. Here’s the OCaml code for it:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="type">Def</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">let</span> af_inet = <span class="type">S</span>.constant <span class="string">&quot;AF_INET&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> af_inet6 = <span class="type">S</span>.constant <span class="string">&quot;AF_INET6&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> af_unix = <span class="type">S</span>.constant <span class="string">&quot;AF_UNIX&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> af_unspec = <span class="type">S</span>.constant <span class="string">&quot;AF_UNSPEC&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> sa_data_len = <span class="type">S</span>.constant <span class="string">&quot;SA_DATA_LEN&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> sa_family_len = <span class="type">S</span>.constant <span class="string">&quot;SA_FAMILY_LEN&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> sock_dgram = <span class="type">S</span>.constant <span class="string">&quot;SOCK_DGRAM&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> sock_stream = <span class="type">S</span>.constant <span class="string">&quot;SOCK_STREAM&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> sock_seqpacket = <span class="type">S</span>.constant <span class="string">&quot;SOCK_STREAM&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> socklen_t_len = <span class="type">S</span>.constant <span class="string">&quot;SOCKLEN_T_LEN&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> ni_maxserv = <span class="type">S</span>.constant <span class="string">&quot;NI_MAXSERV&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> ni_maxhost = <span class="type">S</span>.constant <span class="string">&quot;NI_MAXHOST&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> ni_numerichost = <span class="type">S</span>.constant <span class="string">&quot;NI_NUMERICHOST&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"> <span class="keyword">let</span> ni_numericserv = <span class="type">S</span>.constant <span class="string">&quot;NI_NUMERICSERV&quot;</span> <span class="type">S</span>.<span class="built_in">int</span></span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
-
<p>Pretty straightforward! Some of these constants are defined by the POSIX headers and some are custom defined for our needs, for instance <code>SOCKLEN_T_LEN</code> . Here’s how they are extracted, using the <code>dune</code> build configuration for <code>[gen_constants_c](https://github.com/toots/ocaml-sys-socket/blob/master/src/sys-socket/generator/gen_constants_c.ml)</code>:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> c_headers = <span class="string">&quot;</span></span><br><span class="line"><span class="string">#ifdef _WIN32</span></span><br><span class="line"><span class="string"> #include &lt;winsock2.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;ws2tcpip.h&gt;</span></span><br><span class="line"><span class="string">#else</span></span><br><span class="line"><span class="string"> #include &lt;sys/socket.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;sys/un.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;netdb.h&gt;</span></span><br><span class="line"><span class="string">#endif</span></span><br><span class="line"><span class="string">#define SA_DATA_LEN (sizeof(((struct sockaddr*)0)-&gt;sa_data))</span></span><br><span class="line"><span class="string">#define SA_FAMILY_LEN (sizeof(((struct sockaddr*)0)-&gt;sa_family))</span></span><br><span class="line"><span class="string">#define SOCKLEN_T_LEN (sizeof(socklen_t))</span></span><br><span class="line"><span class="string">#ifndef NI_MAXHOST</span></span><br><span class="line"><span class="string"> #define NI_MAXHOST 1025</span></span><br><span class="line"><span class="string">#endif</span></span><br><span class="line"><span class="string">#ifndef NI_MAXSERV</span></span><br><span class="line"><span class="string"> #define NI_MAXSERV 32</span></span><br><span class="line"><span class="string">#endif</span></span><br><span class="line"><span class="string">&quot;</span></span><br><span class="line"><span class="keyword">let</span> <span class="literal">()</span> =</span><br><span class="line"> <span class="keyword">let</span> fname = <span class="type">Sys</span>.argv.(<span class="number">1</span>) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> oc = open_out_bin fname <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> format =</span><br><span class="line"> <span class="type">Format</span>.formatter_of_out_channel oc</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="type">Format</span>.fprintf format <span class="string">&quot;%s@\n&quot;</span> c_headers;</span><br><span class="line"> <span class="type">Cstubs</span>.<span class="type">Types</span>.write_c format (<span class="keyword">module</span> <span class="type">Sys_socket_constants</span>.<span class="type">Def</span>);</span><br><span class="line"> <span class="type">Format</span>.pp_print_flush format <span class="literal">()</span>;</span><br><span class="line"> close_out oc</span><br></pre></td></tr></table></figure>
-
<p>This OCaml code makes use of <code>ocaml-ctypes</code> to build a binary that exports the OCaml interface defined by <code>Sys_socket_constants.Def</code> . Once compiled, its output looks like this:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">include</span> <span class="type">Ctypes</span></span><br><span class="line"><span class="keyword">let</span> lift x = x</span><br><span class="line"><span class="keyword">open</span> <span class="type">Ctypes_static</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> field : <span class="keyword">type</span> t a. t typ -&gt; <span class="built_in">string</span> -&gt; a typ -&gt; (a, t) field =</span><br><span class="line"> <span class="keyword">fun</span> s fname ftype -&gt; <span class="keyword">match</span> s, fname <span class="keyword">with</span></span><br><span class="line"> | <span class="type">View</span> &#123; ty &#125;, _ -&gt;</span><br><span class="line"> <span class="keyword">let</span> &#123; ftype; foffset; fname &#125; = field ty fname ftype <span class="keyword">in</span></span><br><span class="line"> &#123; ftype; foffset; fname &#125;</span><br><span class="line"> | _ -&gt; failwith (<span class="string">&quot;Unexpected field &quot;</span>^ fname)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> seal : <span class="keyword">type</span> a. a typ -&gt; <span class="built_in">unit</span> = <span class="keyword">function</span></span><br><span class="line"> | <span class="type">Struct</span> &#123; tag; spec = <span class="type">Complete</span> _ &#125; -&gt;</span><br><span class="line"> raise (<span class="type">ModifyingSealedType</span> tag)</span><br><span class="line"> | <span class="type">Union</span> &#123; utag; uspec = <span class="type">Some</span> _ &#125; -&gt;</span><br><span class="line"> raise (<span class="type">ModifyingSealedType</span> utag)</span><br><span class="line"> | <span class="type">View</span> &#123; ty &#125; -&gt; seal ty</span><br><span class="line"> | _ -&gt;</span><br><span class="line"> raise (<span class="type">Unsupported</span> <span class="string">&quot;Sealing a non-structured type&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> <span class="symbol">&#x27;a</span> const = <span class="symbol">&#x27;a</span></span><br><span class="line"><span class="keyword">let</span> constant (<span class="keyword">type</span> t) name (t : t typ) : t = <span class="keyword">match</span> t, name <span class="keyword">with</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;NI_NUMERICSERV&quot;</span> -&gt;</span><br><span class="line"> <span class="number">8</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;NI_NUMERICHOST&quot;</span> -&gt;</span><br><span class="line"> <span class="number">2</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;NI_MAXHOST&quot;</span> -&gt;</span><br><span class="line"> <span class="number">1025</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;NI_MAXSERV&quot;</span> -&gt;</span><br><span class="line"> <span class="number">32</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SOCKLEN_T_LEN&quot;</span> -&gt;</span><br><span class="line"> <span class="number">4</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SOCK_STREAM&quot;</span> -&gt;</span><br><span class="line"> <span class="number">1</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SOCK_STREAM&quot;</span> -&gt;</span><br><span class="line"> <span class="number">1</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SOCK_DGRAM&quot;</span> -&gt;</span><br><span class="line"> <span class="number">2</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SA_FAMILY_LEN&quot;</span> -&gt;</span><br><span class="line"> <span class="number">1</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;SA_DATA_LEN&quot;</span> -&gt;</span><br><span class="line"> <span class="number">14</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;AF_UNSPEC&quot;</span> -&gt;</span><br><span class="line"> <span class="number">0</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;AF_UNIX&quot;</span> -&gt;</span><br><span class="line"> <span class="number">1</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;AF_INET6&quot;</span> -&gt;</span><br><span class="line"> <span class="number">30</span></span><br><span class="line"> | <span class="type">Ctypes_static</span>.<span class="type">Primitive</span> <span class="type">Cstubs_internals</span>.<span class="type">Int</span>, <span class="string">&quot;AF_INET&quot;</span> -&gt;</span><br><span class="line"> <span class="number">2</span></span><br><span class="line"> | _, s -&gt; failwith (<span class="string">&quot;unmatched constant: &quot;</span>^ s)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> enum (<span class="keyword">type</span> a) name ?typedef ?unexpected (alist : (a * <span class="built_in">int64</span>) <span class="built_in">list</span>) =</span><br><span class="line"> <span class="keyword">match</span> name <span class="keyword">with</span></span><br><span class="line"> | s -&gt;</span><br><span class="line"> failwith (<span class="string">&quot;unmatched enum: &quot;</span>^ s)</span><br></pre></td></tr></table></figure>
-
<p>The files used to describe how to build this binary using <code>dune</code> are located in a separate <code>[generator](https://github.com/toots/ocaml-sys-socket/tree/master/src/sys-socket/generator)</code> directory. Here’s the entry to build this one:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">(executable</span><br><span class="line"> (name gen_constants_c)</span><br><span class="line"> (modules gen_constants_c)</span><br><span class="line"> (libraries sys-socket.constants ctypes.stubs))</span><br><span class="line"></span><br><span class="line">(rule</span><br><span class="line"> (targets gen_constants.c)</span><br><span class="line"> (deps (:gen ./gen_constants_c.exe))</span><br><span class="line"> (action (run %&#123;gen&#125; %&#123;targets&#125;)))</span><br><span class="line"></span><br><span class="line">(rule</span><br><span class="line"> (targets gen_constants_c)</span><br><span class="line"> (deps (:c_code ./gen_constants.c))</span><br><span class="line"> (action (run %&#123;ocaml-config:c_compiler&#125; -I %&#123;lib:ctypes:&#125; -I %&#123;ocaml-config:standard_library&#125; -o %&#123;targets&#125; %&#123;c_code&#125;)))</span><br></pre></td></tr></table></figure>
-
<p>This executable is compiled during the next phase. Let’s move into it now!</p>
-<h2 id="Types-pass"><a href="#Types-pass" class="headerlink" title="Types pass"></a>Types pass</h2><p>During that phase, we use the constants exported during the previous phase to describe the various C structures and types. This is by far the most complex part of the code, making use of first-class modules and several OCaml tricks.</p>
+<h2 id="Types-pass"><a class="header-anchor" href="#Types-pass">¶</a>Types pass</h2>
+<p>During that phase, we use the constants exported during the previous phase to describe the various C structures and types. This is by far the most complex part of the code, making use of first-class modules and several OCaml tricks.</p>
<p>First, let’s look at how we tell <code>dune</code> that we need to generate the <code>.ml</code> file exporting our required constants from the previous pass:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">(rule</span><br><span class="line"> (targets sys_socket_generated_constants.ml)</span><br><span class="line"> (deps (:exec ../generator/exec.sh)</span><br><span class="line"> (:gen ../generator/gen_constants_c))</span><br><span class="line"> (action (with-stdout-to %&#123;targets&#125;</span><br><span class="line"> (system &quot;%&#123;exec&#125; %&#123;ocaml-config:system&#125; %&#123;gen&#125;&quot;))))</span><br></pre></td></tr></table></figure>
-
<p>With only this information, if the code refers to a <code>Sys_socket_generated_constants</code> module, <code>dune</code> will know that this module needs to be generated and how to do it. We will explain later the use of the <code>exec.sh</code> wrapper here.</p>
<p>Now that we can make use of the exported constants in our OCaml code, let’s see how we define the <code>Socklen</code> module, exporting abstract types and interface to use <code>socklen_t</code> integers:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="type">Constants</span> = <span class="type">Sys_socket_constants</span>.<span class="type">Def</span>(<span class="type">Sys_socket_generated_constants</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="keyword">type</span> <span class="type">Socklen</span> = <span class="keyword">functor</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) -&gt; <span class="keyword">sig</span></span><br><span class="line"> <span class="keyword">type</span> socklen</span><br><span class="line"> <span class="keyword">val</span> socklen_t : socklen <span class="type">S</span>.typ</span><br><span class="line"> <span class="keyword">val</span> int_of_socklen : socklen -&gt; <span class="built_in">int</span></span><br><span class="line"> <span class="keyword">val</span> socklen_of_int : <span class="built_in">int</span> -&gt; socklen</span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> socklen : (<span class="keyword">module</span> <span class="type">Socklen</span>) =</span><br><span class="line"> <span class="keyword">match</span> <span class="type">Constants</span>.socklen_t_len <span class="keyword">with</span></span><br><span class="line"> | <span class="number">4</span> -&gt; (<span class="keyword">module</span> <span class="keyword">functor</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) -&gt; <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">type</span> socklen = <span class="type">Unsigned</span>.uint32</span><br><span class="line"> <span class="keyword">let</span> socklen_t = <span class="type">S</span>.uint32_t</span><br><span class="line"> <span class="keyword">let</span> int_of_socklen = <span class="type">Unsigned</span>.<span class="type">UInt32</span>.to_int</span><br><span class="line"> <span class="keyword">let</span> socklen_of_int = <span class="type">Unsigned</span>.<span class="type">UInt32</span>.of_int</span><br><span class="line"> <span class="keyword">end</span>)</span><br><span class="line"> | <span class="number">8</span> -&gt; (<span class="keyword">module</span> <span class="keyword">functor</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) -&gt; <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">type</span> socklen = <span class="type">Unsigned</span>.uint64</span><br><span class="line"> <span class="keyword">let</span> socklen_t = <span class="type">S</span>.uint64_t</span><br><span class="line"> <span class="keyword">let</span> int_of_socklen = <span class="type">Unsigned</span>.<span class="type">UInt64</span>.to_int</span><br><span class="line"> <span class="keyword">let</span> socklen_of_int = <span class="type">Unsigned</span>.<span class="type">UInt64</span>.of_int</span><br><span class="line"> <span class="keyword">end</span>)</span><br><span class="line"> | _ -&gt; <span class="keyword">assert</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="type">Socklen</span> = (<span class="keyword">val</span> socklen : <span class="type">Socklen</span>)</span><br></pre></td></tr></table></figure>
-
<p>As you can see, we make use of first-order modules and the size of the <code>socklen_t</code> integer to define the right API for the compiling host. Now let’s see how we define the <code>sockaddr</code> interface:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="keyword">type</span> <span class="type">SaFamily</span> = <span class="keyword">sig</span></span><br><span class="line"> <span class="keyword">type</span> sa_family</span><br><span class="line"> <span class="keyword">val</span> int_of_sa_family : sa_family -&gt; <span class="built_in">int</span></span><br><span class="line"> <span class="keyword">val</span> sa_family_of_int : <span class="built_in">int</span> -&gt; sa_family</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">module</span> <span class="type">T</span> : <span class="keyword">functor</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) -&gt; <span class="keyword">sig</span></span><br><span class="line"> <span class="keyword">val</span> t : sa_family <span class="type">S</span>.typ</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> saFamily : (<span class="keyword">module</span> <span class="type">SaFamily</span>) =</span><br><span class="line"> <span class="keyword">match</span> <span class="type">Constants</span>.sa_family_len <span class="keyword">with</span></span><br><span class="line"> | <span class="number">1</span> -&gt; (<span class="keyword">module</span> <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">type</span> sa_family = <span class="type">Unsigned</span>.uint8</span><br><span class="line"> <span class="keyword">let</span> int_of_sa_family = <span class="type">Unsigned</span>.<span class="type">UInt8</span>.to_int</span><br><span class="line"> <span class="keyword">let</span> sa_family_of_int = <span class="type">Unsigned</span>.<span class="type">UInt8</span>.of_int </span><br><span class="line"> <span class="keyword">module</span> <span class="type">T</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">let</span> t = <span class="type">S</span>.uint8_t</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"> <span class="keyword">end</span>)</span><br><span class="line">...</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="type">SaFamily</span> = (<span class="keyword">val</span> saFamily : <span class="type">SaFamily</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="type">Def</span> (<span class="type">S</span> : <span class="type">Cstubs</span>.<span class="type">Types</span>.<span class="type">TYPE</span>) = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">include</span> <span class="type">Constants</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">include</span> <span class="type">Socklen</span>(<span class="type">S</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">include</span> <span class="type">SaFamily</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">module</span> <span class="type">SaFamilyT</span> = <span class="type">SaFamily</span>.<span class="type">T</span>(<span class="type">S</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> sa_family_t = <span class="type">S</span>.typedef <span class="type">SaFamilyT</span>.t <span class="string">&quot;sa_family_t&quot;</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">module</span> <span class="type">Sockaddr</span> = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">type</span> t = <span class="built_in">unit</span></span><br><span class="line"> <span class="keyword">let</span> t = <span class="type">S</span>.structure <span class="string">&quot;sockaddr&quot;</span></span><br><span class="line"> <span class="keyword">let</span> sa_family = <span class="type">S</span>.field t <span class="string">&quot;sa_family&quot;</span> sa_family_t</span><br><span class="line"> <span class="keyword">let</span> sa_data = <span class="type">S</span>.field t <span class="string">&quot;sa_data&quot;</span> (<span class="type">S</span>.<span class="built_in">array</span> sa_data_len <span class="type">S</span>.<span class="built_in">char</span>)</span><br><span class="line"> <span class="keyword">let</span> <span class="literal">()</span> = <span class="type">S</span>.seal t</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"> </span><br><span class="line"> ...</span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
-
<p>Here, too, we make use of the size of <code>sa_family</code> as exported previously to define the right structure fields.</p>
<p>Next step, we need to compile this interface again to export the right offset for the various structures that have been defined. That’s <code>dune</code>’s job again!</p>
<p>First, the generator code:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> c_headers = <span class="string">&quot;</span></span><br><span class="line"><span class="string">#ifdef _WIN32</span></span><br><span class="line"><span class="string"> #include &lt;winsock2.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;ws2tcpip.h&gt;</span></span><br><span class="line"><span class="string">#else</span></span><br><span class="line"><span class="string"> #include &lt;sys/socket.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;sys/un.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;netinet/in.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;netdb.h&gt;</span></span><br><span class="line"><span class="string">#endif</span></span><br><span class="line"><span class="string">&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="literal">()</span> =</span><br><span class="line"> <span class="keyword">let</span> fname = <span class="type">Sys</span>.argv.(<span class="number">1</span>) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> oc = open_out_bin fname <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> format =</span><br><span class="line"> <span class="type">Format</span>.formatter_of_out_channel oc</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="type">Format</span>.fprintf format <span class="string">&quot;%s@\n&quot;</span> c_headers;</span><br><span class="line"> <span class="type">Cstubs</span>.<span class="type">Types</span>.write_c format (<span class="keyword">module</span> <span class="type">Sys_socket_types</span>.<span class="type">Def</span>);</span><br><span class="line"> <span class="type">Format</span>.pp_print_flush format <span class="literal">()</span>;</span><br><span class="line"> close_out oc</span><br></pre></td></tr></table></figure>
-
<p>And the build instructions:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">(executable</span><br><span class="line"> (name gen_types_c)</span><br><span class="line"> (modules gen_types_c)</span><br><span class="line"> (libraries sys-socket.types ctypes.stubs))</span><br><span class="line"></span><br><span class="line">(rule</span><br><span class="line"> (targets gen_types.c)</span><br><span class="line"> (deps (:gen ./gen_types_c.exe))</span><br><span class="line"> (action (run %&#123;gen&#125; %&#123;targets&#125;)))</span><br><span class="line"></span><br><span class="line">(rule</span><br><span class="line"> (targets gen_types_c)</span><br><span class="line"> (deps (:c_code ./gen_types.c))</span><br><span class="line"> (action (run %&#123;ocaml-config:c_compiler&#125; -I %&#123;lib:ctypes:&#125; -I %&#123;ocaml-config:standard_library&#125; -o %&#123;targets&#125; %&#123;c_code&#125;)))</span><br></pre></td></tr></table></figure>
-
<p>Once, compiled, the exported <code>.ml</code> looks like this:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">include</span> <span class="type">Ctypes</span></span><br><span class="line"><span class="keyword">let</span> lift x = x</span><br><span class="line"><span class="keyword">open</span> <span class="type">Ctypes_static</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> field : <span class="keyword">type</span> t a. t typ -&gt; <span class="built_in">string</span> -&gt; a typ -&gt; (a, t) field =</span><br><span class="line"> <span class="keyword">fun</span> s fname ftype -&gt; <span class="keyword">match</span> s, fname <span class="keyword">with</span></span><br><span class="line">...</span><br><span class="line"> | <span class="type">Struct</span> (&#123; tag = <span class="string">&quot;sockaddr&quot;</span>&#125; <span class="keyword">as</span> s&#x27;), <span class="string">&quot;sa_data&quot;</span> -&gt;</span><br><span class="line"> <span class="keyword">let</span> f = &#123;ftype; fname; foffset = <span class="number">2</span>&#125; <span class="keyword">in</span></span><br><span class="line"> (s&#x27;.fields &lt;- <span class="type">BoxedField</span> f :: s&#x27;.fields; f)</span><br><span class="line"> | <span class="type">Struct</span> (&#123; tag = <span class="string">&quot;sockaddr&quot;</span>&#125; <span class="keyword">as</span> s&#x27;), <span class="string">&quot;sa_family&quot;</span> -&gt;</span><br><span class="line"> <span class="keyword">let</span> f = &#123;ftype; fname; foffset = <span class="number">1</span>&#125; <span class="keyword">in</span></span><br><span class="line"> (s&#x27;.fields &lt;- <span class="type">BoxedField</span> f :: s&#x27;.fields; f)</span><br><span class="line"> | <span class="type">View</span> &#123; ty &#125;, _ -&gt;</span><br><span class="line"> <span class="keyword">let</span> &#123; ftype; foffset; fname &#125; = field ty fname ftype <span class="keyword">in</span></span><br><span class="line"> &#123; ftype; foffset; fname &#125;</span><br><span class="line"> | _ -&gt; failwith (<span class="string">&quot;Unexpected field &quot;</span>^ fname)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> seal : <span class="keyword">type</span> a. a typ -&gt; <span class="built_in">unit</span> = <span class="keyword">function</span></span><br><span class="line">...</span><br><span class="line"> | <span class="type">Struct</span> (&#123; tag = <span class="string">&quot;sockaddr_storage&quot;</span>; spec = <span class="type">Incomplete</span> _ &#125; <span class="keyword">as</span> s&#x27;) -&gt;</span><br><span class="line"> s&#x27;.spec &lt;- <span class="type">Complete</span> &#123; size = <span class="number">128</span>; align = <span class="number">8</span> &#125;</span><br><span class="line"> | <span class="type">Struct</span> (&#123; tag = <span class="string">&quot;sockaddr&quot;</span>; spec = <span class="type">Incomplete</span> _ &#125; <span class="keyword">as</span> s&#x27;) -&gt;</span><br><span class="line"> s&#x27;.spec &lt;- <span class="type">Complete</span> &#123; size = <span class="number">16</span>; align = <span class="number">1</span> &#125;</span><br><span class="line"> | <span class="type">Struct</span> &#123; tag; spec = <span class="type">Complete</span> _ &#125; -&gt;</span><br><span class="line"> raise (<span class="type">ModifyingSealedType</span> tag)</span><br><span class="line"> | <span class="type">Union</span> &#123; utag; uspec = <span class="type">Some</span> _ &#125; -&gt;</span><br><span class="line"> raise (<span class="type">ModifyingSealedType</span> utag)</span><br><span class="line"> | <span class="type">View</span> &#123; ty &#125; -&gt; seal ty</span><br><span class="line"> | _ -&gt;</span><br><span class="line"> raise (<span class="type">Unsupported</span> <span class="string">&quot;Sealing a non-structured type&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> <span class="symbol">&#x27;a</span> const = <span class="symbol">&#x27;a</span></span><br><span class="line"><span class="keyword">let</span> constant (<span class="keyword">type</span> t) name (t : t typ) : t = <span class="keyword">match</span> t, name <span class="keyword">with</span></span><br><span class="line"> | _, s -&gt; failwith (<span class="string">&quot;unmatched constant: &quot;</span>^ s)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> enum (<span class="keyword">type</span> a) name ?typedef ?unexpected (alist : (a * <span class="built_in">int64</span>) <span class="built_in">list</span>) =</span><br><span class="line"> <span class="keyword">match</span> name <span class="keyword">with</span></span><br><span class="line"> | s -&gt;</span><br><span class="line"> failwith (<span class="string">&quot;unmatched enum: &quot;</span>^ s)</span><br></pre></td></tr></table></figure>
-
<p>As you can see, this exports all the offsets required to access the fields inside a <code>sockaddr_t</code> structure. We’re now ready to move to the final stage, which is the actual binding stubs!</p>
-<h2 id="Binding-stubs"><a href="#Binding-stubs" class="headerlink" title="Binding stubs"></a>Binding stubs</h2><p>First step in this pass, just like with the previous ones, we need to configure <code>dune</code> to be able to build the exported <code>.ml</code> code from the <code>types</code> pass:</p>
+<h2 id="Binding-stubs"><a class="header-anchor" href="#Binding-stubs">¶</a>Binding stubs</h2>
+<p>First step in this pass, just like with the previous ones, we need to configure <code>dune</code> to be able to build the exported <code>.ml</code> code from the <code>types</code> pass:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">(rule</span><br><span class="line"> (targets sys_socket_generated_types.ml)</span><br><span class="line"> (deps (:exec ../generator/exec.sh)</span><br><span class="line"> (:gen ../generator/gen_types_c))</span><br><span class="line"> (action (with-stdout-to %&#123;targets&#125;</span><br><span class="line"> (system &quot;%&#123;exec&#125; %&#123;ocaml-config:system&#125; %&#123;gen&#125;&quot;))))</span><br></pre></td></tr></table></figure>
-
<p>And we can now define the proper bindings. Here’s how it looks like:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">open</span> <span class="type">Ctypes</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="type">Def</span> (<span class="type">F</span> : <span class="type">Cstubs</span>.<span class="type">FOREIGN</span>) = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">open</span> <span class="type">F</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">module</span> <span class="type">Types</span> = <span class="type">Sys_socket_types</span>.<span class="type">Def</span>(<span class="type">Sys_socket_generated_types</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">open</span> <span class="type">Types</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> getnameinfo = foreign <span class="string">&quot;getnameinfo&quot;</span> (ptr sockaddr_t @-&gt; socklen_t @-&gt; ptr <span class="built_in">char</span> @-&gt; socklen_t @-&gt; ptr <span class="built_in">char</span> @-&gt; socklen_t @-&gt; <span class="built_in">int</span> @-&gt; (returning <span class="built_in">int</span>))</span><br><span class="line"></span><br><span class="line">...</span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
-
-<p>As you can see, we’re exporting the <code>getnameinfo</code> function, taking various arguments, including a pointer to a <code>sockaddr_t</code> structure and a couple of <code>socklen_t</code> integers, making use of all the various data types and structures previously defined. The exact specifications of this function can be found <a target="_blank" rel="noopener" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html">here</a>. We can now define out top-level API..</p>
-<h2 id="Final-API"><a href="#Final-API" class="headerlink" title="Final API"></a>Final API</h2><p>Building upon the previous modules, we export various OCaml idiomatic APIs that the binding user can now use to build new bindings against the <code>socket.h</code> APIs.</p>
+<p>As you can see, we’re exporting the <code>getnameinfo</code> function, taking various arguments, including a pointer to a <code>sockaddr_t</code> structure and a couple of <code>socklen_t</code> integers, making use of all the various data types and structures previously defined. The exact specifications of this function can be found <a target="_blank" rel="noopener" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html">here</a>. We can now define out top-level API…</p>
+<h2 id="Final-API"><a class="header-anchor" href="#Final-API">¶</a>Final API</h2>
+<p>Building upon the previous modules, we export various OCaml idiomatic APIs that the binding user can now use to build new bindings against the <code>socket.h</code> APIs.</p>
<p>Just like with the previous steps, first we need to configure the build system:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">(rule</span><br><span class="line"> (targets sys_socket_generated_stubs.ml)</span><br><span class="line"> (deps (:gen ./generator/gen_stubs.exe))</span><br><span class="line"> (action (run %&#123;gen&#125; ml %&#123;targets&#125;)))</span><br><span class="line"></span><br><span class="line">(rule</span><br><span class="line"> (targets sys_socket_generated_stubs.c)</span><br><span class="line"> (deps (:gen ./generator/gen_stubs.exe))</span><br><span class="line"> (action (run %&#123;gen&#125; c %&#123;targets&#125;)))</span><br></pre></td></tr></table></figure>
-
<p>This time, we need <code>ocaml-ctypes</code> to generate two compilation units: a <code>.ml</code> file describing the API exported during the <code>stubs</code> phase, as well as the C code to glue it with the C APIs. Here’s the code for that generator:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> c_headers = <span class="string">&quot;</span></span><br><span class="line"><span class="string">#ifdef _WIN32</span></span><br><span class="line"><span class="string"> #include &lt;winsock2.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;ws2tcpip.h&gt;</span></span><br><span class="line"><span class="string">#else</span></span><br><span class="line"><span class="string"> #include &lt;sys/socket.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;netinet/in.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;arpa/inet.h&gt;</span></span><br><span class="line"><span class="string"> #include &lt;netdb.h&gt;</span></span><br><span class="line"><span class="string">#endif</span></span><br><span class="line"><span class="string">#include &lt;string.h&gt;</span></span><br><span class="line"><span class="string">&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="literal">()</span> =</span><br><span class="line"> <span class="keyword">let</span> mode = <span class="type">Sys</span>.argv.(<span class="number">1</span>) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> fname = <span class="type">Sys</span>.argv.(<span class="number">2</span>) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> oc = open_out_bin fname <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> format =</span><br><span class="line"> <span class="type">Format</span>.formatter_of_out_channel oc</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> fn =</span><br><span class="line"> <span class="keyword">match</span> mode <span class="keyword">with</span></span><br><span class="line"> | <span class="string">&quot;ml&quot;</span> -&gt; <span class="type">Cstubs</span>.write_ml</span><br><span class="line"> | <span class="string">&quot;c&quot;</span> -&gt;</span><br><span class="line"> <span class="type">Format</span>.fprintf format <span class="string">&quot;%s@\n&quot;</span> c_headers;</span><br><span class="line"> <span class="type">Cstubs</span>.write_c</span><br><span class="line"> | _ -&gt; <span class="keyword">assert</span> <span class="literal">false</span></span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> fn ~concurrency:<span class="type">Cstubs</span>.unlocked format ~prefix:<span class="string">&quot;sys_socket&quot;</span> (<span class="keyword">module</span> <span class="type">Sys_socket_stubs</span>.<span class="type">Def</span>);</span><br><span class="line"> <span class="type">Format</span>.pp_print_flush format <span class="literal">()</span>;</span><br><span class="line"> close_out oc</span><br></pre></td></tr></table></figure>
-
<p>The exported <code>.ml</code> and <code>.c</code> files are omitted here for simplicity but the reader can generated them themselves from the <code>[ocaml-sys-socket](https://github.com/toots/ocaml-sys-socket)</code> repository if they are curious about their actual content.</p>
<p>We can now export our top-level API:</p>
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">open</span> <span class="type">Ctypes</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">include</span> <span class="type">Sys_socket_types</span>.<span class="type">SaFamily</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">include</span> <span class="type">Sys_socket_stubs</span>.<span class="type">Def</span>(<span class="type">Sys_socket_generated_stubs</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> socklen = <span class="type">Types</span>.socklen</span><br><span class="line"><span class="keyword">let</span> socklen_t = <span class="type">Types</span>.socklen_t</span><br><span class="line"><span class="keyword">let</span> int_of_socklen = <span class="type">Types</span>.int_of_socklen</span><br><span class="line"><span class="keyword">let</span> socklen_of_int = <span class="type">Types</span>.socklen_of_int</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> <span class="type">Sockaddr</span> = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">include</span> <span class="type">Types</span>.<span class="type">Sockaddr</span></span><br><span class="line"> <span class="keyword">let</span> from_sockaddr_storage = from_sockaddr_storage t</span><br><span class="line"> <span class="keyword">let</span> sa_data_len = <span class="type">Types</span>.sa_data_len</span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> getnameinfo sockaddr_ptr =</span><br><span class="line"> <span class="keyword">let</span> maxhost = <span class="type">Types</span>.ni_maxhost <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> s = allocate_n <span class="built_in">char</span> ~count:maxhost <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> maxserv = <span class="type">Types</span>.ni_maxserv <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> p = allocate_n <span class="built_in">char</span> ~count:maxserv <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">match</span> getnameinfo sockaddr_ptr (socklen_of_int (sizeof sockaddr_t))</span><br><span class="line"> s (socklen_of_int maxhost) </span><br><span class="line"> p (socklen_of_int maxserv)</span><br><span class="line"> (<span class="type">Types</span>.ni_numerichost <span class="keyword">lor</span></span><br><span class="line"> <span class="type">Types</span>.ni_numericserv) <span class="keyword">with</span></span><br><span class="line"> | <span class="number">0</span> -&gt;</span><br><span class="line"> <span class="keyword">let</span> host =</span><br><span class="line"> <span class="keyword">let</span> length =</span><br><span class="line"> <span class="type">Unsigned</span>.<span class="type">Size_t</span>.to_int</span><br><span class="line"> (strnlen s (<span class="type">Unsigned</span>.<span class="type">Size_t</span>.of_int maxhost))</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> string_from_ptr s ~length</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> port =</span><br><span class="line"> <span class="keyword">let</span> length =</span><br><span class="line"> <span class="type">Unsigned</span>.<span class="type">Size_t</span>.to_int</span><br><span class="line"> (strnlen p (<span class="type">Unsigned</span>.<span class="type">Size_t</span>.of_int maxserv))</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> port =</span><br><span class="line"> string_from_ptr p ~length</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> int_of_string port</span><br><span class="line"> <span class="keyword">with</span> _ -&gt;</span><br><span class="line"> <span class="keyword">match</span> getservbyname p null <span class="keyword">with</span></span><br><span class="line"> | ptr <span class="keyword">when</span> is_null ptr -&gt; failwith <span class="string">&quot;getnameinfo&quot;</span></span><br><span class="line"> | ptr -&gt;</span><br><span class="line"> <span class="type">Unsigned</span>.<span class="type">UInt16</span>.to_int</span><br><span class="line"> (ntohs (!@ (ptr |-&gt; <span class="type">Types</span>.<span class="type">Servent</span>.s_port)))</span><br><span class="line"> <span class="keyword">in</span></span><br><span class="line"> host, port</span><br><span class="line"> | _ -&gt; failwith <span class="string">&quot;getnameinfo&quot;</span></span><br><span class="line"></span><br><span class="line">...</span><br></pre></td></tr></table></figure>
-
<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">open</span> <span class="type">Ctypes</span></span><br><span class="line"></span><br><span class="line"><span class="comment">(** Ctypes routines for C type socklen_t. *)</span></span><br><span class="line"><span class="keyword">type</span> socklen</span><br><span class="line"><span class="keyword">val</span> socklen_t : socklen typ</span><br><span class="line"><span class="keyword">val</span> int_of_socklen : socklen -&gt; <span class="built_in">int</span></span><br><span class="line"><span class="keyword">val</span> socklen_of_int : <span class="built_in">int</span> -&gt; socklen</span><br><span class="line"></span><br><span class="line"><span class="comment">(** Generic sockaddr_t structure. *)</span></span><br><span class="line"><span class="keyword">module</span> <span class="type">Sockaddr</span> : <span class="keyword">sig</span></span><br><span class="line"> <span class="keyword">type</span> t</span><br><span class="line"> <span class="keyword">val</span> t : t structure typ</span><br><span class="line"> <span class="keyword">val</span> sa_family : (sa_family, t structure) field</span><br><span class="line"> <span class="keyword">val</span> sa_data : (<span class="built_in">char</span> carray, t structure) field</span><br><span class="line"> <span class="keyword">val</span> sa_data_len : <span class="built_in">int</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">val</span> from_sockaddr_storage : <span class="type">SockaddrStorage</span>.t structure ptr -&gt; t structure ptr</span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="comment">(** IP address conversion functions. *)</span></span><br><span class="line"><span class="keyword">val</span> getnameinfo : sockaddr ptr -&gt; <span class="built_in">string</span> * <span class="built_in">int</span></span><br><span class="line"></span><br><span class="line">...</span><br></pre></td></tr></table></figure>
-
<p>That’s it! We now have <code>ocaml-ctypes</code> specific data types and structures that can be used to interface with the host’s native <code>socket.h</code> APIs. Note that we also worked on top of the original low-level binding to <code>getnameinfo</code> to export a higher-level function more idiomatic to the OCaml language.</p>
-<h1 id="Lagniappe-cross-compilation-to-Windows"><a href="#Lagniappe-cross-compilation-to-Windows" class="headerlink" title="Lagniappe: cross-compilation to Windows"></a>Lagniappe: cross-compilation to Windows</h1><p>On windows platforms, <code>liquidsoap</code> is compiled using <code>[ocaml-cross-windows](https://github.com/ocaml-cross/opam-cross-windows)</code> and, since windows does have compatible socket APIs, we wanted to also look at cross-compiling for the windows target, which is where we hit a snag on the current <code>dune</code> support.</p>
+<h1>Lagniappe: cross-compilation to Windows</h1>
+<p>On windows platforms, <code>liquidsoap</code> is compiled using <code>[ocaml-cross-windows](https://github.com/ocaml-cross/opam-cross-windows)</code> and, since windows does have compatible socket APIs, we wanted to also look at cross-compiling for the windows target, which is where we hit a snag on the current <code>dune</code> support.</p>
<p>The problem is that, at each intermediary steps, in the case of a cross-compilation, the compiled binaries need to use the target’s OS headers and not the host’s headers, otherwise we end up using offsets specific to e.g. Debian but for a windows binary.</p>
<p>In this case, this means that the compiled <code>.exe</code> binaries need to be windows binaries and that we need to execute them as windows native binaries, using <code>[wine](https://www.winehq.org/)</code> .</p>
<p><code>dune</code> has a truly amazing <a target="_blank" rel="noopener" href="https://dune.readthedocs.io/en/latest/cross-compilation.html">support for cross-compiling</a>, which we do not cover here, but, unfortunately, its primitives for building and executing binaries do not yet cover this use case. Thus we had to trick it into compiling things the way we wanted to do, which why we are using the <code>exec.sh</code> wrapper. Here’s its code:</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">SYSTEM=<span class="variable">$1</span></span><br><span class="line">CMD=<span class="variable">$2</span></span><br><span class="line">ARG=<span class="variable">$3</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="built_in">test</span> <span class="string">&quot;<span class="variable">$&#123;SYSTEM&#125;</span>&quot;</span> = <span class="string">&quot;mingw&quot;</span>; <span class="keyword">then</span></span><br><span class="line"> wine <span class="variable">$CMD</span> <span class="variable">$ARG</span></span><br><span class="line"><span class="keyword">elif</span> <span class="built_in">test</span> <span class="string">&quot;<span class="variable">$&#123;SYSTEM&#125;</span>&quot;</span> = <span class="string">&quot;mingw64&quot;</span>; <span class="keyword">then</span></span><br><span class="line"> wine64 <span class="variable">$CMD</span> <span class="variable">$ARG</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line"> <span class="variable">$CMD</span> <span class="variable">$ARG</span></span><br></pre></td></tr></table></figure>
-
<p>Now, you can go back to the previous <code>dune</code> files and see how this wrapper allows to execute binaries according to the system that the corresponding <code>ocamlopt</code> compiler has been configured to build for.</p>
-<h1 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h1><p>It’s been a fun time working on this binding! It’s amazing to see the level of details that can be built through <code>ocaml-ctypes</code> using their provided primitives. Ultimately, the binding is very clean and elegant, with very few low-level assumptions.</p>
+<h1>Conclusion</h1>
+<p>It’s been a fun time working on this binding! It’s amazing to see the level of details that can be built through <code>ocaml-ctypes</code> using their provided primitives. Ultimately, the binding is very clean and elegant, with very few low-level assumptions.</p>
<p>Likewise, the simplicity and power of the <code>dune</code> build system makes this very fluid to build. Without it, each of the described steps above would have been much more painful to execute and compile.</p>
-<p>[1]: My bet is that, at the time the POSIX specifications were being written, there we already several inconsistent <code>socket.h</code> headers out in the wild among the various historical UNIX flavors..</p>
+<p>[1]: My bet is that, at the time the POSIX specifications were being written, there we already several inconsistent <code>socket.h</code> headers out in the wild among the various historical UNIX flavors…</p>
</div>
diff --git a/2024/09/15/肩周炎和肩袖损伤的区别/index.html b/2024/09/15/肩周炎和肩袖损伤的区别/index.html
index 1c666b0b..16e591a2 100644
--- a/2024/09/15/肩周炎和肩袖损伤的区别/index.html
+++ b/2024/09/15/肩周炎和肩袖损伤的区别/index.html
@@ -204,15 +204,20 @@
<p>肩袖损伤是由退行性病变或外力等导致肩袖的4块肌肉、肌腱发生病变,进而导致肩关节局部疼痛、活动受限的疾病。</p>
<p>许多肩袖损伤患者无明确的外伤史,而是由长期做过顶运动、提重物或上肢长期固定于一个姿势引起的。</p>
<ul>
-<li><p>肩周炎的疼痛范围广,涉及整个肩关节,肩袖损伤引起的疼痛多出现在肩前方、外上方</p>
+<li>
+<p>肩周炎的疼痛范围广,涉及整个肩关节,肩袖损伤引起的疼痛多出现在肩前方、外上方</p>
</li>
-<li><p>肩周炎的压痛点多而广,肩袖损的伤压痛点多出现在肩前方、上方及肩胛骨外侧缘。</p>
+<li>
+<p>肩周炎的压痛点多而广,肩袖损的伤压痛点多出现在肩前方、上方及肩胛骨外侧缘。</p>
</li>
-<li><p>肩周炎患者对气候变化较为敏感,肩袖损伤患者对气候变化不敏感,对劳累、提重物及做过顶运动较为敏感。</p>
+<li>
+<p>肩周炎患者对气候变化较为敏感,肩袖损伤患者对气候变化不敏感,对劳累、提重物及做过顶运动较为敏感。</p>
</li>
-<li><p>肩周炎患者活动受限范围广,肩袖损伤患者多以肩关节外展活动受限为主,同时伴有外展无力。</p>
+<li>
+<p>肩周炎患者活动受限范围广,肩袖损伤患者多以肩关节外展活动受限为主,同时伴有外展无力。</p>
</li>
-<li><p>肩周炎患者进行上举过顶运动训练后活动范围会好转,症状会减轻;而肩袖损伤患者进行上举过顶运动训练后疼痛加重。</p>
+<li>
+<p>肩周炎患者进行上举过顶运动训练后活动范围会好转,症状会减轻;而肩袖损伤患者进行上举过顶运动训练后疼痛加重。</p>
</li>
</ul>
diff --git a/2024/09/27/Turborepo-简述/index.html b/2024/09/27/Turborepo-简述/index.html
index 91218d7a..505b2d46 100644
--- a/2024/09/27/Turborepo-简述/index.html
+++ b/2024/09/27/Turborepo-简述/index.html
@@ -192,23 +192,27 @@
</div>
</div>
<div class="post-content">
- <h2 id="Turborepo-简介"><a href="#Turborepo-简介" class="headerlink" title="Turborepo 简介"></a>Turborepo 简介</h2><p>Monorepos 有很多优势,但它们难以扩展。每个工作区都有自己的测试套件、自己的 linting 和构建过程。单个 monorepo 可能有数千个任务要执行。</p>
+ <h2 id="Turborepo-简介"><a class="header-anchor" href="#Turborepo-简介">¶</a>Turborepo 简介</h2>
+<p>Monorepos 有很多优势,但它们难以扩展。每个工作区都有自己的测试套件、自己的 linting 和构建过程。单个 monorepo 可能有数千个任务要执行。</p>
<p>Turborepo 是一个专为 JavaScript 和 TypeScript 代码库设计的构建系统,旨在优化 monorepos 和 single-package workspace 中的任务。它通过远程缓存(remote caching)和高效的任务调度(task scheduling)来解决 monorepos 中的扩展问题。Turborepo 也可以增量部署(adopted incrementally),并与各种包管理器配合使用。</p>
<ul>
<li>远程缓存: 存储所有任务的结果,CI 就不需要重复执行相同的工作了。</li>
<li>任务调度:利用所有核心的性能并行处理任务,尽可能的加速。</li>
</ul>
<p><code>turbo</code> 基于 workspace 构建,workspaces 是 JavaScript 生态系统中包管理器的一项功能,允许将多个包分组到一个存储库中:</p>
-<h3 id="Workspace"><a href="#Workspace" class="headerlink" title="Workspace"></a>Workspace</h3><p>在 JavaScript 中,Workspace 是指仓库中的特定实体,可以是<a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#single-package-workspace">单个包</a>或<a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#multi-package-workspace">包的集合</a>。<br>包管理器的 root lock 文件(例如 <code>pnpm-lock.yaml</code>)以及任何其他配置都位于 Wrokspace 的根目录。在 Monorepo 中可以有多个工作区,每个工作区位于存储库的子目录中。</p>
-<h3 id="Single-package-workspace"><a href="#Single-package-workspace" class="headerlink" title="Single-package workspace"></a><a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#single-package-workspace">Single-package workspace</a></h3><p>只有一个独立包的工作区,在工作区根目录下有一个 <code>package.json</code> 文件。</p>
-<h3 id="Multi-package-workspace"><a href="#Multi-package-workspace" class="headerlink" title="Multi-package workspace"></a><a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#multi-package-workspace">Multi-package workspace</a></h3><p>包含多个包的工作区,包含多个 <code>package.json</code> 文件,其中一个位于工作区根目录中用于全局配置,其他位于每个包目录中。</p>
+<h3 id="Workspace"><a class="header-anchor" href="#Workspace">¶</a>Workspace</h3>
+<p>在 JavaScript 中,Workspace 是指仓库中的特定实体,可以是<a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#single-package-workspace">单个包</a>或<a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#multi-package-workspace">包的集合</a>。<br>
+包管理器的 root lock 文件(例如 <code>pnpm-lock.yaml</code>)以及任何其他配置都位于 Wrokspace 的根目录。在 Monorepo 中可以有多个工作区,每个工作区位于存储库的子目录中。</p>
+<h3 id="Single-package-workspace"><a class="header-anchor" href="#Single-package-workspace">¶</a><a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#single-package-workspace">Single-package workspace</a></h3>
+<p>只有一个独立包的工作区,在工作区根目录下有一个 <code>package.json</code> 文件。</p>
+<h3 id="Multi-package-workspace"><a class="header-anchor" href="#Multi-package-workspace">¶</a><a target="_blank" rel="noopener" href="https://vercel.com/docs/vercel-platform/glossary#multi-package-workspace">Multi-package workspace</a></h3>
+<p>包含多个包的工作区,包含多个 <code>package.json</code> 文件,其中一个位于工作区根目录中用于全局配置,其他位于每个包目录中。</p>
<blockquote>
<p>这种类型的工作区通常称为 monorepo</p>
</blockquote>
<hr>
<p>以 npm 为例,turbo 会初始化一个这样的目录结构使其成为有效的 workspace:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">|- package.json</span><br><span class="line">|- package-lock.json</span><br><span class="line">|- turbo.json</span><br><span class="line">|- apps</span><br><span class="line">|-- docs</span><br><span class="line">|--- package.json</span><br><span class="line">|-- web</span><br><span class="line">|--- package.json</span><br><span class="line">|- packages</span><br><span class="line">|--- ui</span><br></pre></td></tr></table></figure>
-
<p>一个 “有效的” turbo 项目至少要有:</p>
<ul>
<li>包管理器描述的包</li>
@@ -219,7 +223,6 @@
</ul>
<p>例如,在根目录的 <code>package.json</code> 中配置:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;workspaces&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="string">&quot;apps/*&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;packages/*&quot;</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>那么 <code>apps</code> 或 <code>packages</code> 目录中有 <code>package.json</code> 的每个目录都将被视为一个包。</p>
<blockquote>
<p>注意:Turborepo 不支持嵌套包,例如 <code>apps/</code> 或 <code>packages/</code> 这种,将一个包放在<code>apps/a</code> 并将另一个包放在 <code>apps/a/b</code> 的结构将导致错误。</p>
@@ -227,10 +230,10 @@
</blockquote>
<p>根目录的 <code>package.json</code> 是 workspace 的基础,常见的配置:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;private&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;scripts&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="string">&quot;turbo run build&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;dev&quot;</span><span class="punctuation">:</span> <span class="string">&quot;turbo run dev&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;lint&quot;</span><span class="punctuation">:</span> <span class="string">&quot;turbo run lint&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;devDependencies&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;turbo&quot;</span><span class="punctuation">:</span> <span class="string">&quot;latest&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;packageManager&quot;</span><span class="punctuation">:</span> <span class="string">&quot;[email protected]&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>而根目录的 <code>turbo.json</code> 用于配置 <code>turbo</code> 的行为。那些 lock 文件是包管理器和 <code>turbo</code> 用于 reproducible 的关键。此外,Turborepo 还利用它们分析工作区中<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/internal-packages">内部包</a>之间的依赖关系。</p>
<hr>
-<h3 id="包中的-package-json"><a href="#包中的-package-json" class="headerlink" title="包中的 package.json"></a>包中的 <code>package.json</code></h3><p><a target="_blank" rel="noopener" href="https://nodejs.org/api/packages.html#name"><code>name</code> 字段</a>用于标识包。它在 workspace 中应该是唯一的。</p>
+<h3 id="包中的-package-json"><a class="header-anchor" href="#包中的-package-json">¶</a>包中的 <code>package.json</code></h3>
+<p><a target="_blank" rel="noopener" href="https://nodejs.org/api/packages.html#name"><code>name</code> 字段</a>用于标识包。它在 workspace 中应该是唯一的。</p>
<blockquote>
<p>最佳做法是为<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/internal-packages">内部包</a>使用命名空间前缀,以避免与 npm 注册表上的其他包发生冲突。例如,如果组织名为 <code>clin</code>,则可以将包命名为 <code>@clin/package-name</code>。</p>
</blockquote>
@@ -238,10 +241,8 @@
<p><a target="_blank" rel="noopener" href="https://nodejs.org/api/packages.html#exports"><code>exports</code> 字段</a>用于指定要使用该包的其他包的入口点。如果要在另一个包中使用一个包中的代码,将从该入口点导入。</p>
<p>例如,如果有一个 <code>@repo/math</code> 包,则可以这么写 <code>exports</code> 字段:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;exports&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;.&quot;</span><span class="punctuation">:</span> <span class="string">&quot;./dist/constants.ts&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;./add&quot;</span><span class="punctuation">:</span> <span class="string">&quot;./dist/add.ts&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;./subtract&quot;</span><span class="punctuation">:</span> <span class="string">&quot;./dist/subtract.ts&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>然后就可以从 <code>@repo/math</code> 包中导入 <code>add</code> 和 <code>subtract</code> 函数了:</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; <span class="variable constant_">GRAVITATIONAL_CONSTANT</span>, <span class="variable constant_">SPEED_OF_LIGHT</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;@repo/math&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; add &#125; <span class="keyword">from</span> <span class="string">&#x27;@repo/math/add&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; subtract &#125; <span class="keyword">from</span> <span class="string">&#x27;@repo/math/subtract&#x27;</span>;</span><br></pre></td></tr></table></figure>
-
<p>以这种方式使用导出有三个主要好处:</p>
<ul>
<li>避免 barrel 文件:barrel 文件是重新导出同一包中其他文件的文件,从而为整个包创建一个入口点。虽然它们可能看起来很方便,但编译器<a target="_blank" rel="noopener" href="https://vercel.com/blog/how-we-optimized-package-imports-in-next-js#what's-the-problem-with-barrel-files">和捆绑程序很难处理</a>它们,并且可能很快导致性能问题。</li>
@@ -253,12 +254,11 @@
<blockquote>
<p>其他:包通常使用 <code>src</code> 目录来存储其源代码并编译到 <code>dist</code> 目录(也应位于包中)。</p>
</blockquote>
-<h2 id="管理依赖项"><a href="#管理依赖项" class="headerlink" title="管理依赖项"></a>管理依赖项</h2><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependencies&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;next&quot;</span><span class="punctuation">:</span> <span class="string">&quot;latest&quot;</span><span class="punctuation">,</span> <span class="comment">// 外部依赖</span></span><br><span class="line"> <span class="attr">&quot;@repo/ui&quot;</span><span class="punctuation">:</span> <span class="string">&quot;*&quot;</span> <span class="comment">// 内部依赖</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
+<h2 id="管理依赖项"><a class="header-anchor" href="#管理依赖项">¶</a>管理依赖项</h2>
+<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependencies&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;next&quot;</span><span class="punctuation">:</span> <span class="string">&quot;latest&quot;</span><span class="punctuation">,</span> <span class="comment">// 外部依赖</span></span><br><span class="line"> <span class="attr">&quot;@repo/ui&quot;</span><span class="punctuation">:</span> <span class="string">&quot;*&quot;</span> <span class="comment">// 内部依赖</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p>在存储库中安装依赖项时,应将其直接安装在使用它的软件包中。包的 <code>package.json</code> 将包含所需的每个依赖项。外部和内部依赖项都是如此。</p>
<p>要在多个包中快速安装依赖项,可以:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install jest --workspace=web --workspace=@repo/ui --save-dev</span><br></pre></td></tr></table></figure>
-
<p>这种做法有几个好处:</p>
<ul>
<li>更清晰:当软件包的依赖项列在其 <code>package.json</code> 中时,更容易理解软件包所依赖的内容。在存储库中工作的开发人员可以一目了然地看到包中使用了哪些依赖项。</li>
@@ -269,94 +269,97 @@
<blockquote>
<p>属于工作区根目录的唯一依赖项是用于管理存储库的工具,而用于构建应用程序和库的依赖项安装在各自的包中。一些适合安装在根中的依赖项示例包括 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/turbo"><code>turbo</code></a>、<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/husky"><code>husky</code></a> 或 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/lint-staged"><code>lint-staged</code></a>。</p>
</blockquote>
-<h3 id="保持同一版本的依赖"><a href="#保持同一版本的依赖" class="headerlink" title="保持同一版本的依赖"></a>保持同一版本的依赖</h3><p>一些 monorepo 维护者更喜欢按照规则在所有软件包中保持对相同版本的依赖关系。有几种方法可以实现此目的:</p>
+<h3 id="保持同一版本的依赖"><a class="header-anchor" href="#保持同一版本的依赖">¶</a>保持同一版本的依赖</h3>
+<p>一些 monorepo 维护者更喜欢按照规则在所有软件包中保持对相同版本的依赖关系。有几种方法可以实现此目的:</p>
<ul>
<li>使用专用的工具,比如 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/syncpack"><code>syncpack</code></a>、<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/@manypkg/cli"><code>manypkg</code></a> 和 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/sherif"><code>sherif</code></a> 等工具可用于此特定目的。</li>
-<li>或者单纯的使用包管理器,可以使用软件包管理器通过一个命令更新依赖项版本:<ul>
+<li>或者单纯的使用包管理器,可以使用软件包管理器通过一个命令更新依赖项版本:
+<ul>
<li><code>npm install typescript@latest --workspaces</code></li>
</ul>
</li>
<li>或者最粗暴的用编辑器一次查找并替换存储库中所有 <code>package.json</code> 文件的依赖项版本。用 <code>“next”: “.*”</code> 之类的正则表达式来查找并替换为所需的版本。完成后再运行包管理器的 install 命令来更新 lock 文件.</li>
</ul>
-<h2 id="内部包"><a href="#内部包" class="headerlink" title="内部包"></a>内部包</h2><p><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/internal-packages">内部包</a>是工作区的构建块(building blocks),是一种在存储库中共享代码的强大方式。Turborepo 读取 <code>package.json</code> 中的依赖项来分析内部包之间的关系,并在后台创建 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 以优化存储库的工作流程。</p>
+<h2 id="内部包"><a class="header-anchor" href="#内部包">¶</a>内部包</h2>
+<p><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/internal-packages">内部包</a>是工作区的构建块(building blocks),是一种在存储库中共享代码的强大方式。Turborepo 读取 <code>package.json</code> 中的依赖项来分析内部包之间的关系,并在后台创建 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 以优化存储库的工作流程。</p>
<p>在创建内部包时,建议创建具有单一 “用途” 的包。这是最佳实践,具体取决于存储库的规模、组织、团队需求等。此策略具有以下几个优点:</p>
<ul>
<li>更易于理解:随着存储库的扩展,在存储库中工作的开发人员将能够更轻松地找到他们需要的代码。</li>
<li>减少每个包的依赖项:每个包使用更少的依赖项,以便 Turborepo 可以更有效地<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/prune">修剪包图的依赖项</a>。</li>
</ul>
-<p>在创建<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-types#application-packages">应用程序包</a>时,最好避免将共享代码放在这些包中。相反,应该为共享代码创建一个单独的包,并让应用程序包依赖于该包。<br>此外,应用程序包不应安装到其他包中。相反,应将它们视为 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 的入口点。</p>
-<h2 id="配置任务"><a href="#配置任务" class="headerlink" title="配置任务"></a>配置任务</h2><p>Turborepo 将始终按照 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration"><code>turbo.json</code> 配置</a>和 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 中描述的顺序运行任务,并尽可能并行化工作以确保一切尽可能快地运行。</p>
+<p>在创建<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-types#application-packages">应用程序包</a>时,最好避免将共享代码放在这些包中。相反,应该为共享代码创建一个单独的包,并让应用程序包依赖于该包。<br>
+此外,应用程序包不应安装到其他包中。相反,应将它们视为 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 的入口点。</p>
+<h2 id="配置任务"><a class="header-anchor" href="#配置任务">¶</a>配置任务</h2>
+<p>Turborepo 将始终按照 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration"><code>turbo.json</code> 配置</a>和 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a> 中描述的顺序运行任务,并尽可能并行化工作以确保一切尽可能快地运行。</p>
<p>根目录的 <code>turbo.json</code> 文件是注册 Turborepo 将运行的任务的位置。定义任务后,将能够使用 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/run"><code>turbo run</code></a> 运行一个或多个任务。</p>
<p><code>tasks</code> 对象中的每个 key 都是一个可以通过 <code>turbo run</code> 执行的任务。Turborepo 将在 <code>package.json</code> 中搜索与任务同名的软件包:</p>
<p><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration#dependson"><code>dependsOn</code> 键</a>用于指定在其他任务开始运行之前必须完成的任务。在大多数情况下,库的<code>build</code>脚本在应用程序的<code>build</code>脚本运行之前完成,所以可以这么写:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;^build&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<blockquote>
-<p><code>^</code> 这个语法告诉 Turborepo 从依赖关系图的底部开始运行任务。如果应用程序依赖于名为 <code>ui</code> 的库,并且该库具有<code>build</code>任务,则 <code>ui</code> 中的<code>build</code>脚本将首先运行。成功完成后,才会运行应用程序中的<code>build</code>任务。<br>这是一个重要的形式,因为它可以确保应用程序的<code>build</code>任务具有编译所需的所有必要依赖项。当依赖关系图发展到具有多个级别的任务依赖关系的更复杂的结构时,此概念也适用。</p>
+<p><code>^</code> 这个语法告诉 Turborepo 从依赖关系图的底部开始运行任务。如果应用程序依赖于名为 <code>ui</code> 的库,并且该库具有<code>build</code>任务,则 <code>ui</code> 中的<code>build</code>脚本将首先运行。成功完成后,才会运行应用程序中的<code>build</code>任务。<br>
+这是一个重要的形式,因为它可以确保应用程序的<code>build</code>任务具有编译所需的所有必要依赖项。当依赖关系图发展到具有多个级别的任务依赖关系的更复杂的结构时,此概念也适用。</p>
</blockquote>
<p>有时可能需要确保同一包中的两个任务按特定顺序运行。例如需要先在库中运行<code>build</code>任务,然后再在同一库中运行<code>test</code>任务。这种情况删掉 <code>^</code> 就行了:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;test&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;build&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>还可以在特定包中指定要依赖的单个任务。例如在任何 <code>lint</code> 任务之前运行 <code>utils</code> 中的<code>build</code>任务:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;lint&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;utils#build&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>或者更加细致的限定 <code>lint</code>:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;web#lint&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;utils#build&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>即 <code>Web 包中的</code> <code>lint</code> 任务只能在 <code>utils</code> 包中的<code>build</code>任务完成后运行。</p>
<p>某些任务可能没有任何依赖项。例如用于在 Markdown 文件中查找拼写错误的任务可能不需要关心其他任务的状态。在这种情况下,省略 <code>dependsOn</code> 键或给个空数组就行了:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;spell-check&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
-<h3 id="指定输入输出"><a href="#指定输入输出" class="headerlink" title="指定输入输出"></a>指定输入输出</h3><p><code>outputs</code> 键告诉 Turborepo 文件和目录在任务成功完成时应该缓存在哪。如果未定义此 key,Turborepo 将不会缓存任何文件。</p>
+<h3 id="指定输入输出"><a class="header-anchor" href="#指定输入输出">¶</a>指定输入输出</h3>
+<p><code>outputs</code> 键告诉 Turborepo 文件和目录在任务成功完成时应该缓存在哪。如果未定义此 key,Turborepo 将不会缓存任何文件。</p>
<p>例如缓存 vite 的输出一般可以这么写:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;outputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;dist/&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p><code>inputs</code> 键用于指定要包含在任务哈希中以进行<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/caching">缓存</a>的文件。默认情况下,Turborepo 将包含包中由 Git 跟踪的所有文件。但是也可以使用 <code>inputs</code> 键更具体地说明哈希中包含哪些文件, 例如,在 Markdown 文件中查找拼写错误的任务可以定义如下::</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;spell-check&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;inputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;/*.md&quot;</span><span class="punctuation">,</span> <span class="string">&quot;/*.mdx&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>可以通过微调 <code>input</code> 以忽略对已知不会影响任务输出的文件的更改来提高某些任务的缓存命中率, 可以使用 <code>$TURBO_DEFAULT$</code> 微语法来微调默认 <code>input</code> 行为:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;inputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;$TURBO_DEFAULT$&quot;</span><span class="punctuation">,</span> <span class="string">&quot;!README.md&quot;</span><span class="punctuation">]</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>这里 Turborepo 使用<code>build</code>任务的默认<code>input</code>,但会忽略对 <code>README.md</code> 文件的更改。如果 <code>README.md</code> 文件发生更改,任务仍将用上缓存。</p>
-<h3 id="Root-任务"><a href="#Root-任务" class="headerlink" title="Root 任务"></a>Root 任务</h3><p>还可以使用 <code>turbo</code> 在 Workspace 根的 <code>package.json</code>中运行脚本。例如,除了每个软件包中的 <code>lint</code> 任务外,可能还需要对 Workspace 根目录中的文件运行 <code>lint:root</code> 任务:</p>
+<h3 id="Root-任务"><a class="header-anchor" href="#Root-任务">¶</a>Root 任务</h3>
+<p>还可以使用 <code>turbo</code> 在 Workspace 根的 <code>package.json</code>中运行脚本。例如,除了每个软件包中的 <code>lint</code> 任务外,可能还需要对 Workspace 根目录中的文件运行 <code>lint:root</code> 任务:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;lint&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;^lint&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;//#lint:root&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span><span class="punctuation">&#125;</span> </span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
-<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><ul>
-<li><p><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/package-configurations">包配置</a>是直接放入包中的<code>turbo.json</code>文件。这允许软件包为其自己的任务定义特定行为,而不会影响存储库的其余部分。</p>
-</li>
-<li><p>有一些始终需要运行的任务,例如缓存生成后的部署脚本。对于这些任务,用 <code>“cache”: false</code> :</p>
+<h3 id="其他"><a class="header-anchor" href="#其他">¶</a>其他</h3>
+<ul>
+<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/package-configurations">包配置</a>是直接放入包中的<code>turbo.json</code>文件。这允许软件包为其自己的任务定义特定行为,而不会影响存储库的其余部分。</li>
+<li>有一些始终需要运行的任务,例如缓存生成后的部署脚本。对于这些任务,用 <code>“cache”: false</code> :</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;deploy&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;^build&quot;</span><span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;cache&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;outputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;dist/&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-</li>
-<li><p>某些任务可以并行运行,例如 Linter 不需要等待依赖项中的输出成功才能运行:</p>
+<ul>
+<li>某些任务可以并行运行,例如 Linter 不需要等待依赖项中的输出成功才能运行:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;transit&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;^transit&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;check-types&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;transit&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>这里用到了 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#transit-nodes">Transit Nodes</a> (就是名为 <code>transit</code> 的任务),这些 Transit Node 使用不执行任何操作的任务在软件包依赖项之间创建关系,这里用了名称 <code>transit</code>,但可以将任务命名为 Workspace 中尚未包含脚本的任何名称。</p>
</blockquote>
-</li>
-</ul>
-<h2 id="正在运行的任务"><a href="#正在运行的任务" class="headerlink" title="正在运行的任务"></a>正在运行的任务</h2><p>当在软件包的目录中时,<code>turbo</code> 会自动将命令范围限定为该软件包的 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a>:</p>
+<h2 id="正在运行的任务"><a class="header-anchor" href="#正在运行的任务">¶</a>正在运行的任务</h2>
+<p>当在软件包的目录中时,<code>turbo</code> 会自动将命令范围限定为该软件包的 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#package-graph">Package Graph</a>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd apps/docs</span><br><span class="line">turbo build</span><br></pre></td></tr></table></figure>
<p>将使用 <code>turbo.json</code> 中注册的<code>build</code>任务运行 <code>docs</code> 包的<code>build</code>任务。</p>
<blockquote>
<p>但也可以<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/running-tasks#using-filters">使用过滤器</a>覆盖 Automatic Package Scoping。</p>
</blockquote>
-<h3 id="运行多个任务"><a href="#运行多个任务" class="headerlink" title="运行多个任务"></a>运行多个任务</h3><p><code>Turbo</code> 能够运行多个任务,并尽可能并行化:</p>
+<h3 id="运行多个任务"><a class="header-anchor" href="#运行多个任务">¶</a>运行多个任务</h3>
+<p><code>Turbo</code> 能够运行多个任务,并尽可能并行化:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">turbo run build test lint check-types</span><br></pre></td></tr></table></figure>
-
-<h2 id="缓存"><a href="#缓存" class="headerlink" title="缓存"></a>缓存</h2><p>Turborepo 的缓存在本地工作时可以节省大量时间 - 启用<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/remote-caching">远程缓存</a>时,它的功能更加强大,可在整个团队和 CI 之间共享缓存。</p>
-<h3 id="缓存什么?"><a href="#缓存什么?" class="headerlink" title="缓存什么?"></a>缓存什么?</h3><ul>
+<h2 id="缓存"><a class="header-anchor" href="#缓存">¶</a>缓存</h2>
+<p>Turborepo 的缓存在本地工作时可以节省大量时间 - 启用<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/remote-caching">远程缓存</a>时,它的功能更加强大,可在整个团队和 CI 之间共享缓存。</p>
+<h3 id="缓存什么?"><a class="header-anchor" href="#缓存什么?">¶</a>缓存什么?</h3>
+<ul>
<li>在 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration#outputs"><code>turbo.json 的 outputs</code> 键</a>中定义的任务的文件输出。</li>
<li>任务的终端输出,从任务第一次运行时开始将这些日志恢复到终端。</li>
<li>对输入进行哈希处理,为任务运行创建一个 “fingerprints”。当 “fingerprints” 匹配时,运行任务将命中缓存。</li>
</ul>
-<h3 id="其他-1"><a href="#其他-1" class="headerlink" title="其他"></a>其他</h3><ul>
+<h3 id="其他-v2"><a class="header-anchor" href="#其他-v2">¶</a>其他</h3>
+<ul>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/run#--dry----dry-run"><code>--dry</code> 标志</a>,可用于查看如果在没有实际运行任务的情况下运行任务会发生什么。当不确定正在运行的任务时,这对于调试缓存问题非常有用。</li>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/run#--summarize"><code>--summarize</code> 标志</a>,可用于获取任务的所有输入、输出等的概览。比较两个摘要将揭示两个任务的哈希值不同的原因。</li>
<li>强制 <code>turbo</code> 重新执行已缓存的任务,请使用 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/run#--force"><code>--force</code> 标志</a>。请注意,这将禁用读取缓存,而不是写入。</li>
</ul>
-<h2 id="开发工作流"><a href="#开发工作流" class="headerlink" title="开发工作流"></a>开发工作流</h2><p>在 <code>turbo.json</code> 中定义开发任务 (development task) 会告诉 Turborepo 将运行一个长期任务。这对于运行开发服务器、运行测试或构建应用程序等操作非常有用:</p>
+<h2 id="开发工作流"><a class="header-anchor" href="#开发工作流">¶</a>开发工作流</h2>
+<p>在 <code>turbo.json</code> 中定义开发任务 (development task) 会告诉 Turborepo 将运行一个长期任务。这对于运行开发服务器、运行测试或构建应用程序等操作非常有用:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dev&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;cache&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;persistent&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<ul>
<li><code>&quot;cache&quot;: false</code>:告诉 Turborepo 不要尝试缓存任务的结果。由于这是一项开发任务,可能会频繁更改代码,因此缓存结果没有用。</li>
<li><code>&quot;persistent&quot;: true</code>:告诉 Turborepo 保持任务运行,直到停止它。此键用作终端 UI 的信号,用于将任务视为长时间运行和交互式任务。此外,它还可以防止意外依赖不会退出的任务。</li>
@@ -364,13 +367,13 @@
<p>一些脚本允许使用 <code>stdin</code> 在其中键入以进行交互式输入。使用<a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration#ui">终端 UI</a>,可以选择一个任务,输入它,然后像往常一样使用 <code>stdin</code>。</p>
<p>需要运行用于设置开发环境或预构建包的脚本。可以使用 <code>dependsOn</code> 确保这些任务在 <code>dev</code> 任务之前运行:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dev&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;cache&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;persistent&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;//#dev:setup&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;//#dev:setup&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;outputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;.codegen/&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>这里用的是 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks#registering-root-tasks">Root Task</a>,但可以对 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks#depending-on-a-specific-task-in-a-specific-package">packages 中的任意任务</a>使用相同的思路。</p>
-<h3 id="Watch-mode"><a href="#Watch-mode" class="headerlink" title="Watch mode"></a>Watch mode</h3><p>许多工具都有一个内置的 watcher,比如 <a target="_blank" rel="noopener" href="https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options"><code>tsc --watch</code></a>,它会响应源代码中的更改。有些则没有,<code>Turbo Watch</code> 为任何工具添加了依赖项感知的 Watcher。对源代码的更改将遵循在 <code>turbo.json</code> 中描述的 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#task-graph">Task Graph (任务图</a>),例如:</p>
+<h3 id="Watch-mode"><a class="header-anchor" href="#Watch-mode">¶</a>Watch mode</h3>
+<p>许多工具都有一个内置的 watcher,比如 <a target="_blank" rel="noopener" href="https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options"><code>tsc --watch</code></a>,它会响应源代码中的更改。有些则没有,<code>Turbo Watch</code> 为任何工具添加了依赖项感知的 Watcher。对源代码的更改将遵循在 <code>turbo.json</code> 中描述的 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts/package-and-task-graph#task-graph">Task Graph (任务图</a>),例如:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dev&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;persistent&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;cache&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;lint&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;dependsOn&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;^lint&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-
<p>当运行 <code>turbo watch dev lint</code> 时,会看到每当更改源代码时,<code>lint</code> 脚本都会重新运行,尽管 ESLint 没有内置的 watcher。<code>Turbo Watch</code> 还知道内部依赖关系,因此 <code>@repo/UI</code> 中的代码更改将在 <code>@repo/UI</code> 和 <code>Web</code> 中重新运行任务。</p>
-<h2 id="环境变量"><a href="#环境变量" class="headerlink" title="环境变量"></a>环境变量</h2><p>Turborepo 需要根据环境变量来决定是否改变应用程序的行为。在 <code>turbo.json</code> 文件中使用 <code>env</code> 和 <code>globalEnv</code> 键:</p>
+<h2 id="环境变量"><a class="header-anchor" href="#环境变量">¶</a>环境变量</h2>
+<p>Turborepo 需要根据环境变量来决定是否改变应用程序的行为。在 <code>turbo.json</code> 文件中使用 <code>env</code> 和 <code>globalEnv</code> 键:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;globalEnv&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;IMPORTANT_GLOBAL_VARIABLE&quot;</span><span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;env&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;MY_API_URL&quot;</span><span class="punctuation">,</span> <span class="string">&quot;MY_API_KEY&quot;</span><span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>globalEnv</code>:更改此列表中任何环境变量的值都将更改所有任务的哈希值。</li>
@@ -379,29 +382,31 @@
<blockquote>
<p>Turborepo 会自动将前缀通配符添加到常见框架的 <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/configuration#env"><code>env</code></a> 键中 (### <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#framework-inference">Framework Inference</a>)</p>
</blockquote>
-<h3 id="Environment-mode"><a href="#Environment-mode" class="headerlink" title="Environment mode"></a>Environment mode</h3><p>Turborepo 的 Environment Mode 允许控制哪些环境变量在运行时可用于任务:</p>
+<h3 id="Environment-mode"><a class="header-anchor" href="#Environment-mode">¶</a>Environment mode</h3>
+<p>Turborepo 的 Environment Mode 允许控制哪些环境变量在运行时可用于任务:</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#strict-mode">严格模式</a>(默认):将环境变量过滤为仅在 <code>turbo.json</code> 的 <code>env</code> 和 <code>globalEnv</code> 键中指定的环境变量。</li>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#loose-mode">宽松模式</a>:允许进程的所有环境变量可用。</li>
</ul>
-<h3 id="其他-2"><a href="#其他-2" class="headerlink" title="其他"></a>其他</h3><ul>
-<li><p><code>.env</code> 文件非常适合在本地处理应用程序。Turborepo 不会将 .env 文件加载到任务的运行时中,而是让它们由框架或 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/dotenv"><code>dotenv</code></a> 等工具处理。但是,<code>turbo</code> 必须知道 <code>.env</code> 文件中值的更改,以便它可以将它们用于哈希。如果在两次构建之间更改 <code>.env</code> 文件中的变量,则 <code>build</code> 任务应该不会用上缓存。所以可以将其添加到 <code>input</code> 键中:</p>
+<h3 id="其他-v3"><a class="header-anchor" href="#其他-v3">¶</a>其他</h3>
+<ul>
+<li><code>.env</code> 文件非常适合在本地处理应用程序。Turborepo 不会将 .env 文件加载到任务的运行时中,而是让它们由框架或 <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/dotenv"><code>dotenv</code></a> 等工具处理。但是,<code>turbo</code> 必须知道 <code>.env</code> 文件中值的更改,以便它可以将它们用于哈希。如果在两次构建之间更改 <code>.env</code> 文件中的变量,则 <code>build</code> 任务应该不会用上缓存。所以可以将其添加到 <code>input</code> 键中:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;globalDependencies&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;.env&quot;</span><span class="punctuation">]</span><span class="punctuation">,</span> <span class="comment">// All task hashes</span></span><br><span class="line"> <span class="attr">&quot;tasks&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;build&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;inputs&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;$TURBO_DEFAULT$&quot;</span><span class="punctuation">,</span> <span class="string">&quot;.env&quot;</span><span class="punctuation">,</span> <span class="string">&quot;.env.local&quot;</span><span class="punctuation">]</span> <span class="comment">// Only the `build` task hash</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-</li>
-<li><p>不建议在存储库的根目录中使用 <code>.env</code> 文件。相反,建议将 <code>.env</code> 文件放入使用它们的包中。</p>
-</li>
-<li><p><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/eslint-config-turbo"><code>eslint-config-turbo</code> 软件包</a>可帮助查找代码中使用但未在 <code>turbo.json</code>中列出的环境变量。这有助于确保在配置中考虑所有环境变量。</p>
-</li>
-<li><p>Turborepo 在任务开始时对任务的环境变量进行哈希处理。如果在任务期间创建或更改环境变量,Turborepo 将不知道这些更改,也不会在任务哈希中考虑这些更改。</p>
-</li>
+<ul>
+<li>不建议在存储库的根目录中使用 <code>.env</code> 文件。相反,建议将 <code>.env</code> 文件放入使用它们的包中。</li>
+<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/reference/eslint-config-turbo"><code>eslint-config-turbo</code> 软件包</a>可帮助查找代码中使用但未在 <code>turbo.json</code>中列出的环境变量。这有助于确保在配置中考虑所有环境变量。</li>
+<li>Turborepo 在任务开始时对任务的环境变量进行哈希处理。如果在任务期间创建或更改环境变量,Turborepo 将不知道这些更改,也不会在任务哈希中考虑这些更改。</li>
</ul>
<hr>
-<h2 id="最后"><a href="#最后" class="headerlink" title="最后"></a>最后</h2><ul>
+<h2 id="最后"><a class="header-anchor" href="#最后">¶</a>最后</h2>
+<ul>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/crafting-your-repository/constructing-ci">配置 CI</a></li>
<li><a target="_blank" rel="noopener" href="https://turbo.build/repo/docs/core-concepts">核心概念</a></li>
</ul>
<blockquote>
-<p>本快速入门文档参照 Turborepo 2.x 官方文档: <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs">https://turbo.build/repo/docs</a><br>最后一次编辑:二〇二四年九月二十七日下午六点〇七分</p>
+<p>本快速入门文档参照 Turborepo 2.x 官方文档: <a target="_blank" rel="noopener" href="https://turbo.build/repo/docs">https://turbo.build/repo/docs</a><br>
+最后一次编辑:二〇二四年九月二十七日下午六点〇七分</p>
</blockquote>
</div>
diff --git a/2024/10/06/Obsidian-Vault-的-obsidian-目录中的各文件作用/index.html b/2024/10/06/Obsidian-Vault-的-obsidian-目录中的各文件作用/index.html
index 55d63647..0be6fce9 100644
--- a/2024/10/06/Obsidian-Vault-的-obsidian-目录中的各文件作用/index.html
+++ b/2024/10/06/Obsidian-Vault-的-obsidian-目录中的各文件作用/index.html
@@ -194,29 +194,30 @@
<div class="post-content">
<p>一个简单的例子是:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">.obsidian</span><br><span class="line">├── appearance.json</span><br><span class="line">├── app.json</span><br><span class="line">├── community-plugins.json</span><br><span class="line">├── core-plugins.json</span><br><span class="line">├── core-plugins-migration.json</span><br><span class="line">├── plugins</span><br><span class="line">│   └── obsidian-git</span><br><span class="line">│   ├── data.json</span><br><span class="line">│   ├── main.js</span><br><span class="line">│   ├── manifest.json</span><br><span class="line">│   └── styles.css</span><br><span class="line">└── workspace.json</span><br></pre></td></tr></table></figure>
-
<p>其中:</p>
<ul>
-<li><p><code>appearance.json</code> 包含当前 vault 的外观设置,例如主题、字体大小和行高,例如:</p>
+<li><code>appearance.json</code> 包含当前 vault 的外观设置,例如主题、字体大小和行高,例如:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;interfaceFontFamily&quot;</span><span class="punctuation">:</span> <span class="string">&quot;HarmonyOS Sans SC&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;textFontFamily&quot;</span><span class="punctuation">:</span> <span class="string">&quot;HarmonyOS Sans SC&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;monospaceFontFamily&quot;</span><span class="punctuation">:</span> <span class="string">&quot;FrankMono&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;accentColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;cssTheme&quot;</span><span class="punctuation">:</span> <span class="string">&quot;Listive&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;nativeMenus&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-</li>
-<li><p><code>app.json</code> 包含了编辑器的一些设置,例如 vim mode 和断行设置:</p>
+<ul>
+<li><code>app.json</code> 包含了编辑器的一些设置,例如 vim mode 和断行设置:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;vimMode&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;strictLineBreaks&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;promptDelete&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
-</li>
-<li><p><code>community-plugins.json</code>:包含有关当前 vault 中安装的社区插件的数据,例如:</p>
+<ul>
+<li><code>community-plugins.json</code>:包含有关当前 vault 中安装的社区插件的数据,例如:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">[</span></span><br><span class="line"> <span class="string">&quot;dataview&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;novel-word-count&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;remotely-save&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;obsidian-tasks-plugin&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;obsidian-style-settings&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;obsidian-advanced-slides&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;calendar&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;3d-graph-new&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;webpage-html-export&quot;</span></span><br><span class="line"><span class="punctuation">]</span></span><br></pre></td></tr></table></figure>
-</li>
-<li><p><code>core-plugins.json</code>: 就是当前 valut 中的所有内置插件,例如:</p>
+<ul>
+<li><code>core-plugins.json</code>: 就是当前 valut 中的所有内置插件,例如:</li>
+</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"> <span class="string">&quot;file-explorer&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;global-search&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;switcher&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;graph&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;backlink&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;canvas&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;outgoing-link&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;tag-pane&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;page-preview&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;daily-notes&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;templates&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;note-composer&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;command-palette&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;editor-status&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;bookmarks&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;outline&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;word-count&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">&quot;file-recovery&quot;</span></span><br><span class="line"><span class="punctuation">]</span></span><br></pre></td></tr></table></figure>
-
-<pre><code> - `core-plugins-migration.json`: 就是 `core-plugins.json` 中的内置插件的开关状态,例如:
+<pre><code> - `core-plugins-migration.json`: 就是 `core-plugins.json` 中的内置插件的开关状态,例如:
</code></pre>
-</li>
-</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;file-explorer&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;global-search&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;switcher&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;graph&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;backlink&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;canvas&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;outgoing-link&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;tag-pane&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;properties&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;page-preview&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;daily-notes&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;templates&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;note-composer&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;command-palette&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;slash-command&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;editor-status&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;bookmarks&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;markdown-importer&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;zk-prefixer&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;random-note&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;outline&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;word-count&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;slides&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;audio-recorder&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;workspaces&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;file-recovery&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;publish&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;sync&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<ul>
-<li><code>workspace.json</code>:包含有关当前 Vault 工作区的数据,包括打开的文件、窗口和布局的设置,例如:<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;main&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">   <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;7bc59326f5497d4a&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;split&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;children&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">     <span class="punctuation">&#123;</span></span><br><span class="line">       <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;06fc674d29eb4c3a&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;tabs&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;children&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;97d62f14e2fad2f0&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;README.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;c94063b5e5f6f995&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;README.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;143d5ea7a56d7e1d&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;测试.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span></span><br><span class="line">       <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;currentTab&quot;</span><span class="punctuation">:</span> <span class="number">2</span></span><br><span class="line">     <span class="punctuation">&#125;</span></span><br><span class="line"> ...</span><br></pre></td></tr></table></figure></li>
+<li><code>workspace.json</code>:包含有关当前 Vault 工作区的数据,包括打开的文件、窗口和布局的设置,例如:</li>
</ul>
+<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;main&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">   <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;7bc59326f5497d4a&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;split&quot;</span><span class="punctuation">,</span></span><br><span class="line">   <span class="attr">&quot;children&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">     <span class="punctuation">&#123;</span></span><br><span class="line">       <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;06fc674d29eb4c3a&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;tabs&quot;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;children&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;97d62f14e2fad2f0&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;README.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;c94063b5e5f6f995&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;README.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">         <span class="punctuation">&#123;</span></span><br><span class="line">           <span class="attr">&quot;id&quot;</span><span class="punctuation">:</span> <span class="string">&quot;143d5ea7a56d7e1d&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;leaf&quot;</span><span class="punctuation">,</span></span><br><span class="line">           <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">             <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;markdown&quot;</span><span class="punctuation">,</span></span><br><span class="line">             <span class="attr">&quot;state&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">               <span class="attr">&quot;file&quot;</span><span class="punctuation">:</span> <span class="string">&quot;测试.md&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;source&quot;</span><span class="punctuation">,</span></span><br><span class="line">               <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line">             <span class="punctuation">&#125;</span></span><br><span class="line">           <span class="punctuation">&#125;</span></span><br><span class="line">         <span class="punctuation">&#125;</span></span><br><span class="line">       <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">       <span class="attr">&quot;currentTab&quot;</span><span class="punctuation">:</span> <span class="number">2</span></span><br><span class="line">     <span class="punctuation">&#125;</span></span><br><span class="line"> ...</span><br></pre></td></tr></table></figure>
</div>
diff --git a/2024/10/18/10-Tips-for-Productive-FSharp-Scripting/index.html b/2024/10/18/10-Tips-for-Productive-FSharp-Scripting/index.html
index 544f7f2b..791be5f7 100644
--- a/2024/10/18/10-Tips-for-Productive-FSharp-Scripting/index.html
+++ b/2024/10/18/10-Tips-for-Productive-FSharp-Scripting/index.html
@@ -202,30 +202,29 @@
<blockquote>
<p>Note: these tips are not necessarily ordered by usefulness. For that matter, there might or might not be exactly 10 of them :)</p>
</blockquote>
-<h2 id="Tip-1-Use-fsx-Files-for-Interactive-Coding"><a href="#Tip-1-Use-fsx-Files-for-Interactive-Coding" class="headerlink" title="Tip 1: Use .fsx Files for Interactive Coding"></a>Tip 1: Use <code>.fsx</code> Files for Interactive Coding</h2><p>You can use the F# Interactive 2 ways: you can directly type code into FSI, the F# Interactive window, or you can write code in an <code>.fsx</code> file, and select pieces of the code you want to execute. I recommend the second approach, for at least two reasons. First, FSI is a very primitive environment, <code>.fsx</code> files provide a much richer experience (IntelliSense). Then this encourages writing clean scripts you can reuse later.</p>
+<h2 id="Tip-1-Use-fsx-Files-for-Interactive-Coding"><a class="header-anchor" href="#Tip-1-Use-fsx-Files-for-Interactive-Coding">¶</a>Tip 1: Use <code>.fsx</code> Files for Interactive Coding</h2>
+<p>You can use the F# Interactive 2 ways: you can directly type code into FSI, the F# Interactive window, or you can write code in an <code>.fsx</code> file, and select pieces of the code you want to execute. I recommend the second approach, for at least two reasons. First, FSI is a very primitive environment, <code>.fsx</code> files provide a much richer experience (IntelliSense). Then this encourages writing clean scripts you can reuse later.</p>
<blockquote>
<p>This is not specific to scripts, but… if you are on Visual Studio, do yourself a service and install the <a target="_blank" rel="noopener" href="http://fsprojects.github.io/VisualFSharpPowerTools/">Visual F# Power Tools</a> - you’ll get nice things such as better code highlighting, refactoring, and more.</p>
</blockquote>
<p>To execute code interactively, simply type code in an <code>.fsx</code> file, select a block of code, and hit Alt + Enter. The selected code will be evaluated, and the result will show up in the FSI window. In Visual Studio, you can also select code and right-click “Execute in Interactive”, but shortcuts are way faster.</p>
<blockquote>
-<p>You can also execute a single-line with Alt + ‘. I rarely use this option, but this can save you time because you don’t need to select the entire line of code.</p>
+<p>You can also execute a single-line with Alt + '. I rarely use this option, but this can save you time because you don’t need to select the entire line of code.</p>
</blockquote>
<blockquote>
-<p>In case the keyboard shortcuts to send code to FSI do not work anymore (ReSharper used to over-write them in the past), you can reset them in Visual Studio, by going to Tools &#x2F; Options &#x2F; Environment &#x2F; Keyboard. The 2 commands you need to map are EditorContextMenus.CodeWindow.ExecuteInInteractive and EditorContextMenus.CodeWindow.ExecuteLineInInteractive.</p>
+<p>In case the keyboard shortcuts to send code to FSI do not work anymore (ReSharper used to over-write them in the past), you can reset them in Visual Studio, by going to Tools / Options / Environment / Keyboard. The 2 commands you need to map are EditorContextMenus.CodeWindow.ExecuteInInteractive and EditorContextMenus.CodeWindow.ExecuteLineInInteractive.</p>
</blockquote>
<p>You can also use these shortcuts from a regular <code>.fs</code> file, which can be handy if you want to validate that a piece of code is behaving the way you want.</p>
<blockquote>
<p>Interactive coding is by far my main usage for scripts - I use it extensively to prototype designs, run dumb tasks, or explore data or libraries. I realized recently that a few of my C# friends use LinqPad for the same purpose.</p>
</blockquote>
-<h2 id="Tip-2-What-is-it"><a href="#Tip-2-What-is-it" class="headerlink" title="Tip 2: What is it?"></a>Tip 2: What is <code>it</code>?</h2><p>While I encourage working primarily from <code>.fsx</code> files, the FSI window is also very helpful. I use it primarily for small verifications. For instance, I might have in my script file code like this:</p>
+<h2 id="Tip-2-What-is-it"><a class="header-anchor" href="#Tip-2-What-is-it">¶</a>Tip 2: What is <code>it</code>?</h2>
+<p>While I encourage working primarily from <code>.fsx</code> files, the FSI window is also very helpful. I use it primarily for small verifications. For instance, I might have in my script file code like this:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">let add x y =</span><br><span class="line"> x + y</span><br></pre></td></tr></table></figure>
-
<p>Once I send it for evaluation into FSI, I will see the following show up in FSI:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">val add : x:int -&gt; y:int -&gt; int</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
-
<p>My function <code>add</code> is now in memory, in my FSI session; I can start typing in the FSI window and use it:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&gt; add 1 2;;</span><br><span class="line">val it : int = 3</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
-
<p>Enter does not trigger execution in FSI. The <code>;;</code> indicates to FSI “Please execute everything I just typed, up to that point”. This is useful if you want to type multiple lines of code in FSI, and execute them as a block.</p>
<blockquote>
<p><code>it</code>: in our <code>add 1 2</code> example, the result showed up as <code>it</code>. We simply ran add, but didn’t assign the result to anything. <code>it</code> now contains the result, until we run another expression. If you want to re-use that value, you can assign it in FSI, by doing for instance <code>let x = it;;</code>.′</p>
@@ -237,20 +236,20 @@
<p>FSI often shows an abbreviated version of values for large items. For instance, <code>[1..999]</code> will show up as <code>val it : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62; 63; 64; 65; 66; 67; 68; 69; 70; 71; 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82; 83; 84; 85; 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; 100; ...]</code> - note the … at the end, which indicate that there is more.</p>
</blockquote>
<p>What if you inadvertently started a very long computation, or an infinite loop? In Visual Studio, you can either kill the session entirely, by right-clicking over the FSI window and selecting “Reset Interactive Session” or Ctrl + Alt + R, or cancel the latest evaluation you requested (“Cancel Interactive Evaluation”, or Ctrl + Break.).</p>
-<h2 id="Tip-3-Run-Scripts-from-the-Command-Line"><a href="#Tip-3-Run-Scripts-from-the-Command-Line" class="headerlink" title="Tip 3: Run Scripts from the Command Line"></a>Tip 3: Run Scripts from the Command Line</h2><p>Besides interactive scripting, you can also run a script from the command line, by using <code>FSI.exe</code>:</p>
+<h2 id="Tip-3-Run-Scripts-from-the-Command-Line"><a class="header-anchor" href="#Tip-3-Run-Scripts-from-the-Command-Line">¶</a>Tip 3: Run Scripts from the Command Line</h2>
+<p>Besides interactive scripting, you can also run a script from the command line, by using <code>FSI.exe</code>:</p>
<p><code>&gt;fsi.exe &quot;C:\myscript.fsx&quot;</code></p>
<blockquote>
-<p><code>FSI.exe</code> is typically located at <code>C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0</code>. You can also install it separately, see <a target="_blank" rel="noopener" href="http://fsharp.org/">fsharp.org&#x2F;use</a> section for instructions for various platforms.</p>
+<p><code>FSI.exe</code> is typically located at <code>C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0</code>. You can also install it separately, see <a target="_blank" rel="noopener" href="http://fsharp.org/">fsharp.org/use</a> section for instructions for various platforms.</p>
</blockquote>
<p>You can define different behaviors in your script, depending on whether it is run interactively or from the command line, like this:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#if INTERACTIVE</span><br><span class="line">let msg = &quot;Interactive&quot;</span><br><span class="line">#else</span><br><span class="line">let msg = &quot;Not Interactive&quot;</span><br><span class="line">#endif</span><br><span class="line"></span><br><span class="line">printfn &quot;%s&quot; msg</span><br></pre></td></tr></table></figure>
-
<p><em>Updated, Sep 19: thanks Matt Klein for <a target="_blank" rel="noopener" href="http://stackoverflow.com/q/39581342/114519">pointing the issue</a>.</em></p>
<p>For more information on FSI from the command line, <a target="_blank" rel="noopener" href="https://msdn.microsoft.com/en-us/library/dd233175.aspx">check the reference page here</a>.</p>
<p><em>Updated, Feb 20: <a target="_blank" rel="noopener" href="https://twitter.com/genTauro42">Ramon Soto Mathiesen</a> points out that <a target="_blank" rel="noopener" href="https://twitter.com/genTauro42/status/696407757835132928">Tip 9 also applies to the command line</a>.</em></p>
-<h2 id="Tip-4-Use-Relative-Paths"><a href="#Tip-4-Use-Relative-Paths" class="headerlink" title="Tip 4: Use Relative Paths"></a>Tip 4: Use Relative Paths</h2><p>Sometimes, your script will reference another resource; for instance, you need to read the contents of a <code>.txt</code> file somewhere. You can use absolute path, as in:</p>
+<h2 id="Tip-4-Use-Relative-Paths"><a class="header-anchor" href="#Tip-4-Use-Relative-Paths">¶</a>Tip 4: Use Relative Paths</h2>
+<p>Sometimes, your script will reference another resource; for instance, you need to read the contents of a <code>.txt</code> file somewhere. You can use absolute path, as in:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">File.ReadAllLines @&quot;C:/data/myfile.txt&quot;</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>Pre-pending a string with <code>@</code> makes it a verbatim string, and ignore escape sequences, such as <code>\</code>.</p>
</blockquote>
@@ -260,28 +259,22 @@
<p>However, if that resource lives in a location relative to your script, consider using relative path, so that you can move your script folder around without breaking it.</p>
<p>Relative paths can be a bit tricky; for instance, running the following code interactively…</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">System.Environment.CurrentDirectory</span><br></pre></td></tr></table></figure>
-
<p>… produces a potentially unexpected result in FSI:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">val it : string = &quot;C:\Users\Mathias Brandewinder\AppData\Local\Temp&quot;</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
-
<p>You can avoid these issues by using built-in constants, which refer respectively to the directory where the script lives, the script file name, and the current line of the script:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">__SOURCE_DIRECTORY__</span><br><span class="line">__SOURCE_FILE__</span><br><span class="line">__LINE__</span><br></pre></td></tr></table></figure>
-
<p>So if your folder structure was along these lines…</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">root</span><br><span class="line"> /src/script.fsx</span><br><span class="line"> /data/data.txt</span><br></pre></td></tr></table></figure>
-
<p>… you could refer to the data file <code>data.txt</code> from your script like this:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">let path = System.IO.Path.Combine(__SOURCE_DIRECTORY__,&quot;..&quot;,&quot;data/data.txt&quot;)</span><br><span class="line">System.IO.File.ReadAllText path</span><br></pre></td></tr></table></figure>
-
-<h2 id="Tip-5-Including-Assemblies"><a href="#Tip-5-Including-Assemblies" class="headerlink" title="Tip 5: Including Assemblies"></a>Tip 5: Including Assemblies</h2><p>By default, FSI loads <code>FSharp.Core</code> and nothing else. If you want to use <code>System.DateTime</code>, you will need to first <code>open System</code> in your script. If you want to use an assembly that is not part of the standard .NET distribution, you will need to reference it first using <code>#r</code>. Imagine for instance that you installed the Nuget package <code>fsharp.data</code>; to use it in your script, you would do something like:</p>
+<h2 id="Tip-5-Including-Assemblies"><a class="header-anchor" href="#Tip-5-Including-Assemblies">¶</a>Tip 5: Including Assemblies</h2>
+<p>By default, FSI loads <code>FSharp.Core</code> and nothing else. If you want to use <code>System.DateTime</code>, you will need to first <code>open System</code> in your script. If you want to use an assembly that is not part of the standard .NET distribution, you will need to reference it first using <code>#r</code>. Imagine for instance that you installed the Nuget package <code>fsharp.data</code>; to use it in your script, you would do something like:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#r @&quot;../packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll&quot;</span><br><span class="line">open FSharp.Data</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>When you execute <code>open System</code> in interactive, don’t worry if nothing seems to happen: the only result is a new <code>&gt;</code> showing up in FSI.</p>
</blockquote>
<p>For assemblies that are part of .NET but not referenced by default, you can use a shorter version:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#r @&quot;System.Xaml&quot;</span><br><span class="line">open System.Xaml</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>In Visual Studio, you can right-click a reference from Solution Explorer, and send to F# interactive. You can then directly open it, and start using it in FSI.</p>
</blockquote>
@@ -295,48 +288,47 @@
<p><a target="_blank" rel="noopener" href="https://twitter.com/jeroldhaas">@jeroldhaas</a> <a target="_blank" rel="noopener" href="https://twitter.com/sergey_tihon">@sergey_tihon</a> <a target="_blank" rel="noopener" href="https://twitter.com/brandewinder">@brandewinder</a> Use <a target="_blank" rel="noopener" href="https://twitter.com/hashtag/I?src=hash">#I</a> <strong>SOURCE_DIRECTORY</strong>, it is wondrous, very satisfying. All relative paths then work</p>
<p>— Don Syme (@dsyme) <a target="_blank" rel="noopener" href="https://twitter.com/dsyme/status/696429115184955393">February 7, 2016</a></p>
</blockquote>
-<h2 id="Tip-6-Use-Paket"><a href="#Tip-6-Use-Paket" class="headerlink" title="Tip 6: Use Paket"></a>Tip 6: Use <code>Paket</code></h2><p>The Nuget package manager is useful to consume existing packages. However, by default, Nuget stores assemblies in a folder that includes the package version number. This is very impractical for a script. In our example above, if <code>fsharp.data</code> gets an update, our script reference will be broken once we update the Nuget package:</p>
+<h2 id="Tip-6-Use-Paket"><a class="header-anchor" href="#Tip-6-Use-Paket">¶</a>Tip 6: Use <code>Paket</code></h2>
+<p>The Nuget package manager is useful to consume existing packages. However, by default, Nuget stores assemblies in a folder that includes the package version number. This is very impractical for a script. In our example above, if <code>fsharp.data</code> gets an update, our script reference will be broken once we update the Nuget package:</p>
<p><code>#r @&quot;../packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll&quot;</code></p>
<p>Fixing the script requires manually editing the version number in the path, which quickly becomes a pain. <a target="_blank" rel="noopener" href="https://fsprojects.github.io/Paket/">Paket</a> provides a better experience, because it stores packages without the version number, in this case, under:</p>
<p><code>#r @&quot;../packages/FSharp.Data/lib/net40/FSharp.Data.dll&quot;</code></p>
<p>Your scripts will now gracefully handle version number changes.</p>
<p>If you end up consuming numerous packages, you can make your life even easier, by referencing paths where assemblies might be searched for, using <code>#I</code>:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#I @&quot;../packages/</span><br><span class="line">#r @&quot;FSharp.Data/lib/net40/FSharp.Data.dll&quot;</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>If your primary goal is to “just script”, consider using <a target="_blank" rel="noopener" href="https://atom.io/">Atom</a> or <a target="_blank" rel="noopener" href="https://code.visualstudio.com/">VSCode</a>, with the <a target="_blank" rel="noopener" href="http://ionide.io/">Ionide plugin</a>. You can create and run free-standing F# scripts, with beautiful <a target="_blank" rel="noopener" href="http://ionide.io/#paket-integration">Paket integration</a>.</p>
</blockquote>
-<h2 id="Tip-7-Include-Files"><a href="#Tip-7-Include-Files" class="headerlink" title="Tip 7: Include Files"></a>Tip 7: Include Files</h2><p>You might want to use the code from an existing file in your script. Suppose that we have a code file <code>Code.fs</code> somewhere, looking like this:</p>
+<h2 id="Tip-7-Include-Files"><a class="header-anchor" href="#Tip-7-Include-Files">¶</a>Tip 7: Include Files</h2>
+<p>You might want to use the code from an existing file in your script. Suppose that we have a code file <code>Code.fs</code> somewhere, looking like this:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">namespace Mathias</span><br><span class="line"></span><br><span class="line">module Common =</span><br><span class="line"> let hello name = sprintf &quot;Hello, %s&quot; name</span><br></pre></td></tr></table></figure>
-
<p>You can use that code from your script, by using the <code>#load</code> directive:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#load &quot;Code.fs&quot;</span><br><span class="line">open Mathias.Common</span><br><span class="line">hello &quot;World&quot;</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>You might have to close and re-open the script file if you end up changing the contents of the file.</p>
</blockquote>
<blockquote>
<p>If the file you are attempting to load contains references to other assemblies or files, you might get an error on the <code>#load</code> statement: “One or more errors in loaded files. The namespace or module … is not defined”. Simply reference the missing assemblies above the <code>#load</code> statement, so that your script uses the same dependencies as the file it refers to.</p>
</blockquote>
-<h2 id="Tip-8-Profile-your-Code-with-time"><a href="#Tip-8-Profile-your-Code-with-time" class="headerlink" title="Tip 8: Profile your Code with #time"></a>Tip 8: Profile your Code with #time</h2><p>Another handy directive, <code>#time</code>, turns on basic profiling. Once it is executed, for every block of code you send for execution you will see timing and garbage collection information. For instance, running this code…</p>
+<h2 id="Tip-8-Profile-your-Code-with-time"><a class="header-anchor" href="#Tip-8-Profile-your-Code-with-time">¶</a>Tip 8: Profile your Code with #time</h2>
+<p>Another handy directive, <code>#time</code>, turns on basic profiling. Once it is executed, for every block of code you send for execution you will see timing and garbage collection information. For instance, running this code…</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#time</span><br><span class="line">[| 1 .. 10000000 |] |&gt; Array.map (fun x -&gt; x * x)</span><br></pre></td></tr></table></figure>
-
<p>… will produce the following in FSI:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">--&gt; Timing now on</span><br><span class="line"></span><br><span class="line">Real: 00:00:00.887, CPU: 00:00:00.828, GC gen0: 2, gen1: 2, gen2: 2</span><br><span class="line">val it : int [] =</span><br><span class="line"> [|1; 4; 9; 16; 25; 36; 49; // snipped for brevity</span><br></pre></td></tr></table></figure>
-
<p>We get the wall time and CPU time it took, as well as some information about garbage collection in generations 0, 1 and 2. This would not replace a full-blown profiler, but this is an awfully convenient tool to figure out quickly if there are obvious ways to improve a piece of code.</p>
<p>Note that every time you execute <code>#time</code>, the timer will be switched from on to off, or vice-versa. This is not always convenient; you can also explicitly set it to the desired state, like this:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#time &quot;on&quot;</span><br><span class="line">// everything now is timed</span><br><span class="line">#time &quot;off&quot;</span><br></pre></td></tr></table></figure>
-
<blockquote>
<p>If you are interested in profiling, you should take a look at <a target="_blank" rel="noopener" href="http://www.privateeye.io/">PrivateEye</a>; check out <a target="_blank" rel="noopener" href="https://twitter.com/gregyoung">Greg Young</a>’s <a target="_blank" rel="noopener" href="https://vimeo.com/131637366">talk at NDC Oslo 2015</a> to get a feel for what it does.</p>
</blockquote>
-<h2 id="Tip-9-Turn-64-bits-on"><a href="#Tip-9-Turn-64-bits-on" class="headerlink" title="Tip 9: Turn 64-bits on"></a>Tip 9: Turn 64-bits on</h2><p>Hat tip to <a target="_blank" rel="noopener" href="https://twitter.com/rickasaurus">Rick Minerich</a> for that one. I’ll refer you to his blog post to see how to <a target="_blank" rel="noopener" href="http://richardminerich.com/2013/03/setting-up-fsharp-interactive-for-machine-learning-with-large-datasets/">set FSI to 64 bits to handle large datasets</a>.</p>
-<h2 id="Tip-10-Bonus-Material"><a href="#Tip-10-Bonus-Material" class="headerlink" title="Tip 10: Bonus Material"></a>Tip 10: Bonus Material</h2><p>Did you know that you could…</p>
+<h2 id="Tip-9-Turn-64-bits-on"><a class="header-anchor" href="#Tip-9-Turn-64-bits-on">¶</a>Tip 9: Turn 64-bits on</h2>
+<p>Hat tip to <a target="_blank" rel="noopener" href="https://twitter.com/rickasaurus">Rick Minerich</a> for that one. I’ll refer you to his blog post to see how to <a target="_blank" rel="noopener" href="http://richardminerich.com/2013/03/setting-up-fsharp-interactive-for-machine-learning-with-large-datasets/">set FSI to 64 bits to handle large datasets</a>.</p>
+<h2 id="Tip-10-Bonus-Material"><a class="header-anchor" href="#Tip-10-Bonus-Material">¶</a>Tip 10: Bonus Material</h2>
+<p>Did you know that you could…</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://channel9.msdn.com/Events/Visual-Studio/Visual-Studio-2015-Final-Release-Event/Six-Quick-Picks-from-Visual-F-40">debug an F# script? (around 0:12:35 in)</a></li>
<li><a target="_blank" rel="noopener" href="http://www.swensensoftware.com/fseye">inspect the objects in your FSI session with FsEye?</a></li>
-<li>change the FSI font size in Tools&#x2F;Options&#x2F;Environment&#x2F;Fonts and Colors&#x2F;Show Settings for&#x2F;F# Interactive?</li>
+<li>change the FSI font size in Tools/Options/Environment/Fonts and Colors/Show Settings for/F# Interactive?</li>
<li>add your own pretty-printer to FSI, <a target="_blank" rel="noopener" href="https://github.com/mathnet/mathnet-numerics/blob/master/src/FSharp/MathNet.Numerics.fsx">like this</a>?</li>
<li>mess with your coworkers’ mental sanity, by executing <code>(*</code> (opening a multiline comment) in FSI? (credit: <a target="_blank" rel="noopener" href="https://twitter.com/tomaspetricek">Tomas</a>)</li>
<li>simplify loading references with Visual Studio and Power Tools? (credit: <a target="_blank" rel="noopener" href="https://twitter.com/kitlovesfsharp">Kit Eason</a>, see details in comments section).</li>
diff --git a/2024/10/18/Building-custom-fibers-library-in-FSharp/index.html b/2024/10/18/Building-custom-fibers-library-in-FSharp/index.html
index 73182fbe..42f0d0eb 100644
--- a/2024/10/18/Building-custom-fibers-library-in-FSharp/index.html
+++ b/2024/10/18/Building-custom-fibers-library-in-FSharp/index.html
@@ -202,7 +202,8 @@
<p>The general idea is simple - we want a fine-grained concurrency primitive, that will let us easily compose chain of operations in sequential manner. Of course we could use threads here, but the question is: are threads fine-grained? In many managed languages with OS threads exposed, they can be quite heavy eg. by default in .NET each thread takes around 1MB of memory and requires calling kernel code to cooperate with other threads, which is an expensive operation on its own.</p>
<p>What we’re after, are more lightweight structures (less than 1kB), that can live fully in a user space, so that we can have even millions of them cooperating frequently with each other without heavy performance penalties.</p>
<p>Before we begin, I think it’s good to discuss different designs. We’ll cover several different topics to be able to make more informed decisions, that we’re up to apply to our own solution.</p>
-<h3 id="Preemptive-vs-cooperative-scheduler"><a href="#Preemptive-vs-cooperative-scheduler" class="headerlink" title="Preemptive vs cooperative scheduler"></a>Preemptive vs cooperative scheduler</h3><p>Scheduler is a subsystem, which direct responsibility is to assign CPU core processing power to a particular fiber. It’s also responsible for coordinating fibers execution. The two most common categories of schedulers are preemptive and cooperative.</p>
+<h3 id="Preemptive-vs-cooperative-scheduler"><a class="header-anchor" href="#Preemptive-vs-cooperative-scheduler">¶</a>Preemptive vs cooperative scheduler</h3>
+<p>Scheduler is a subsystem, which direct responsibility is to assign CPU core processing power to a particular fiber. It’s also responsible for coordinating fibers execution. The two most common categories of schedulers are preemptive and cooperative.</p>
<p>A preemptive scheduler is the one, that’s always in control of fiber execution. It’s able to decide on its own, when fiber can be started and stopped. The most obvious example of such is a thread scheduler existing on most operating systems.</p>
<p>Preemptive scheduler usually works in one of two ways:</p>
<ul>
@@ -213,20 +214,24 @@
<p>A cooperative scheduler doesn’t have a concept of preemption - once started by the scheduler, a fiber will execute until it doesn’t give back the control willingly. This is often done with dedicated programming constructs, and often is known as yielding, parking or awaiting.</p>
<p>In cooperative variant, a fiber body is usually split into series of discrete steps, between which fiber gives control back to the scheduler.</p>
<p>Keep in mind that these two are not mutually exclusive - a preemptive scheduler often provides a way for a fiber to return control back to it when it’s known that fiber won’t be executing any longer eg. because it has been put to sleep for a while.</p>
-<h3 id="Stackless-vs-stackful"><a href="#Stackless-vs-stackful" class="headerlink" title="Stackless vs. stackful"></a>Stackless vs. stackful</h3><p>A concept, that’s somewhat related to a topic above is the idea of stackless and stackful coroutines.</p>
-<p>A stackful variant is aware of underlying execution stack and can preserve&#x2F;restore parts of it when yielding&#x2F;continuing a fiber. Examples of this approach could be Go, Lua, Python asyncio and in the future, also <a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=NV46KFV1m-4&ref=bartoszsypytkowski.com">Java Loom</a> project. Implementing such option (if it’s not implemented by a runtime already) usually requires diving deep into low-level internals, since execution stack is not something that most managed languages offers the users to play with, and doing so without coordination with runtime can cause problems - like determining liveness of objects for GC purposes.</p>
+<h3 id="Stackless-vs-stackful"><a class="header-anchor" href="#Stackless-vs-stackful">¶</a>Stackless vs. stackful</h3>
+<p>A concept, that’s somewhat related to a topic above is the idea of stackless and stackful coroutines.</p>
+<p>A stackful variant is aware of underlying execution stack and can preserve/restore parts of it when yielding/continuing a fiber. Examples of this approach could be Go, Lua, Python asyncio and in the future, also <a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=NV46KFV1m-4&amp;ref=bartoszsypytkowski.com">Java Loom</a> project. Implementing such option (if it’s not implemented by a runtime already) usually requires diving deep into low-level internals, since execution stack is not something that most managed languages offers the users to play with, and doing so without coordination with runtime can cause problems - like determining liveness of objects for GC purposes.</p>
<p>Stackless coroutine usually captures locals that we want to preserve as part of callback object (lambda), that is allocated as an object on the heap and scheduled on yield continuation. These steps are usually visible directly in code (eg. await in C#, Rust and JavaScript, but also joints of Scala for-comprehensions, bang-suffix in F# or Haskell do-notation), but sometimes can be implicit like in case of Kotlin. Take into account that while many languages offer syntax support for those constructs, it’s not explicitly necessary to work - take a look at JavaScript and <code>Promise.then</code> as an example.</p>
<p>Stackless coroutines usually construct their logic around one of two concepts:</p>
<ol>
<li>Finite state machines - this variant is usually faster and can be encoded manually (example of such case is Akka actors), but for a human eye it usually doesn’t really read as a sequential step-by-step program execution, unless it has some support from the compiler itself (see: C# and Rust).</li>
-<li>Monadic sequencing via bind&#x2F;flatMap operator, which is very popular in functional languages. While we cover it in more details in the rest of this blog post, for now it’s enough to say that it’s a way to chain callback-based behaviors together in a way, that resembles standard sequential code.</li>
+<li>Monadic sequencing via bind/flatMap operator, which is very popular in functional languages. While we cover it in more details in the rest of this blog post, for now it’s enough to say that it’s a way to chain callback-based behaviors together in a way, that resembles standard sequential code.</li>
</ol>
-<p>For sure one of the advantages of stackful coroutines is that they’re <em>mono-colored</em>: you can yield&#x2F;continue coroutine execution from within any other function, while in the stackless variant splits your world into <em>two-colored</em> functions - synchronous and asynchronous - where async one can be only called and yielded safely (without blocking underlying OS thread) from within another async function.</p>
-<h3 id="Eager-vs-lazy-fibers"><a href="#Eager-vs-lazy-fibers" class="headerlink" title="Eager vs lazy fibers"></a>Eager vs lazy fibers</h3><p>We already mentioned two important events in fiber execution life cycle - starting and parking. Here I briefly discuss about different design decisions on when to start a fiber execution.</p>
+<p>For sure one of the advantages of stackful coroutines is that they’re <em>mono-colored</em>: you can yield/continue coroutine execution from within any other function, while in the stackless variant splits your world into <em>two-colored</em> functions - synchronous and asynchronous - where async one can be only called and yielded safely (without blocking underlying OS thread) from within another async function.</p>
+<h3 id="Eager-vs-lazy-fibers"><a class="header-anchor" href="#Eager-vs-lazy-fibers">¶</a>Eager vs lazy fibers</h3>
+<p>We already mentioned two important events in fiber execution life cycle - starting and parking. Here I briefly discuss about different design decisions on when to start a fiber execution.</p>
<p>Eager execution means, that fiber is started automatically after its creation. An example of such are Scala <code>Future[A]</code> and JavaScript <code>Promise</code>. Since execution process starts right away, we’re willingly resign from a certain degree of control over how or when to execute given fiber. Usually this is solved by wrapping a fiber creation into another function or lambda.</p>
<p>Lazy execution is much more common and preferred way of work, as it allows us to separate place where we want to define our asynchronous sequence of steps from the place, where the execution details are defined. It’s used in C# TPL as well as pretty much in all functional languages implementations (excluding Scala futures mentioned earlier).</p>
-<h3 id="Interruption"><a href="#Interruption" class="headerlink" title="Interruption"></a>Interruption</h3><p>There are also few decisions regarding premature escaping the fiber execution, also known as interruption&#x2F;cancelation: one of them requires passing special object - a token - between method calls and explicit checking for its completion. It is how C# Tasks work. However putting such requirement onto the API user can be cumbersome and error-prone option. Therefore pretty much every other coroutine library either allows to direcly interrupt a fiber or (like in case of F# Async) passes cancelation tokens and check if they were triggered under the hood.</p>
-<h2 id="Implementation"><a href="#Implementation" class="headerlink" title="Implementation"></a>Implementation</h2><p>Since we talked a bit about various approaches, let’s get to the meat of this blog post: implementing our own coroutine library in F#. So, what properties will it have?:</p>
+<h3 id="Interruption"><a class="header-anchor" href="#Interruption">¶</a>Interruption</h3>
+<p>There are also few decisions regarding premature escaping the fiber execution, also known as interruption/cancelation: one of them requires passing special object - a token - between method calls and explicit checking for its completion. It is how C# Tasks work. However putting such requirement onto the API user can be cumbersome and error-prone option. Therefore pretty much every other coroutine library either allows to direcly interrupt a fiber or (like in case of F# Async) passes cancelation tokens and check if they were triggered under the hood.</p>
+<h2 id="Implementation"><a class="header-anchor" href="#Implementation">¶</a>Implementation</h2>
+<p>Since we talked a bit about various approaches, let’s get to the meat of this blog post: implementing our own coroutine library in F#. So, what properties will it have?:</p>
<ol>
<li>We use cooperative scheduling (we don’t want to tweak the compiler) of stackless fibers with support from F# computation expression for nice syntax.</li>
<li>We use simple approach by defining custom <code>bind</code> operator with support from F# computation expressions. No state machines.</li>
@@ -236,31 +241,26 @@
<p>All of these give us in very similar approach to that found inside of native F# <code>Async</code> data type. To begin with, we’ll simply define the shape of our fiber.</p>
<p>Underneath, pretty much every cooperative stackless coroutine approach uses callbacks to drive the flow of synchronous segments of code to be executed one after another. So what we need is a callback which takes a result of previous coroutine and schedules in within some context of execution:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">Fiber</span><span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">=</span> Fiber <span class="keyword">of</span> (ExecutionContext <span class="operator">-&gt;</span> FiberCallback<span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">-&gt;</span> <span class="type">unit</span>)</span><br></pre></td></tr></table></figure>
-
<p>Here we’ll represent Fiber as a simple single-case discriminated union. We could as well define other specialized cases, like:</p>
<ul>
<li>Situation when coroutine is executed immediately and doesn’t need to be awaited on: think about variant of <code>ValueTask</code> from C# Task Parallel Library.</li>
<li>Case when coroutine fails - in that case we might want to store an artificial tracing context that would allow us to create nicely-formatted “stack traces”: since .NET Core 2.1, C# already provides similar solution however AFAIK it’s been solved differently.</li>
</ul>
-<p>Ok, but what are <code>ExecutionContext</code> and <code>FiberCallback&lt;&#39;a&gt;</code>? Let’s start from callback. We can represent it as follows:</p>
+<p>Ok, but what are <code>ExecutionContext</code> and <code>FiberCallback&lt;'a&gt;</code>? Let’s start from callback. We can represent it as follows:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">FiberCallback</span><span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">=</span> FiberResult<span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">-&gt;</span> unit</span><br></pre></td></tr></table></figure>
-
-<p>It’s just a simple function, which takes result of previous fiber execution and handles it. What’s the <code>FiberResult&lt;&#39;a&gt;</code> then?</p>
-<p>Our fiber can complete successfully (returning a value) or fail with an exception. We’ll be conservative here and won’t go into more typed world of <a target="_blank" rel="noopener" href="http://degoes.net/articles/bifunctor-io?ref=bartoszsypytkowski.com">IO bifunctor</a>. We can easy define these possible outputs in F# using <code>Result&lt;&#39;a, exn&gt;</code>.</p>
+<p>It’s just a simple function, which takes result of previous fiber execution and handles it. What’s the <code>FiberResult&lt;'a&gt;</code> then?</p>
+<p>Our fiber can complete successfully (returning a value) or fail with an exception. We’ll be conservative here and won’t go into more typed world of <a target="_blank" rel="noopener" href="http://degoes.net/articles/bifunctor-io?ref=bartoszsypytkowski.com">IO bifunctor</a>. We can easy define these possible outputs in F# using <code>Result&lt;'a, exn&gt;</code>.</p>
<p>Question is: is that exhaustive? Well… no. As we already mentioned, there’s a 3rd state, often overlooked or conflated with failure: a canceled fiber. A canceled fiber doesn’t produce any output - since it was canceled before completion. In F# we already know how to represent an absence of value - simply use an option. Therefore our ultimate Fiber result type could look like this:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">FiberResult</span><span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">=</span> Result<span class="operator">&lt;</span><span class="symbol">&#x27;a</span>, exn<span class="operator">&gt;</span> option</span><br></pre></td></tr></table></figure>
-
<p>Now, the <code>ExecutionContext</code>. While it can be compound of many different capabilities throughout the system - even to serve as functional equivalent of dependency injection - here I’ll use it only for implicit passing of specific scheduler info and cancelation tokens from one fiber to another.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">ExecutionContext</span> <span class="operator">=</span> IScheduler <span class="operator">*</span> Cancel</span><br></pre></td></tr></table></figure>
-
<p><code>IScheduler</code> interface is used to abstract component responsible for running our fibers. At the moment all we need is an ability to schedule fiber execution:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Interface&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">IScheduler</span> <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">abstract</span> Schedule<span class="operator">:</span> (<span class="type">unit</span> <span class="operator">-&gt;</span> <span class="type">unit</span>) <span class="operator">-&gt;</span> <span class="type">unit</span></span><br></pre></td></tr></table></figure>
-
<p>While the name and signature imply multithreaded execution model, it doesn’t have to be the case. We can even implement scheduler which will simulate everything on a single core.</p>
<p>For now, we can simply implement a scheduler API on top of our standard .NET thread pool:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Scheduler</span><br><span class="line"></span><br><span class="line"><span class="keyword">open</span> System.Threading</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> shared <span class="operator">=</span> </span><br><span class="line"> &#123; <span class="keyword">new</span> ISchedule <span class="keyword">with</span></span><br><span class="line"> <span class="keyword">member</span> __.Schedule fn <span class="operator">=</span> </span><br><span class="line"> ThreadPool.QueueUserWorkItem(WaitCallback (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> fn())) <span class="operator">|&gt;</span> <span class="built_in">ignore</span> &#125;</span><br></pre></td></tr></table></figure>
-
-<h3 id="Cancellation"><a href="#Cancellation" class="headerlink" title="Cancellation"></a>Cancellation</h3><p>Now it’s a time for cancellation tokens. Of course we could just make use of a flag - conceptually working like native .NET <code>CancellationToken</code>. However given implicit cancellation, it may not be enough. Example:</p>
+<h3 id="Cancellation"><a class="header-anchor" href="#Cancellation">¶</a>Cancellation</h3>
+<p>Now it’s a time for cancellation tokens. Of course we could just make use of a flag - conceptually working like native .NET <code>CancellationToken</code>. However given implicit cancellation, it may not be enough. Example:</p>
<blockquote>
<p>Imagine, that inside our fiber we’re scheduling the race between two other fibers ie. one writing data to a file and other which will complete after timeout. Now, whenever one of them completes first, we want to cancel another one to stop wasting resources for result that no longer matters.</p>
</blockquote>
@@ -272,21 +272,21 @@
</ol>
<p>This behavior implies at least using two separate tokens, however in practice it will be more pragmatic to make our <code>Cancel</code> token work as a tree hierarchy - this way we can easily keep track of things and support more complex scenarios.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Sealed;AllowNullLiteral&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">Cancel</span>(parent<span class="operator">:</span> Cancel) <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> flag<span class="operator">:</span> <span class="type">int</span> <span class="operator">=</span> <span class="number">0</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> children<span class="operator">:</span> Cancel <span class="type">list</span> <span class="operator">=</span> []</span><br><span class="line"> <span class="keyword">new</span>() <span class="operator">=</span> Cancel(<span class="literal">null</span>)</span><br><span class="line"> <span class="comment">/// Check if token was cancelled</span></span><br><span class="line"> <span class="keyword">member</span> __.Cancelled <span class="operator">=</span> flag <span class="operator">=</span> <span class="number">1</span></span><br><span class="line"> <span class="comment">/// Remove child token</span></span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">private</span> __.RemoveChild(child) <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">rec</span> loop child <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> children&#x27; <span class="operator">=</span> children</span><br><span class="line"> <span class="keyword">let</span> nval <span class="operator">=</span> children&#x27; <span class="operator">|&gt;</span> List.filter ((<span class="operator">&lt;&gt;</span>) child)</span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">not</span> (obj.ReferenceEquals(children&#x27;, Interlocked.CompareExchange(<span class="operator">&amp;</span>children, nval, children&#x27;)))</span><br><span class="line"> <span class="keyword">then</span> loop child</span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">not</span> (List.isEmpty children) <span class="keyword">then</span> loop child</span><br><span class="line"> <span class="comment">/// Create a new child token and return it.</span></span><br><span class="line"> <span class="keyword">member</span> this.AddChild () <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">rec</span> loop child <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> children&#x27; <span class="operator">=</span> children</span><br><span class="line"> <span class="keyword">if</span> (obj.ReferenceEquals(children&#x27;, Interlocked.CompareExchange(<span class="operator">&amp;</span>children, child<span class="operator">::</span>children&#x27;, children&#x27;)))</span><br><span class="line"> <span class="keyword">then</span> child</span><br><span class="line"> <span class="keyword">else</span> loop child</span><br><span class="line"> loop (Cancel this)</span><br><span class="line"> <span class="comment">/// Cancel a token</span></span><br><span class="line"> <span class="keyword">member</span> this.Cancel() <span class="operator">=</span></span><br><span class="line"> <span class="keyword">if</span> Interlocked.Exchange(<span class="operator">&amp;</span>flag, <span class="number">1</span>) <span class="operator">=</span> <span class="number">0</span> <span class="keyword">then</span></span><br><span class="line"> <span class="keyword">for</span> child <span class="keyword">in</span> Interlocked.Exchange(<span class="operator">&amp;</span>children, []) <span class="keyword">do</span> child.Cancel()</span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">not</span> (isNull parent) <span class="keyword">then</span> parent.RemoveChild(this)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
-
<p>The general idea is simple: every new cancellation token (except root) may have a parent and a list of children. Canceling parent means canceling its children as well. After cancellation, we need to unpin child from its parent (therefore need for <code>RemveChild</code> operation) to avoid memory leaks.</p>
-<h5 id="Lock-free-updates"><a href="#Lock-free-updates" class="headerlink" title="Lock-free updates"></a>Lock-free updates</h5><p>What might be confusing for some in the code above, are recursive loops inside of <code>AddChild</code>&#x2F;<code>RemoveChild</code> operations. This is a good place to introduce lock-free algorithms: we use atomic operations from <a target="_blank" rel="noopener" href="https://www.bartoszsypytkowski.com/building-custom-fibers-library-in-f/docs.microsoft.com/en-us/dotnet/api/system.threading.interlocked">Interlocked</a> class to make sure that we can replace field references within a single CPU instruction, therefore making such field update safe without synchronized access. This is also known as Compare-And-Swap semantics.</p>
-<p>This alone however is not enough, as <code>Interlocked.CompareExchange(&amp;field, new&#39;, old)</code> can only safely replace a single field with new value if it contained an old one. This means that you cannot safely add or remove element to the list. So what can we do?</p>
+<h5 id="Lock-free-updates"><a class="header-anchor" href="#Lock-free-updates">¶</a>Lock-free updates</h5>
+<p>What might be confusing for some in the code above, are recursive loops inside of <code>AddChild</code>/<code>RemoveChild</code> operations. This is a good place to introduce lock-free algorithms: we use atomic operations from <a target="_blank" rel="noopener" href="https://www.bartoszsypytkowski.com/building-custom-fibers-library-in-f/docs.microsoft.com/en-us/dotnet/api/system.threading.interlocked">Interlocked</a> class to make sure that we can replace field references within a single CPU instruction, therefore making such field update safe without synchronized access. This is also known as Compare-And-Swap semantics.</p>
+<p>This alone however is not enough, as <code>Interlocked.CompareExchange(&amp;field, new', old)</code> can only safely replace a single field with new value if it contained an old one. This means that you cannot safely add or remove element to the list. So what can we do?</p>
<ol>
<li>We’re taking a value from the field.</li>
<li>Update that value.</li>
<li>Conditionally put it back again. What if in the meantime the field was already replaced by another concurrently running thread? In that case <code>Interlocked.CompareExchange</code> will return field value other that the one we read in step 1. This is why we compare its result with the variable we expected.</li>
-<li>If the expectation fails, we’ll retry - hence a recursive loop. Eventually even in high contention scenarios we should be able to complete after few retries. Given cheap and idempotent update operation, this still will be way faster than trying to call kernel code to obtain mutex&#x2F;semaphore lock.</li>
+<li>If the expectation fails, we’ll retry - hence a recursive loop. Eventually even in high contention scenarios we should be able to complete after few retries. Given cheap and idempotent update operation, this still will be way faster than trying to call kernel code to obtain mutex/semaphore lock.</li>
</ol>
<p>While this may sound like something error prone - we can potentially add the same element multiple times - in practice it’s safe, because our collection here is an immutable data structure. Adding the same element multiple times without updating the reference will always produce the same result.</p>
-<h3 id="Back-on-track…"><a href="#Back-on-track…" class="headerlink" title="Back on track…"></a>Back on track…</h3><p>Now we have pretty much all core structures. We’re ready to start building our fiber operators. Starting from the basic ones - a successfully completed fiber and the failed one:</p>
+<h3 id="Back-on-track…"><a class="header-anchor" href="#Back-on-track…">¶</a>Back on track…</h3>
+<p>Now we have pretty much all core structures. We’re ready to start building our fiber operators. Starting from the basic ones - a successfully completed fiber and the failed one:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> success r <span class="operator">=</span> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (_, c) next <span class="operator">-&gt;</span> </span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span> <span class="keyword">else</span> next (<span class="literal">Some</span> (<span class="literal">Ok</span> r))</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> fail ex <span class="operator">=</span> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (_, c) next <span class="operator">-&gt;</span> </span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span> <span class="keyword">else</span> next (<span class="literal">Some</span> (<span class="literal">Error</span> ex))</span><br></pre></td></tr></table></figure>
-
-<p>Here, we simply pass a result&#x2F;error to our Fiber callback:</p>
+<p>Here, we simply pass a result/error to our Fiber callback:</p>
<ul>
<li>Cancelled fiber call <code>next</code> callback with <code>None</code> - as fibers cancelled before completion produce output .</li>
<li>Successful call results in passing <code>Some (Ok result)</code> to a callback…</li>
@@ -295,41 +295,36 @@
<p>You’ll be able to see a cancellation check made here as preamble of pretty much every operator body, which we’ll define. While it may sound cumbersome remember: we do that so that users of our fibers won’t have to :)</p>
<p>Next very important operation is result mapping - we want to map result of one fiber into something else, returning another (lazy) fiber:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> mapResult (fn<span class="operator">:</span> <span class="type">Result</span><span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span> <span class="operator">-&gt;</span> <span class="type">Result</span><span class="operator">&lt;</span><span class="symbol">&#x27;b</span><span class="operator">&gt;</span>) (Fiber call) <span class="operator">=</span> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> <span class="keyword">try</span> </span><br><span class="line"> call (s, c) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> next (Option.map fn result))</span><br><span class="line"> <span class="keyword">with</span> e <span class="operator">-&gt;</span> next (<span class="literal">Some</span> (<span class="literal">Error</span> e))</span><br></pre></td></tr></table></figure>
-
<p>We can use this function to compose more traditionally-looking <code>map</code> function…</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> map (fn<span class="operator">:</span> <span class="symbol">&#x27;a</span> <span class="operator">-&gt;</span> <span class="symbol">&#x27;b</span>) fiber <span class="operator">=</span> mapResult (Result.map fn) fiber</span><br></pre></td></tr></table></figure>
-
-<p>… however <code>mapResult</code> is more powerful - you could easily imagine using to apply failure recovery (a.k.a <code>try</code>&#x2F;<code>catch</code> semantics) by simply mapping <code>Error exception</code> → <code>Ok recoveredValue</code>:</p>
+<p>… however <code>mapResult</code> is more powerful - you could easily imagine using to apply failure recovery (a.k.a <code>try</code>/<code>catch</code> semantics) by simply mapping <code>Error exception</code> → <code>Ok recoveredValue</code>:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> catch fn fiber <span class="operator">=</span> mapResult (<span class="keyword">function</span> <span class="literal">Error</span> e <span class="operator">-&gt;</span> fn e <span class="operator">|</span> ok <span class="operator">-&gt;</span> ok) fiber</span><br></pre></td></tr></table></figure>
-
<p>Another must-have function is binding operator (also know as <code>flatMap</code> in other languages like Scala, or <code>Promise.then</code> in JavaScript). It gives us the ability to compose fibers together - we’ll also use it when we come up to building a computation expression for our fibers.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> bind (fn<span class="operator">:</span> <span class="symbol">&#x27;a</span> <span class="operator">-&gt;</span> Fiber<span class="operator">&lt;</span><span class="symbol">&#x27;b</span><span class="operator">&gt;</span>) (Fiber call) <span class="operator">=</span> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span> </span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> call (s, c) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">match</span> result <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span> (<span class="literal">Ok</span> r) <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">let</span> (Fiber call2) <span class="operator">=</span> fn r</span><br><span class="line"> call2 (s, c) next <span class="comment">// pass `next` callback over to next fiber</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span> next <span class="literal">None</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span> (<span class="literal">Error</span> e) <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Error</span> e)))</span><br><span class="line"> <span class="keyword">with</span> e <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Error</span> e))</span><br></pre></td></tr></table></figure>
-
<p>It’s simple - we execute one fiber from within another, passing the <code>next</code> callback from outer function as an argument to inner one.</p>
-<h3 id="Fiber-computation-expressions"><a href="#Fiber-computation-expressions" class="headerlink" title="Fiber computation expressions"></a>Fiber computation expressions</h3><p>With these few functions we’re already prepared to build a basic computation expression, that will enable us programming with fibers in pleasant way:</p>
+<h3 id="Fiber-computation-expressions"><a class="header-anchor" href="#Fiber-computation-expressions">¶</a>Fiber computation expressions</h3>
+<p>With these few functions we’re already prepared to build a basic computation expression, that will enable us programming with fibers in pleasant way:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Struct&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">FiberBuilder</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Zero <span class="operator">=</span> Fiber.success (Unchecked.defaultof<span class="operator">&lt;</span>_<span class="operator">&gt;</span>)</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.ReturnFrom fib <span class="operator">=</span> fib</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Return value <span class="operator">=</span> Fiber.success value</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Bind(fib, fn) <span class="operator">=</span> Fiber.bind fn fib</span><br><span class="line"></span><br><span class="line"><span class="meta">[&lt;AutoOpen&gt;]</span></span><br><span class="line"><span class="keyword">module</span> FiberBuilder <span class="operator">=</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> fib <span class="operator">=</span> FiberBuilder()</span><br></pre></td></tr></table></figure>
-
<p>While in F# <a target="_blank" rel="noopener" href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions?ref=bartoszsypytkowski.com">there are many more operators</a> we could pack into our computation expression, these are basic ones that will let it work. With such construct, we’ll be able to write programs like:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="keyword">inline</span> millis n <span class="operator">=</span> TimeSpan.FromMilliseconds (float n)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> program<span class="operator">:</span> Fiber<span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span> <span class="operator">=</span> <span class="keyword">fib</span> &#123;</span><br><span class="line"> <span class="keyword">let</span> a <span class="operator">=</span> <span class="keyword">fib</span> &#123;</span><br><span class="line"> <span class="keyword">do!</span> Fiber.delay (millis <span class="number">1000</span>) <span class="comment">// create some artificial delay</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">3</span></span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">let!</span> b <span class="operator">=</span> a <span class="operator">|&gt;</span> Fiber.timeout (millis <span class="number">3000</span>) <span class="comment">// execute task within specified timeout</span></span><br><span class="line"> <span class="keyword">return</span> b &#125;</span><br></pre></td></tr></table></figure>
-
<p>Sure, we have neither delay nor timeout operators at the moment, but at least you know where are we heading now :)</p>
-<h3 id="Delayed-execution"><a href="#Delayed-execution" class="headerlink" title="Delayed execution"></a>Delayed execution</h3><p>In order to implement delays, we could theoretically just call <code>Thread.Sleep</code> and get over it, but this approach is devastating from any coroutine library point of view. Most user-space thread libraries work by using a predefined fixed pool of OS-level threads and scheduling coroutines on them - you can read more about building thread pools <a target="_blank" rel="noopener" href="https://www.bartoszsypytkowski.com/thread-safety-with-affine-thread-pools/">here</a>.</p>
+<h3 id="Delayed-execution"><a class="header-anchor" href="#Delayed-execution">¶</a>Delayed execution</h3>
+<p>In order to implement delays, we could theoretically just call <code>Thread.Sleep</code> and get over it, but this approach is devastating from any coroutine library point of view. Most user-space thread libraries work by using a predefined fixed pool of OS-level threads and scheduling coroutines on them - you can read more about building thread pools <a target="_blank" rel="noopener" href="https://www.bartoszsypytkowski.com/thread-safety-with-affine-thread-pools/">here</a>.</p>
<p>However, <code>Thread.Sleep(timeout)</code> doesn’t know thread pooling mechanism - all it knows about is that we called suspending current OS thread of execution. This means, that this thread will not be awoken by kernel until timeout completes. What it means, is that none of our fibers will be able to use that thread. This is bad, because usually thread pools are made to fit in-line with number of machine CPU cores. In practice, <code>Thread.Sleep</code> may keep one of our CPU cores idle, wasting machine power in the process.</p>
<p>For this reason we usually want to build a suspendable fibers, that will respect our thread pool. This however cannot be done without cooperation with scheduler itself. Therefore, we need to extend API of our scheduler:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">IScheduler</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">abstract</span> Schedule<span class="operator">:</span> (<span class="type">unit</span> <span class="operator">-&gt;</span> <span class="type">unit</span>) <span class="operator">-&gt;</span> <span class="type">unit</span></span><br><span class="line"> <span class="keyword">abstract</span> Delay<span class="operator">:</span> TimeSpan <span class="operator">*</span> (<span class="type">unit</span> <span class="operator">-&gt;</span> <span class="type">unit</span>) <span class="operator">-&gt;</span> <span class="type">unit</span></span><br></pre></td></tr></table></figure>
-
<p>And our simple implementation of it as well:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> shared <span class="operator">=</span> </span><br><span class="line"> &#123; <span class="keyword">new</span> IScheduler <span class="keyword">with</span></span><br><span class="line"> <span class="keyword">member</span> __.Schedule fn <span class="operator">=</span> <span class="operator">....</span></span><br><span class="line"> <span class="keyword">member</span> this.Delay (timeout<span class="operator">:</span> TimeSpan, fn) <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> t <span class="operator">=</span> Unchecked.defaultof<span class="operator">&lt;</span>Timer<span class="operator">&gt;</span></span><br><span class="line"> <span class="keyword">let</span> callback <span class="operator">=</span> <span class="keyword">fun</span> _ <span class="operator">-&gt;</span> </span><br><span class="line"> t.Dispose()</span><br><span class="line"> fn()</span><br><span class="line"> ()</span><br><span class="line"> t <span class="operator">&lt;-</span> <span class="keyword">new</span> Timer(callback, <span class="literal">null</span>, int timeout.TotalMilliseconds, Timeout.Infinite)</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
-
<p>We’ll use a .NET timers here to implement our delays. With these in our hands, our<code>Fiber.delay</code> operation is trivial to implement:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> delay (timeout)<span class="operator">:</span> Fiber<span class="operator">&lt;</span><span class="type">unit</span><span class="operator">&gt;</span> <span class="operator">=</span></span><br><span class="line"> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> s.Delay(timeout, <span class="keyword">fun</span> () <span class="operator">-&gt;</span> </span><br><span class="line"> <span class="keyword">if</span> c.Cancelled </span><br><span class="line"> <span class="keyword">then</span> next <span class="literal">None</span> </span><br><span class="line"> <span class="keyword">else</span> next (<span class="literal">Some</span> (<span class="literal">Ok</span> ())))</span><br></pre></td></tr></table></figure>
-
-<h3 id="Composing-parallel-fibers"><a href="#Composing-parallel-fibers" class="headerlink" title="Composing parallel fibers"></a>Composing parallel fibers</h3><p>We’re slowly getting to the end. What I left for this blog post was to implement two basic operators, that are prevalent in most coroutine libraries:</p>
+<h3 id="Composing-parallel-fibers"><a class="header-anchor" href="#Composing-parallel-fibers">¶</a>Composing parallel fibers</h3>
+<p>We’re slowly getting to the end. What I left for this blog post was to implement two basic operators, that are prevalent in most coroutine libraries:</p>
<ul>
<li><code>Fiber.parallel</code> which will schedule multiple fibers to run in parallel and returns a fiber which aggregates their results.</li>
<li>Running two fibers in parallel and returning the result of whichever completes first, while cancelling a second one. We already discussed this approach before. Here I’ll call it <code>Fiber.race</code>.</li>
</ul>
-<h4 id="Aggregating-parallel-results"><a href="#Aggregating-parallel-results" class="headerlink" title="Aggregating parallel results"></a>Aggregating parallel results</h4><p>We’ll start from building a parallel operator, which will change our array of fibers into fiber with an array of results. But let’s define the semantics of that operation first:</p>
+<h4 id="Aggregating-parallel-results"><a class="header-anchor" href="#Aggregating-parallel-results">¶</a>Aggregating parallel results</h4>
+<p>We’ll start from building a parallel operator, which will change our array of fibers into fiber with an array of results. But let’s define the semantics of that operation first:</p>
<ul>
<li>Our result fiber completes only when all of the aggregated fibers completed with successful result.</li>
<li>If any of the fibers fails, the resulting fiber also fails.</li>
@@ -337,32 +332,28 @@
</ul>
<p>The core skeleton of that operation could look like following:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> parallel (fibers<span class="operator">:</span> Fiber<span class="operator">&lt;</span><span class="symbol">&#x27;a</span><span class="operator">&gt;</span>[])<span class="operator">:</span> Fiber<span class="operator">&lt;</span><span class="symbol">&#x27;a</span>[]<span class="operator">&gt;</span> <span class="operator">=</span></span><br><span class="line"> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> <span class="keyword">let</span> child <span class="operator">=</span> c.AddChild()</span><br><span class="line"> <span class="keyword">let</span> successes <span class="operator">=</span> Array.zeroCreate remaining</span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> remaining <span class="operator">=</span> Array.length fibs</span><br><span class="line"> fibers <span class="operator">|&gt;</span> Array.iteri (<span class="keyword">fun</span> idx (Fiber call) <span class="operator">-&gt;</span></span><br><span class="line"> s.Schedule (<span class="keyword">fun</span> () <span class="operator">-&gt;</span> <span class="comment">(* to be defined *)</span>)</span><br><span class="line"> )</span><br></pre></td></tr></table></figure>
-
<p>Here, we create a dedicated cancellation token, an array of results and a countdown counter - we’re going to decrement it every time one of our fibers completes to know when we’re ready to return a complete result. I’ve left a placeholder for a lambda body that we actually want to schedule. We’re going to fill it right away:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// defined above: s.Schedule &lt;| fun () -&gt;</span></span><br><span class="line">call (s, child) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span> </span><br><span class="line"><span class="keyword">match</span> result <span class="keyword">with</span></span><br><span class="line"><span class="operator">|</span> <span class="literal">Some</span> (<span class="literal">Ok</span> success) <span class="operator">-&gt;</span></span><br><span class="line"> <span class="comment">// fill the result array</span></span><br><span class="line"> successes.[idx] <span class="operator">&lt;-</span> success</span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="operator">&amp;&amp;</span> Interlocked.Exchange(<span class="operator">&amp;</span>remaining, <span class="number">-1</span>) <span class="operator">&gt;</span> <span class="number">0</span> <span class="keyword">then</span></span><br><span class="line"> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">elif</span> Interlocked.Decrement(<span class="operator">&amp;</span>remaining) <span class="operator">=</span> <span class="number">0</span> <span class="keyword">then</span></span><br><span class="line"> <span class="comment">// if all results have been returned, call the `next` callback</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> next (<span class="literal">Some</span> (<span class="literal">Ok</span> successes))</span><br><span class="line"><span class="operator">|</span> <span class="literal">Some</span> (<span class="literal">Error</span> fail) <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> Interlocked.Exchange(<span class="operator">&amp;</span>remaining, <span class="number">-1</span>) <span class="operator">&gt;</span> <span class="number">0</span> <span class="keyword">then</span> </span><br><span class="line"> child.Cancel() <span class="comment">// we failed, cancel other fibers</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> next (<span class="literal">Some</span> (<span class="literal">Error</span> fail))</span><br><span class="line"><span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> Interlocked.Exchange(<span class="operator">&amp;</span>remaining, <span class="number">-1</span>) <span class="operator">&gt;</span> <span class="number">0</span> <span class="keyword">then</span> next <span class="literal">None</span>)</span><br></pre></td></tr></table></figure>
-
<p>As you probably noticed, we’re using <code>Interlocked</code> class again - that’s because now we have multiple fibers running in parallel, therefore our access to shared mutable values is not thread safe. This includes <code>remaining</code> counter decrement operation. This however doesn’t apply to <code>successes.[i] &lt;- success</code> - since every fiber knows and touches only its own index within result array, there’s no worry that any other will try to push its result in the same place.</p>
-<p>What you also can see, we’re using a <code>-1</code> here as a magic value - we’ll use it on the counter as a flag to determine if any of the fibers failed&#x2F;was cancelled - and if so, which one of them will call the <code>next</code> callback.</p>
-<h4 id="Racing-to-completion"><a href="#Racing-to-completion" class="headerlink" title="Racing to completion"></a>Racing to completion</h4><p>With first operator (<code>Fiber.parallel</code>) ready, now it’s the time to implement <code>Fiber.race</code>. Since I’ve discussed it behavior multiple times in this post already, let’s dive straight into the code:</p>
+<p>What you also can see, we’re using a <code>-1</code> here as a magic value - we’ll use it on the counter as a flag to determine if any of the fibers failed/was cancelled - and if so, which one of them will call the <code>next</code> callback.</p>
+<h4 id="Racing-to-completion"><a class="header-anchor" href="#Racing-to-completion">¶</a>Racing to completion</h4>
+<p>With first operator (<code>Fiber.parallel</code>) ready, now it’s the time to implement <code>Fiber.race</code>. Since I’ve discussed it behavior multiple times in this post already, let’s dive straight into the code:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> race (Fiber left) (Fiber right)<span class="operator">:</span> Fiber<span class="operator">&lt;</span>Choice<span class="operator">&lt;</span><span class="symbol">&#x27;a</span>, <span class="symbol">&#x27;b</span><span class="operator">&gt;&gt;</span> <span class="operator">=</span></span><br><span class="line"> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> flag <span class="operator">=</span> <span class="number">0</span></span><br><span class="line"> <span class="keyword">let</span> cancelChild <span class="operator">=</span> c.AddChild()</span><br><span class="line"> <span class="keyword">let</span> run fiber choice <span class="operator">=</span></span><br><span class="line"> <span class="comment">(* to be described *)</span></span><br><span class="line"> run left Choice1Of2</span><br><span class="line"> run right Choice2Of2</span><br></pre></td></tr></table></figure>
-
<p>So again, we want to have shared mutable flag, which we’ll use to determine, which of the fibers finished as a first one to be able to call fiber’s callback safely and cancel the other. You may see, that our returned fiber uses <code>Choice&lt;,&gt;</code> type - this means, that our left and right fibers can have results of different types. We’ll use that soon, but first we need to complete our <code>run</code> function body:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> run fiber choice <span class="operator">=</span></span><br><span class="line"> s.Schedule (<span class="keyword">fun</span> () <span class="operator">-&gt;</span></span><br><span class="line"> fiber (s, cancelChild) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> Interlocked.Exchange(<span class="operator">&amp;</span>flag, <span class="number">1</span>) <span class="operator">=</span> <span class="number">0</span> <span class="keyword">then</span></span><br><span class="line"> cancelChild.Cancel()</span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">match</span> result <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span> next <span class="literal">None</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span>(<span class="literal">Ok</span> v) <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Ok</span>(choice v)))</span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span>(<span class="literal">Error</span> e) <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Error</span> e))))</span><br></pre></td></tr></table></figure>
-
<p>What we do here is simply trying to race to “reserve” out flag variable - the winner gets his result mapped to corresponding choice, while looser gets cancelled.</p>
<p>What’s interesting, we can now combine our <code>race</code> and <code>delay</code> functions to easily implement timeout mechanism:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> timeout (t<span class="operator">:</span> TimeSpan) fiber <span class="operator">=</span></span><br><span class="line"> Fiber <span class="operator">&lt;|</span> <span class="keyword">fun</span> (s, c) next <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">let</span> (Fiber call) <span class="operator">=</span> race (delay t) fiber</span><br><span class="line"> call (s, c) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> c.Cancelled <span class="keyword">then</span> next <span class="literal">None</span></span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">match</span> result <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span> next <span class="literal">None</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span>(<span class="literal">Ok</span> (Choice1Of2 _)) <span class="operator">-&gt;</span> next <span class="literal">None</span> <span class="comment">// timeout won</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span>(<span class="literal">Ok</span> (Choice2Of2 v)) <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Ok</span> v))</span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span>(<span class="literal">Error</span> e) <span class="operator">-&gt;</span> next (<span class="literal">Some</span>(<span class="literal">Error</span> e))</span><br><span class="line"> )</span><br></pre></td></tr></table></figure>
-
<p>The one last thing left for us, is to be able to run out fibers on the main thread - otherwise we’d start our program, schedule fibers to run in the background and then close the program without waiting for the results.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> blocking (s<span class="operator">:</span> IScheduler) (cancel<span class="operator">:</span> Cancel) (Fiber fn) <span class="operator">=</span></span><br><span class="line"> <span class="keyword">use</span> waiter <span class="operator">=</span> <span class="keyword">new</span> ManualResetEventSlim(<span class="literal">false</span>)</span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> res <span class="operator">=</span> <span class="literal">None</span></span><br><span class="line"> s.Schedule(<span class="keyword">fun</span> () <span class="operator">-&gt;</span> fn (s, cancel) (<span class="keyword">fun</span> result <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">not</span> cancel.Cancelled <span class="keyword">then</span></span><br><span class="line"> Interlocked.Exchange(<span class="operator">&amp;</span>res, <span class="literal">Some</span> result) <span class="operator">|&gt;</span> <span class="built_in">ignore</span></span><br><span class="line"> waiter.Set()))</span><br><span class="line"> waiter.Wait()</span><br><span class="line"> res.Value</span><br></pre></td></tr></table></figure>
-
<p>It’s simple - we’ll use standard synchronization primitives provided by .NET runtime, to hold current OS thread until we complete. Sure it’s blocking an OS thread, but we’ll eventually need that if we don’t want our program’s main function to finish before all fibers inside the thread pool complete.</p>
-<h3 id="Simulating-real-environment-in-tests"><a href="#Simulating-real-environment-in-tests" class="headerlink" title="Simulating real environment in tests"></a>Simulating real environment in tests</h3><p>In theory, we could be done here. But, if you managed to read up to this point, we may want to cover one last scenario. Imagine that we’d want to test our fibers. However running tests using standard thread pool scheduler can lead to funky issues:</p>
+<h3 id="Simulating-real-environment-in-tests"><a class="header-anchor" href="#Simulating-real-environment-in-tests">¶</a>Simulating real environment in tests</h3>
+<p>In theory, we could be done here. But, if you managed to read up to this point, we may want to cover one last scenario. Imagine that we’d want to test our fibers. However running tests using standard thread pool scheduler can lead to funky issues:</p>
<ul>
<li>Sometimes you may trigger some race conditions in your code, that only happen in specific situations (like high CPU contention) and are almost impossible to reproduce during debug sessions.</li>
-<li>Other times you may have some lengthy delays&#x2F;timeouts in your code, like waiting for seconds or even minutes before continuing. Guess what: now your test will wait for just as long.</li>
+<li>Other times you may have some lengthy delays/timeouts in your code, like waiting for seconds or even minutes before continuing. Guess what: now your test will wait for just as long.</li>
</ul>
-<p>These are not new problems. They are well known in world of concurrent and distributed systems. What we need, is a simulation of execution environment. If you want to listen more about that concept, I could recommend you <a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=4fFDFbi3toc&ref=bartoszsypytkowski.com">this presentaton</a>. To run our test predictably, we’ll create a dedicated test scheduler, which will run our code in deterministic fashion (on a single core) and in a way that’s detached from other invariants eg. actual physical clock and random number generator.</p>
+<p>These are not new problems. They are well known in world of concurrent and distributed systems. What we need, is a simulation of execution environment. If you want to listen more about that concept, I could recommend you <a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=4fFDFbi3toc&amp;ref=bartoszsypytkowski.com">this presentaton</a>. To run our test predictably, we’ll create a dedicated test scheduler, which will run our code in deterministic fashion (on a single core) and in a way that’s detached from other invariants eg. actual physical clock and random number generator.</p>
<p>The idea here is simple - our scheduler will operate on notion of virtual timeline. When we’ll try to schedule a new function - to trigger either immediately or after some timeout - we’ll store it inside an ordered collection, a timeline. Some of the technical decisions we also made for purposes of this implementation:</p>
<ul>
<li>Whenever a fiber is going to schedule multiple parallel executions “at the same time”, we’ll put them all into a single bucket on a timeline. Later on I’ll cover, why this is useful.</li>
@@ -370,20 +361,16 @@
</ul>
<p>After describing the concept behind the algorithm, the actual implementation really shouldn’t be that surprising:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">TestScheduler</span>(now<span class="operator">:</span> DateTime) <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> running <span class="operator">=</span> <span class="literal">false</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> currentTime <span class="operator">=</span> now.Ticks</span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> timeline <span class="operator">=</span> Map.empty</span><br><span class="line"> <span class="keyword">let</span> schedule delay fn <span class="operator">=</span> <span class="comment">(* to be defined *)</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">rec</span> run () <span class="operator">=</span> <span class="comment">(* to be defined *)</span></span><br><span class="line"> <span class="keyword">interface</span> IScheduler <span class="keyword">with</span></span><br><span class="line"> <span class="keyword">member</span> this.Schedule fn <span class="operator">=</span> </span><br><span class="line"> schedule <span class="number">0</span>L fn</span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">not</span> running <span class="keyword">then</span></span><br><span class="line"> running <span class="operator">&lt;-</span> <span class="literal">true</span></span><br><span class="line"> run ()</span><br><span class="line"> <span class="keyword">member</span> this.Delay (timeout<span class="operator">:</span> TimeSpan, fn) <span class="operator">=</span> schedule timeout.Ticks fn</span><br></pre></td></tr></table></figure>
-
<p>We’re using a <code>running</code> flag here to not try to invoke <code>run</code> multiple times in nested manner - this would cause non-tailable recursion and potential stack overflow in more expensive tests.</p>
<p>The schedule function is pretty simple - calculate expected execution time for a function, then add that function to be executed at that point in time.</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> schedule delay fn <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">let</span> at <span class="operator">=</span> currentTime <span class="operator">+</span> delay</span><br><span class="line"> timeline <span class="operator">&lt;-</span></span><br><span class="line"> <span class="keyword">match</span> Map.tryFind at timeline <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span> Map.add at [fn] timeline </span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span> fns <span class="operator">-&gt;</span> Map.add at (fn<span class="operator">::</span>fns) timeline</span><br></pre></td></tr></table></figure>
-
<p>Given all of the code we already survived in this blog post, run loop should be pretty simple:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> run () <span class="operator">=</span></span><br><span class="line"> <span class="keyword">match</span> Seq.tryHead timeline <span class="keyword">with</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">None</span> <span class="operator">-&gt;</span> running <span class="operator">&lt;-</span> <span class="literal">false</span></span><br><span class="line"> <span class="operator">|</span> <span class="literal">Some</span> (KeyValue(time, bucket)) <span class="operator">-&gt;</span></span><br><span class="line"> timeline <span class="operator">&lt;-</span> Map.remove time timeline</span><br><span class="line"> currentTime <span class="operator">&lt;-</span> time</span><br><span class="line"> <span class="keyword">for</span> fn <span class="keyword">in</span> List.rev bucket <span class="keyword">do</span> </span><br><span class="line"> fn () </span><br><span class="line"> run ()</span><br></pre></td></tr></table></figure>
-
<p>We’ll try to pick the first entry from the timeline - since here we use F# map, which is sorted in ascending order, we know that first entry is the one with the shortest execution timeout. We update our “current” time to match the expected one we calculated earlier, and finally we execute all functions scheduled at that time and repeat the loop all over until we eventually run out of scheduled actions.</p>
<p>Now here’s the trick - we use <code>List.rev</code> to execute functions in the same order in which they were scheduled, because we want our tests to be deterministic and our bugs to be reproducible. However this is not the only strategy - since we know that functions in the same bucket could as well be executing in parallel, we could shuffle them around in different permutations for early discovery of some data races! I’ll won’t dive into it, but leave that idea as food for thoughts for you.</p>
<p>One last note about the test scheduler is that isolating it from the actual physical clock means, we cannot trust our time functions (like <code>DateTime.UtcNow</code>) any longer. This shouldn’t really be an issue though - because relying on physical time would potentially make our tests indeterministic, we didn’t want to use it anyway, right?</p>
<p>However, we need to be able to obtain current time from the scheduler, so we need to extend its API:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">IScheduler</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">abstract</span> UtcNow<span class="operator">:</span> <span class="type">unit</span> <span class="operator">-&gt;</span> <span class="type">unit</span></span><br><span class="line"> <span class="comment">// ... other methods</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">type</span> <span class="title class_">TestScheduler</span>() <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">mutable</span> currentTime <span class="operator">=</span> DateTime.UtcNow.Ticks</span><br><span class="line"> <span class="comment">// ... rest of the implementation</span></span><br><span class="line"> <span class="keyword">interface</span> IScheduler <span class="keyword">with</span></span><br><span class="line"> <span class="keyword">member</span> __.UtcNow() <span class="operator">=</span> DateTime(currentTime)</span><br><span class="line"> <span class="comment">// ... other methods</span></span><br></pre></td></tr></table></figure>
-
<p>And that’s all. As always, if you got confused or have a problems along the way, you can get the entire code <a target="_blank" rel="noopener" href="https://gist.github.com/Horusiath/9c790691130150b524aaa9ab426ed982?ref=bartoszsypytkowski.com">here</a>. I wanted to thank to Anthony Lloyd for his initial work on porting Scala <a target="_blank" rel="noopener" href="https://zio.dev/?ref=bartoszsypytkowski.com">ZIO</a> library to F#, which brought me an inspiration to write this piece.</p>
</div>
diff --git a/2024/10/18/Dealing-with-complex-dependency-injection-in-FSharp/index.html b/2024/10/18/Dealing-with-complex-dependency-injection-in-FSharp/index.html
index 90da8977..b10d650b 100644
--- a/2024/10/18/Dealing-with-complex-dependency-injection-in-FSharp/index.html
+++ b/2024/10/18/Dealing-with-complex-dependency-injection-in-FSharp/index.html
@@ -203,48 +203,44 @@
<p>On the other side in functional space, there’s no one opinionated solution or approach - various things have been proposed, usually depending on features that languages and compiler have to offer. And since pretty much all functional languages offer this thing known as partial application, for many years it was the most common answer for the problem of managing dependencies.</p>
<p>In short we’re talking about dependency injection by function parameter, like:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// foo requires 2 dependencies to serve the incoming request</span></span><br><span class="line"><span class="keyword">let</span> foo bar baz request <span class="operator">=</span> <span class="operator">???</span></span><br><span class="line"><span class="comment">// we&#x27;re providing dependencies by partial application</span></span><br><span class="line"><span class="keyword">let</span> wired <span class="operator">=</span> foo dependency1 dependency2</span><br><span class="line"><span class="comment">// now wired can serve request directly without calling </span></span><br><span class="line"><span class="comment">// dependencies every time</span></span><br><span class="line"><span class="keyword">let</span> response <span class="operator">=</span> wired request</span><br></pre></td></tr></table></figure>
-
-<p>It’s very simple, doesn’t require reflection or dedicated library. However there are several pain points coming with this approach - visible especially as our code base grows and become more complex. However latest approaches popularized by libraries like Scala <a target="_blank" rel="noopener" href="https://zio.dev/?ref=bartoszsypytkowski.com">ZIO</a> or Haskell’s <a target="_blank" rel="noopener" href="https://youtu.be/idU7GdlfP9Q?t=1394&ref=bartoszsypytkowski.com">Polysemy</a> challenge this approach.</p>
-<h2 id="Partial-application"><a href="#Partial-application" class="headerlink" title="Partial application"></a>Partial application</h2><p>There are some design decisions, when partial application doesn’t always give a clear answer. Example:</p>
+<p>It’s very simple, doesn’t require reflection or dedicated library. However there are several pain points coming with this approach - visible especially as our code base grows and become more complex. However latest approaches popularized by libraries like Scala <a target="_blank" rel="noopener" href="https://zio.dev/?ref=bartoszsypytkowski.com">ZIO</a> or Haskell’s <a target="_blank" rel="noopener" href="https://youtu.be/idU7GdlfP9Q?t=1394&amp;ref=bartoszsypytkowski.com">Polysemy</a> challenge this approach.</p>
+<h2 id="Partial-application"><a class="header-anchor" href="#Partial-application">¶</a>Partial application</h2>
+<p>There are some design decisions, when partial application doesn’t always give a clear answer. Example:</p>
<blockquote>
-<p>Imagine using a set of methods, that are closely related and - in object oriented world - encapsulated within  a single object, like database query&#x2F;execute or different logging methods (debug&#x2F;info&#x2F;warning&#x2F;error).</p>
+<p>Imagine using a set of methods, that are closely related and - in object oriented world - encapsulated within  a single object, like database query/execute or different logging methods (debug/info/warning/error).</p>
</blockquote>
<p>Now, given that our function needs to use potentially more than one of these, how should we pass our arguments?:</p>
<ol>
<li>Functional purist path - pass every dependency as a separate function parameter: <code>let doSmth logError logInfo = ??</code>. While it allows us to precisely describe what this function uses, it would of course lead to explosion of function parameters. Additionally every time you need new function in your existing code, you need to partially apply it at all call sites.</li>
<li>Describe operations using ADT (algebraic data types) and inject a function that will work as an interpreter for them: <code>let doSmth (log: LogEvent -&gt; unit) = ??</code>. While it’s easy to mock (you don’t need to implement everything, only pattern match on cases that matter for a particular test) and reduces params affinity, it also comes with a lot of indirection, that may lead to harder to grasp, especially during debugging. Sometimes a performance penalty is also to be expected.</li>
-<li>Fallback to objects&#x2F;interfaces and pass them as methods: <code>let doSmth (logger: ILogger) = ??</code>. While interfaces may simplify dependency tree, it’s not always obvious when to use it. Mocking story is also more painful + interfaces are not inferred by F# compiler.</li>
+<li>Fallback to objects/interfaces and pass them as methods: <code>let doSmth (logger: ILogger) = ??</code>. While interfaces may simplify dependency tree, it’s not always obvious when to use it. Mocking story is also more painful + interfaces are not inferred by F# compiler.</li>
</ol>
<p>These are quite common options I’ve seen in the wild - each having their own advantages and disadvantages. Which one to use? Good question, as in practice with codebases that are old enough, you usually see 2 or even all 3 of them mixed together. This can lead to some confusion and obscurity over time.</p>
<p>What’s worse, none of these cases really solves problem of dependency management - all they do is just try to reduce it to a manageable scope. Eventually you’ll end up manually wiring - by partial application - dozens of functions and managing all of the dependencies between them by hand.</p>
-<h3 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h3><p>In order to get better understanding, we’ll use a fairly simple example - changing user password:</p>
+<h3 id="Example"><a class="header-anchor" href="#Example">¶</a>Example</h3>
+<p>In order to get better understanding, we’ll use a fairly simple example - changing user password:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> fetchUser (db<span class="operator">:</span> IDbConnection) userId <span class="operator">=</span> </span><br><span class="line"> db.QueryFirstAsync(Sql.FetchUser, &#123;<span class="operator">|</span> userId <span class="operator">=</span> userid<span class="operator">|</span> &#125;)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">let</span> updateUser (db<span class="operator">:</span> IDbConnection) user <span class="operator">=</span> db.ExecuteAsync(Sql.UpdateUser, user)</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> changePass (logger<span class="operator">:</span> ILogger) fetch update <span class="operator">=</span> <span class="keyword">fun</span> req <span class="operator">-&gt;</span> <span class="keyword">task</span> &#123;</span><br><span class="line"> <span class="keyword">let!</span> user <span class="operator">=</span> fetch req.UserId</span><br><span class="line"> <span class="keyword">if</span> user.Hash <span class="operator">=</span> bcrypt user.Salt req.OldPass <span class="keyword">then</span></span><br><span class="line"> <span class="keyword">let</span> salt <span class="operator">=</span> generateSalt ()</span><br><span class="line"> <span class="keyword">let</span> user&#x27; <span class="operator">=</span> &#123; user <span class="keyword">with</span> Salt <span class="operator">=</span> salt; Hash <span class="operator">=</span> bcrypt salt req.NewPass &#125;</span><br><span class="line"> <span class="keyword">do!</span> update user&#x27;</span><br><span class="line"> logger.LogInformation <span class="string">&quot;Password change: user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Ok</span> ()</span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> logger.LogError <span class="string">&quot;Password change unauthorized: user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Error</span> <span class="string">&quot;Old password is invalid&quot;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
-
<p>Here we have a fairly short snippet with some dependencies? But how many in practice?:</p>
<ul>
-<li>Number of parameters suggest 3, but depending on our choices it could be 4 (if we decide to pass log error and info separately) or 2 (if we conflate fetch&#x2F;update into dedicated interface).</li>
+<li>Number of parameters suggest 3, but depending on our choices it could be 4 (if we decide to pass log error and info separately) or 2 (if we conflate fetch/update into dedicated interface).</li>
<li>It’s not hard to imagine that in the future our <code>bcrypt</code> hashing function may turn out to be configurable - maybe even per each user. That may need a configurable parameter.</li>
<li>Maybe aside of the logger we may be needing a separate telemetry mechanism to count number of incoming request or password validation failures? That means another parameter.</li>
<li>Salt generation is pseudo-random process - it we want our function to be deterministic, we should probably parametrize it over explicitly passed <code>Random</code> as well.</li>
</ul>
<p>As you see, what seemed to be simple task at the beginning can quickly blow up out of proportion. As the number of arguments grows, the more nasty our wiring code eventually becomes. Quite common pattern is to hide all of that nastiness under the carpet a.k.a. composition root. However this doesn’t have to be the case.</p>
<p>Below we’ll cover another approach for dealing with dependencies - inspired by Scala <a target="_blank" rel="noopener" href="https://medium.com/@pascal.mengelt/what-are-the-benefits-of-the-zio-modules-with-zlayers-3bf6cc064a9b?ref=bartoszsypytkowski.com">ZIO</a> library - using incremental steps, from first principles to monadic bindings.</p>
-<h2 id="Managing-dependencies-beyond-partial-application"><a href="#Managing-dependencies-beyond-partial-application" class="headerlink" title="Managing dependencies beyond partial application"></a>Managing dependencies beyond partial application</h2><p>Let’s start from how our code from above will eventually look like at the end of this step:</p>
+<h2 id="Managing-dependencies-beyond-partial-application"><a class="header-anchor" href="#Managing-dependencies-beyond-partial-application">¶</a>Managing dependencies beyond partial application</h2>
+<p>Let’s start from how our code from above will eventually look like at the end of this step:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> changePass env <span class="operator">=</span> <span class="keyword">fun</span> req <span class="operator">-&gt;</span> <span class="keyword">task</span> &#123;</span><br><span class="line"> <span class="keyword">let!</span> user <span class="operator">=</span> Db.fetchUser env req.UserId</span><br><span class="line"> <span class="keyword">if</span> user.Hash <span class="operator">=</span> bcrypt user.Salt req.OldPass <span class="keyword">then</span></span><br><span class="line"> <span class="keyword">let</span> salt <span class="operator">=</span> Random.bytes env <span class="number">32</span></span><br><span class="line"> <span class="keyword">do!</span> Db.updateUser <span class="keyword">env</span> &#123; user <span class="keyword">with</span> Salt <span class="operator">=</span> salt; Hash <span class="operator">=</span> bcrypt salt req.NewPass &#125;</span><br><span class="line"> Log.info env <span class="string">&quot;Changed password for user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Ok</span> ()</span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> Log.error env <span class="string">&quot;Password change unauthorized: user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Error</span> <span class="string">&quot;Old password is invalid&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
-<p>As you may notice, all of our partially applied parameters disappeared, replaced by some single cryptic <code>env</code> parameter. We’ll get there soon. We also packed similar capabilities into corresponding modules (<code>Db</code>&#x2F;<code>Log</code>&#x2F;<code>Random</code>). Lets start from defining them:</p>
+<p>As you may notice, all of our partially applied parameters disappeared, replaced by some single cryptic <code>env</code> parameter. We’ll get there soon. We also packed similar capabilities into corresponding modules (<code>Db</code>/<code>Log</code>/<code>Random</code>). Lets start from defining them:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Interface&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">ILogger</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">abstract</span> Debug<span class="operator">:</span> <span class="type">string</span> <span class="operator">-&gt;</span> <span class="type">unit</span></span><br><span class="line"> <span class="keyword">abstract</span> <span class="literal">Error</span><span class="operator">:</span> <span class="type">string</span> <span class="operator">-&gt;</span> <span class="type">unit</span> </span><br><span class="line"></span><br><span class="line"><span class="meta">[&lt;Interface&gt;]</span> <span class="keyword">type</span> <span class="title class_">ILog</span> <span class="operator">=</span> <span class="keyword">abstract</span> Logger<span class="operator">:</span> ILogger</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> Log <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> debug (env<span class="operator">:</span> #ILog) fmt <span class="operator">=</span> Printf.kprintf env.Logger.Debug fmt</span><br><span class="line"> <span class="keyword">let</span> error (env<span class="operator">:</span> #ILog) fmt <span class="operator">=</span> Printf.kprintf env.Logger.<span class="literal">Error</span> fmt</span><br></pre></td></tr></table></figure>
-
<p>Now we can say something more about <code>env</code>. The secret is in <code>#ILog</code> signature, which means that our environment can be any generic type implementing <code>ILog</code> interface. As soon you’ll see, this approach is highly composable, but before that we’ll need another module:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Interface&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">IDatabase</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">abstract</span> Query<span class="operator">:</span> <span class="type">string</span> <span class="operator">*</span> <span class="symbol">&#x27;i</span> <span class="operator">-&gt;</span> Task<span class="operator">&lt;</span><span class="symbol">&#x27;o</span><span class="operator">&gt;</span></span><br><span class="line"> <span class="keyword">abstract</span> Execute<span class="operator">:</span> <span class="type">string</span> <span class="operator">*</span> <span class="symbol">&#x27;i</span> <span class="operator">-&gt;</span> Task</span><br><span class="line"> </span><br><span class="line"><span class="meta">[&lt;Interface&gt;]</span> <span class="keyword">type</span> <span class="title class_">IDb</span> <span class="operator">=</span> <span class="keyword">abstract</span> Database<span class="operator">:</span> IDatabase</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span> Db <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">let</span> fetchUser (env<span class="operator">:</span> #IDb) userId <span class="operator">=</span> </span><br><span class="line"> env.Database.Query(Sql.FetchUser, &#123;<span class="operator">|</span> userId <span class="operator">=</span> userId <span class="operator">|</span>&#125;)</span><br><span class="line"> <span class="keyword">let</span> updateUser (env<span class="operator">:</span> #IDb) user <span class="operator">=</span> env.Database.Execute(Sql.UpdateUser, user)</span><br></pre></td></tr></table></figure>
-
<p>Now what will happen if we use functions from both <code>Log</code> and <code>Db</code> modules? As it turns out, F# compiler can properly infer generic constraints over these interfaces. The result <code>env</code> type constraint is inferred to be an union - just like set union, which also means that it handles duplicates for us - of all constraints of other functions using <code>env</code> in its scope:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> foo env <span class="operator">=</span> <span class="comment">// env :&gt; IDb and env :&gt; ILog</span></span><br><span class="line"> <span class="keyword">let</span> user <span class="operator">=</span> Db.fetchUser env <span class="number">123</span> <span class="comment">// env :&gt; IDb</span></span><br><span class="line"> Log.debug env <span class="string">&quot;User: %A&quot;</span> user <span class="comment">// env :&gt; ILog</span></span><br></pre></td></tr></table></figure>
-
-<p>Now why did we use two separate interfaces (<code>ILog</code>&#x2F;<code>ILogger</code>) instead of making environment implement <code>ILogger</code> directly? This is more practical approach that will let us isolate capabilities of particular modules rather than putting them flat into our environment. Example:</p>
+<p>Now why did we use two separate interfaces (<code>ILog</code>/<code>ILogger</code>) instead of making environment implement <code>ILogger</code> directly? This is more practical approach that will let us isolate capabilities of particular modules rather than putting them flat into our environment. Example:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Log <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> live <span class="operator">:</span> ILogger <span class="operator">=</span> <span class="operator">??</span> <span class="comment">// create logger interface</span></span><br><span class="line"></span><br><span class="line"><span class="meta">[&lt;Struct&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">AppEnv</span> <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">interface</span> ILog <span class="keyword">with</span> <span class="keyword">member</span> _.Logger <span class="operator">=</span> Log.live</span><br><span class="line"> <span class="keyword">interface</span> IDb <span class="keyword">with</span> <span class="keyword">member</span> _.Database <span class="operator">=</span> Db.live connectionString</span><br><span class="line"> </span><br><span class="line">foo (AppEnv())</span><br></pre></td></tr></table></figure>
-
-<p>We cannot eagerly provide a specific implementation of <code>ILog</code>&#x2F;<code>IDb</code>, because they’re yet to be defined as part of by our environment type (which may need to implement many interfaces). To maintain module encapsulation <code>Log</code> module shouldn’t be aware of existence or implementation of <code>IDb</code> interface and vice versa for <code>Db</code> module. What we can do however is to provide <code>live</code> implementation of <code>ILogger</code>, which encapsulates capabilities required by the <code>Log</code> module. This way we don’t need to know details of <code>ILogger</code> when defining our environment type.</p>
+<p>We cannot eagerly provide a specific implementation of <code>ILog</code>/<code>IDb</code>, because they’re yet to be defined as part of by our environment type (which may need to implement many interfaces). To maintain module encapsulation <code>Log</code> module shouldn’t be aware of existence or implementation of <code>IDb</code> interface and vice versa for <code>Db</code> module. What we can do however is to provide <code>live</code> implementation of <code>ILogger</code>, which encapsulates capabilities required by the <code>Log</code> module. This way we don’t need to know details of <code>ILogger</code> when defining our environment type.</p>
<p>Strong sides of this approach?:</p>
<ul>
<li>We only need to provide a single environment object instead of (potentially) unbounded list of parameters. Since it’s always one, it’s easier to generalize and compose other functions over it.</li>
@@ -255,12 +251,12 @@
<li>It doesn’t impose specific restrictions on libraries and frameworks.</li>
</ul>
<p>Now we could as well stop here - IMHO this approach is already good and useful for most cases. We can also try to push it further. As you’ve seen, our code now requires quite a lot of <code>env</code> passing around. Could we do something about this? It turns out that yes, we could.</p>
-<h2 id="Reader-monad"><a href="#Reader-monad" class="headerlink" title="Reader monad"></a>Reader monad</h2><p>Before we continue: what we’re going to cover now is less useful in terms of current state of F# ecosystem for the reasons I’ll mention later.</p>
+<h2 id="Reader-monad"><a class="header-anchor" href="#Reader-monad">¶</a>Reader monad</h2>
+<p>Before we continue: what we’re going to cover now is less useful in terms of current state of F# ecosystem for the reasons I’ll mention later.</p>
<p>The pattern we’ll use here is known as a <a target="_blank" rel="noopener" href="https://fsharpforfunandprofit.com/posts/elevated-world-6/?ref=bartoszsypytkowski.com">Reader Monad</a>. While it’s useful in certain situations, it’s not widely used - IMO it’s fault lies in the name itself, which somehow managed to sound both borderline meaningless and scary in ears of many developers.</p>
<p>The rest of this blog post will be introduction to this style in F#, however focused solely around problem of dependency management - we’ll ignore other aspects of monads.</p>
-<p>We’ll going to reuse our environment type from above, but now encode it directly into another type we’ll call <code>Effect</code>. Since I’ve mentioned that our pattern has M-word in it, you can safely assume that our handler’s logic will be defined as a lazy sequence of steps to be executed (sounds almost like async&#x2F;await). In F# we’ll sugar them by using custom computation expression (I’m going to call it <code>effect &#123; ... &#125;</code>) returning our effect type, which we’ll define as:</p>
+<p>We’ll going to reuse our environment type from above, but now encode it directly into another type we’ll call <code>Effect</code>. Since I’ve mentioned that our pattern has M-word in it, you can safely assume that our handler’s logic will be defined as a lazy sequence of steps to be executed (sounds almost like async/await). In F# we’ll sugar them by using custom computation expression (I’m going to call it <code>effect &#123; ... &#125;</code>) returning our effect type, which we’ll define as:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Struct&gt;]</span> <span class="keyword">type</span> <span class="title class_">Effect</span><span class="operator">&lt;</span><span class="symbol">&#x27;env</span>, <span class="symbol">&#x27;out</span><span class="operator">&gt;</span> <span class="operator">=</span> Effect <span class="keyword">of</span> (<span class="symbol">&#x27;env</span> <span class="operator">-&gt;</span> <span class="symbol">&#x27;out</span>)</span><br></pre></td></tr></table></figure>
-
<p>Where:</p>
<ul>
<li><code>env</code> is our environment type we already talked about above.</li>
@@ -268,30 +264,25 @@
</ul>
<p>Eventually, with this type in hand our simple request handler will be looking like that:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> changePass req <span class="operator">=</span> <span class="keyword">effect</span> &#123;</span><br><span class="line"> <span class="keyword">let!</span> user <span class="operator">=</span> Db.fetchUser req.UserId</span><br><span class="line"> <span class="keyword">if</span> user.Hash <span class="operator">=</span> bcrypt user.Salt req.OldPass <span class="keyword">then</span></span><br><span class="line"> <span class="keyword">let!</span> salt <span class="operator">=</span> Random.bytes <span class="number">32</span></span><br><span class="line"> <span class="keyword">do!</span> Db.<span class="keyword">updateUser</span> &#123; user <span class="keyword">with</span> Salt <span class="operator">=</span> salt; Hash <span class="operator">=</span> bcrypt salt req.NewPass &#125;</span><br><span class="line"> <span class="keyword">do!</span> Log.info <span class="string">&quot;Changed password for user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Ok</span> ()</span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> <span class="keyword">do!</span> Log.error <span class="string">&quot;Password change unauthorized: user %i&quot;</span> user.Id</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">Error</span> <span class="string">&quot;Old password is invalid&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
-
<p>As you see, there’s no more <code>env</code> parameter being passed around. It’s now an implicit part of our effect expression. However at the moment we didn’t provide enough infrastructure in our code to make that thing work. What we’re going to need is a set of operators, we can use to make our computation expression happen.</p>
-<p>First we’re going to need some <code>Effect&lt;&#39;env,&#39;out&gt;</code> constructors:</p>
+<p>First we’re going to need some <code>Effect&lt;'env,'out&gt;</code> constructors:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Effect <span class="operator">=</span></span><br><span class="line"> <span class="comment">/// Create value with no dependency requirements.</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">inline</span> value (x<span class="operator">:</span> <span class="symbol">&#x27;out</span>)<span class="operator">:</span> Effect<span class="operator">&lt;</span><span class="symbol">&#x27;env</span>,<span class="symbol">&#x27;out</span><span class="operator">&gt;</span> <span class="operator">=</span> Effect (<span class="keyword">fun</span> _ <span class="operator">-&gt;</span> x)</span><br><span class="line"> <span class="comment">/// Create value which uses depenendency.</span></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">inline</span> apply (fn<span class="operator">:</span> <span class="symbol">&#x27;env</span> <span class="operator">-&gt;</span> <span class="symbol">&#x27;out</span>)<span class="operator">:</span> Effect<span class="operator">&lt;</span><span class="symbol">&#x27;env</span>,<span class="symbol">&#x27;out</span><span class="operator">&gt;</span> <span class="operator">=</span> Effect fn</span><br></pre></td></tr></table></figure>
-
<p>We also need some way to run our effect to be able to make it… well effectful:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Effect <span class="operator">=</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">(* ...other functions... *)</span></span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> run (env<span class="operator">:</span> <span class="symbol">&#x27;env</span>) (Effect fn)<span class="operator">:</span> <span class="symbol">&#x27;out</span> <span class="operator">=</span> fn env</span><br></pre></td></tr></table></figure>
-
<p>And since we already mentioned <code>Effect</code> is monad, we also gonna need a <code>bind</code> function as well if we want to compose our effects together:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Effect <span class="operator">=</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">(* ...other functions... *)</span></span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">inline</span> bind (fn<span class="operator">:</span> <span class="symbol">&#x27;a</span> <span class="operator">-&gt;</span> Effect<span class="operator">&lt;</span><span class="symbol">&#x27;env</span>,<span class="symbol">&#x27;b</span><span class="operator">&gt;</span>) effect <span class="operator">=</span></span><br><span class="line"> Effect (<span class="keyword">fun</span> env <span class="operator">-&gt;</span></span><br><span class="line"> <span class="keyword">let</span> x <span class="operator">=</span> run env effect <span class="comment">// compute result of the first effect</span></span><br><span class="line"> run env (fn x) <span class="comment">// run second effect, based on result of first one</span></span><br><span class="line"> )</span><br></pre></td></tr></table></figure>
-
<p>This is pretty much it. We’re just going to add compose all of these into builder type to make it usable as F# computation expression:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">[&lt;Struct&gt;]</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">EffectBuilder</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Return value <span class="operator">=</span> Effect.value value</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Zero () <span class="operator">=</span> Effect.value (Unchecked.defaultof<span class="operator">&lt;</span>_<span class="operator">&gt;</span>)</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.ReturnFrom (effect<span class="operator">:</span> Effect<span class="operator">&lt;</span><span class="symbol">&#x27;env</span>, <span class="symbol">&#x27;out</span><span class="operator">&gt;</span>) <span class="operator">=</span> effect</span><br><span class="line"> <span class="keyword">member</span> <span class="keyword">inline</span> __.Bind(effect, fn) <span class="operator">=</span> Effect.bind fn effect</span><br><span class="line"> </span><br><span class="line"><span class="keyword">let</span> effect <span class="operator">=</span> EffectBuilder()</span><br></pre></td></tr></table></figure>
-
<p>Of course this, we still need to adapt the modules we prepared earlier to now operate on effects rater than plain functions. We can make this easier by using our <code>Effect.apply</code> function, like:</p>
<figure class="highlight fsharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> Log <span class="operator">=</span> </span><br><span class="line"> <span class="keyword">let</span> debug fmt <span class="operator">=</span></span><br><span class="line"> <span class="keyword">let</span> ap s <span class="operator">=</span> Effect.apply (<span class="keyword">fun</span> (x<span class="operator">:</span> #ILog) <span class="operator">-&gt;</span> x.Logger.Debug s)</span><br><span class="line"> Printf.kprintf ap fmt</span><br></pre></td></tr></table></figure>
-
<p>So - as you may have noticed in final form of our effect-based <code>changePass</code> function - in result we almost fully erased all of the dependency-wiring code from our example. There are several downsides of this approach:</p>
<ul>
-<li>We do a lot of more bindings (see <code>let!</code>&#x2F;<code>do!</code> expressions), which means more lambda closures, indirection (wait to see call stacks) and more allocations.</li>
+<li>We do a lot of more bindings (see <code>let!</code>/<code>do!</code> expressions), which means more lambda closures, indirection (wait to see call stacks) and more allocations.</li>
<li>Altogether we also erased <code>task &#123; ... &#125;</code> computation expression and with it an out-of-the-box ability to write asynchronous code. This is one of the downsides of using monads - cross-type composition is painful.</li>
</ul>
-<p>Of course we could enrich our <code>Effect</code> type to be able to bind it with <code>Task</code>&#x2F;<code>Async</code>. That however means, that our pattern grows in complexity and becomes more of a framework rather than something to be easily applied into existing code. Is that bad? Not necessarily, but for sure comes with a bigger commitment, as now you’re not only writing business logic but eventually maintain new effect library. Maybe in future this concept will grow into its own space in favor of the F# ecosystem.</p>
-<h2 id="Summary"><a href="#Summary" class="headerlink" title="Summary"></a>Summary</h2><p>We came from partial application as tool for dependency injection, over more structured approach promoting single environment type with help of powerful F# type inference, up to encapsulating it into a Reader Monad. That’s a long way. I hope you’ll give it a try and it will help you determine the approach that works for you.</p>
+<p>Of course we could enrich our <code>Effect</code> type to be able to bind it with <code>Task</code>/<code>Async</code>. That however means, that our pattern grows in complexity and becomes more of a framework rather than something to be easily applied into existing code. Is that bad? Not necessarily, but for sure comes with a bigger commitment, as now you’re not only writing business logic but eventually maintain new effect library. Maybe in future this concept will grow into its own space in favor of the F# ecosystem.</p>
+<h2 id="Summary"><a class="header-anchor" href="#Summary">¶</a>Summary</h2>
+<p>We came from partial application as tool for dependency injection, over more structured approach promoting single environment type with help of powerful F# type inference, up to encapsulating it into a Reader Monad. That’s a long way. I hope you’ll give it a try and it will help you determine the approach that works for you.</p>
</div>
diff --git a/2024/11/15/西柚对药物的影响/index.html b/2024/11/15/西柚对药物的影响/index.html
index 9355886f..fe60b20c 100644
--- a/2024/11/15/西柚对药物的影响/index.html
+++ b/2024/11/15/西柚对药物的影响/index.html
@@ -198,7 +198,8 @@
</div>
</div>
<div class="post-content">
- <p>西柚,橙子之类中的呋喃香豆素会抑制肝脏中  CYP3A4 酶的活性,经肝脏代谢的药物,正常是肝脏中的酶在发挥作用,CYP3A4 酶就是其中一种,吃药的同时又吃了西柚相当于无形中增加了药物剂量,曾经有人吃硝苯地平的同时,喝了大概 500mL 的西柚汁,结果血压迅速下降导致了危险。<br>除此之外这种酶参与了现今使用近半数药物的代谢,总体来说,呋喃香豆素可以使药物以 2~10 倍的量进入血液,目前已知的,有超过 85 种药物会受到西柚的影响,但药物种类实在太多了,很难找到会受西柚影响的完整药物名单。最稳妥的方案还是吃药的时候别他妈吃西柚了</p>
+ <p>西柚,橙子之类中的呋喃香豆素会抑制肝脏中  CYP3A4 酶的活性,经肝脏代谢的药物,正常是肝脏中的酶在发挥作用,CYP3A4 酶就是其中一种,吃药的同时又吃了西柚相当于无形中增加了药物剂量,曾经有人吃硝苯地平的同时,喝了大概 500mL 的西柚汁,结果血压迅速下降导致了危险。<br>
+除此之外这种酶参与了现今使用近半数药物的代谢,总体来说,呋喃香豆素可以使药物以 2~10 倍的量进入血液,目前已知的,有超过 85 种药物会受到西柚的影响,但药物种类实在太多了,很难找到会受西柚影响的完整药物名单。最稳妥的方案还是吃药的时候别他妈吃西柚了</p>
</div>
diff --git a/2024/11/26/如何管理用户界面中的危险操作/index.html b/2024/11/26/如何管理用户界面中的危险操作/index.html
index 4048f462..d60f9de0 100644
--- a/2024/11/26/如何管理用户界面中的危险操作/index.html
+++ b/2024/11/26/如何管理用户界面中的危险操作/index.html
@@ -202,11 +202,13 @@
<p>“任何可能出错的事情都会出错。”我们的目标是防止出现问题,并在出现问题时减轻后果。</p>
</blockquote>
<p>界面是用户与系统通信的中介层,界面中的交互通常需要用户执行某些操作。不同的操作可能会导致不同的结果,其中可能有一些对于双方来说都非常重要甚至危险的操作。</p>
-<p>所以经常需要提供额外的保护措施来“保护”用户执行一些危险甚至无法恢复的操作。<br>这里的“保护”并不是完全的阻止,否则这个操作也没有存在的必要。</p>
+<p>所以经常需要提供额外的保护措施来“保护”用户执行一些危险甚至无法恢复的操作。<br>
+这里的“保护”并不是完全的阻止,否则这个操作也没有存在的必要。</p>
<blockquote>
<p>“良好的错误消息很重要,但最好的设计首先会小心地防止问题发生。要么消除容易出错的情况,要么检查它们并在用户承诺操作之前向他们提供确认选项。”</p>
</blockquote>
-<h2 id="什么是危险行为?"><a href="#什么是危险行为?" class="headerlink" title="什么是危险行为?"></a>什么是危险行为?</h2><p>危险行为并不意味着要删除某些内容,具体的危险行为应该由系统的“领域”来定义,例如:</p>
+<h2 id="什么是危险行为?"><a class="header-anchor" href="#什么是危险行为?">¶</a>什么是危险行为?</h2>
+<p>危险行为并不意味着要删除某些内容,具体的危险行为应该由系统的“领域”来定义,例如:</p>
<ul>
<li>进行金融交易</li>
<li>签署法律文件</li>
@@ -214,8 +216,10 @@
<li>授予某些用户权限</li>
<li>…</li>
</ul>
-<h2 id="确认危险行为的方法"><a href="#确认危险行为的方法" class="headerlink" title="确认危险行为的方法"></a>确认危险行为的方法</h2><p>最常用的一种方法是要求用户明确确认他们的操作,这种方法也有很多实现上的细节,但无论从什么角度实现都有优劣:</p>
-<h3 id="Modal-Dialog"><a href="#Modal-Dialog" class="headerlink" title="Modal Dialog"></a>Modal Dialog</h3><p>首先需要明确 Modal Dialog 和 Non-modal Dialog 的区别。</p>
+<h2 id="确认危险行为的方法"><a class="header-anchor" href="#确认危险行为的方法">¶</a>确认危险行为的方法</h2>
+<p>最常用的一种方法是要求用户明确确认他们的操作,这种方法也有很多实现上的细节,但无论从什么角度实现都有优劣:</p>
+<h3 id="Modal-Dialog"><a class="header-anchor" href="#Modal-Dialog">¶</a>Modal Dialog</h3>
+<p>首先需要明确 Modal Dialog 和 Non-modal Dialog 的区别。</p>
<blockquote>
<p>“Modal 是一种设计技术,它以一个独立的模式呈现内容,阻止用户与父视图交互,并需要明确的操作来退出。”</p>
</blockquote>
@@ -232,7 +236,8 @@
</ol>
<p>除此之外,还有更加严格的保护,例如在某些情况下,可以让用户输入某些内容来“解锁”操作,例如 Github 在删除仓库的时候需要输入仓库名称才能删除,这能让用户明确的知道自己在做什么,在删除哪个仓库。</p>
<p>最后,根据 <a target="_blank" rel="noopener" href="https://lawsofux.com/law-of-proximity/">临近法则</a> ,确认操作的按钮最好放在左侧。</p>
-<h4 id="Danger-Zone"><a href="#Danger-Zone" class="headerlink" title="Danger Zone"></a>Danger Zone</h4><p>对于关键的操作,可以使用 Danger Zone,常见的实现方式是将这一类关键的操作单独放在某一个页面的同一处,例如页面的底部。如果操作比较多,可以考虑使用一个单独的页面存放。</p>
+<h4 id="Danger-Zone"><a class="header-anchor" href="#Danger-Zone">¶</a>Danger Zone</h4>
+<p>对于关键的操作,可以使用 Danger Zone,常见的实现方式是将这一类关键的操作单独放在某一个页面的同一处,例如页面的底部。如果操作比较多,可以考虑使用一个单独的页面存放。</p>
<p>使用 Danger Zone 存放关键操作组件也有一些基本要素:</p>
<ol>
<li>使用红色或其他富含警示性颜色的警告图标或边框,在视觉上将 Danger Zone 与页面的其他部分区分开来。</li>
@@ -240,14 +245,16 @@
<li>对于一些非常关键且无法恢复的行为,可以要求用户进行额外的操作。例如要求用户重复输入密码或使用 2FA。</li>
<li>只存放真正关键的操作。避免为了拥有一个 Danger Zone 而搞出一个 Danger Zone。</li>
</ol>
-<h3 id="Inline-Guard"><a href="#Inline-Guard" class="headerlink" title="Inline Guard"></a>Inline Guard</h3><p>这个方法解释起来挺简单,可以用在一些零碎的页面元素中,例如有一个删除一条消息的按钮,可以在用户单击这个按钮之后将其变为红色背景并修改按钮字体为 “确认删除”,用户再次点击就确认删除了。这用来防止误点击非常有用。</p>
+<h3 id="Inline-Guard"><a class="header-anchor" href="#Inline-Guard">¶</a>Inline Guard</h3>
+<p>这个方法解释起来挺简单,可以用在一些零碎的页面元素中,例如有一个删除一条消息的按钮,可以在用户单击这个按钮之后将其变为红色背景并修改按钮字体为 “确认删除”,用户再次点击就确认删除了。这用来防止误点击非常有用。</p>
<p>但是也有一些细节需要注意:</p>
<ol>
<li>这种方法对于不那么危险的动作来说很方便,注意是“不那么危险”</li>
<li>一个“不那么危险”的操作应该可以恢复,所以应该提供一个选项来撤消操作或将已删除的项目放到回收站之类的地方,这是确保用户安全操作的良好组合。</li>
</ol>
<p>Inline Guard 不能滥用,当用户非常频繁的遇到时会烦死,得权衡一下。</p>
-<h3 id="其他方案"><a href="#其他方案" class="headerlink" title="其他方案"></a>其他方案</h3><p>还有一些方案这里简单说一下,一是 2FA,基本不用过多解释,二是双人验证甚至多人验证,就是用户发起的一个操作需要两个以上的人来验证才可以执行,例如 Github 的 Merge PR。</p>
+<h3 id="其他方案"><a class="header-anchor" href="#其他方案">¶</a>其他方案</h3>
+<p>还有一些方案这里简单说一下,一是 2FA,基本不用过多解释,二是双人验证甚至多人验证,就是用户发起的一个操作需要两个以上的人来验证才可以执行,例如 Github 的 Merge PR。</p>
<p>当系统要求用户进行一些额外的操作时,应该明确其最初的目的,因为:</p>
<ul>
<li>认知惯性:一个人倾向于近乎惯性地决定,即使这些决定不适合当前情况。例如,绝大多数人不阅读用户协议。他们只是同意冗长的文本,因为从法律角度来看这是必要的。(是的我就是这样)</li>
@@ -255,10 +262,13 @@
<li>人类倾向于以更简单、更省力的方式思考和解决问题,而不是更复杂、更省力的方式,无论智力如何。所以许多用户只是点击“是”或“同意”而没有仔细阅读文本。</li>
</ul>
<p>所以在某些情况下,我们可以用一些更加优雅的方法:</p>
-<h3 id="延迟"><a href="#延迟" class="headerlink" title="延迟"></a>延迟</h3><p>上面 Inline Guard 用在删除消息的场景下,也可以点击删除按钮直接删除,但同时显示一个倒计时的 Toast 并附带一个“撤销”的按钮来提醒用户。</p>
-<h2 id="撤销"><a href="#撤销" class="headerlink" title="撤销"></a>撤销</h2><p>允许用户撤消刚刚执行的操作,从而提供一个安全网来减少因犯错误而产生的焦虑。<br>与 Modal Dialog 这种中断系统并要求用户确认的模式不同,撤消允许完成操作后在需要时选择撤消操作,从而提供更流畅的体验。</p>
+<h3 id="延迟"><a class="header-anchor" href="#延迟">¶</a>延迟</h3>
+<p>上面 Inline Guard 用在删除消息的场景下,也可以点击删除按钮直接删除,但同时显示一个倒计时的 Toast 并附带一个“撤销”的按钮来提醒用户。</p>
+<h2 id="撤销"><a class="header-anchor" href="#撤销">¶</a>撤销</h2>
+<p>允许用户撤消刚刚执行的操作,从而提供一个安全网来减少因犯错误而产生的焦虑。<br>
+与 Modal Dialog 这种中断系统并要求用户确认的模式不同,撤消允许完成操作后在需要时选择撤消操作,从而提供更流畅的体验。</p>
<p>它非常适合非破坏性、不可恢复的操作以及不会产生重大和直接后果的操作。</p>
-<p>撤消选项与“软删除”的概念密切相关,“软删除” 的意思是:当用户通过 UI 删除某些内容时,_看起来它已被删除_,但在数据库中,我们保留数据但将其标记为已删除。数据不会丢失,这就是为什么可以使用撤消选项,因为我们实际上并没有删除任何内容,而是将其标记为已删除。</p>
+<p>撤消选项与“软删除”的概念密切相关,“软删除” 的意思是:当用户通过 UI 删除某些内容时,<em>看起来它已被删除</em>,但在数据库中,我们保留数据但将其标记为已删除。数据不会丢失,这就是为什么可以使用撤消选项,因为我们实际上并没有删除任何内容,而是将其标记为已删除。</p>
<p>晚安。</p>
</div>
diff --git a/2024/12/15/OCaml-News-2024-7/index.html b/2024/12/15/OCaml-News-2024-7/index.html
index a3391c9e..20623ee9 100644
--- a/2024/12/15/OCaml-News-2024-7/index.html
+++ b/2024/12/15/OCaml-News-2024-7/index.html
@@ -193,143 +193,198 @@
</div>
<div class="post-content">
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> ^o3</span><br><span class="line">~/\_/\_|)</span><br><span class="line">|/=_=\|</span><br><span class="line">&quot; &quot;</span><br><span class="line"></span><br><span class="line">^~~~~~~~~~~~这其实是用 ASCII 画的一个骆驼。</span><br></pre></td></tr></table></figure>
-
-<h3 id="语言的发展"><a href="#语言的发展" class="headerlink" title="语言的发展"></a>语言的发展</h3><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-5-2-1-released/15634">OCaml 5.2.1 released</a></p>
+<h3 id="语言的发展"><a class="header-anchor" href="#语言的发展">¶</a>语言的发展</h3>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-5-2-1-released/15634">OCaml 5.2.1 released</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/feedback-help-wanted-upcoming-ocaml-org-cookbook-feature/14127">Feedback &#x2F; Help Wanted: Upcoming OCaml.org Cookbook Feature</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/feedback-help-wanted-upcoming-ocaml-org-cookbook-feature/14127">Feedback / Help Wanted: Upcoming OCaml.org Cookbook Feature</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/second-beta-release-of-ocaml-5-3-0/15700">Second beta release of OCaml 5.3.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/second-beta-release-of-ocaml-5-3-0/15700">Second beta release of OCaml 5.3.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/terrateams-open-source-ocaml-repository/15645">Terrateam’s open source Ocaml repository</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/terrateams-open-source-ocaml-repository/15645">Terrateam’s open source Ocaml repository</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-mlx-syntax-dialect/15035">[ANN] .mlx syntax dialect</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-mlx-syntax-dialect/15035">[ANN] .mlx syntax dialect</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-opam-2-3-0-is-out/15609">[ANN] opam 2.3.0 is out!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-opam-2-3-0-is-out/15609">[ANN] opam 2.3.0 is out!</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://fun-ocaml.com/">Fun OCaml 2024 - Berlin - September 16+17, 2024</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//fun-ocaml.com/">Fun OCaml 2024 - Berlin - September 16+17, 2024</a></p>
</li>
-<li><p><strong><a href="https://link.zhihu.com/?target=https://www.youtube.com/@FUNOCaml">Fun OCaml is an open source hacking event dedicated to OCaml enthusiasts and professionals around the globe!</a></strong></p>
+<li>
+<p><strong><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/%40FUNOCaml">Fun OCaml is an open source hacking event dedicated to OCaml enthusiasts and professionals around the globe!</a></strong></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13526">Simplify the build of cross compilers by shym · Pull Request #13526 · ocaml&#x2F;ocaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13526">Simplify the build of cross compilers by shym · Pull Request #13526 · ocaml/ocaml</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13580">“Mark-delay” performance improvement to major GC by NickBarnes · Pull Request #13580 · ocaml&#x2F;ocaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13580">“Mark-delay” performance improvement to major GC by NickBarnes · Pull Request #13580 · ocaml/ocaml</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13416">Use WinAPI concurrency primitives on Windows ports (remove winpthreads) by MisterDA · Pull Request #13416 · ocaml&#x2F;ocaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13416">Use WinAPI concurrency primitives on Windows ports (remove winpthreads) by MisterDA · Pull Request #13416 · ocaml/ocaml</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13404">Atomic record fields by clef-men · Pull Request #13404 · ocaml&#x2F;ocaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml/ocaml/pull/13404">Atomic record fields by clef-men · Pull Request #13404 · ocaml/ocaml</a></p>
</li>
</ul>
-<h3 id="视频"><a href="#视频" class="headerlink" title="视频"></a>视频</h3><ul>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/playlist?list=PLP3MfTGqcNVJMFcWWDF6VSPJB7zuKN5yQ">All the talk recordings from FUN OCaml 2024 in Berlin, September 16 + 17, 2024.</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=wbrELQrzwQk">[ICFP24] Oxidizing OCaml with Modal Memory Management</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=7yYC6EGYg10">[OCaml24] Priodomainslib: Prioritized Fine-grained Parallelism for Multicore OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=KEkmcXVtFi0">[OCaml24] ChorCaml: Functional Choreographic Programming in OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=vanyv3ZEto8">[OCaml24] Saturn: a library of verified concurrent data structures for OCaml 5</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=mUzOBC3V0ds">Beyond the Basics of LSP: Advanced IDE services for OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=BUpRPSzkrH0">Why Terrateam chose OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=8zTN3rtcED4">A Crash Course in OCaml Modules • Tim McGilchrist • YOW! 2015</a></li>
-<li><a href="https://link.zhihu.com/?target=https://watch.ocaml.org/w/peT3MdWjS1BYYMbowEJ1gv">Outreachy May 2024 Demo</a></li>
-<li><a href="https://link.zhihu.com/?target=https://www.youtube.com/watch?v=JFZvnGD_hV8">Octane: A Query Builder for OCaml</a></li>
+<h3 id="视频"><a class="header-anchor" href="#视频">¶</a>视频</h3>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/playlist%3Flist%3DPLP3MfTGqcNVJMFcWWDF6VSPJB7zuKN5yQ">All the talk recordings from FUN OCaml 2024 in Berlin, September 16 + 17, 2024.</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DwbrELQrzwQk">[ICFP24] Oxidizing OCaml with Modal Memory Management</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3D7yYC6EGYg10">[OCaml24] Priodomainslib: Prioritized Fine-grained Parallelism for Multicore OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DKEkmcXVtFi0">[OCaml24] ChorCaml: Functional Choreographic Programming in OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3Dvanyv3ZEto8">[OCaml24] Saturn: a library of verified concurrent data structures for OCaml 5</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DmUzOBC3V0ds">Beyond the Basics of LSP: Advanced IDE services for OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DBUpRPSzkrH0">Why Terrateam chose OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3D8zTN3rtcED4">A Crash Course in OCaml Modules • Tim McGilchrist • YOW! 2015</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//watch.ocaml.org/w/peT3MdWjS1BYYMbowEJ1gv">Outreachy May 2024 Demo</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//www.youtube.com/watch%3Fv%3DJFZvnGD_hV8">Octane: A Query Builder for OCaml</a></li>
</ul>
-<h3 id="讨论"><a href="#讨论" class="headerlink" title="讨论"></a>讨论</h3><ul>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/what-are-the-biggest-reasons-newcomers-give-up-on-ocaml/10958">What are the biggest reasons newcomers give up on OCaml?</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/do-you-use-return-to-describe-a-function/15615">Do you use “return” to describe a function?</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocaml-cycle-detection-and-garbage-collector/15757">OCaml Cycle detection and Garbage Collector</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/modeling-rust-trait-objects-subtyping-relation-via-ocaml-polymorphic-variants/15644">Modeling Rust trait objects subtyping relation via OCaml polymorphic variants</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ocamldebug-using-dune/15595">Ocamldebug using dune</a></li>
-<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/typesafe-sql-with-octane-ml/15582">Typesafe SQL with Octane.ml</a></li>
+<h3 id="讨论"><a class="header-anchor" href="#讨论">¶</a>讨论</h3>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/what-are-the-biggest-reasons-newcomers-give-up-on-ocaml/10958">What are the biggest reasons newcomers give up on OCaml?</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/do-you-use-return-to-describe-a-function/15615">Do you use “return” to describe a function?</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocaml-cycle-detection-and-garbage-collector/15757">OCaml Cycle detection and Garbage Collector</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/modeling-rust-trait-objects-subtyping-relation-via-ocaml-polymorphic-variants/15644">Modeling Rust trait objects subtyping relation via OCaml polymorphic variants</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ocamldebug-using-dune/15595">Ocamldebug using dune</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/typesafe-sql-with-octane-ml/15582">Typesafe SQL with Octane.ml</a></li>
</ul>
-<h3 id="文章"><a href="#文章" class="headerlink" title="文章"></a>文章</h3><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/using-map-and-ppx-yojson/12524">Using Map and ppx yojson</a></p>
+<h3 id="文章"><a class="header-anchor" href="#文章">¶</a>文章</h3>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/using-map-and-ppx-yojson/12524">Using Map and ppx yojson</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/correct-syntax-to-add-compare-ppx/15764">Correct syntax to add compare ppx</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/correct-syntax-to-add-compare-ppx/15764">Correct syntax to add compare ppx</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/tiny-educational-concurrent-i-o-and-promises-library/15703">Tiny educational concurrent I&#x2F;O and promises library</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/tiny-educational-concurrent-i-o-and-promises-library/15703">Tiny educational concurrent I/O and promises library</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/good-example-of-handwritten-lexer-recursive-descent-parser/15672">Good example of handwritten Lexer + Recursive Descent Parser?</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/good-example-of-handwritten-lexer-recursive-descent-parser/15672">Good example of handwritten Lexer + Recursive Descent Parser?</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/new-part-pragmatic-category-theory-part-2-published/15056">[NEW PART] Pragmatic Category Theory: Part 2 published!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/new-part-pragmatic-category-theory-part-2-published/15056">[NEW PART] Pragmatic Category Theory: Part 2 published!</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://dev.to/chshersh/pragmatic-category-theory-part-1-semigroup-intro-1ign">Pragmatic Category Theory | Part 1: Semigroup Intro</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//dev.to/chshersh/pragmatic-category-theory-part-1-semigroup-intro-1ign">Pragmatic Category Theory | Part 1: Semigroup Intro</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://dev.to/chshersh/pragmatic-category-theory-part-2-composing-semigroups-87">Pragmatic Category Theory | Part 2: Composing Semigroups</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//dev.to/chshersh/pragmatic-category-theory-part-2-composing-semigroups-87">Pragmatic Category Theory | Part 2: Composing Semigroups</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/installing-ocaml-on-a-mac-m1-mini/15642">Installing OCaml on a mac m1 mini</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/installing-ocaml-on-a-mac-m1-mini/15642">Installing OCaml on a mac m1 mini</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/a-case-for-feminism-in-programming-language-design/15478">« A Case for Feminism in Programming Language Design »</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/a-case-for-feminism-in-programming-language-design/15478">« A Case for Feminism in Programming Language Design »</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://dl.acm.org/doi/pdf/10.1145/3689492.3689809">A Case for Feminism in Programming Language Design.pdf</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//dl.acm.org/doi/pdf/10.1145/3689492.3689809">A Case for Feminism in Programming Language Design.pdf</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://www.lexifi.com/blog/ocaml/decoders/">Vdom 0.3 brings Elm-style decoders to OCaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//www.lexifi.com/blog/ocaml/decoders/">Vdom 0.3 brings Elm-style decoders to OCaml</a></p>
</li>
</ul>
-<h3 id="生态"><a href="#生态" class="headerlink" title="生态"></a>生态</h3><ul>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/re2ocaml-regexp-compiler/15669">Re2ocaml regexp compiler</a></p>
+<h3 id="生态"><a class="header-anchor" href="#生态">¶</a>生态</h3>
+<ul>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/re2ocaml-regexp-compiler/15669">Re2ocaml regexp compiler</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/eliom-11-1-towards-web-assembly-support/15704">Eliom 11.1: Towards Web Assembly support</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/eliom-11-1-towards-web-assembly-support/15704">Eliom 11.1: Towards Web Assembly support</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-new-releases-of-merlin-and-ocaml-lsp/15752">[ANN] New releases of Merlin and OCaml-LSP</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-new-releases-of-merlin-and-ocaml-lsp/15752">[ANN] New releases of Merlin and OCaml-LSP</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/new-release-of-baby/15754">New release of baby</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/new-release-of-baby/15754">New release of baby</a></p>
</li>
-<li><p><code>baby</code>is an OCaml library that offers persistent sets and maps based on balanced binary search trees. It offers replacements for OCaml’s<code>Set</code>and<code>Map</code>modules.</p>
+<li>
+<p><code>baby</code>is an OCaml library that offers persistent sets and maps based on balanced binary search trees. It offers replacements for OCaml’s<code>Set</code>and<code>Map</code>modules.</p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dune-3-17/15770">[ANN] Dune 3.17</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-dune-3-17/15770">[ANN] Dune 3.17</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-jsont-0-1-0-declarative-json-data-manipulation-for-ocaml/15702">[ANN] Jsont 0.1.0 – Declarative JSON data manipulation for OCaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-jsont-0-1-0-declarative-json-data-manipulation-for-ocaml/15702">[ANN] Jsont 0.1.0 – Declarative JSON data manipulation for OCaml</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-release-of-saturn-1-0/15763">[ANN] Release of Saturn 1.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-release-of-saturn-1-0/15763">[ANN] Release of Saturn 1.0</a></p>
<ul>
<li>Saturn is a collection of concurrent-safe data structures designed for OCaml 5.</li>
</ul>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-areas-and-adversaries/15706/3">[ANN] Areas and Adversaries</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-areas-and-adversaries/15706/3">[ANN] Areas and Adversaries</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-release-of-cppo-1-8-0/15749">[ANN] Release of cppo 1.8.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-release-of-cppo-1-8-0/15749">[ANN] Release of cppo 1.8.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-capnp-rpc-2-0/15739">[ANN] capnp-rpc 2.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-capnp-rpc-2-0/15739">[ANN] capnp-rpc 2.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-advent-of-code-project-template/13539">[ANN] Advent of Code project template</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-advent-of-code-project-template/13539">[ANN] Advent of Code project template</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-testo-0-1-0-a-new-testing-framework-for-ocaml/15624">[ANN] Testo 0.1.0 - a new testing framework for OCaml</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-testo-0-1-0-a-new-testing-framework-for-ocaml/15624">[ANN] Testo 0.1.0 - a new testing framework for OCaml</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-vdom-0-3-functional-ui-applications-now-with-custom-event-handlers/13298">[ANN] vdom 0.3: functional UI applications now with custom event handlers</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-vdom-0-3-functional-ui-applications-now-with-custom-event-handlers/13298">[ANN] vdom 0.3: functional UI applications now with custom event handlers</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/visualizing-dependencies-between-ocaml-modules/15254">Visualizing dependencies between Ocaml modules</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/visualizing-dependencies-between-ocaml-modules/15254">Visualizing dependencies between Ocaml modules</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-mariadb-1-2-0/15709">[ANN] mariadb 1.2.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-mariadb-1-2-0/15709">[ANN] mariadb 1.2.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-new-release-of-monolith/15701">[ANN] New release of Monolith</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-new-release-of-monolith/15701">[ANN] New release of Monolith</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-first-release-of-hachis/15309">[ANN] First release of hachis</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-first-release-of-hachis/15309">[ANN] First release of hachis</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-liquidsoap-2-3-0/15677">[ANN] Liquidsoap 2.3.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-liquidsoap-2-3-0/15677">[ANN] Liquidsoap 2.3.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808/3">[ANN] dream-html &amp; pure-html 3.5.2</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808/3">[ANN] dream-html &amp; pure-html 3.5.2</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-js-of-ocaml-5-9-0/15674">[ANN] Js_of_ocaml 5.9.0</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-js-of-ocaml-5-9-0/15674">[ANN] Js_of_ocaml 5.9.0</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-ppx-deriving-ezjsonm/15637">[ANN] ppx_deriving_ezjsonm</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-ppx-deriving-ezjsonm/15637">[ANN] ppx_deriving_ezjsonm</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-smaws-preview-release-an-aws-sdk-for-ocaml-using-eio/15635">[ANN] smaws preview release, an AWS SDK for OCaml using eio</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-smaws-preview-release-an-aws-sdk-for-ocaml-using-eio/15635">[ANN] smaws preview release, an AWS SDK for OCaml using eio</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-aws-s3-4-0-1/2451">[ANN] aws-s3 4.0.1</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-aws-s3-4-0-1/2451">[ANN] aws-s3 4.0.1</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/first-release-of-cmdlang/15616">First release of cmdlang</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/first-release-of-cmdlang/15616">First release of cmdlang</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-eliom-11-and-ocsigen-start-7/15487">[ANN] Eliom 11 and Ocsigen Start 7</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-eliom-11-and-ocsigen-start-7/15487">[ANN] Eliom 11 and Ocsigen Start 7</a></p>
</li>
-<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-jane-street-ocaml-extensions-now-with-developer-tooling/15597">[ANN] Jane Street OCaml extensions – now with developer tooling!</a></p>
+<li>
+<p><a href="https://link.zhihu.com/?target=https%3A//discuss.ocaml.org/t/ann-jane-street-ocaml-extensions-now-with-developer-tooling/15597">[ANN] Jane Street OCaml extensions – now with developer tooling!</a></p>
</li>
</ul>
-<h3 id="亮点项目"><a href="#亮点项目" class="headerlink" title="亮点项目"></a>亮点项目</h3><ul>
-<li><a href="https://link.zhihu.com/?target=https://github.com/tjdevries/octane.ml">GitHub - tjdevries&#x2F;octane.ml: The fastest, hottest</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/semgrep/testo">Github - semgrep&#x2F;testo: Test framework for OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/sim642/odep">GitHub - sim642&#x2F;odep: Dependency graphs for OCaml modules, libraries and packages</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/LexiFi/ocaml-vdom">GitHub - LexiFi&#x2F;ocaml-vdom: Elm architecture and (V)DOM for OCaml</a></li>
-<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml-community/ocaml-mariadb">GitHub - ocaml-community&#x2F;ocaml-mariadb: OCaml bindings to MariaDB, supporting the nonblocking API</a></li>
-<li><a href="https://link.zhihu.com/?target=https://cambium.inria.fr/~fpottier/monolith/doc/monolith/Monolith/">Monolith (monolith.Monolith)</a>: Monolith offers facilities for testing an OCaml library by comparing its implementation (known as the candidate implementation) against a reference implementation.</li>
+<h3 id="亮点项目"><a class="header-anchor" href="#亮点项目">¶</a>亮点项目</h3>
+<ul>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/tjdevries/octane.ml">GitHub - tjdevries/octane.ml: The fastest, hottest</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/semgrep/testo">Github - semgrep/testo: Test framework for OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/sim642/odep">GitHub - sim642/odep: Dependency graphs for OCaml modules, libraries and packages</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/LexiFi/ocaml-vdom">GitHub - LexiFi/ocaml-vdom: Elm architecture and (V)DOM for OCaml</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//github.com/ocaml-community/ocaml-mariadb">GitHub - ocaml-community/ocaml-mariadb: OCaml bindings to MariaDB, supporting the nonblocking API</a></li>
+<li><a href="https://link.zhihu.com/?target=https%3A//cambium.inria.fr/~fpottier/monolith/doc/monolith/Monolith/">Monolith (monolith.Monolith)</a>: Monolith offers facilities for testing an OCaml library by comparing its implementation (known as the candidate implementation) against a reference implementation.</li>
</ul>
</div>
diff --git a/2024/12/18/二〇二四年十二月十八日/index.html b/2024/12/18/二〇二四年十二月十八日/index.html
index 1044a5fa..a6159f04 100644
--- a/2024/12/18/二〇二四年十二月十八日/index.html
+++ b/2024/12/18/二〇二四年十二月十八日/index.html
@@ -188,9 +188,14 @@
<p>城市中独自等公车时灰白的空气,手背上青紫的针眼,嘈杂人群中的巴宝莉香水味,和长椅上听着音乐的人,都不是我。</p>
<p>我是从土里长出来的,是从一方山林中长出来的。</p>
<p>我在长大后成为了那一方小世界的神明,只要进了那片山林,就知道太阳从哪个方向升起,就知道每一阵风的走向,就知道从眼前经过的每一个生命从何而来。</p>
-<p>我没有家,但是太阳升起的时候牵着老狗站在家人的坟包前,身后土地上的影子就是我的全家福。<br>​<br>在无声的融雪中泪流满面的大地,在白驹过隙的生命中,我瞥见了永恒。</p>
-<p>但我无法描述它,不能说,也不能想,却又不能忘。<br>它不能变成语言,它也无法变成语言,一旦变成语言就不再是它了。<br>它是一片朦胧的温馨与寂寥,是一片成熟的希望与绝望,它的领地只有心和我身后的坟包。</p>
-<p>北风似万鬼过境,<br>吹扤岭尾田堘。</p>
+<p>我没有家,但是太阳升起的时候牵着老狗站在家人的坟包前,身后土地上的影子就是我的全家福。<br>
+​<br>
+在无声的融雪中泪流满面的大地,在白驹过隙的生命中,我瞥见了永恒。</p>
+<p>但我无法描述它,不能说,也不能想,却又不能忘。<br>
+它不能变成语言,它也无法变成语言,一旦变成语言就不再是它了。<br>
+它是一片朦胧的温馨与寂寥,是一片成熟的希望与绝望,它的领地只有心和我身后的坟包。</p>
+<p>北风似万鬼过境,<br>
+吹扤岭尾田堘。</p>
</div>