data TwoLists = TL {doubleList :: [Double], intList :: [Int]}
Almost all of the operations of this type map, fold, etc on one of the
lists or the other, and then return a new instance of the type. So I am
implementing to functions dFmap, and iFmap. I actually would like all of
the list functions, but I don't want to reimplement them.
So my question is, what is the haskell way of handling a type like this. Is
there some sort of TwoTypeTraversable I should be deriving from? Essential
is there a Haskell idiom for this situation.
-Jonathan
Hmm. Class in haskell means something similar to interface in OOP. Yes
it is confusing.
> data TwoLists = TL {doubleList :: [Double], intList :: [Int]}
>
> Almost all of the operations of this type map, fold, etc on one of the
> lists or the other, and then return a new instance of the type.
It may be my level of English bit I cannot understend this sentence.
> So I am implementing to functions dFmap, and iFmap.
What is dFmap and iFmap?
> I actually would like all of the list functions, but I don't want to
> reimplement them.
>
Hmm. If you need to combine the lists I'd suggest zip/zipWith. If simply
map/fold over one then just write (or similar):
foldr f i . doubleList
If you mean if there is class:
class BiFunctor f where
fmap2 :: (a -> c) -> (b -> d) -> f a b -> f c d
fmap2 f g = fmap2b g . fmap2a f
fmap2a :: (a -> c) -> f a b -> f c b
fmap2a f = fmap2 f id
fmap2b :: (b -> d) -> f a b -> f a d
fmap2b = fmap2 id
To write:
data TwoLists a b = TwoLists [a] [b]
instance BiFunctor TwoLists where
fmap2 f g (TwoLists a b) = TwoLists (map f a) (map g b)
then as far as I know - no - but you can always write your own.
Regards
_______________________________________________
Beginners mailing list
Begi...@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
There is such a class in the category-extras package, although it is
so general that it is probably not worth the effort of trying to
understand it unless you really need the extra abstraction.
-Brent
For the record - what is the name of it? I tried to search through
category-extras twice.
Regards
Control.Functor.Bifunctor. It took me a while to find it, too (I've
had to re-find it several times); I didn't actually say where to find
it in my first email because I knew it would take me a long time.
Unfortunately, coherent organization is not among category-extras'
strengths. ;-)
-Brent