packages feed

readme-lhs-0.2.0: index.html

<meta charset="utf-8"> <link rel="stylesheet" href="other/lhs.css">
<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1 id="readme-lhs-build-status"><a href="https://tonyday567.github.io/readme-lhs/index.html">readme-lhs</a> <a href="https://travis-ci.org/tonyday567/readme-lhs"><img src="https://travis-ci.org/tonyday567/readme-lhs.svg" alt="Build Status" /></a></h1>
<blockquote cite>
The language in which we express our ideas has a strong influence on our thought processes. ~ Knuth
</blockquote>
<p>A literate-programming friendly; tight work-flow stack template.</p>
<h2 id="otherreadme-lhs.hsfiles">other/readme-lhs.hsfiles</h2>
<pre><code>stack new project-name readme-lhs
cd project-name
stack build
$(stack path --local-install-root)/bin/readme-lhs-example
$(stack path --local-bin)/pandoc -f markdown -i other/header.md readme.md example/example.lhs other/footer.md -t html -o index.html --filter pandoc-include --mathjax</code></pre>
<p>Which:</p>
<ul class="incremental">
<li>runs an executable, which places some output in a markdown file</li>
<li>gathers together the readme.md and the example.lhs into an index.html</li>
</ul>
<h1 id="alternative-templates">alternative templates</h1>
<p>Or grab some of the other templates from this repo:</p>
<h2 id="otherreadme-hs.hsfiles">other/readme-hs.hsfiles</h2>
<p>like the lhs version, but hs based</p>
<h2 id="otherbatteries.hsfiles">other/batteries.hsfiles</h2>
<p>This is my latest working template, overly influenced by <a href="https://lexi-lambda.github.io/blog/2018/02/10/an-opinionated-guide-to-haskell-in-2018/">lexi-lambda's opinionated guide</a>. The template includes:</p>
<ul class="incremental">
<li>some minor tweaks to protolude</li>
<li>lens, foldl, formatting &amp; text as must have libraries</li>
<li>generic-lens-labels</li>
</ul>
<h1 id="code">code</h1>
<h2 id="ghc-options"><a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/flags.html#flag-reference">ghc options</a></h2>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">{-# OPTIONS_GHC -Wall #-}</span></code></pre></div>
<h2 id="pragmas"><a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/lang.html">pragmas</a></h2>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="co">-- doctest doesn&#39;t look at the cabal file, so you need pragmas here</span>
<span class="ot">{-# LANGUAGE NoImplicitPrelude #-}</span>
<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>
<span class="ot">{-# LANGUAGE DataKinds #-}</span>
<span class="ot">{-# LANGUAGE DeriveGeneric #-}</span>
<span class="ot">{-# LANGUAGE ScopedTypeVariables #-}</span>
<span class="ot">{-# LANGUAGE TypeOperators #-}</span>
<span class="ot">{-# LANGUAGE FlexibleInstances #-}</span></code></pre></div>
<h2 id="libraries"><a href="https://www.stackage.org/">libraries</a></h2>
<ul class="incremental">
<li><a href="https://www.stackage.org/package/protolude">protolude</a></li>
<li><a href="https://www.stackage.org/package/optparse-generic">optparse-generic</a></li>
</ul>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import </span><span class="dt">Protolude</span>
<span class="kw">import </span><span class="dt">Options.Generic</span></code></pre></div>
<h2 id="code-1">code</h2>
<ul class="incremental">
<li><a href="https://www.stackage.org/package/hoogle">hoogle</a></li>
</ul>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Opts</span> w <span class="fu">=</span> <span class="dt">Opts</span>
  {<span class="ot"> number ::</span> w <span class="ot">::</span><span class="fu">:</span> <span class="dt">Maybe</span> <span class="dt">Integer</span> <span class="fu">&lt;?&gt;</span> <span class="st">&quot;The number you want to product to&quot;</span>
  } <span class="kw">deriving</span> (<span class="dt">Generic</span>)

<span class="kw">instance</span> <span class="dt">ParseRecord</span> (<span class="dt">Opts</span> <span class="dt">Wrapped</span>)

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
<span class="ot">  o ::</span> <span class="dt">Opts</span> <span class="dt">Unwrapped</span> <span class="ot">&lt;-</span> unwrapRecord <span class="st">&quot;an example app for readme-lhs&quot;</span>
  <span class="kw">let</span> n <span class="fu">=</span> fromMaybe <span class="dv">10</span> (number o)
  <span class="kw">let</span> answer <span class="fu">=</span> product [<span class="dv">1</span><span class="fu">..</span>n]
  putStrLn (show answer <span class="fu">&lt;&gt;</span> <span class="st">&quot; 👍&quot;</span><span class="ot"> ::</span> <span class="dt">Text</span>)
  writeFile <span class="st">&quot;other/answer.md&quot;</span>
    (<span class="st">&quot;$\\prod_{i=1}^{&quot;</span> <span class="fu">&lt;&gt;</span> show n <span class="fu">&lt;&gt;</span> <span class="st">&quot;} i = &quot;</span> <span class="fu">&lt;&gt;</span>
     show answer <span class="fu">&lt;&gt;</span> <span class="st">&quot;$&quot;</span>)</code></pre></div>
<h2 id="output">output</h2>
<p><span class="math inline">\(\prod_{i=1}^{10} i = 3628800\)</span></p>
<h2 id="tests">tests</h2>
<p><a href="https://www.stackage.org/package/doctest">doctest</a></p>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="co">-- | doctests</span>
<span class="co">-- &gt;&gt;&gt; let n = 10</span>
<span class="co">-- &gt;&gt;&gt; product [1..n]</span>
<span class="co">-- 3628800</span></code></pre></div>
<hr />
<div class="footer">
<p>Made with love 'n' care; and <a href="https://haskell-lang.org/">haskell</a>, <a href="https://pandoc.org">pandoc</a>, and <a href="https://docs.haskellstack.org/en/stable/README/">stack</a>.</p>
</div>