*Pete Chown and Dan Doel. Thank you for your solution. I actually It was not homework . It was just a a past exam question trying to answer . * **but your solution is very long , so I don't think he wants answer this long in the exams. I think this answer agree100 f g = map f xs == map g xs where xs = [1..100] from Richard O'Keefe is do the job.
**Anyway , your solution help understand more about Haskell not only this question . Many thanks to you guys. On 27 May 2010 02:04, Dan Doel <[email protected]> wrote: > On Wednesday 26 May 2010 5:38:57 pm Pete Chown wrote: > > test :: (Eq a) => (Int -> a) -> (Int -> a) -> Bool > > test f1 f2 = unsafePerformIO $ do > > goodSoFar <- newIORef True > > forLoop 1 100 $ \i -> > > when (f1 i /= f2 i) $ writeIORef goodSoFar False > > readIORef goodSoFar > > The problem with this algorithm is that it needlessly tests f1 against f2 > for > all i, even when a non-matching value has has already been found. Using the > power of call-with-current-continuation, I have constructed an algorithm > that > lacks this deficiency: > > import Control.Monad.Cont > > test f g = flip runCont id . callCC $ \escape -> > do forM_ [1..100] $ \n -> > when (f n /= g n) $ > escape False > return True > > This should perform almost 75% less work in the testFunc1 case! It > certainly > feels much snappier. > > -- Dan > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Mujtaba Ali Alboori
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
