readme-lhs Build Status

The language in which we express our ideas has a strong influence on our thought processes. ~ Knuth

A literate-programming friendly; tight work-flow stack template.

other/readme-lhs.hsfiles

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

Which:

alternative templates

Or grab some of the other templates from this repo:

other/readme-hs.hsfiles

like the lhs version, but hs based

other/batteries.hsfiles

This is my latest working template, overly influenced by lexi-lambda's opinionated guide. The template includes:

code

ghc options

{-# OPTIONS_GHC -Wall #-}

pragmas

-- doctest doesn't look at the cabal file, so you need pragmas here
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}

libraries

import Protolude
import Options.Generic

code

data Opts w = Opts
  { number :: w ::: Maybe Integer <?> "The number you want to product to"
  } deriving (Generic)

instance ParseRecord (Opts Wrapped)

main :: IO ()
main = do
  o :: Opts Unwrapped <- unwrapRecord "an example app for readme-lhs"
  let n = fromMaybe 10 (number o)
  let answer = product [1..n]
  putStrLn (show answer <> " 👍" :: Text)
  writeFile "other/answer.md"
    ("$\\prod_{i=1}^{" <> show n <> "} i = " <>
     show answer <> "$")

output

\(\prod_{i=1}^{10} i = 3628800\)

tests

doctest

-- | doctests
-- >>> let n = 10
-- >>> product [1..n]
-- 3628800