RE: [Haskell-cafe] is value evaluated?

2009-05-09 Thread Sittampalam, Ganesh
Brandon S. Allbery KF8NH wrote:
> On May 8, 2009, at 16:31 , Sittampalam, Ganesh wrote:
>> Brandon S. Allbery KF8NH wrote:
>>> Unless it catches exceptions itself (which strikes me as a bad idea;
>>> it becomes a trivial way to ignore exceptions, leading to bad
>>> programming practices) either they're handled inside the _|_ (in
>>> which case it isn't _|_ from the standpoint of our test) or in an
>>> outer scope (in which case our test produces _|_ from the standpoint
>>> of the exception handler).
>> 
>> Surely it just needs to inspect the thunk to decide whether it's _|_
>> or not, rather than entering it?
> 
> 
> The point is it can never be given a thunk that is _|_ because
> exception handling will have either converted it to a non-_|_ or
> shunted past the test.

You can set up a thunk in one place, enter it wrapped in a catch in
another place, and then inspect it in a third place, e.g. (somewhat
pseudo-code):

do let x = if 1==1 then error "foo" else 3
   y <- catch (evaluate x) (\_ -> 2)
   b <- isEvaluated x

Cheers,

Ganesh

=== 
 Please access the attached hyperlink for an important electronic 
communications disclaimer: 
 http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
 
=== 
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-09 Thread Brandon S. Allbery KF8NH

On May 8, 2009, at 16:31 , Sittampalam, Ganesh wrote:

Brandon S. Allbery KF8NH wrote:

Unless it catches exceptions itself (which strikes me as a bad idea;
it becomes a trivial way to ignore exceptions, leading to bad
programming practices) either they're handled inside the _|_ (in
which case it isn't _|_ from the standpoint of our test) or in an
outer scope (in which case our test produces _|_ from the standpoint
of the exception handler).


Surely it just needs to inspect the thunk to decide whether it's _|_  
or

not, rather than entering it?



The point is it can never be given a thunk that is _|_ because  
exception handling will have either converted it to a non-_|_ or  
shunted past the test.  And while my earlier com ent suggested that  
the test could conceivably itself do exception handling, you're right  
that all it does is inspect to see if a given thunk has been entered,  
so in fact exception handling shouldn't apply.  In the end, when  
handed _|_ it can only produce False because a _|_ that has been  
entered cannot reach the test.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-09 Thread Lennart Augustsson
But testing for something being evaluated has to be in the IO monad,
or else you're going to break the semantics.

On Fri, May 8, 2009 at 4:14 PM, Don Stewart  wrote:
> Andy Gill has been advocating programmatic access to the 'is evaluated'
> status bit for years now. 'seq' becomes cheaper, and we can write
> operational properties/assertions about strictness.
>
> -- Don
>
>
> jochem:
>> Nikhil Patil wrote:
>> > Hi,
>> >
>> > I am curious to know if there is a function in Haskell to find if a
>> certain
>> > value has already been evaluated. The function I need would have the type:
>> >
>> >> (?!) :: a -> Bool
>>
>> I will call this function `evaluated', since it is not a binary operator.
>>
>> The existence of such a function would violate referential transparency.
>>
>> What would the value of
>> ( evaluated (fibs !! 100), evaluated (fibs !! 100) )
>> be ? Suppose that I first print the `fst' of this tuple, then print the
>> 101st Fibonacci nummber, and then print the `snd' of this tuple. By lazy
>> evaluation, one would expect that this yields
>>
>> False
>> 
>> True
>>
>> but this violates referential transparency.
>>
>> Cheers,
>> --
>> Jochem Berndsen | joc...@functor.nl
>> GPG: 0xE6FABFAB
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Don Stewart
Andy Gill has been advocating programmatic access to the 'is evaluated'
status bit for years now. 'seq' becomes cheaper, and we can write
operational properties/assertions about strictness.

-- Don


jochem:
> Nikhil Patil wrote:
> > Hi,
> >
> > I am curious to know if there is a function in Haskell to find if a
> certain
> > value has already been evaluated. The function I need would have the type:
> >
> >> (?!) :: a -> Bool
> 
> I will call this function `evaluated', since it is not a binary operator.
> 
> The existence of such a function would violate referential transparency.
> 
> What would the value of
> ( evaluated (fibs !! 100), evaluated (fibs !! 100) )
> be ? Suppose that I first print the `fst' of this tuple, then print the
> 101st Fibonacci nummber, and then print the `snd' of this tuple. By lazy
> evaluation, one would expect that this yields
> 
> False
> 
> True
> 
> but this violates referential transparency.
> 
> Cheers,
> -- 
> Jochem Berndsen | joc...@functor.nl
> GPG: 0xE6FABFAB
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Sittampalam, Ganesh
Brandon S. Allbery KF8NH wrote:
> On May 8, 2009, at 13:08 , Sittampalam, Ganesh wrote:
>> Brandon S. Allbery KF8NH wrote:
>>> and therefore must be in IO.  You may be thinking that it would
>>> return a result for _|_, but as described if you fed it _|_ it could
>>> only produce False (if the _|_ has been evaluated you would not be
>>> able to reach the test).
>> 
>> It could probably return True in GHC since you can catch exceptions.
>> That still doesn't mean it solves the halting problem, of course.
> 
> Unless it catches exceptions itself (which strikes me as a bad idea;
> it becomes a trivial way to ignore exceptions, leading to bad
> programming practices) either they're handled inside the _|_ (in
> which case it isn't _|_ from the standpoint of our test) or in an
> outer scope (in which case our test produces _|_ from the standpoint
> of the exception handler). 

Surely it just needs to inspect the thunk to decide whether it's _|_ or
not, rather than entering it?

Ganesh

=== 
 Please access the attached hyperlink for an important electronic 
communications disclaimer: 
 http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
 
=== 
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Brandon S. Allbery KF8NH

On May 8, 2009, at 13:08 , Sittampalam, Ganesh wrote:

Brandon S. Allbery KF8NH wrote:

and therefore must be in IO.  You may be thinking that it would
return a result for _|_, but as described if you fed it _|_ it could
only produce False (if the _|_ has been evaluated you would not be
able to reach the test).


It could probably return True in GHC since you can catch exceptions.
That still doesn't mean it solves the halting problem, of course.


Unless it catches exceptions itself (which strikes me as a bad idea;  
it becomes a trivial way to ignore exceptions, leading to bad  
programming practices) either they're handled inside the _|_ (in which  
case it isn't _|_ from the standpoint of our test) or in an outer  
scope (in which case our test produces _|_ from the standpoint of the  
exception handler).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Sittampalam, Ganesh
Brandon S. Allbery KF8NH wrote:
> On May 8, 2009, at 01:33 , Joe Fredette wrote:
>> That strikes me as being bad in a "I'm violating the Halting Problem"
>> sort of way- but I'm not sure how. Is there some contradictory
>> construction that could be built from such a function?
> 
> I don't think it is; surely the Haskell runtime knows which thunks it
> has evaluated.  It just explicitly violates referential transparency,
> and therefore must be in IO.  You may be thinking that it would
> return a result for _|_, but as described if you fed it _|_ it could
> only produce False (if the _|_ has been evaluated you would not be
> able to reach the test). 

It could probably return True in GHC since you can catch exceptions.
That still doesn't mean it solves the halting problem, of course.

Ganesh

=== 
 Please access the attached hyperlink for an important electronic 
communications disclaimer: 
 http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
 
=== 
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Joe Fredette
That must have been the vibe I was getting. My haskell-spider senses 
were tingling, I just overshot RT and went for the Halting Problem.


/Joe

Brandon S. Allbery KF8NH wrote:

On May 8, 2009, at 01:33 , Joe Fredette wrote:
That strikes me as being bad in a "I'm violating the Halting Problem" 
sort of way- but I'm not sure how. Is there some contradictory 
construction that

could be built from such a function?


I don't think it is; surely the Haskell runtime knows which thunks it 
has evaluated.  It just explicitly violates referential transparency, 
and therefore must be in IO.  You may be thinking that it would return 
a result for _|_, but as described if you fed it _|_ it could only 
produce False (if the _|_ has been evaluated you would not be able to 
reach the test).


begin:vcard
fn:Joseph Fredette
n:Fredette;Joseph
adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America
email;internet:jfred...@gmail.com
tel;home:1-508-966-9889
tel;cell:1-508-254-9901
x-mozilla-html:FALSE
url:lowlymath.net, humbuggery.net
version:2.1
end:vcard

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Brandon S. Allbery KF8NH

On May 8, 2009, at 01:33 , Joe Fredette wrote:
That strikes me as being bad in a "I'm violating the Halting  
Problem" sort of way- but I'm not sure how. Is there some  
contradictory construction that

could be built from such a function?


I don't think it is; surely the Haskell runtime knows which thunks it  
has evaluated.  It just explicitly violates referential transparency,  
and therefore must be in IO.  You may be thinking that it would return  
a result for _|_, but as described if you fed it _|_ it could only  
produce False (if the _|_ has been evaluated you would not be able to  
reach the test).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-08 Thread Ketil Malde
Nikhil Patil  writes:

> I am curious to know if there is a function in Haskell to find if a certain
> value has already been evaluated. The function I need would have the type:
>
>> (?!) :: a -> Bool

Well, obviously you can't do this, it would violate referential
transparency.  Except if you define it as

   (?!) :: a -> Bool
   (?!) x = x `seq` True

..but that's probably not what you meant? :-)

> And I expect it to be such that the following terminates after printing the
> first 101 fibonacci numbers.

>> fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
>>
>> main = do print $ fibs !! 100
>>   print $ takeWhile (?!) fibs

The obvious problem is that the pure function "takeWhile (?!) fibs"
would return different things depending on what has happened to "fibs"
earlier in the program.

The run-time system has information about evaluation status, so it
might be possible to query it - but you'd need to do so in IO.  I also
seem to remember a debugger being able to display evaluated and
unevaluated thunks?  Also, you might be able to inspect evaluation by
something like 

  fibs2 = sequence' [ print ("evaluating:"++show x)) >> return x | x <- fibs ]

where sequence' is a lazy version of sequence.  This is a bit clunky,
but occasionally useful.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-07 Thread Jochem Berndsen
Nikhil Patil wrote:
> Hi,
>
> I am curious to know if there is a function in Haskell to find if a
certain
> value has already been evaluated. The function I need would have the type:
>
>> (?!) :: a -> Bool

I will call this function `evaluated', since it is not a binary operator.

The existence of such a function would violate referential transparency.

What would the value of
( evaluated (fibs !! 100), evaluated (fibs !! 100) )
be ? Suppose that I first print the `fst' of this tuple, then print the
101st Fibonacci nummber, and then print the `snd' of this tuple. By lazy
evaluation, one would expect that this yields

False

True

but this violates referential transparency.

Cheers,
-- 
Jochem Berndsen | joc...@functor.nl
GPG: 0xE6FABFAB
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is value evaluated?

2009-05-07 Thread Joe Fredette
That strikes me as being bad in a "I'm violating the Halting Problem" 
sort of way- but I'm not sure how. Is there some contradictory 
construction that

could be built from such a function?

Nikhil Patil wrote:
Hi, 


I am curious to know if there is a function in Haskell to find if a certain
value has already been evaluated. The function I need would have the type:

  

(?!) :: a -> Bool



And I expect it to be such that the following terminates after printing the
first 101 fibonacci numbers.

  

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

main = do print $ fibs !! 100
  print $ takeWhile (?!) fibs



Although I guess I can imagine the following not terminating:

  

  print $ filter (?!) fibs



I would find such a function immensely useful in "printing out" my infinite 
lists.

Thanks!

nikhil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

  
begin:vcard
fn:Joseph Fredette
n:Fredette;Joseph
adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America
email;internet:jfred...@gmail.com
tel;home:1-508-966-9889
tel;cell:1-508-254-9901
x-mozilla-html:FALSE
url:lowlymath.net, humbuggery.net
version:2.1
end:vcard

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe