Merge pull request #1407 from akhesaCaro/using_derivingvia_uverb

Using DerivingVia in UVerb's cookbook
This commit is contained in:
Caroline GAUDREAU 2021-04-09 16:43:12 +02:00 committed by GitHub
commit bc6144716b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -4,12 +4,19 @@ Servant allows you to talk about the exceptions you throw in your API
types. This is not limited to actual exceptions, you can write types. This is not limited to actual exceptions, you can write
handlers that respond with arbitrary open unions of types. handlers that respond with arbitrary open unions of types.
## Compatibility
:warning: This cookbook is compatible with GHC 8.6.1 or higher :warning:
## Preliminaries ## Preliminaries
```haskell ```haskell
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}
@ -154,12 +161,8 @@ Example usage:
```haskell ```haskell
data Foo = Foo Int Int Int data Foo = Foo Int Int Int
deriving (Show, Eq, GHC.Generic) deriving (Show, Eq, GHC.Generic, ToJSON)
deriving HasStatus via WithStatus 200 Foo
instance ToJSON Foo
instance HasStatus Foo where
type StatusOf Foo = 200
data Bar = Bar data Bar = Bar
deriving (Show, Eq, GHC.Generic) deriving (Show, Eq, GHC.Generic)

View File

@ -28,6 +28,8 @@ executable cookbook-uverb
, swagger2 , swagger2
, wai , wai
, warp , warp
default-language: Haskell2010 if impl(ghc < 8.6.1)
buildable: False
default-language: Haskell2010
ghc-options: -Wall -pgmL markdown-unlit ghc-options: -Wall -pgmL markdown-unlit
build-tool-depends: markdown-unlit:markdown-unlit build-tool-depends: markdown-unlit:markdown-unlit