
On Fri, Dec 25, 2009 at 01:48:25AM +0100, Maciej Piechotka wrote:
On Thu, 2009-12-24 at 22:21 +0000, jonathanGfischoff@gmail.com wrote:
I have a class that is basically:
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
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