Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-14 Thread Andrew Coppin
Colin Adams wrote: 2009/1/13 Andrew Coppin andrewcop...@btinternet.com: One of the wonderful things about Haskell is that almost any time anybody posts code, at least one person will think up an alternative but equivilent way of achieving the same goal - sometimes by radically different

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread Neil Mitchell
Hi convert b 0 = [] convert b n = n `mod` b : convert b (n `div` b) convert b = unfoldr (\n - if n 0 then Just (n `mod` b, n `div` b) else Nothing) To my untrained eyes the second looks more complex... It can't be implemented in the HLint list recursion functions I've got at the moment

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread Yitzchak Gale
Andrew Coppin wrote: Does it suggest unfoldr too? I think Neil's idea to have this customizable is a good one. It's often a matter of taste. I would rarely want to use unfoldr, and I wouldn't want HList to bother me about it. Instead, I prefer to use iterate for both of Andrew's examples:

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread Andrew Coppin
Robin Green wrote: On Mon, 12 Jan 2009 21:04:35 +0100 (CET) Henning Thielemann lemm...@henning-thielemann.de wrote: On Mon, 12 Jan 2009, Andrew Coppin wrote: convert b = unfoldr (\n - if n 0 then Just (n `mod` b, n `div` b) else Nothing) I have the nice function 'toMaybe'

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread Colin Adams
2009/1/13 Andrew Coppin andrewcop...@btinternet.com: One of the wonderful things about Haskell is that almost any time anybody posts code, at least one person will think up an alternative but equivilent way of achieving the same goal - sometimes by radically different steps. Maybe we should

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread John Goerzen
Colin Adams wrote: 2009/1/13 Andrew Coppin andrewcop...@btinternet.com: One of the wonderful things about Haskell is that almost any time anybody posts code, at least one person will think up an alternative but equivilent way of achieving the same goal - sometimes by radically different

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread George Pollard
On Mon, 2009-01-12 at 21:48 +, Robin Green wrote: convert b = unfoldr (\n - if n 0 then Just (n `mod` b, n `div` b) else Nothing) I have the nice function 'toMaybe' which simplifies this to: unfoldr (\n - toMaybe (n0) (n `mod` b, n `div` b)) I would use the more general

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-13 Thread Ketil Malde
Colin Adams colinpaulad...@googlemail.com writes: One of the wonderful things about Haskell is that almost any time anybody posts code, at least one person will think up an alternative but equivilent way of achieving the same goal - sometimes by radically different steps. Maybe we should

[Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-12 Thread Andrew Coppin
Neil Mitchell wrote: Hi Andrew, HLint will automatically detect if you should have used a map, a foldr or a foldl and suggest how to change your code. In the GHC, darcs and Hoogle code bases there are no obvious map-like functions, which is a good sign :-) ...What an intriguing

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-12 Thread Henning Thielemann
On Mon, 12 Jan 2009, Andrew Coppin wrote: Off the top of my head, try this: convert b 0 = [] convert b n = n `mod` b : convert b (n `div` b) (Takes a number and yields the radix-B representation of it. Backwards.) convert b = unfoldr (\n - if n 0 then Just (n `mod` b, n `div` b) else

Re: [Haskell-cafe] unfoldr [ANN: HLint 1.2]

2009-01-12 Thread Robin Green
On Mon, 12 Jan 2009 21:04:35 +0100 (CET) Henning Thielemann lemm...@henning-thielemann.de wrote: On Mon, 12 Jan 2009, Andrew Coppin wrote: Off the top of my head, try this: convert b 0 = [] convert b n = n `mod` b : convert b (n `div` b) (Takes a number and yields the radix-B