[Haskell-cafe] code example

armin langhofer office at langhofer.at
Sun Dec 19 17:31:09 EST 2004


hi all

i'm going to write an exam in haskell tomorrow (monday) and i therefore 
i have to understand what this does:



repeat_until::(a->Bool)->(a->a)->a->a
repeat_until crit change x
  |crit x = x --zufrieden
  |otherwise = repeat_until crit change (change x) --weiter


fix::(Float->Float)->Float->Float
fix f = repeat_until pred f
   where pred x = (abs(f x -x) <= 0.01)

square::Float->Float
square x = x*x


this is the use:
================
Prelude> :l e:\haskell\burstall.hs
Main> fix square 0.01
0.01
(56 reductions, 80 cells)
Main> fix square 0.1
0.01
(92 reductions, 128 cells)
Main> fix square 1
1.0
(54 reductions, 77 cells)
Main>
Main>




it seems that i dont have a clue how it works. maybe some of you could 
explain it to me that i can pass the exam tomorrow,

thanx and best regards, armin.
-- 
armin langhofer
snail:  fischer von erlachstr. 29
snail:  a-5020 salzburg
phone:  +43 699 11648495
email:  office at langhofer.at
gnupg:  http://langhofer.at/pubkey.txt


More information about the Haskell-Cafe mailing list