RosettaCodeData/Task/Permutations-Derangements/Haskell/permutations-derangements-3.hs
2025-02-27 18:35:13 -05:00

14 lines
386 B
Haskell

import Data.Ratio ((%), numerator)
infixl 7 *.
(*.) :: Num a => a -> [a] -> [a]
x *. (p:ps) = x*p : x*.ps
instance Num a => Num [a] where
negate = map negate
(+) = zipWith (+)
(*) (p:ps) (q:qs) = p*q : ((p*.qs) + ps*(q:qs))
fromInteger n = fromInteger n:repeat 0
expseq :: [Rational] -> [Rational]
expseq ps = zipWith (\p q -> p*fromInteger q) ps (scanl (*) 1 [1..])