[Haskell-cafe] least fixed points above something
Edsko de Vries
devriese at cs.tcd.ie
Thu Mar 19 11:53:23 EDT 2009
I've used a similar function myself, but why write it in such a
complicated way? How about
lfp :: Eq a => (a -> a) -> a -> a
lfp f x
| f x == x = x
| otherwise = lfp f (f x)
Edsko
On 19 Mar 2009, at 09:49, Jens Blanck wrote:
> Hi,
>
> I found myself writing the following
>
> leastFixedPoint :: (Eq a) => (a -> a) -> a -> a
> leastFixedPoint f x = fst . head . dropWhile (uncurry (/=)) $ zip l
> (tail l)
> where l = iterate f x
>
> and was a bit surprised that I couldn't get any matches on hoogle
> for the type above. The closest one is fix :: (a -> a) -> a but that
> sort of assumes that we're starting the fixed point search from the
> bottom element (undefined).
>
> Anyway, is there a nicer way of doing the above?
>
> Jens
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list