I'm having a problem handling my nested data types in my functions. Below is a simpler example of the issue I'm having and I'm not sure how to compute these functions properly. Any help will be much appreciated!
> data Ab = Add Ab Bc | Bc
> deriving (Show, Eq)
> data Bc = Sub Bc Cd | Cd
> deriving (Show, Eq)
> data Cd = Val Int
> deriving (Show, Eq)
> aDealer :: Ab -> Int
> aDealer (Add a b) = (aDealer a) + (bDealer b)
> aDealer b = bDealer b -- WHAT TO PUT HERE
> bDealer :: Bc -> Int
> bDealer (Sub b c) = (bDealer b) + (cDealer c)
> bDealer c = cDealer c -- WHAT TO PUT HERE
> cDealer :: Cd -> Int
> cDealer (Val c) = c
The error this code gives me is miss matched types (e.g. in aDealer b = bDealer b I get miss-matched types where bDealer can't take in Ab) I understand why I get this error but am un sure how to work round it :/
Bc :: Abis not a value of typeBcso it can't be passed tobDealer. What wouldbDealerdo with it? You are mixing up value namespace and type namespace it seems like.... | Bc Bc? Then you can writeaDealer (Bc b) = bDealer b. If you can't write the function you want over the datatype you have, that is usually an indicator that your datatype is wrong.