I haven't found any good examples of this kind of situations.
I have this kind of datatypes and a class with instances:
data Type1 = Const1 | Const2
deriving Show
data Type2 = Type2 Int
deriving Show
class Class a where
function :: a -> Int
instance Class Type1 where
function Const1 = 2
function Const2 = 3
instance Class Type2 where
function (Type2 x) = x * 2
Should add instances that can compute this way:
function [Just (Const2), Nothing, Just (Const1)]
function [Nothing, Nothing, Just (Type2 1), Just (Type2 2)]
Is there a way to do this something like this?
instance Class (Maybe a) where
function Nothing = 0
function (Just x) = function x <--- gives an error
instance Class [a] where
function [] = 0
function [x] = function x <--- error
function (x:sx) = function x + function xs <--- error