morley-1.7.0: Developer tools for the Michelson Language
Safe HaskellNone
LanguageHaskell2010

Michelson.Typed.Haskell.ValidateDescription

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 :: FieldDescriptions) (typ :: Type) :: Constraint 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.

Equations

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