For Programmers: Free Programming Magazines  


Home > Archive > Functional > March 2006 > Instantiation VS definition









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Instantiation VS definition
Kiuhnm

2006-03-23, 7:03 pm

Let us consider the following code (Clean):[color=darkred]
/*
iterate :: (t->t) t -> [t]
iterate f x = [x: iterate f (f x)]

takeWhile :: (a -> Bool) [a] -> [a]
takeWhile f [] = []
takeWhile f [x:xs]
| f x = [x:takeWhile f xs]
| otherwise = []
*/
Start = takeWhile ((<> ) 0.0) (iterate (\x = x/10.0) 1.0)
<<<

I am a little surprised that this code works.
Is it because of the "laziness" of Clean?

Kiuhnm
Dinko Tenev

2006-03-23, 7:03 pm

Kiuhnm wrote:
> Let us consider the following code (Clean):
> /*
> iterate :: (t->t) t -> [t]
> iterate f x = [x: iterate f (f x)]
>
> takeWhile :: (a -> Bool) [a] -> [a]
> takeWhile f [] = []
> takeWhile f [x:xs]
> | f x = [x:takeWhile f xs]
> | otherwise = []
> */
> Start = takeWhile ((<> ) 0.0) (iterate (\x = x/10.0) 1.0)
> <<<
>
> I am a little surprised that this code works.
> Is it because of the "laziness" of Clean?


Yes.

I think you're going to love FP ;)

Cheers,

Dinko

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com