[Haskell-cafe] least fixed points above something
Alberto G. Corona
agocorona at gmail.com
Thu Mar 19 13:35:48 EDT 2009
Anyway, these functions do not get the least fixed point ot r, but a fixed
point of f starting from the seed x. it is'n?
http://en.wikipedia.org/wiki/Fixed_point_(mathematics)
2009/3/19 Neil Mitchell <ndmitchell at gmail.com>
> > 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)
>
> I've used a similar function too, but your version computes f x twice
> per iteration, I wrote mine as:
> 't
> fix :: Eq a => (a -> a) -> a -> a
> fix f x = if x == x2 then x else fix f x2
> where x2 = f x
>
> I find this fix much more useful than the standard fix.
>
> Thanks
>
> Neil
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090319/3ebd11da/attachment.htm
More information about the Haskell-Cafe
mailing list