[Haskell-cafe] adding the elements of two lists

Ketil Malde ketil at malde.org
Thu Mar 29 09:34:38 CEST 2012


"Richard O'Keefe" <ok at cs.otago.ac.nz> writes:

> newtype PS a = PS [a] deriving (Eq, Show)
>
> u f (PS x)        = PS $ map f x
> b f (PS x) (PS y) = PS $ zipWith f x y
> to_ps x           = PS (x : repeat 0)

BTW, isn't this a good candidate for an Applicative instance (similar to
ZipList)?

 u f p     = f <$> p          -- or u = fmap
 b f p1 p2 = f <$> p1 <*> p2

Not a big deal for the Num instance, perhaps, but more general than u
and b, and it might make it easier to work with in other ways.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list