To learn haskell I've been building an framework much like Python Pandas.
In this scenario, I've defined a data called Series
data Series
= SInt [Int] ByteString
| SFloat [Float] ByteString
| SByteString [ByteString] ByteString
deriving (Show, Eq)
But due Haskell type system and my knowledge, I program simple functions like a Scalar Sum with this very repetitive coding pattern
sScalarSum :: Series -> Either Int Float
sScalarSum (SInt i _) = Left $ Data.List.sum i
sScalarSum (SFloat i _) = Right $ Data.List.sum i
sScalarSum (SByteString _ _) =
error "Cannot sum strings. use applyDType to convert series to float or int"
Is there any form of overloading to minimize this code?
Can't I just do something like this?
sScalarSum :: Series -> Either Int Float
sScalarSum (Series i _) = Left $ Data.List.sum i