Friedrich Dominicus wrote: > But again I'm wondering if this: > > makeChange :: Int -> [Int] -> [Int] > makeChange 0 (c:coins) = 0:makeChange 0 coins > makeChange 0 [] = [] > makeChange n (coin_val:coins) = let (how_many,rest) = divMod n coin_val > in > how_many:makeChange rest coins > > could be replaces by some combination of HOFs. Could someone give me a > hand here? How about this: makeChanges total coins = tail $ map fst $ scanl (\(how_many,rest) -> divMod rest) (0,total) coins But I doubt this is easier to understand. BTW, your first two branches can be combined: makeChange 0 = map (const 0) -- Zhanyong Wan
- Another question about higher order functions Friedrich Dominicus
- Re: Another question about higher order functions Zhanyong Wan
- Re: Another question about higher order funct... Friedrich Dominicus
- Re: Another question about higher order functions Paul Hudak
- Re: Another question about higher order functions Zhanyong Wan
- Re: Another question about higher order funct... Zhanyong Wan
- Re: Another question about higher order funct... Friedrich Dominicus
- Re: Another question about higher order functions Friedrich Dominicus
- Re: Another question about higher order functions Benjamin L. Russell
- Re: Another question about higher order funct... Friedrich Dominicus
- RE: Another question about higher order functions Simon Peyton-Jones
