I declare the following newtypes:
newtype Code = Code String deriving (Show)
newtype Name = Name String deriving (Show)
newtype Account = Account (Code, Name) deriving (Show)
So:
*Main Lib> :t Code
Code :: String -> Code
*Main Lib> :t Name
Name :: String -> Name
*Main Lib> :t Account
Account :: (Code, Name) -> Account
and then I create some instances:
cn = Code "1.1.1"
nn = Name "Land And Buildings"
an = Account (cn, nn)
*Main Lib> an
Account (Code "1.1.1",Name "Land And Buildings")
Now I need to access for example just the Code
field from the variable an
, something like an.Code
How can I do that?
Is it better to use Data
instead of a newtype
? If Haskell lets me create a newtype named tuple, then I guess there should be an easy way to access the elements inside.