In order to return Either a b
, you have to use either Left y
or Right x
, where y :: a
and x :: b
. You correctly used Left "...."
and Right
in all but the last pattern:
data NestedList a=Elem a | List [NestedList a] deriving Show
append::NestedList a->NestedList a->Either String (NestedList a)
append (Elem x) (Elem y) = Right $ List [Elem x, Elem y]
append (_) (Elem _) = Left $ "Elements are not allowed"
append (Elem _) (_) = Left $ "Elements are not allowed"
append (List a) (List b) = Right $ List(a++b)
-- ^^^^^