{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, EmptyDataDecls #-}{-
The HList library
(C) 2004-2006, Oleg Kiselyov, Ralf Laemmel, Keean Schupke
A model of labels as needed for extensible records. As before,
all the information about labels is recorded in their type, so
the labels of records may be purely phantom. In general,
Labels are exclusively type-level entities and have no run-time
representation.
Record labels are triplets of type-level naturals, namespace,
and description. The namespace part helps avoid confusions between
labels from different Haskell modules. The description is
an arbitrary nullary type constructor.
For the sake of printing, the namespace part and the description
are required to be the instance of Show. One must make sure that
the show functions does not examine the value, as descr is purely phantom.
Here's an example of the good Label description:
data MyLabelDescr; instance Show MyLabelDescr where show _ = "descr"
which obviously can be automated with Template Haskell.
This model requires all labels in a record to inhabit the same namespace.
-}moduleData.HList.Label2whereimportData.HList.FakePreludeimportData.HList.Record(ShowLabel(..))-- Labels are type-level naturalsdataLabelxnsdesc-- labels are exclusively type-level entities-- Construct the first labelfirstLabel::ns->desc->LabelHZeronsdescfirstLabel=undefined-- Construct the next labelnextLabel::Labelxnsdesc->desc'->Label(HSuccx)nsdesc'nextLabel=undefined-- Equality on labels (descriptions are ignored)instanceHEqxx'b=>HEq(Labelxnsdesc1)(Labelx'nsdesc2)b-- Show labelinstance(HNatx,Showdesc)=>ShowLabel(Labelxnsdesc)whereshowLabel=show.getdwheregetd::Labelxnsdesc->descgetd=undefinedinstance(HNatx,HNat2Integralx,Showns)=>Show(Labelxnsdesc)whereshowl=unwords["L",show((hNat2Integralx)::Integer),showns]wheregeti::Labelxnsdesc->(x,ns)-- for the sake of Hugsgeti=undefined(x,ns)=getil