From 603d8ce03502ae023ddeed9ae422672fd7a34b7f Mon Sep 17 00:00:00 2001 From: David Fox Date: Thu, 23 Nov 2023 09:32:06 -0800 Subject: [PATCH] Update --- haskell-transformations/index.html | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/haskell-transformations/index.html b/haskell-transformations/index.html index 4404a72..8374391 100644 --- a/haskell-transformations/index.html +++ b/haskell-transformations/index.html @@ -119,4 +119,42 @@

Changing a Sum Type to a Type Class

Lists of the sum type can be temporarily supported using ExistentialQuantifiers. - + + +

Changing a Type Class to a Record

+
    +
  1. Methods become fields +
  2. The constraint becomes a function argument +
  3. The constraint is replaced by the superclasses +
+ +

Changing a Record into functions

+
    +
  1. Initial + data TemplateTypeInfo template = + TemplateTypeInfo + { templateKeyPath :: PathTo 'L (ReportType template) (TemplateId template) + , templateHtmlPath :: PathTo 'L (ReportType template) (ValueType template) + , templateLibraryPath :: PathTo 'L (ProfileType template) (AssocList RenderedUnicode (ValueType template)) + } deriving Generic +
  2. Rename the fileds + data TemplateTypeInfo template = + TemplateTypeInfo + { templateKeyPath' :: PathTo 'L (ReportType template) (TemplateId template) + , templateHtmlPath' :: PathTo 'L (ReportType template) (ValueType template) + , templateLibraryPath' :: PathTo 'L (ProfileType template) (AssocList RenderedUnicode (ValueType template)) + } deriving Generic +
  3. Add a class for each field: + class TemplateKeyPath template a where + templateKeyPath :: a -> PathTo 'L (ReportType template) (TemplateId template) + instance TemplateKeyPath template (TemplateTypeInfo template) where + templateKeyPath = templateKeyPath' @template + class TemplateHtmlPath template a where + templateHtmlPath :: a -> PathTo 'L (ReportType template) (ValueType template) + instance TemplateHtmlPath template (TemplateTypeInfo template) where + templateHtmlPath = templateHtmlPath' @template + class TemplateLibraryPath template a where + templateLibraryPath :: a -> PathTo 'L (ProfileType template) (AssocList RenderedUnicode (ValueType template)) + instance TemplateLibraryPath template (TemplateTypeInfo template) where + templateLibraryPath = templateLibraryPath' @template +