mirror of
https://github.com/i-am-tom/higgledy.git
synced 2024-08-17 03:50:23 +03:00
commit
9c7b830bdc
1
README.lhs
Symbolic link
1
README.lhs
Symbolic link
@ -0,0 +1 @@
|
||||
README.md
|
25
README.md
25
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 ()
|
||||
```
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user