[clean-list] 'nother 'newbie 'question

Cristian Baboi cristi at ot.onrc.ro
Wed Dec 19 11:56:57 MET 2007


Let me show you other version in Haskell

module Hugs where

-- this is the example
unu :: Fractional a => (a -> a) -> a
unu f  = until ((==) 0.0)  (f)  1.0


-- this is some predicate written explicitely
eg :: Eq a => (b -> a) -> a -> b -> Bool
eg f y  = \x -> (f x) == y

-- this is one form of the solution
doi :: Fractional a => (a -> a) -> a
doi f = until (eg f 0.0)  (f)  1.0

-- this is other form of the same solution
trei :: Fractional a => (a -> a) -> a
trei f = until (\x-> ((f x)==0.0))  (f) 1.0

-- this is the same as the above with f instantiated to \x->x/10.0
patru = until (\x-> (x/10.0==0.0))  (\x->x/10.0) 1.0



On Tue, 18 Dec 2007 13:56:13 +0200, David Minor <david-m at orbotech.com>  
wrote:

> Thanks for the haskelly hint, here's my clean answer:
>
>
> Start = second (until (\x = (first x) == 0.0) (reduce) (1.0,1.0))
>
> first (a, _) = a
> second (_ , b) = b
>
> reduce :: (Real,Real) -> (Real, Real)
> reduce (x,y) = (x/10.0, x)


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
  part000.txt - is OK
http://www.eset.com



More information about the clean-list mailing list