Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ddssff committed Nov 23, 2023
1 parent 456f158 commit 603d8ce
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion haskell-transformations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,42 @@ <h2>Changing a Sum Type to a Type Class</h2>
Lists of the sum type can be temporarily supported using
ExistentialQuantifiers.
</li>
</ul>
</ol>

<h2>Changing a Type Class to a Record</h2>
<ol>
<li>Methods become fields
<li>The constraint becomes a function argument
<li>The constraint is replaced by the superclasses
</ol>

<h2>Changing a Record into functions</h2>
<ol>
<li>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
<li>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
<li>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
</ol>

0 comments on commit 603d8ce

Please sign in to comment.