I have an interesting problem, well at least to me and I can't seem to figure out how to resolve it, so i'm hoping you can help.
instance (Finite a, Finite b) => Finite (Either a b) where
elems = combineLists [Left x | x <- elems] [Right x | x <-elems]
size ??? = (size a) + (size b)
I'm working on an assignment for a class and the purpose for this particular portion is to make the size function more efficient than simply counting all the elements in elems. I've settled on summing the two types that make up the list, but i can't seem to create the signature of the size function.
From Prelude: Either a b = Left a | Right b
The first thing I tried was to match 'Either' but of course, it is a type so that doesn't work. Next I tried ((Left a) | (Right b)) but no go on that either. Nothing else seems to match the type Either a b
I was able to get size (Left a) to compile, but since it's missing the b component, I recieve the error:
Ambiguous type variable `b' in the constraint:
`Finite b' arising from a use of `size' at <interactive>:1:0-12
which of course makes sense in the context, but I really have no clue how to match Either a b.
Anybody have any thoughts?