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

2009-01-14 Thread Andrew Coppin
Colin Adams wrote: 2009/1/13 Andrew Coppin : 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 have a

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

2009-01-13 Thread Ketil Malde
"Colin Adams" 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 have a name for this ef

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 (n>0) (n `mod` b, n `div` b)) > > I would use the

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

2009-01-13 Thread John Goerzen
Colin Adams wrote: > 2009/1/13 Andrew Coppin : > >> 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 sh

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

2009-01-13 Thread Colin Adams
2009/1/13 Andrew Coppin : > 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 have a name for this ef

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 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' which simplifies this to: u

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 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

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 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 representation of

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 Not

[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 idea