diff options
| author | muqiuhan <[email protected]> | 2023-06-22 10:56:22 +0000 |
|---|---|---|
| committer | muqiuhan <[email protected]> | 2023-06-22 10:56:22 +0000 |
| commit | 6f776f55fea31dd12e5af18af519ac7d02dd7f4e (patch) | |
| tree | c72c4cb1c01777dd906172ce1f41d085ede5038e /2023 | |
| parent | e6158eb85d917cea33aef29a0d51f6ca19718790 (diff) | |
| download | blog-6f776f55fea31dd12e5af18af519ac7d02dd7f4e.tar.gz | |
deploy: 5065a383b04f53c3f276768fe2cad5da7f821452
Diffstat (limited to '2023')
| -rw-r--r-- | 2023/04/25/二零二三年四月二十五日/index.html | 2 | ||||
| -rw-r--r-- | 2023/04/29/OCaml_News_20230429/index.html | 255 | ||||
| -rw-r--r-- | 2023/05/06/OCaml_News_20230506/index.html | 264 | ||||
| -rw-r--r-- | 2023/05/09/OCaml_News_20230509/index.html | 284 | ||||
| -rw-r--r-- | 2023/05/15/OCaml_News_20230515/index.html | 263 | ||||
| -rw-r--r-- | 2023/05/21/OCaml_News_20230521/index.html | 320 | ||||
| -rw-r--r-- | 2023/05/31/OCaml_News_20230531/index.html | 279 | ||||
| -rw-r--r-- | 2023/06/10/二零二三年六月十日/index.html | 4 | ||||
| -rw-r--r-- | 2023/06/11/OCaml_News_20230611/index.html | 309 | ||||
| -rw-r--r-- | 2023/06/17/发热及超高热危象/index.html | 2 |
10 files changed, 4 insertions, 1978 deletions
diff --git a/2023/04/25/二零二三年四月二十五日/index.html b/2023/04/25/二零二三年四月二十五日/index.html index b13a0366..504de1cd 100644 --- a/2023/04/25/二零二三年四月二十五日/index.html +++ b/2023/04/25/二零二三年四月二十五日/index.html @@ -172,7 +172,7 @@ <div class="icon arrow-left"></div> <div class="post-link"> - <a href="/2023/04/29/OCaml_News_20230429/">Prev</a> + <a href="/2023/06/10/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AD%E6%9C%88%E5%8D%81%E6%97%A5/">Prev</a> </div> </div> diff --git a/2023/04/29/OCaml_News_20230429/index.html b/2023/04/29/OCaml_News_20230429/index.html deleted file mode 100644 index cb66a8ee..00000000 --- a/2023/04/29/OCaml_News_20230429/index.html +++ /dev/null @@ -1,255 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News Intro | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News Intro - - - </div> - <span class="post-date"> - Apr 29, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <p>这里是OCaml News,一个整合了OCaml社区以及周边生态最新信息的地方,先前一直在OCaml群内发送零散的信息,太细碎了,于是在此归纳整理,不过这一系列的更新频率是不规律的,并不遵循Weekly之类的频率,而是帖满即发。</p> -<p>总体上每一次更新分为三大类:</p> -<ol> -<li>论坛,即 <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/">discuss.ocaml.org</a> 上有趣的新帖子</li> -<li>生态,即OCaml本身或周边生态中中出现的新工具,库</li> -<li>文章,即OCaml相关的最新论文,博客文章</li> -</ol> -<p>所以:</p> -<hr> -<h1 id="???-二〇二三年四月二十九日"><a href="#???-二〇二三年四月二十九日" class="headerlink" title="??? - 二〇二三年四月二十九日"></a>??? - 二〇二三年四月二十九日</h1><h2 id="呼吁新的-opam-存储库维护者"><a href="#呼吁新的-opam-存储库维护者" class="headerlink" title="呼吁新的 opam 存储库维护者"></a>呼吁新的 opam 存储库维护者</h2><p><a target="_blank" rel="noopener" href="https://opam.ocaml.org/">OPAM</a>是OCaml的官方包管理器,它通过<a target="_blank" rel="noopener" href="https://github.com/ocaml/opam-repository">opam-repository</a>存储OCaml包,opam-repository由少数人力共同维护,以确保包的时效性、和高质量。OPAM的维护团队正在寻找新的贡献者来帮助他们维护opam-repository。</p> -<p>帮助维护opam-repository并不是OCaml或OPAM方面的专家才能参与。新加入的维护者将从审查和批准对repo的更改开始,经过几周的工作后,你可以决定留下来继续做这份工作,届时将被授予完全访问权限。</p> -<p>论坛原帖:<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/call-for-new-opam-repository-maintainers/12041">https://discuss.ocaml.org/t/call-for-new-opam-repository-maintainers/12041</a></p> -<h2 id="Local-Type-Definition"><a href="#Local-Type-Definition" class="headerlink" title="Local Type Definition"></a>Local Type Definition</h2><p>OCaml目前并不支持类似如下的Local Type Definition:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> f : <span class="built_in">unit</span> -> <span class="built_in">unit</span> = </span><br><span class="line"> <span class="keyword">fun</span> <span class="literal">()</span> -></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">type</span> t = <span class="type">A</span> | <span class="type">B</span> <span class="keyword">in</span></span><br><span class="line"> ...</span><br></pre></td></tr></table></figure> - -<p>但可以通过let open一个只有t的module来实现:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> f : <span class="built_in">unit</span> -> <span class="built_in">unit</span> = </span><br><span class="line"> <span class="keyword">fun</span> <span class="literal">()</span> -></span><br><span class="line"> <span class="keyword">let</span> <span class="keyword">open</span> <span class="keyword">struct</span> <span class="keyword">type</span> t = <span class="type">A</span> | <span class="type">B</span> <span class="keyword">end</span> <span class="keyword">in</span></span><br><span class="line"> ...</span><br></pre></td></tr></table></figure> - -<p>其实前者可以当作后者的糖,但目前还没实现,这是相关PR: <a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/pull/12151">Add local type definition syntax #12151</a></p> -<p>论坛原帖:<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/local-type-definition">https://discuss.ocaml.org/t/local-type-definition</a></p> -<h2 id="使用LablGtk3实现的七个GUI示例"><a href="#使用LablGtk3实现的七个GUI示例" class="headerlink" title="使用LablGtk3实现的七个GUI示例"></a>使用LablGtk3实现的七个GUI示例</h2><p>行业中存在各种各样不同语言的GUI工具包和各种各样不同的GUI开发方式。7GUIs代表GUI编程中典型的七项任务。</p> -<p>项目页面:<a target="_blank" rel="noopener" href="https://7guis.github.io/7guis/">https://7guis.github.io/7guis/</a><br>使用LablGtk3实现的7GUIs Github连接:<a target="_blank" rel="noopener" href="https://github.com/F-loyer/7guis-ocaml-lablgtk3">https://github.com/F-loyer/7guis-ocaml-lablgtk3</a></p> -<h2 id="使用Dream编写REST-API"><a href="#使用Dream编写REST-API" class="headerlink" title="使用Dream编写REST API"></a>使用Dream编写REST API</h2><p>这篇文章是使用Dream、Yojson和Caqti的经验之谈,这篇文章的重点不是做出价值判断(X框架好,Y框架不好之类的),而是理解如何将一个工作流程转换为另一个工作流程的概念.</p> -<p>文章连接:<a target="_blank" rel="noopener" href="https://jsthomas.github.io/ocaml-dream-api.html">https://jsthomas.github.io/ocaml-dream-api.html</a></p> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/05/06/OCaml_News_20230506/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/04/25/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%9B%9B%E6%9C%88%E4%BA%8C%E5%8D%81%E4%BA%94%E6%97%A5/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/05/06/OCaml_News_20230506/index.html b/2023/05/06/OCaml_News_20230506/index.html deleted file mode 100644 index eafd35fe..00000000 --- a/2023/05/06/OCaml_News_20230506/index.html +++ /dev/null @@ -1,264 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/5/6 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/5/6 - - - </div> - <span class="post-date"> - May 6, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年四月二十九日-二〇二三年五月六日"><a href="#二〇二三年四月二十九日-二〇二三年五月六日" class="headerlink" title="二〇二三年四月二十九日 - 二〇二三年五月六日"></a>二〇二三年四月二十九日 - 二〇二三年五月六日</h1><h2 id="Dune正在探索集成包管理,提供统一的开发体验"><a href="#Dune正在探索集成包管理,提供统一的开发体验" class="headerlink" title="Dune正在探索集成包管理,提供统一的开发体验"></a>Dune正在探索集成包管理,提供统一的开发体验</h2><p>dune, opam, opam-monorepo团队在几个月前联合起来,共同解决这个来自之前社区报告中的重要痛点。</p> -<p>在dune的github上有对于这项工作的详细解释:<a target="_blank" rel="noopener" href="https://github.com/ocaml/dune/issues/7680">https://github.com/ocaml/dune/issues/7680</a></p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101">https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101</a></p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101">论坛原帖:https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101</a></p> -<h2 id="OCaml-x2F-C-FFI对象的生命周期问题"><a href="#OCaml-x2F-C-FFI对象的生命周期问题" class="headerlink" title="OCaml/C FFI对象的生命周期问题"></a>OCaml/C FFI对象的生命周期问题</h2><p>OCaml manual中有一节名为<a target="_blank" rel="noopener" href="https://v2.ocaml.org/manual/intfc.html#s%3Ac-gc-harmony"><br>5 Living in harmony with the garbage collector</a>,其中介绍了六个规则,帮助编写C FFI。</p> -<p>对于如下C代码:</p> -<figure class="highlight c"><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">value <span class="title function_">pair</span><span class="params">(value a, value b)</span> {</span><br><span class="line"> CAMLparam2(a, b); <span class="comment">/*required*/</span></span><br><span class="line"> CAMLlocal1(r); <span class="comment">/*required*/</span></span><br><span class="line"> r = caml_alloc(<span class="number">2</span>,<span class="number">0</span>);</span><br><span class="line"> Store_field(r,<span class="number">0</span>,a);</span><br><span class="line"> Store_field(r,<span class="number">1</span>,b);</span><br><span class="line"> CAMLreturn(r); <span class="comment">/*required*/</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure> - -<p>这里的<code>CAMLlocal1(r)</code>并不是必须的,如果a和b是立即值,那么其他注释有<code>require</code>的代码。也不是必须的,对于这六个规则应该持保留态度,它们并不是必须严格遵守的,只是为了更安全。</p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-c-ffi-object-lifetimes/12099">论坛原帖:https://discuss.ocaml.org/t/ocaml-c-ffi-object-lifetimes/12099</a></p> -<h2 id="使用Elm-Style编写函数式Web应用"><a href="#使用Elm-Style编写函数式Web应用" class="headerlink" title="使用Elm Style编写函数式Web应用"></a>使用Elm Style编写函数式Web应用</h2><p>Fmlib 是一个函数式库,其中包含以下组件:</p> -<ul> -<li>Fmlib_std: 标准的数据结构(B树等)</li> -<li>Fmlib_pretty: Pretty Printing</li> -<li>Fmlib_parse: Parsing</li> -<li>Fmlib_browser: Web应用程序</li> -<li>Fmlib_js: 与浏览器/Nodejs交互</li> -</ul> -<p>github仓库:<a target="_blank" rel="noopener" href="https://github.com/hbr/fmlib">https://github.com/hbr/fmlib</a></p> -<p>一些简单的示例:<a target="_blank" rel="noopener" href="https://hbr.github.io/fmlib/webapp/index.html">https://hbr.github.io/fmlib/webapp/index.html</a></p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-functional-web-applications-running-in-the-browser/11984">论坛原帖:https://discuss.ocaml.org/t/ann-functional-web-applications-running-in-the-browser/11984</a></p> -<h2 id="使用OCaml编写NeoVIM插件"><a href="#使用OCaml编写NeoVIM插件" class="headerlink" title="使用OCaml编写NeoVIM插件"></a>使用OCaml编写NeoVIM插件</h2><p>VCaml是一个用于在 OCaml 中编写 Neovim 插件的库。</p> -<p>github仓库: <a target="_blank" rel="noopener" href="https://github.com/janestreet/vcaml">https://github.com/janestreet/vcaml</a></p> -<p>论坛上相关的讨论: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/repo-for-nvim-plugins-in-ocaml-neovim-vcaml/12049">https://discuss.ocaml.org/t/repo-for-nvim-plugins-in-ocaml-neovim-vcaml/12049</a></p> -<h2 id="Format和PPrint在实践中的对比"><a href="#Format和PPrint在实践中的对比" class="headerlink" title="Format和PPrint在实践中的对比"></a>Format和PPrint在实践中的对比</h2><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/format-vs-pprint-in-practice/12087">论坛原帖: https://discuss.ocaml.org/t/format-vs-pprint-in-practice/12087</a></p> -<h2 id="BLAS-x2F-LAPACK的OCaml-Binding"><a href="#BLAS-x2F-LAPACK的OCaml-Binding" class="headerlink" title="BLAS/LAPACK的OCaml Binding"></a>BLAS/LAPACK的OCaml Binding</h2><p>这个 OCaml 库绑定了两个广泛使用的数学 FORTRAN 库:</p> -<ul> -<li>BLAS : <a href="www.netlib.org/blas/">www.netlib.org/blas/</a></li> -<li>LAPAK : <a href="www.netlib.org/lapack/">www.netlib.org/lapack/</a></li> -</ul> -<p>Github仓库:<a target="_blank" rel="noopener" href="https://github.com/mmottl/lacaml">https://github.com/mmottl/lacaml</a></p> -<h2 id="基于Effects的实验性WebServer"><a href="#基于Effects的实验性WebServer" class="headerlink" title="基于Effects的实验性WebServer"></a>基于Effects的实验性WebServer</h2><p>Github仓库: <a target="_blank" rel="noopener" href="https://github.com/avsm/eeww">https://github.com/avsm/eeww</a></p> -<h2 id="纯(?)函数式SSH库"><a href="#纯(?)函数式SSH库" class="headerlink" title="纯(?)函数式SSH库"></a>纯(?)函数式SSH库</h2><p>awa-ssh是一个使用ISC协议开源的OCaml SSH库<br>Github仓库:<a target="_blank" rel="noopener" href="https://github.com/mirage/awa-ssh">https://github.com/mirage/awa-ssh</a></p> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/05/09/OCaml_News_20230509/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/04/29/OCaml_News_20230429/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/05/09/OCaml_News_20230509/index.html b/2023/05/09/OCaml_News_20230509/index.html deleted file mode 100644 index ec61d448..00000000 --- a/2023/05/09/OCaml_News_20230509/index.html +++ /dev/null @@ -1,284 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/5/9 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/5/9 - - - </div> - <span class="post-date"> - May 9, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年五月六日-二〇二三年五月九日"><a href="#二〇二三年五月六日-二〇二三年五月九日" class="headerlink" title="二〇二三年五月六日 - 二〇二三年五月九日"></a>二〇二三年五月六日 - 二〇二三年五月九日</h1><h2 id="在Eio中不使用Unix和Sys模块实现所有I-x2F-O和文件系统操作?"><a href="#在Eio中不使用Unix和Sys模块实现所有I-x2F-O和文件系统操作?" class="headerlink" title="在Eio中不使用Unix和Sys模块实现所有I/O和文件系统操作?"></a>在Eio中不使用Unix和Sys模块实现所有I/O和文件系统操作?</h2><blockquote> -<p>EIO: <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/eio">Effects-based direct-style IO for multicore OCaml</a></p> -</blockquote> -<p>例如<code>Sys.is_directory</code>, <code>Sys.file_exists</code>,<code>Sys.is_regular_file</code>这些函数在Eio中并没有相关的实现, 因为Eio目前还缺少很多文件操作的实现: <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/eio/issues/510">Add missing file operations #510</a>。</p> -<p>但退一步,如果需要,可以用 <code>Eio_unix.run_in_systhread</code>来运行Unix的相关操作从而不阻塞Eio线程。</p> -<p>关于执行外部命令, 例如<code>Sys.command</code>或<code>Unix.create_process</code>函数, 在Eio中可以通过<code>Eio.Process</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></pre></td><td class="code"><pre><span class="line"># <span class="type">Eio_main</span>.run @@ <span class="keyword">fun</span> env -></span><br><span class="line"> <span class="keyword">let</span> proc_mgr = <span class="type">Eio</span>.<span class="type">Stdenv</span>.process_mgr env <span class="keyword">in</span></span><br><span class="line"> <span class="type">Eio</span>.<span class="type">Process</span>.run proc_mgr [<span class="string">"echo"</span>; <span class="string">"hello"</span>];;</span><br><span class="line">hello</span><br><span class="line">- : <span class="built_in">unit</span> = <span class="literal">()</span></span><br></pre></td></tr></table></figure> - -<p>相关文档: <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/eio#running-processes">https://github.com/ocaml-multicore/eio#running-processes</a></p> -<p>论坛原帖:<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/what-are-equivalent-to-some-sys-functions-in-eio-and-other-eio-questions/12126">https://discuss.ocaml.org/t/what-are-equivalent-to-some-sys-functions-in-eio-and-other-eio-questions/12126</a></p> -<h2 id="为一个现有的Dune项目生成最小的mli文件"><a href="#为一个现有的Dune项目生成最小的mli文件" class="headerlink" title="为一个现有的Dune项目生成最小的mli文件"></a>为一个现有的Dune项目生成最小的mli文件</h2><blockquote> -<p>Reanalyze: <a target="_blank" rel="noopener" href="https://github.com/rescript-association/reanalyze">Experimental analyses for ReScript and OCaml: globally dead values/types, exception analysis, and termination analysis.</a></p> -</blockquote> -<p>reanalyze可以分析项目中的dead code, 它并不能直接实现这个需求, 但可能可以利用这些信息对实施相关分析提供一个良好的起点。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-to-create-the-minimal-mli-files-using-dune/12115">https://discuss.ocaml.org/t/how-to-create-the-minimal-mli-files-using-dune/12115</a></p> -<h2 id="自动派生枚举转换函数"><a href="#自动派生枚举转换函数" class="headerlink" title="自动派生枚举转换函数"></a>自动派生枚举转换函数</h2><p>主要想实现的是自动生成如下代码中的 <code>_foo</code> 和 <code>_bar</code> 函数。 也就是将具有无参数constructors的variant视为enum,并为每个constructor映射一个整数值:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> my_enum = <span class="type">A</span> | <span class="type">B</span> | <span class="type">C</span> | <span class="type">D</span> | <span class="type">E</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> _foo (x : my_enum) : <span class="built_in">int</span> =</span><br><span class="line"> <span class="keyword">match</span> x <span class="keyword">with</span></span><br><span class="line"> | <span class="type">A</span> -> <span class="number">0</span></span><br><span class="line"> | <span class="type">B</span> -> <span class="number">1</span></span><br><span class="line"> | <span class="type">C</span> -> <span class="number">2</span></span><br><span class="line"> | <span class="type">D</span> -> <span class="number">3</span></span><br><span class="line"> | <span class="type">E</span> -> <span class="number">4</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> _bar (n : <span class="built_in">int</span>) : my_enum =</span><br><span class="line"> <span class="keyword">match</span> n <span class="keyword">with</span></span><br><span class="line"> | <span class="number">0</span> -> <span class="type">A</span></span><br><span class="line"> | <span class="number">1</span> -> <span class="type">B</span></span><br><span class="line"> | <span class="number">2</span> -> <span class="type">C</span></span><br><span class="line"> | <span class="number">3</span> -> <span class="type">D</span></span><br><span class="line"> | <span class="number">4</span> -> <span class="type">E</span></span><br><span class="line"> | _ -> failwith <span class="string">"not handled"</span></span><br></pre></td></tr></table></figure> - -<p><code>ppx_deriving</code>有enum deriver, 可以实现,例如</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></pre></td><td class="code"><pre><span class="line"># <span class="keyword">type</span> insn = <span class="type">Const</span> | <span class="type">Push</span> | <span class="type">Pop</span> | <span class="type">Add</span> [@@deriving enum];;</span><br><span class="line"><span class="keyword">type</span> insn = <span class="type">Const</span> | <span class="type">Push</span> | <span class="type">Pop</span> | <span class="type">Add</span></span><br><span class="line"><span class="keyword">val</span> insn_to_enum : insn -> <span class="built_in">int</span> = <<span class="keyword">fun</span>></span><br><span class="line"><span class="keyword">val</span> insn_of_enum : <span class="built_in">int</span> -> insn option = <<span class="keyword">fun</span>></span><br><span class="line"><span class="keyword">val</span> min_insn : <span class="built_in">int</span> = <span class="number">0</span></span><br><span class="line"><span class="keyword">val</span> max_insn : <span class="built_in">int</span> = <span class="number">3</span></span><br><span class="line"># insn_to_enum <span class="type">Pop</span>;;</span><br><span class="line">- : <span class="built_in">int</span> = <span class="number">2</span></span><br><span class="line"># insn_of_enum <span class="number">3</span>;;</span><br><span class="line">- : insn option = <span class="type">Some</span> <span class="type">Add</span></span><br></pre></td></tr></table></figure> - -<p>相关文档: <a target="_blank" rel="noopener" href="https://github.com/ocaml-ppx/ppx_deriving#plugin-enum">https://github.com/ocaml-ppx/ppx_deriving#plugin-enum</a></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/auto-derive-enum-conversions/12119">https://discuss.ocaml.org/t/auto-derive-enum-conversions/12119</a></p> -<h2 id="在Linux上编译OCaml程序,-在FreeBSD上跑"><a href="#在Linux上编译OCaml程序,-在FreeBSD上跑" class="headerlink" title="在Linux上编译OCaml程序, 在FreeBSD上跑"></a>在Linux上编译OCaml程序, 在FreeBSD上跑</h2><blockquote> -<p>以Linux和FreeBSD都在x86-64架构上运行为例</p> -</blockquote> -<p>如果程序是纯OCaml(没有C bindings之类的),那么只要目标系统中有OCaml解释器(ocamlrun), ocamlc生成的字节码就可以运行, 如果不是的话…</p> -<p>从Linux x86-64到FreeBSD x86-64从表面上看似乎没有太大的困难。 如果知道怎么配置Linux到FreeBSD的交叉编译器(最好使用clang和FreeBSD sysroot),并且愿意维护交叉编译器,<br>可以联系<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/u/jbeckford">jbeckford</a>,他愿意合作将其添加到<code>dkml-base-compiler.4.14.x</code>中。</p> -<p>相关阅读: <a target="_blank" rel="noopener" href="https://docs.freebsd.org/en/books/handbook/linuxemu/">Linux的二进制兼容性</a></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-to-compile-ocaml-program-on-linux-for-running-on-freebsd/12110">https://discuss.ocaml.org/t/how-to-compile-ocaml-program-on-linux-for-running-on-freebsd/12110</a></p> -<h2 id="OCaml的速度竞赛"><a href="#OCaml的速度竞赛" class="headerlink" title="OCaml的速度竞赛"></a>OCaml的速度竞赛</h2><blockquote> -<p>speed-comparison: <a target="_blank" rel="noopener" href="https://github.com/niklas-heer/speed-comparison">A repo which compares the speed of different programming languages</a></p> -</blockquote> -<p>这里用OCaml实现了莱布尼茨算法用于计算圆周率:</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></pre></td><td class="code"><pre><span class="line"><span class="comment">(* ocamlopt -O2 -o leibniz leibniz.ml && strip leibniz *)</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">rec</span> calc sum curr upto =</span><br><span class="line"> <span class="keyword">if</span> curr >= upto <span class="keyword">then</span> sum</span><br><span class="line"> <span class="keyword">else</span> calc (sum +. <span class="number">1.</span> /. float_of_int curr) (curr + <span class="number">4</span>) upto</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> calc rounds =</span><br><span class="line"> <span class="keyword">let</span> double = rounds * <span class="number">2</span> <span class="keyword">in</span></span><br><span class="line"> calc <span class="number">0.</span> (<span class="number">1</span> - double) (double + <span class="number">1</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> rounds_txt = open_in_bin <span class="string">"rounds.txt"</span> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> rounds = int_of_string (input_line rounds_txt) <span class="keyword">in</span></span><br><span class="line"> close_in rounds_txt;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> pi = <span class="number">4.</span> *. calc rounds <span class="keyword">in</span></span><br><span class="line"> <span class="type">Printf</span>.printf <span class="string">"%.16f\n"</span> pi</span><br></pre></td></tr></table></figure> - -<p>但性能:</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></pre></td><td class="code"><pre><span class="line">$ time ./leibniz</span><br><span class="line"><span class="number">3.1415926435899633</span></span><br><span class="line">./leibniz <span class="number">0.38</span>s user <span class="number">0.00</span>s system <span class="number">99</span>% cpu <span class="number">0.388</span> total</span><br></pre></td></tr></table></figure> - -<p>比Go版本:</p> -<figure class="highlight golang"><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 ./leibniz_go</span><br><span class="line"><span class="number">3.141592663589326</span></span><br><span class="line">./leibniz_go <span class="number">0.13</span>s user <span class="number">0.01</span>s system <span class="number">95</span>% cpu <span class="number">0.142</span> total</span><br></pre></td></tr></table></figure> - -<p>慢了很多, 这是因为从生成的<a target="_blank" rel="noopener" href="https://godbolt.org/z/xWrTxa3ov">汇编代码</a>来看, OCaml编译器无法在递归调用中unbox浮点数用于返回值。而命令式版本:</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">let</span> calc rounds =</span><br><span class="line"> <span class="keyword">let</span> sum = <span class="built_in">ref</span> <span class="number">0.</span> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> curr = <span class="built_in">ref</span> (<span class="number">1</span> - rounds * <span class="number">2</span>) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">for</span> _ = <span class="number">0</span> <span class="keyword">to</span> rounds - <span class="number">1</span> <span class="keyword">do</span></span><br><span class="line"> sum := !sum +. <span class="number">1.</span> /. float_of_int !curr;</span><br><span class="line"> curr := !curr + <span class="number">4</span>;</span><br><span class="line"> <span class="keyword">done</span>;</span><br><span class="line"> !sum</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> rounds_txt = open_in_bin <span class="string">"rounds.txt"</span> <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> rounds = int_of_string (input_line rounds_txt) <span class="keyword">in</span></span><br><span class="line"> close_in rounds_txt;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> pi = <span class="number">4.</span> *. calc rounds <span class="keyword">in</span></span><br><span class="line"> <span class="type">Printf</span>.printf <span class="string">"%.16f\n"</span> pi</span><br></pre></td></tr></table></figure> -<p>的性能将会好得多(<a target="_blank" rel="noopener" href="https://godbolt.org/z/sW46nh1GK">对应的汇编</a>)</p> -<p>所以为了使数字运算的OCaml代码运行得更快,应该避免递归调用(这会抑制unbox浮点值)。</p> -<p>论坛原帖:<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-speed-comparison-calculating-pi-with-leibniz-optimize/12112">https://discuss.ocaml.org/t/ocaml-speed-comparison-calculating-pi-with-leibniz-optimize/12112</a></p> -<hr> -<h2 id="一些库"><a href="#一些库" class="headerlink" title="一些库"></a>一些库</h2><ul> -<li>OCaml PPX deriver for reflection : <a target="_blank" rel="noopener" href="https://github.com/thierry-martinez/refl">https://github.com/thierry-martinez/refl</a></li> -<li>LexiFi runtime types : <a target="_blank" rel="noopener" href="https://github.com/LexiFi/lrt">https://github.com/LexiFi/lrt</a></li> -<li>Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType : <a target="_blank" rel="noopener" href="https://github.com/rescript-association/genType">https://github.com/rescript-association/genType</a></li> -</ul> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/05/15/OCaml_News_20230515/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/05/06/OCaml_News_20230506/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/05/15/OCaml_News_20230515/index.html b/2023/05/15/OCaml_News_20230515/index.html deleted file mode 100644 index dd363e54..00000000 --- a/2023/05/15/OCaml_News_20230515/index.html +++ /dev/null @@ -1,263 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/5/15 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/5/15 - - - </div> - <span class="post-date"> - May 15, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年五月九日-二〇二三年五月十五日"><a href="#二〇二三年五月九日-二〇二三年五月十五日" class="headerlink" title="二〇二三年五月九日 - 二〇二三年五月十五日"></a>二〇二三年五月九日 - 二〇二三年五月十五日</h1><h2 id="关于OCaml最新的并行特性相关文档"><a href="#关于OCaml最新的并行特性相关文档" class="headerlink" title="关于OCaml最新的并行特性相关文档"></a>关于OCaml最新的并行特性相关文档</h2><ol> -<li>Eio的README有很多例子: <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/eio">https://github.com/ocaml-multicore/eio</a></li> -<li>ocaml-multicore组织官方的教程仓库: <a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/parallel-programming-in-multicore-ocaml">https://github.com/ocaml-multicore/parallel-programming-in-multicore-ocaml</a></li> -<li>OCaml的Manual: <a target="_blank" rel="noopener" href="https://v2.ocaml.org/releases/5.0/htmlman/parallelism.html">https://v2.ocaml.org/releases/5.0/htmlman/parallelism.html</a></li> -</ol> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/new-concurrency-features/12158">https://discuss.ocaml.org/t/new-concurrency-features/12158</a></p> -<h2 id="使用OCaml通过串口与STM32通信"><a href="#使用OCaml通过串口与STM32通信" class="headerlink" title="使用OCaml通过串口与STM32通信"></a>使用OCaml通过串口与STM32通信</h2><p>在Linux/Unix上可以:</p> -<ul> -<li>适用于linux/unix的oserial: <a target="_blank" rel="noopener" href="https://github.com/m-laniakea/oserial">https://github.com/m-laniakea/oserial</a></li> -<li>直接打开 <code>/dev/XXX</code> 文件用Unix模块相关的API与其交互, 一个例子: <a target="_blank" rel="noopener" href="https://gist.github.com/dbuenzli/035bc5c8598069360dd7301f55e7774a">https://gist.github.com/dbuenzli/035bc5c8598069360dd7301f55e7774a</a></li> -</ul> -<p>Windows目前没有解决方案。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/is-there-any-library-of-ocaml-to-use-serial-port-of-pc/3658">https://discuss.ocaml.org/t/is-there-any-library-of-ocaml-to-use-serial-port-of-pc/3658</a></p> -<h2 id="使用OCaml构建IOS-APP"><a href="#使用OCaml构建IOS-APP" class="headerlink" title="使用OCaml构建IOS APP"></a>使用OCaml构建IOS APP</h2><ul> -<li>通过Js_of_ocaml编译为JavaScript并使用像CapacitorJS(甚至是旧的Cordova)这样的框架或许是一条路子。</li> -<li><a target="_blank" rel="noopener" href="http://psellos.com/aboutus.html">Psellos</a>是一个注重现代函数式语言(OCaml, F#, Haskell)的组织,它们维护了一个将OCaml编译到IOS的交叉编译器: <a target="_blank" rel="noopener" href="http://psellos.com/ocaml/compile-to-iphone.html">http://psellos.com/ocaml/compile-to-iphone.html</a></li> -<li>ocaml-cocoa的demo: <a target="_blank" rel="noopener" href="https://github.com/dboris/ocaml-cocoa/blob/master/examples/count_clicks.ml">https://github.com/dboris/ocaml-cocoa/blob/master/examples/count_clicks.ml</a></li> -</ul> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/building-ios-apps-with-ocaml/12153">https://discuss.ocaml.org/t/building-ios-apps-with-ocaml/12153</a></p> -<h2 id="Ahref现在使用Melange构建"><a href="#Ahref现在使用Melange构建" class="headerlink" title="Ahref现在使用Melange构建"></a>Ahref现在使用Melange构建</h2><p><a href="">Melange</a>是结合使用 OCaml 和 Reason 生成 JavaScript 的工具组合。<br><a target="_blank" rel="noopener" href="https://ahrefs.com/">Ahrefs</a>是一个SEO软件套装,包含外链建设、关键字研究、竞争对手分析,排名跟踪和站点审核等工具。Ahrefs内部的大多数功能都是为营销专业人员设计的。</p> -<p>自去年 9 月以来,Melange、Dune 和 Ahrefs 开发团队一直致力于加强 Dune 和 Melange 之间的集成。作为一家在后端使用大量 OCaml 的公司,Ahrefs看到了Melange可以将其前端技术栈与OCaml更紧密结合(通过使用Melange与UI相关的JavaScript生态系统集成)。因此,该公司决定投资并积极参与以实现这种整合。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ahrefs-is-now-built-with-melange/12107">https://discuss.ocaml.org/t/ahrefs-is-now-built-with-melange/12107</a></p> -<h2 id="Ahref正在招聘OCaml开发人员"><a href="#Ahref正在招聘OCaml开发人员" class="headerlink" title="Ahref正在招聘OCaml开发人员"></a>Ahref正在招聘OCaml开发人员</h2><p>一如既往,Ahrefs正在寻找OCaml开发人员,他们总部位于新加坡,团队遍布各地,所以也支持远程,详见:<br><a target="_blank" rel="noopener" href="https://ahrefs.com/jobs/ocaml-developer">https://ahrefs.com/jobs/ocaml-developer</a></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ahrefs-is-hiring/12136">https://discuss.ocaml.org/t/ahrefs-is-hiring/12136</a></p> -<h2 id="string-literals-inside-comments-5745"><a href="#string-literals-inside-comments-5745" class="headerlink" title="string literals inside comments #5745"></a>string literals inside comments #5745</h2><p>草,OCaml的parser不会忽略注释中的引号:</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">$ echo '(* "test *)' | ocaml </span><br><span class="line">OCaml version 5.0.0</span><br><span class="line">Enter #help;; for help.</span><br><span class="line"></span><br><span class="line"># (* "test *)tive `utop_prompt_fancy_light'.</span><br><span class="line"># * </span><br><span class="line">Error: This comment contains an unterminated string literal</span><br><span class="line">Line 1, characters 3-4: String literal begins here</span><br><span class="line"># </span><br></pre></td></tr></table></figure> - -<p>而经过讨论认为修复这个问题是向后不兼容的,所以修复这个词法分析器错误的风险似乎大于好处,就给close了。</p> -<p>相关issue: <a target="_blank" rel="noopener" href="https://github.com/ocaml/ocaml/issues/5745">https://github.com/ocaml/ocaml/issues/5745</a></p> -<p>有趣的是F#也继承了这个问题:</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></pre></td><td class="code"><pre><span class="line">$ echo '(* "test *)' | dotnet fsi</span><br><span class="line"></span><br><span class="line">Microsoft (R) F# Interactive version 12.5.0.0 for F# 7.0</span><br><span class="line">Copyright (c) Microsoft Corporation. All Rights Reserved.</span><br><span class="line"></span><br><span class="line">For help type #help;;</span><br><span class="line"></span><br><span class="line">> </span><br><span class="line"> (* "test *)</span><br><span class="line"> ^^</span><br><span class="line"></span><br><span class="line">/home/muqiu-han/stdin(1,1): error FS0517: End of file in string embedded in comment begun at or before here</span><br></pre></td></tr></table></figure> - - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/05/21/OCaml_News_20230521/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/05/09/OCaml_News_20230509/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/05/21/OCaml_News_20230521/index.html b/2023/05/21/OCaml_News_20230521/index.html deleted file mode 100644 index 263db05f..00000000 --- a/2023/05/21/OCaml_News_20230521/index.html +++ /dev/null @@ -1,320 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/5/21 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/5/21 - - - </div> - <span class="post-date"> - May 21, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年五月十五日-二〇二三年五月二十一日"><a href="#二〇二三年五月十五日-二〇二三年五月二十一日" class="headerlink" title="二〇二三年五月十五日 - 二〇二三年五月二十一日"></a>二〇二三年五月十五日 - 二〇二三年五月二十一日</h1><h2 id="Fmlib-browser-0-5-4"><a href="#Fmlib-browser-0-5-4" class="headerlink" title="Fmlib_browser 0.5.4"></a>Fmlib_browser 0.5.4</h2><p>之前介绍过的<a target="_blank" rel="noopener" href="https://github.com/hbr/fmlib">Fmlib: Ocaml函数式Monadic库</a>更新了其中的 <a target="_blank" rel="noopener" href="https://hbr.github.io/fmlib/odoc/fmlib_browser/">Fmlib_browser</a>模块, Fmlib_browser可以帮助用Elm-Style开发纯函数式风格的Web App。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-release-0-5-4-of-fmlib-browser/12184">https://discuss.ocaml.org/t/ann-release-0-5-4-of-fmlib-browser/12184</a></p> -<h2 id="测试一下OCaml的FFI"><a href="#测试一下OCaml的FFI" class="headerlink" title="测试一下OCaml的FFI"></a>测试一下OCaml的FFI</h2><p>以 《<a target="_blank" rel="noopener" href="https://lemire.me/blog/2023/05/19/the-absurd-cost-of-finalizers-in-go/">The absurd cost of finalizers in Go</a>》 这篇文章作为动机,测试一下OCaml FFI方面的性能比Go好多少或差多少:</p> -<table> -<thead> -<tr> -<th>test</th> -<th>ocaml 5.0</th> -<th>go 1.19.9</th> -</tr> -</thead> -<tbody><tr> -<td>native add</td> -<td>0.3 ns</td> -<td>0.3 ns</td> -</tr> -<tr> -<td>foreign add</td> -<td>1.5 ns</td> -<td>60.4 ns</td> -</tr> -<tr> -<td>c allocate & free</td> -<td>4.0 ns</td> -<td>71.6 ns</td> -</tr> -<tr> -<td>allocate & free</td> -<td>17.2 ns</td> -<td>133.3 ns</td> -</tr> -<tr> -<td>alloc auto</td> -<td>125.6 ns</td> -<td>1180 ns</td> -</tr> -<tr> -<td>alloc dummy</td> -<td>131.0 ns</td> -<td>1197 ns</td> -</tr> -<tr> -<td>alloc custom</td> -<td>109.4 ns</td> -<td>-</td> -</tr> -</tbody></table> -<p>但这不一定是一个准确的测试,例如应该使用<code>Sys.time</code>还是<code>Unix.gettimeofday</code>来计算时间还有待商榷, 更详细的请看论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/critique-my-use-of-ffi/12193">https://discuss.ocaml.org/t/critique-my-use-of-ffi/12193</a></p> -<h2 id="OCaml在改善开发人员体验方面取得的进展"><a href="#OCaml在改善开发人员体验方面取得的进展" class="headerlink" title="OCaml在改善开发人员体验方面取得的进展"></a>OCaml在改善开发人员体验方面取得的进展</h2><p><a target="_blank" rel="noopener" href="https://ocaml.org/docs/platform">OCaml Platform</a>是提高OCaml工作效率的工具集。 他们在OCaml平台上所做的所有工作都有一个目标: <em>改善 OCaml开发人员的体验</em>。</p> -<p>以下是目前正在研究并改善的一些工作流程:</p> -<ol> -<li><p>构建包:构建工作流的直接目标是消除与使用两种不同的工具进行包管理和构建系统相关的差异。例如OCaml开发者通常需要使用opam下载包再用dune作为构建系统构建包,为此,他们计划将opam直接集成到dune中,使其成为构建OCaml项目所需的单一工具,就像cargo一样。 这项工作也可以改进其他工作流程,例如处理多个项目,交叉编译等。</p> -<blockquote> -<p>计划在此: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101">https://discuss.ocaml.org/t/explorations-on-package-management-in-dune/12101</a></p> -</blockquote> -</li> -<li><p>编译为JavaScript: 不断改善将OCaml编译为JavaScript的工具。 改善dune与Js_of_ocaml的集成,他们也一直在致力于Dune和<a target="_blank" rel="noopener" href="https://github.com/melange-re/melange">Melange</a>的集成, Melange fork自<a target="_blank" rel="noopener" href="https://github.com/rescript-lang/rescript-compiler">ReScript</a>编译器,专注于与OCaml生态系统集成。</p> -</li> -<li><p>文档生成: OCaml包的文档是 OCaml2020至2022调查中的一个主要痛点。 他们正在努力改善OCaml开发人员创建高质量的文档的体验。 例如通过添加新功能、改进导航和扩展odoc标记语法以支持丰富的内容(例如表格、图像和图形)来使odoc生成的文档手册更加高质量。 初次之外还将把OCaml的编辑器支持引入Web和第三方平台,例如OCaml Playground 和 GitHub Codespaces。</p> -</li> -<li><p>代码格式化: 提高准确性, 增强向后兼容性, 更加深入地集成dune和ocamlformat</p> -</li> -</ol> -<p>与此同时,OCaml Platform也一直在寻找新的维护者和贡献者, 具体的可以看论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-platform-newsletter-april-2023/12187">https://discuss.ocaml.org/t/ocaml-platform-newsletter-april-2023/12187</a></p> -<h2 id="在odoc中内嵌HTML"><a href="#在odoc中内嵌HTML" class="headerlink" title="在odoc中内嵌HTML"></a>在odoc中内嵌HTML</h2><p>通过 <code>{%html: <p>foo</p> %}</code> 来实现, <a target="_blank" rel="noopener" href="https://github.com/ocaml/odoc/blob/72ac2cfdf34ecc0ed574f9e4dd692f5d9b3da412/test/generators/cases/markup.mli#L142C1-L152">例如</a>:</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></pre></td><td class="code"><pre><span class="line">{1 Raw HTML}</span><br><span class="line"></span><br><span class="line">Raw HTML can be {%html:<input type="text" placeholder="inserted">%} as</span><br><span class="line">inline elements into sentences.</span><br><span class="line"></span><br><span class="line">{%html:</span><br><span class="line"><blockquote></span><br><span class="line"> If the raw HTML is the only thing in a paragraph, it is treated as a block</span><br><span class="line"> element, and won't be wrapped in paragraph tags by the HTML generator.</span><br><span class="line"></blockquote></span><br><span class="line">%}</span><br></pre></td></tr></table></figure> - - -<p>论坛原帖:<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/is-it-possible-to-include-inline-html-in-ocaml-documentation-odoc/12177">https://discuss.ocaml.org/t/is-it-possible-to-include-inline-html-in-ocaml-documentation-odoc/12177</a></p> -<h2 id="开源的OCaml静态博客生成工具"><a href="#开源的OCaml静态博客生成工具" class="headerlink" title="开源的OCaml静态博客生成工具"></a>开源的OCaml静态博客生成工具</h2><ul> -<li><a target="_blank" rel="noopener" href="https://github.com/xhtmlboi/yocaml">YOCaml: A static site generator, mostly written in OCaml</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/roddyyaga/finch">Finch: Simple and fast site generator </a></li> -</ul> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/open-source-tool-to-make-a-static-blog-in-ocaml/11967">https://discuss.ocaml.org/t/open-source-tool-to-make-a-static-blog-in-ocaml/11967</a></p> -<h2 id="一些GADT的实践用法"><a href="#一些GADT的实践用法" class="headerlink" title="一些GADT的实践用法"></a>一些GADT的实践用法</h2><p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/open-source-projects-using-gadts/9640">这个帖子</a> 列出了一些使用了GADT的开源项目,除此之外,还有一篇 <a target="_blank" rel="noopener" href="https://gopiandcode.uk/logs/log-ways-of-sql-in-ocaml.html">《Petrol:使用 GADT 在 OCaml 中嵌入类型安全的 SQL API》</a>。</p> -<p>函数式语言实现中的LR parser generator生成的代码是无类型的、不必要的低效代码,使用GADT,可以生成类型良好(不会意外崩溃或失败)且高效的解析器, 这篇论文讲了细节: <a target="_blank" rel="noopener" href="http://cambium.inria.fr/~fpottier/publis/fpottier-regis-gianas-typed-lr.pdf">Towards efficient, typed LR parsers</a></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/a-bestiary-of-gadt-examples/12143">https://discuss.ocaml.org/t/a-bestiary-of-gadt-examples/12143</a></p> -<h2 id="对-OCaml-org-的改进"><a href="#对-OCaml-org-的改进" class="headerlink" title="对 OCaml.org 的改进"></a>对 OCaml.org 的改进</h2><p>本月,OCaml发布了从3月开始准备的一项改善 OCaml.org 的Learn板块的<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/you-started-to-learn-ocaml-less-than-12-months-ago-please-help-us-with-our-user-survey-on-the-ocaml-org-learning-area/11945">调查结果</a>。该调查在各种平台上进行了推广,包括官方OCaml讨论平台,Discord,LinkedIn,Twitter等,并得到了积极的相应,从五月份开始,官方会根据调查结果改善Learn板块。</p> -<p>除了的Learn板块的改进之外,官方还对文档进行了一些较小的改进,具体表现在ocaml官网的仓库中许多未完成的包含对学习区域现有文档页面更新的pr, 这些pr将在五月份合并大部分。</p> -<p>除此之外还有大量细节的更改可以查看论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-org-newsletter-april-2023/12173">https://discuss.ocaml.org/t/ocaml-org-newsletter-april-2023/12173</a></p> -<h2 id="生态"><a href="#生态" class="headerlink" title="生态"></a>生态</h2><ul> -<li><a target="_blank" rel="noopener" href="https://github.com/dinosaure/cri">cri: IRC protocol in OCaml</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/dinosaure/bob">bob: A peer-to-peer file-transfer tool in OCaml</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/dinosaure/art">art: Adaptive Radix Tree in OCaml</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/dbuenzli/uucd">uucd: Unicode character database decoder for OCaml</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/lukstafi/ocannl">OCANNL: OCaml Compiles Algorithms for Neural Networks Learning</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/Octachron/codept">codept: Contextual Ocaml DEPendencies Tool: alternative ocaml dependency analyzer</a></li> -<li><a target="_blank" rel="noopener" href="https://github.com/Armael/pp_loc">pp_loc: Pretty-printing for error source locations</a></li> -</ul> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/05/31/OCaml_News_20230531/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/05/15/OCaml_News_20230515/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/05/31/OCaml_News_20230531/index.html b/2023/05/31/OCaml_News_20230531/index.html deleted file mode 100644 index d2299d1b..00000000 --- a/2023/05/31/OCaml_News_20230531/index.html +++ /dev/null @@ -1,279 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/5/31 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/5/31 - - - </div> - <span class="post-date"> - May 31, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年五月二十一-二〇二三年五月三十一日"><a href="#二〇二三年五月二十一-二〇二三年五月三十一日" class="headerlink" title="二〇二三年五月二十一 - 二〇二三年五月三十一日"></a>二〇二三年五月二十一 - 二〇二三年五月三十一日</h1><h2 id="为什么OCaml中总是约定俗成的写-type-t"><a href="#为什么OCaml中总是约定俗成的写-type-t" class="headerlink" title="为什么OCaml中总是约定俗成的写 type t = ... ?"></a>为什么OCaml中总是约定俗成的写 <code>type t = ...</code> ?</h2><p>在OCaml中我们经常会看到:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="type">Foo</span> = <span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">type</span> t = ...</span><br><span class="line"> ...</span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure> -<p>这种写法已经存在于29年前的 <a target="_blank" rel="noopener" href="https://github.com/camllight/camllight/blob/master/sources/src/lib/hashtbl.mli#L5">Caml Light sources</a> 中, SML里面也能看到这种写法。 按照惯例,当一个模块定义了一个唯一的核心抽象数据类型时,就写成<code>type t = ...</code>。</p> -<p>为什么要这么写也有比较多原因,具体可以看论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/why-is-ocaml-convention-to-use-type-t/12256">https://discuss.ocaml.org/t/why-is-ocaml-convention-to-use-type-t/12256</a></p> -<p>但可以知道的是,有了这个约定之后Functor的使用会更加方便。 例如标准库的<code>Set</code>模块,大家都可以直接:</p> -<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Set</span>.<span class="type">Make</span>(<span class="type">Foo</span>)</span><br></pre></td></tr></table></figure> - -<p>而不是多写一些无用的代码:</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></pre></td><td class="code"><pre><span class="line"><span class="type">Set</span>.<span class="type">Make</span>(<span class="keyword">struct</span></span><br><span class="line"> <span class="keyword">include</span> <span class="type">Foobar</span></span><br><span class="line"> <span class="keyword">type</span> t = foobar</span><br><span class="line"> <span class="keyword">let</span> compare = compare_foobar </span><br><span class="line"><span class="keyword">end</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure> - -<h2 id="如何更高效的使用OCaml"><a href="#如何更高效的使用OCaml" class="headerlink" title="如何更高效的使用OCaml"></a>如何更高效的使用OCaml</h2><p>在这个帖子中,针对在OCaml中使用新的库由于因为文档很少并且需要阅读源码导致非常耗时的问题展开了讨论:</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-do-you-stay-productive-in-ocaml/8221">https://discuss.ocaml.org/t/how-do-you-stay-productive-in-ocaml/8221</a></p> -<h2 id="求值顺序"><a href="#求值顺序" class="headerlink" title="求值顺序"></a>求值顺序</h2><p>在OCaml中,想这样的代码:</p> -<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">foo(f x, f y, f z)</span><br></pre></td></tr></table></figure> -<p>会先对 <code>f z</code> 求值而不是 <code>f x</code>,OCaml官方并没有定义求值顺序,实现上是从右到左的,如果想从左到右只能一个个let。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/evaluation-order/12258">https://discuss.ocaml.org/t/evaluation-order/12258</a></p> -<h2 id="OCaml-Platform路线图"><a href="#OCaml-Platform路线图" class="headerlink" title="OCaml Platform路线图"></a>OCaml Platform路线图</h2><p>在2020年的OCaml Platform会议中,avsm和OCaml Platform团队提出了针对开发工具(例如编辑器)的改进,使开发效率提升,这三年以来OCaml的开发工具和开发人员体验发生了很大变化,OCaml Platform的工作也取得了重大进展。</p> -<blockquote> -<p>2020年OCaml Platform会议视频: <a target="_blank" rel="noopener" href="https://watch.ocaml.org/w/2KbfRNv2oLtkKXkbd5u9F1">https://watch.ocaml.org/w/2KbfRNv2oLtkKXkbd5u9F1</a></p> -</blockquote> -<p>对于未来,OCaml Platform打算研究新的OCaml工作流原型。并认为应该反思过去三年所做的一切并制定未来三年的路线图。</p> -<p>所以在过去的几个月里,OCaml Platform一直致力于收集尽可能多的社区反馈,并组织了几个会议,会见了使用OCaml的来自各个行业的开发者,并从他们口中了解相关的需求和痛点。在会议中还共同思考了理想的 OCaml 开发人员体验应该是什么。</p> -<p>OCaml Platform希望由社区驱动自身,所以公布了路线图,并开始收集反馈并对其进行更新迭代:</p> -<blockquote> -<p>OCaml Platfrom路线图: <a target="_blank" rel="noopener" href="https://github.com/tarides/ocaml-platform-roadmap">https://github.com/tarides/ocaml-platform-roadmap</a></p> -</blockquote> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/a-roadmap-for-the-ocaml-platform-seeking-your-feedback/12238">https://discuss.ocaml.org/t/a-roadmap-for-the-ocaml-platform-seeking-your-feedback/12238</a></p> -<h2 id="OCaml的Debug体验"><a href="#OCaml的Debug体验" class="headerlink" title="OCaml的Debug体验"></a>OCaml的Debug体验</h2><p>VS Code唯一的debug支持是 <a target="_blank" rel="noopener" href="https://github.com/hackwaly/ocamlearlybird/">hackwaly/ocamlearlybird</a> , 但遗憾的是它已经不积极维护了(根据 README 判断它只支持 4.11 和 4.12)。</p> -<p>所以在出现更好的替代方案之前…</p> -<blockquote> -<p>The most effective debugging tool is still careful thought, coupled with judiciously placed print statements!!!</p> -</blockquote> -<p>不过除此之外还是有很多Debug相关的库和方案的,比如上一期的 <a target="_blank" rel="noopener" href="https://github.com/lukstafi/ppx_minidebug">ppx_minidebug</a> 和 <a target="_blank" rel="noopener" href="https://github.com/dariusf/ppx_debug">ppx_debug</a> 或者是 <a target="_blank" rel="noopener" href="https://github.com/dariusf/ppx_interact">ppx_interact</a>。</p> -<p>具体的可以看论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/enhancing-ocaml-debugging-experience-in-visual-studio-code/12236">https://discuss.ocaml.org/t/enhancing-ocaml-debugging-experience-in-visual-studio-code/12236</a></p> -<h2 id="类似-MIT-Scratch-x2F-Berkeley-Snap-x2F-Google-Blockly-之类的OCaml实现?"><a href="#类似-MIT-Scratch-x2F-Berkeley-Snap-x2F-Google-Blockly-之类的OCaml实现?" class="headerlink" title="类似 MIT Scratch/Berkeley Snap/Google Blockly 之类的OCaml实现?"></a>类似 MIT Scratch/Berkeley Snap/Google Blockly 之类的OCaml实现?</h2><p><a target="_blank" rel="noopener" href="https://github.com/google/blockly">Blockly</a>是一个基于网络的可视化编程编辑器。</p> -<p>OCaml中也有类似的 <a target="_blank" rel="noopener" href="https://hazel.org/">Hazle</a></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/exists-scratch-snap-blockly-for-ocaml-js/12234">https://discuss.ocaml.org/t/exists-scratch-snap-blockly-for-ocaml-js/12234</a></p> -<h2 id="Tiny-httpd-v0-13"><a href="#Tiny-httpd-v0-13" class="headerlink" title="Tiny_httpd v0.13"></a>Tiny_httpd v0.13</h2><p><a target="_blank" rel="noopener" href="https://github.com/c-cube/tiny_httpd">Tiny_httpd</a> 是一个极简的 HTTP 1.1 服务器库,它依赖线程(或线程池)而不是异步/协作多任务处理。可能有点异端。</p> -<h2 id="Parany-v14-0-0"><a href="#Parany-v14-0-0" class="headerlink" title="Parany v14.0.0"></a>Parany v14.0.0</h2><p><a target="_blank" rel="noopener" href="https://github.com/UnixJunkie/parany">Parany</a>可以用于并行化任何类型的计算,在这个版本中作者将运行时切换回了<code>fork+marshal</code></p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/new-major-release-of-parany-v14-0-0/12208">https://discuss.ocaml.org/t/new-major-release-of-parany-v14-0-0/12208</a></p> -<h2 id="Merlin-v4-9"><a href="#Merlin-v4-9" class="headerlink" title="Merlin v4.9"></a>Merlin v4.9</h2><p><a target="_blank" rel="noopener" href="https://github.com/ocaml/merlin">Merlin</a> 是为OCaml提供现代IDE功能的编辑器后端服务,这个新版本带来了许多改进和错误修复。而且发现并修复了一个重要的内存消耗问题.</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-new-release-merlin-4-9/12277">https://discuss.ocaml.org/t/ann-new-release-merlin-4-9/12277</a></p> -<h2 id="OCaml-Learn板块更新"><a href="#OCaml-Learn板块更新" class="headerlink" title="OCaml Learn板块更新"></a>OCaml Learn板块更新</h2><p>社区成员为官网的<a target="_blank" rel="noopener" href="https://staging.ocaml.org/docs">Learn板块</a>贡献了以章有关<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/creating-a-tutorial-on-sequences/12091">Sequence</a>的教程。</p> -<p>论坛原帖: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/creating-a-tutorial-on-sequences/12091">https://discuss.ocaml.org/t/creating-a-tutorial-on-sequences/12091</a></p> -<h2 id="生态"><a href="#生态" class="headerlink" title="生态"></a>生态</h2><ul> -<li><a target="_blank" rel="noopener" href="https://github.com/janestreet/streamable">streamable</a>: A collection of types suitable for incremental serialization. </li> -<li><a target="_blank" rel="noopener" href="https://github.com/janestreet/incr_dom">incr_dom</a>: A library for building dynamic webapps, using Js_of_ocaml.</li> -</ul> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/06/10/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AD%E6%9C%88%E5%8D%81%E6%97%A5/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/05/21/OCaml_News_20230521/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/06/10/二零二三年六月十日/index.html b/2023/06/10/二零二三年六月十日/index.html index 317f333f..4dd0ebaf 100644 --- a/2023/06/10/二零二三年六月十日/index.html +++ b/2023/06/10/二零二三年六月十日/index.html @@ -168,7 +168,7 @@ <div class="icon arrow-left"></div> <div class="post-link"> - <a href="/2023/06/11/OCaml_News_20230611/">Prev</a> + <a href="/2023/06/17/%E5%8F%91%E7%83%AD%E5%8F%8A%E8%B6%85%E9%AB%98%E7%83%AD%E5%8D%B1%E8%B1%A1/">Prev</a> </div> </div> @@ -176,7 +176,7 @@ <div class="icon arrow-right"></div> <div class="post-link"> - <a href="/2023/05/31/OCaml_News_20230531/">Next</a> + <a href="/2023/04/25/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%9B%9B%E6%9C%88%E4%BA%8C%E5%8D%81%E4%BA%94%E6%97%A5/">Next</a> </div> </div> diff --git a/2023/06/11/OCaml_News_20230611/index.html b/2023/06/11/OCaml_News_20230611/index.html deleted file mode 100644 index 3fa81655..00000000 --- a/2023/06/11/OCaml_News_20230611/index.html +++ /dev/null @@ -1,309 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> -<meta name="viewport" - content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -<meta http-equiv="X-UA-Compatible" content="ie=edge"> - - <meta name="author" content="含暮秋"> - - - <meta name="subtitle" content="暮秋小屋"> - - - <meta name="description" content="不卑不亢的码农, 朴素的民谣诗人"> - - - <meta name="keywords" content="韩暮秋,MuqiuHan"> - - - - -<title>OCaml News 2023/6/11 | 暮秋小屋</title> - - - - - -<style> - @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&family=Roboto+Mono&display=swap'); -</style> - - - - <!-- stylesheets list from _config.yml --> - - <link rel="stylesheet" href="/css/style.css"> - - - - - - <!-- scripts list from _config.yml --> - - <script src="/js/frame.js"></script> - - - - - - <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> - <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - - - - - - - - <!-- hexo injector head_end start --> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"> -<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head> - <body> - <div class="mask-border"> - </div> - - <div class="wrapper"> - - <div class="header"> - <div class="flex-container"> - <div class="header-inner"> - <div class="site-brand-container"> - <a href="/"> - - 暮秋小屋 - - </a> - </div> - <div id="menu-btn" class="menu-btn" onclick="toggleMenu()"> - Menu - </div> - <nav class="site-nav"> - <ul class="menu-list"> - - - <li class="menu-item"> - <a href="/">主页</a> - </li> - - - - <li class="menu-item"> - <a href="/tags/Technique/">技术</a> - </li> - - - - <li class="menu-item"> - <a href="/Projects">项目</a> - </li> - - - - <li class="menu-item"> - <a href="/categories/gallery/">日记本</a> - </li> - - - - <li class="menu-item"> - <a href="/about">关于</a> - </li> - - - - </ul> - </nav> - </div> - </div> -</div> - - - <div class="main"> - <div class="flex-container"> - <article id="post"> - - - <div class="post-head"> - <div class="post-info"> - <div class="tag-list"> - - - <span class="post-tag"> - <a href="/tags/OCaml/"> - OCaml - </a> - </span> - - <span class="post-tag"> - <a href="/tags/Technique/"> - Technique - </a> - </span> - - - </div> - <div class="post-title"> - - - OCaml News 2023/6/11 - - - </div> - <span class="post-date"> - Jun 11, 2023 - </span> - </div> - <div class="post-img"> - - <div class="h-line-primary"></div> - - </div> -</div> - <div class="post-content"> - <h1 id="二〇二三年五月三十一日-二〇二三年六月十一日"><a href="#二〇二三年五月三十一日-二〇二三年六月十一日" class="headerlink" title="二〇二三年五月三十一日 - 二〇二三年六月十一日"></a>二〇二三年五月三十一日 - 二〇二三年六月十一日</h1><h2 id="Lambda演算中的可计算性极限"><a href="#Lambda演算中的可计算性极限" class="headerlink" title="Lambda演算中的可计算性极限"></a>Lambda演算中的可计算性极限</h2><p>OCaml 的用户可能有兴趣阅读有关 lambda 演算的理论论文。</p> -<p>“ <a target="_blank" rel="noopener" href="https://hbr.github.io/Lambda-Calculus/computability/text.html">Limits of Computability in Lambda Calculus</a>“ 这篇论文介绍了在lambda演算中有一些函数是不可计算的。</p> -<p>详细讨论可以看<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/limits-of-computability-in-lambda-calculus/12295">论坛原帖</a></p> -<h2 id="OCaml-5-1-0-alpha2"><a href="#OCaml-5-1-0-alpha2" class="headerlink" title="OCaml 5.1.0~alpha2"></a>OCaml 5.1.0~alpha2</h2><p>随着 OCaml 5.1.0 持续稳定的工作进展,OCaml 5.1.0 的第二个 alpha 版本发布了, 这个版本修复了GC和Windows ABI的问题。<br>除此之外,类型系统兼容性得到增强,恢复支持 s390x/IBM Z</p> -<p>详细的更新可以查看 <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/second-alpha-release-of-ocaml-5-1-0/12299">论坛原帖</a></p> -<h2 id="OCaml中能否实现-constraint-不等"><a href="#OCaml中能否实现-constraint-不等" class="headerlink" title="OCaml中能否实现 constraint 不等"></a>OCaml中能否实现 constraint 不等</h2><p>OCaml提供了对类型定义添加约束的方法, 即<code>constraint</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> <span class="type">A</span> = <span class="keyword">struct</span> <span class="keyword">type</span> t = <span class="built_in">int</span> <span class="keyword">end</span></span><br><span class="line"><span class="keyword">module</span> <span class="type">B</span> = <span class="keyword">struct</span> <span class="keyword">type</span> t = <span class="built_in">float</span> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="comment">(** Error: This type constructor expands to type t but is used here with type float *)</span></span><br><span class="line"><span class="keyword">type</span> t = <span class="type">A</span>.t <span class="keyword">constraint</span> t = <span class="type">B</span>.t</span><br></pre></td></tr></table></figure> - -<p>能否实现判断两个类型是不兼容的呢? 比如: <code>type t = A.t constraint t <> B.t</code>。</p> -<p>类型相关的理论在学了在学了呜呜,目前来看这不是个好的做法…,详细可以看<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/type-inequality-constraints/12364#main-container">论坛原帖</a></p> -<h2 id="在OCaml5的并行程序中使用全局哈希表是否安全?"><a href="#在OCaml5的并行程序中使用全局哈希表是否安全?" class="headerlink" title="在OCaml5的并行程序中使用全局哈希表是否安全?"></a>在OCaml5的并行程序中使用全局哈希表是否安全?</h2><p>这里指的应该是 <code>Stdlib.Hashtbl</code>。</p> -<p>只能安全一点点,因为对哈希表访问没有同步,所以只是内存安全而不是线程安全。<br>文档指出,对哈希表的不同步访问是程序员的锅,要么使用锁保护表,要么用并发哈希表的不同实现。<br>在表没有涉及大小调整操作的情况下,共享哈希表是安全的。在调整大小的情况下,添加/删除可能会与任何其他操作产生冲突。</p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/is-it-safe-to-use-a-global-hash-table-in-an-ocaml-5-parallel-program/11144/1">查看论坛原帖</a></p> -<h2 id="谈谈你心目中理想ML的样子吧!"><a href="#谈谈你心目中理想ML的样子吧!" class="headerlink" title="谈谈你心目中理想ML的样子吧!"></a>谈谈你心目中理想ML的样子吧!</h2><ul> -<li>Haskell的类型系统和简洁 </li> -<li>OCaml的模块系统和对象系统</li> -<li>Rust的low level内存控制和借用以及并发检查</li> -<li>Lisp的宏系统和REPL</li> -<li>JetBrains相关IDE支持</li> -<li>和x86_64汇编一样的编译速度</li> -</ul> -<p>有种许愿的美,🙏</p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/whats-your-laundry-list-of-features-for-an-ideal-ml/10217/5">查看论坛上其他愿望</a></p> -<h2 id="OOP-Visitors在Polymorphic情况下的类型错误"><a href="#OOP-Visitors在Polymorphic情况下的类型错误" class="headerlink" title="OOP Visitors在Polymorphic情况下的类型错误"></a>OOP Visitors在Polymorphic情况下的类型错误</h2><p>像Java里面:</p> -<figure class="highlight java"><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="keyword">interface</span> <span class="title class_">Tree</span> {</span><br><span class="line"> <span class="keyword">public</span> <B> B <span class="title function_">accept</span><span class="params">(TreeVisitor<B> v)</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">TreeVisitor</span><B> {</span><br><span class="line"> <span class="keyword">public</span> B <span class="title function_">visitLeaf</span><span class="params">(Leaf t)</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Leaf</span> <span class="keyword">implements</span> <span class="title class_">Tree</span> {</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">final</span> <span class="type">int</span> value;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="title function_">Leaf</span><span class="params">(<span class="type">int</span> value)</span> {</span><br><span class="line"> <span class="built_in">this</span>.value = value;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <B> B <span class="title function_">accept</span><span class="params">(TreeVisitor<B> v)</span> {</span><br><span class="line"> <span class="keyword">return</span> v.visitLeaf(<span class="built_in">this</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure> - -<p>要是直接翻译成OCaml:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="keyword">virtual</span> tree =</span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> accept : <span class="symbol">'a</span> . <span class="symbol">'a</span> tree_visitor -> <span class="symbol">'a</span></span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">and</span> <span class="keyword">virtual</span> [<span class="symbol">'a</span>] tree_visitor =</span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> visit_leaf : (leaf -> <span class="symbol">'a</span>)</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">and</span> leaf (i : <span class="built_in">int</span>) =</span><br><span class="line"> <span class="keyword">object</span> (self)</span><br><span class="line"> <span class="keyword">method</span> get = i</span><br><span class="line"></span><br><span class="line"> <span class="keyword">method</span> accept (v : <span class="symbol">'a</span> tree_visitor) : <span class="symbol">'a</span> =</span><br><span class="line"> v#visit_leaf (self :> leaf)</span><br><span class="line"> <span class="keyword">end</span></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></pre></td><td class="code"><pre><span class="line">File "visitor.ml", line 3, characters 28-54:</span><br><span class="line">3 | method virtual accept : 'a . 'a tree_visitor -> 'a</span><br><span class="line"> ^^^^^^^^^^^^^^^^^^^^^^^^^^</span><br><span class="line">Error: The universal type variable 'a cannot be generalized:</span><br><span class="line"> it escapes its scope.</span><br></pre></td></tr></table></figure> - -<p>OCaml的类在定义时是单态的,比如:</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> [<span class="symbol">'a</span>] c (x:<span class="symbol">'a</span>) = </span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> x = x</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"><span class="keyword">and</span> d = </span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> strange = (<span class="keyword">new</span> c <span class="number">0</span>)#x</span><br><span class="line"> <span class="keyword">end</span></span><br></pre></td></tr></table></figure> - -<p>这里<code>c</code>是:</p> -<figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> [<span class="symbol">'a</span>] c : <span class="symbol">'a</span> -> <span class="keyword">object</span> <span class="keyword">constraint</span> <span class="symbol">'a</span> = <span class="built_in">int</span> <span class="keyword">method</span> x : <span class="symbol">'a</span> <span class="keyword">end</span></span><br></pre></td></tr></table></figure> -<p>因为在d里面 <code>new c 0</code> 定义了一个 <code>int c</code> 的对象。</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="keyword">virtual</span> [<span class="symbol">'a</span>, <span class="symbol">'leaf</span>, <span class="symbol">'node</span>, <span class="symbol">'empty</span>] open_tree_visitor = </span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> visit_leaf : <span class="symbol">'leaf</span> -> <span class="symbol">'a</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> visit_node : <span class="symbol">'node</span> -> <span class="symbol">'a</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> visit_empty : <span class="symbol">'empty</span> -> <span class="symbol">'a</span></span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="keyword">virtual</span> tree = </span><br><span class="line"> <span class="keyword">object</span></span><br><span class="line"> <span class="keyword">method</span> <span class="keyword">virtual</span> accept : <span class="symbol">'a</span> .</span><br><span class="line"> (<span class="symbol">'a</span>, <span class="symbol">'leaf</span>, <span class="symbol">'node</span>, <span class="symbol">'empty</span>) open_tree_visitor -> <span class="symbol">'a</span></span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">and</span> leaf (i : <span class="built_in">int</span>) = </span><br><span class="line"> <span class="keyword">object</span> (self:<span class="symbol">'self</span>)</span><br><span class="line"> <span class="keyword">inherit</span> tree</span><br><span class="line"> <span class="keyword">method</span> get = i</span><br><span class="line"> <span class="keyword">method</span> accept v = v#visit_leaf (self :> leaf)</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">and</span> node (x : tree) (y: tree) = </span><br><span class="line"> <span class="keyword">object</span> (self:<span class="symbol">'self</span>)</span><br><span class="line"> <span class="keyword">inherit</span> tree</span><br><span class="line"> <span class="keyword">method</span> left = x</span><br><span class="line"> <span class="keyword">method</span> right = y</span><br><span class="line"> <span class="keyword">method</span> accept v = v#visit_node (self :> node)</span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">and</span> empty = </span><br><span class="line"> <span class="keyword">object</span> (self:<span class="symbol">'self</span>)</span><br><span class="line"> <span class="keyword">inherit</span> tree</span><br><span class="line"> <span class="keyword">method</span> accept v = v#visit_empty (self :> empty)</span><br><span class="line"> <span class="keyword">end</span></span><br></pre></td></tr></table></figure> - -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/type-errors-in-polymorphic-oop-visitors/12357">查看论坛原帖</a></p> -<h2 id="进一步约束模块的接口"><a href="#进一步约束模块的接口" class="headerlink" title="进一步约束模块的接口"></a>进一步约束模块的接口</h2><blockquote> -<p>基于dune,有一个模块<code>A.ml</code>它的接口是<code>A.mli</code>,但是当它在主模块中时,我想使用进一步约束过的的接口<code>A_sub.mli</code>,因为只有<code>A_Sub</code>的功能对用户有用。</p> -</blockquote> -<p>其实在library下面声明一个和library同名的 <code>xxx.ml</code>,在里面写 <code>module A = struct include A end</code> 就可以啦,很常见的做法。</p> -<p>详细讨论可以<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/export-wrapped-modules-with-a-restricted-interface/12361">查看论坛原帖</a></p> -<h2 id="OCaml环不环保?"><a href="#OCaml环不环保?" class="headerlink" title="OCaml环不环保?"></a>OCaml环不环保?</h2><p><a target="_blank" rel="noopener" href="https://infra.ocaml.org/2023/05/30/emissions-monitoring.html">这篇文章</a>说道,对于在 ocaml.org 集群中监测的19台机器,<br>每周大约产生70公斤的二氧化碳当量, </p> -<p>自 ocaml.org 重新设计以来, 社区一直致力于对环境影响负责。第一步是通过计算使用的能源总量来准确量化影响,为了确定未来所做的任何改善是否能减少二氧化碳排放量。</p> -<p>为此,开发了一个用于获取各种碳强度API的HTTP客户端: <a target="_blank" rel="noopener" href="https://github.com/geocaml/carbon-intensity">carbon-intensity</a></p> -<p>英国特定地区API的非常简单,使用只需要用户提供Eio的网络功能:</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></pre></td><td class="code"><pre><span class="line"># <span class="type">Eio_main</span>.run @@ <span class="keyword">fun</span> env -></span><br><span class="line"> <span class="type">Mirage_crypto_rng_eio</span>.run (<span class="keyword">module</span> <span class="type">Mirage_crypto_rng</span>.<span class="type">Fortuna</span>) env @@ <span class="keyword">fun</span> _ -></span><br><span class="line"> <span class="type">Carbon</span>.<span class="type">Gb</span>.get_intensity env#net</span><br><span class="line"> |> <span class="type">Eio</span>.traceln <span class="string">"%a"</span> <span class="type">Carbon</span>.<span class="type">Gb</span>.<span class="type">Intensity</span>.pp;;</span><br><span class="line">+period: <span class="number">2022</span>-<span class="number">08</span>-<span class="number">28</span>T17:<span class="number">30</span>Z - <span class="number">2022</span>-<span class="number">08</span>-<span class="number">28</span>T18:<span class="number">00</span>Z</span><br><span class="line">+forecast: <span class="number">255</span> gCO2/kWh</span><br><span class="line">+actual: <span class="type">None</span></span><br><span class="line">+index: high</span><br><span class="line">+</span><br><span class="line">- : <span class="built_in">unit</span> = <span class="literal">()</span></span><br></pre></td></tr></table></figure> - -<p>某些API需要更多配置,例如法国的需要token:</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></pre></td><td class="code"><pre><span class="line"># <span class="type">Eio_main</span>.run @@ <span class="keyword">fun</span> env -></span><br><span class="line"> <span class="type">Mirage_crypto_rng_eio</span>.run (<span class="keyword">module</span> <span class="type">Mirage_crypto_rng</span>.<span class="type">Fortuna</span>) env @@ <span class="keyword">fun</span> _ -></span><br><span class="line"> <span class="keyword">let</span> token = <span class="type">Eio</span>.<span class="type">Path</span>.(load (env#fs / <span class="string">".co2-token"</span>)) <span class="keyword">in</span></span><br><span class="line"> <span class="keyword">let</span> t = <span class="type">Carbon</span>.<span class="type">Co2_signal</span>.v token <span class="keyword">in</span></span><br><span class="line"> <span class="type">Carbon</span>.<span class="type">Co2_signal</span>.get_intensity ~net:env#net ~country_code:<span class="type">`FR</span> t</span><br><span class="line"> |> <span class="type">Eio</span>.traceln <span class="string">"%a"</span> <span class="type">Carbon</span>.<span class="type">Co2_signal</span>.<span class="type">Intensity</span>.pp;;</span><br><span class="line">+country: <span class="type">FR</span></span><br><span class="line">+datetime: <span class="number">2022</span>-<span class="number">08</span>-<span class="number">29</span>T11:<span class="number">00</span>:<span class="number">00.000</span>Z</span><br><span class="line">+intensity: <span class="number">99</span> gCO2/kWh</span><br><span class="line">+fossil fuel percentage: <span class="number">15.230000</span></span><br><span class="line">- : <span class="built_in">unit</span> = <span class="literal">()</span></span><br></pre></td></tr></table></figure> - -<p>更详细的可以看<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/initial-emissions-monitoring-of-the-ocaml-org-infrastructure/12335">论坛原帖</a>, 以及论坛上<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ocaml-carbon-footprint/8580">关于carbon-intensity的帖子</a></p> -<h2 id="float-of-int的细节"><a href="#float-of-int的细节" class="headerlink" title="float_of_int的细节"></a>float_of_int的细节</h2><p>试图弄清楚 <code>float_of_int</code> 在amd64和arm64上的行为, 生成的 Cmm 大概是<br><code>box_float (Cop(Cfloatofint (untag_int myfloat)))</code></p> -<p>在 amd64 上,它被转换为序列:</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">(** untag_int *)</span><br><span class="line">sarq $1, %rax</span><br><span class="line">cvtsi2sdq %rax, %xmm0</span><br></pre></td></tr></table></figure> - -<p>而在arm64上使用scvtf实现。</p> -<p><a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342">论坛原帖</a></p> -<h2 id="Debugging-Native-Code-in-OCaml!"><a href="#Debugging-Native-Code-in-OCaml!" class="headerlink" title="Debugging Native Code in OCaml!"></a>Debugging Native Code in OCaml!</h2><p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=OV19_FqAUCw">本视频</a>适用于:</p> -<ul> -<li>非 OCaml 开发人员对 OCaml 的工作原理感到好奇</li> -<li>中级 OCaml 开发人员</li> -</ul> -<p>更多讨论可以看<a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/ann-debugging-native-code-in-second-ocaml-youtube-video/12315">论坛原帖</a></p> -<h2 id="Outreachy-Summer-2023"><a href="#Outreachy-Summer-2023" class="headerlink" title="Outreachy Summer 2023"></a>Outreachy Summer 2023</h2><p>Outreachy是一项带薪远程实习计划,目的是促进开源和开放科学的多样性。Outreachy的实习是为那些在本国()技术行业面临代表性不足、歧视或系统性偏见的人提供的。</p> -<p>关于今年Outreachy的信息可以看这个帖子: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/outreachy-summer-2023/11159/2">Outreachy Summer 2023</a><br>如果想加入,可以看: <a target="_blank" rel="noopener" href="https://discuss.ocaml.org/t/become-an-outreachy-mentor-support-the-growth-and-diversity-of-the-ocaml-community/8213">Become an Outreachy Mentor: support the growth and diversity of the OCaml community</a></p> -<h2 id="一些生态"><a href="#一些生态" class="headerlink" title="一些生态"></a>一些生态</h2><ul> -<li><a target="_blank" rel="noopener" href="https://github.com/c-cube/ocaml-minisat/">OCaml-Minisat github repo</a> minisat是一个小巧快速的SAT Solver, 这是其OCaml Bining</li> -<li><a target="_blank" rel="noopener" href="https://github.com/ocaml/MPP-language-blender">MPP</a> 兼容OCaml5咯, mpp就是meta preprocesser</li> -<li><a target="_blank" rel="noopener" href="https://github.com/mjambon/caml2html">caml2html</a>可以将OCaml源码文件转换成带高亮的HTML</li> -<li><a target="_blank" rel="noopener" href="https://github.com/c-cube/ocaml-containers/releases/tag/v3.12">containers</a> 3.12发布了</li> -<li><a target="_blank" rel="noopener" href="https://github.com/ocaml-multicore/multicoretests">multicoretests</a>是用于测试Multicore OCaml 的 PBT 测试套件和库</li> -</ul> - -</div> - -<script> - window.onload = detectors(); -</script> - <div class="post-footer"> - <div class="h-line-primary"></div> - <nav class="post-nav"> - <div class="prev-item"> - - <div class="icon arrow-left"></div> - <div class="post-link"> - <a href="/2023/06/17/%E5%8F%91%E7%83%AD%E5%8F%8A%E8%B6%85%E9%AB%98%E7%83%AD%E5%8D%B1%E8%B1%A1/">Prev</a> - </div> - - </div> - <div class="next-item"> - - <div class="icon arrow-right"></div> - <div class="post-link"> - <a href="/2023/06/10/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AD%E6%9C%88%E5%8D%81%E6%97%A5/">Next</a> - </div> - - </div> - </nav> -</div> - - - <div class="post-comment"> - - - - - - - -</div> - - -</article> - </div> - </div> - - <div class="footer"> - <div class="flex-container"> - <div class="footer-text"> - - - | - - - 希望路过的人可以添点柴火让这里暖和点 - - </div> - </div> -</div> - - </div> - - - - - </body> -</html> diff --git a/2023/06/17/发热及超高热危象/index.html b/2023/06/17/发热及超高热危象/index.html index 2935f4ab..0f7ee0fa 100644 --- a/2023/06/17/发热及超高热危象/index.html +++ b/2023/06/17/发热及超高热危象/index.html @@ -299,7 +299,7 @@ <div class="icon arrow-right"></div> <div class="post-link"> - <a href="/2023/06/11/OCaml_News_20230611/">Next</a> + <a href="/2023/06/10/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AD%E6%9C%88%E5%8D%81%E6%97%A5/">Next</a> </div> </div> |
