Using the syntax of records with algebraic data types with multiple constructors

The next type of data is the representation of phosphatidic acid (PA is a subclass of lipid). Using mass spectrometry, there are various levels of structural details that can be obtained (i.e., from a simple knowledge of the mass of a lipid up to a complete structural characteristic).

I currently have a PA data type as -

data PA   = ClassLevelPA       IntegerMass
          | CombinedRadylsPA   CombinedRadyls
          | UnknownSnPA        Radyl Radyl
          | KnownSnPA          { paSn1 :: Radyl
                               , paSn2 :: Radyl }
          deriving (Show, Eq, Ord)

This combines constructors with write syntax with those who don't (perhaps a bad idea). Alternatively, I could do one of the following:

data PA   = ClassLevelPA       { paIntegerMass :: IntegerMass }
          | CombinedRadylsPA   { paCombinedRadyls :: CombinedRadyls }
          | UnknownSnPA        { paR1 :: Radyl 
                               , paR2 :: Radyl }
          | KnownSnPA          { paSn1 :: Radyl
                               , paSn2 :: Radyl }

data PA   = ClassLevelPA       IntegerMass
          | CombinedRadylsPA   CombinedRadyls
          | UnknownSnPA        Radyl Radyl
          | KnownSnPA          Radyl Radyl

paSn1 paSn2, , . , , ( , GHC OverloadedRecordFields). , , ?

+4
1

, . , , , / lens. . ( ) , , . , Magic Template Haskell ( , _), .

+9

Source: https://habr.com/ru/post/1612676/


All Articles