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

Neil Mitchell ndmitchell at gmail.com
Tue Jan 13 04:30:30 EST 2009


>> 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 since they first search for a pattern-match on []/(:) on the
left to start the process, but maybe one day.

> I have the nice function 'toMaybe' which simplifies this to:
>  unfoldr (\n -> toMaybe (n>0) (n `mod` b, n `div` b))
> Maybe HLint can also suggest non-base functions? ;-)

Yes, sure - but not by default. See

The idea is that if someone wants to maintain a separate Hints file,
say HackageHints.hs, then an individual user can decide to add import
HackageHints to their Hints.hs and use the additional hints, which may
require arbitrary Haskell libraries.



More information about the Haskell-Cafe mailing list