diff --git a/README.lhs b/README.lhs new file mode 120000 index 0000000..42061c0 --- /dev/null +++ b/README.lhs @@ -0,0 +1 @@ +README.md \ No newline at end of file diff --git a/README.md b/README.md index dcd69f4..e844e1e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ When we work with [higher-kinded data](https://reasonablypolymorphic.com/blog/higher-kinded-data), we find ourselves writing types like: -```haskell +```{haskell, ignore} data User f = User { name :: f String @@ -24,7 +24,7 @@ lot of boilerplate deriving to do. Wouldn't it be nice if we could get back to writing simple types as we know and love them, and get all this stuff for _free_? -```haskell +```{haskell, ignore} data User = User { name :: String @@ -50,7 +50,7 @@ example data types: {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeApplications #-} -module Example where +module Main where import Control.Lens ((.~), (^.), (&), Const (..), Identity, anyOf) import Data.Functor.Const (Const (..)) @@ -124,7 +124,7 @@ Of course, this method requires every field to be monoidal. If we try with `Identity`, for example, we're in trouble if all our fields aren't themselves monoids: -```haskell +```{haskell, ignore} eg2 :: Bare Triple eg2 = mempty -- error: @@ -196,7 +196,7 @@ choice): ```haskell eg9 :: Partial User eg9 = eg0 & field @"name" .~ pure "Evil Tom" - & field @"likesDogs" .~ pure False + & field @"likesDogs" .~ pure False -- User -- { name = Last {getLast = Just "Evil Tom"} -- , age = Last {getLast = Nothing} @@ -217,7 +217,7 @@ Finally, thanks to the fact that this library exploits some of the internals of `generic-lens`, we'll also get a nice type error when we mention a field that doesn't exist in our type: -```haskell +```{haskell, ignore} eg11 :: Identity () eg11 = eg3 ^. field @"oops" -- error: @@ -254,7 +254,7 @@ eg13 = eg9 & position @2 .~ pure 25 Similarly, the internals here come to us courtesy of `generic-lens`, so the type errors are a delight: -```haskell +```{haskell, ignore} eg14 :: Identity () eg14 = deconstruct @Identity triple ^. position @4 -- error: @@ -288,3 +288,14 @@ eg16 :: [String] eg16 = labelsWhere (isNothing . getLast) eg9 -- ["age"] ``` + +### Documentation + +All the docs in this library are tested on `cabal new-test`. Furthermore, this +README is tested by `markdown-unlit`. To keep _that_ happy, we do need a `main` +in this file, so just ignore the following :) + +```haskell +main :: IO () +main = pure () +``` diff --git a/higgledy.cabal b/higgledy.cabal index 33e0388..0566f97 100644 --- a/higgledy.cabal +++ b/higgledy.cabal @@ -42,3 +42,14 @@ test-suite test type: exitcode-stdio-1.0 hs-source-dirs: test default-language: Haskell2010 + +test-suite readme + build-depends: base + , barbies ^>= 1.1.0 + , lens ^>= 4.17 + , higgledy + main-is: README.lhs + type: exitcode-stdio-1.0 + default-language: Haskell2010 + ghc-options: -pgmL markdown-unlit -Wall + build-tool-depends: markdown-unlit:markdown-unlit