morley-1.20.0: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Michelson.Typed.Haskell.ValidateDescription

Description

Type-level field description validators

Synopsis

Documentation

type FieldDescriptions = [(Symbol, (Maybe Symbol, [(Symbol, Symbol)]))] Source #

Description of constructors and fields of some datatype.

This type is just two nested maps represented as associative lists. It is supposed to be interpreted like this:

[(Constructor name, (Maybe constructor description, [(Field name, Field description)]))]

Example with a concrete data type:

data Foo
  = Foo
      { fFoo :: Int
      }
  | Bar
      { fBar :: Text
      }
  deriving (Generic)

type FooDescriptions =
  '[ '( "Foo", '( 'Just "foo constructor",
      , '[ '("fFoo", "some number")
         ])
      )
   , '( "Bar", '( 'Nothing,
      , '[ '("fBar", "some string")
         ])
      )
   ]

type family FieldDescriptionsValid descr typ where ... Source #

This type family checks that field descriptions mention only existing constructors and fields.

When descr is empty this family does nothing, to avoid breaking for built-in, non-ADT types.

When descr is not empty, this family will demand Generic instance for typ and fail with a TypeError if there none.

>>> data Foo = Foo { fooField :: () } -- no Generic instance
>>> () :: FieldDescriptionsValid '[ '("Foo", '(Nothing, '[ '("fooField", "")]))] Foo => ()
...
... No Generic instance for Foo.
... Generic is needed to validate TypeDocFieldDescriptions.
...
>>> data Foo = Foo { fooField :: () } deriving Generic
>>> () :: FieldDescriptionsValid '[ '("Foo", '(Nothing, '[ '("fooField", "")]))] Foo => ()
()

Equations

FieldDescriptionsValid '[] _ = () 
FieldDescriptionsValid descr typ = IfStuck (Rep typ) (DelayError ((('Text "No Generic instance for " ':<>: 'ShowType typ) ':<>: 'Text ".") ':$$: 'Text "Generic is needed to validate TypeDocFieldDescriptions.")) (Pure (FieldDescriptionsValidImpl descr typ))