[clean-list] 'nother 'newbie 'question
David Minor
david-m at orbotech.com
Tue Dec 18 12:56:13 MET 2007
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)
-----Original Message-----
From: Cristian Baboi [mailto:cristi at ot.onrc.ro]
Sent: Monday, December 17, 2007 4:50 PM
To: David Minor
Subject: Re: [clean-list] 'nother 'newbie 'question
On Mon, 17 Dec 2007 15:54:51 +0200, David Minor <david-m at orbotech.com>
wrote:
> Hello Again,
>
> Thanks for the great response to my previous question. I'm now stuck on
> exercise 2.5 2. Getting the basic start with "until" is easy.
>
>
> Start = until ((==) 0.0) (\x = x/10.0) 1.0
>
>
> But how do I get it to save and return the value before the until
> predicate is fulfilled?
>
Sorry for Haskell code, but I don't have Clean at hand right now.
-- the definition of until instantiated for some types
repeta::((Double,Double)->Bool)
->((Double,Double)->(Double,Double))->(Double,Double)->(Double,Double)
repeta p f x
| p x = x
| otherwise = repeta p f (f x)
-- the function
ff::(Double,Double)->(Double,Double)
ff (x, _) = (x/10.0,x)
-- the predicate
gg::(Double,Double)->Bool
gg (a,_) = a==0.0
-- the call
hh::(Double,Double)
hh=repeta gg ff (1.0,1.0)
________ 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