use strict data in the codec module

This commit is contained in:
Tom Sydney Kerckhove 2021-11-05 16:31:08 +01:00
parent ecb575e2d0
commit a1f1225f7d
3 changed files with 18 additions and 14 deletions

View File

@ -37,6 +37,7 @@ library
, containers , containers
, mtl , mtl
, scientific , scientific
, swagger
, text , text
, vector , vector
default-language: Haskell2010 default-language: Haskell2010

View File

@ -19,5 +19,6 @@ library:
- containers - containers
- mtl - mtl
- scientific - scientific
- swagger
- text - text
- vector - vector

View File

@ -2,7 +2,9 @@
{-# LANGUAGE GADTs #-} {-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
module Autodocodec.Codec where module Autodocodec.Codec where
@ -39,7 +41,7 @@ data Codec context input output where
-- | Encode a 'Bool' to a @boolean@ value, and decode a @boolean@ value as a 'Bool'. -- | Encode a 'Bool' to a @boolean@ value, and decode a @boolean@ value as a 'Bool'.
BoolCodec :: BoolCodec ::
-- | Name of the @bool@, for error messages and documentation. -- | Name of the @bool@, for error messages and documentation.
!(Maybe Text) -> (Maybe Text) ->
-- | -- |
ValueCodec Bool Bool ValueCodec Bool Bool
-- | Encode 'Text' to a @string@ value, and decode a @string@ value as a 'Text'. -- | Encode 'Text' to a @string@ value, and decode a @string@ value as a 'Text'.
@ -47,7 +49,7 @@ data Codec context input output where
-- This is named after the primitive type "String" in json, not after the haskell type string. -- This is named after the primitive type "String" in json, not after the haskell type string.
StringCodec :: StringCodec ::
-- | Name of the @string@, for error messages and documentation. -- | Name of the @string@, for error messages and documentation.
!(Maybe Text) -> (Maybe Text) ->
-- | -- |
ValueCodec Text Text ValueCodec Text Text
-- | Encode 'Scientific' to a @number@ value, and decode a @number@ value as a 'Scientific'. -- | Encode 'Scientific' to a @number@ value, and decode a @number@ value as a 'Scientific'.
@ -55,23 +57,23 @@ data Codec context input output where
-- NOTE: We use 'Scientific' here because that is what aeson uses. -- NOTE: We use 'Scientific' here because that is what aeson uses.
NumberCodec :: NumberCodec ::
-- | Name of the @number@, for error messages and documentation. -- | Name of the @number@, for error messages and documentation.
!(Maybe Text) -> (Maybe Text) ->
-- | -- |
ValueCodec Scientific Scientific ValueCodec Scientific Scientific
-- | Encode a 'Vector' of values as an @array@ value, and decode an @array@ value as a 'Vector' of values. -- | Encode a 'Vector' of values as an @array@ value, and decode an @array@ value as a 'Vector' of values.
ArrayOfCodec :: ArrayOfCodec ::
-- | Name of the @array@, for error messages and documentation. -- | Name of the @array@, for error messages and documentation.
!(Maybe Text) -> (Maybe Text) ->
-- | -- |
!(ValueCodec input output) -> (ValueCodec input output) ->
-- | -- |
ValueCodec (Vector input) (Vector output) ValueCodec (Vector input) (Vector output)
-- | Encode a value as a an @object@ value using the given 'ObjectCodec', and decode an @object@ value as a value using the given 'ObjectCodec'. -- | Encode a value as a an @object@ value using the given 'ObjectCodec', and decode an @object@ value as a value using the given 'ObjectCodec'.
ObjectOfCodec :: ObjectOfCodec ::
-- | Name of the @object@, for error messages and documentation. -- | Name of the @object@, for error messages and documentation.
!(Maybe Text) -> (Maybe Text) ->
-- | -- |
!(ObjectCodec input output) -> (ObjectCodec input output) ->
-- | -- |
ValueCodec input output ValueCodec input output
-- | Encode a 'JSON.Object', and decode any 'JSON.Object'. -- | Encode a 'JSON.Object', and decode any 'JSON.Object'.
@ -86,9 +88,9 @@ data Codec context input output where
EqCodec :: EqCodec ::
(Show value, Eq value) => (Show value, Eq value) =>
-- | Value to match -- | Value to match
!value -> value ->
-- | Codec for the value -- | Codec for the value
!(ValueCodec value value) -> (ValueCodec value value) ->
-- | -- |
ValueCodec value value ValueCodec value value
-- | Map a codec in both directions. -- | Map a codec in both directions.
@ -98,11 +100,11 @@ data Codec context input output where
-- Otherwise we would have to have another constructor here. -- Otherwise we would have to have another constructor here.
MapCodec :: MapCodec ::
-- | -- |
!(oldOutput -> Either String newOutput) -> (oldOutput -> Either String newOutput) ->
-- | -- |
!(newInput -> oldInput) -> (newInput -> oldInput) ->
-- | -- |
!(Codec context oldInput oldOutput) -> (Codec context oldInput oldOutput) ->
Codec context newInput newOutput Codec context newInput newOutput
-- | Encode/Decode an 'Either' value -- | Encode/Decode an 'Either' value
-- --
@ -113,9 +115,9 @@ data Codec context input output where
-- This codec is used to implement choice. -- This codec is used to implement choice.
EitherCodec :: EitherCodec ::
-- | Codec for the 'Left' side -- | Codec for the 'Left' side
!(ValueCodec input1 output1) -> (ValueCodec input1 output1) ->
-- | Codec for the 'Right' side -- | Codec for the 'Right' side
!(ValueCodec input2 output2) -> (ValueCodec input2 output2) ->
-- | -- |
ValueCodec (Either input1 input2) (Either output1 output2) ValueCodec (Either input1 input2) (Either output1 output2)
-- | A comment codec -- | A comment codec