Re: "Strong typing vs. strong testing"

2010-10-04 Thread salil
On Sep 30, 1:38 pm, Lie Ryan  wrote:
> The /most/ correct version of maximum() function is probably one written
> in Haskell as:
>
> maximum :: Integer -> Integer -> Integer
> maximum a b = if a > b then a else b
>
> Integer in Haskell has infinite precision (like python's int, only
> bounded by memory), but Haskell also have static type checking, so you
> can't pass just any arbitrary objects.
>
> But even then, it's still not 100% correct. If you pass a really large
> values that exhaust the memory, the maximum() could still produce
> unwanted result.
>
> Second problem is that Haskell has Int, the bounded integer, and if you
> have a calculation in Int that overflowed in some previous calculation,
> then you can still get an incorrect result. In practice, the
> type-agnostic language with *mandatory* infinite precision arithmetic
> wins in terms of correctness. Any language which only has optional
> infinite precision arithmetic can always produce erroneous result.


I have not programmed in Haskell that much, but I think Haskell
inferences type "Integer" (the infinite precision) by default and not
"Int" (finite precision) type for the integers. So, the programmer who
specifically mentions "Int" in the signature of the function, is
basically overriding this default behavior for specific reasons
relevant to the application, for example, for performance. I think
Haskell's way is the right. It is providing "safe behavior"  as
default and at the same time treating programmer as adults, at least
in this case.

I think dynamic languages are attractive because they make programs
less verbose. But, statically typed languages with type inference
(Haskell, OCaML, Scala, F#) is a very good compromise because they
offer both type safety and succinctness. And when we need algorithms
that should work the same independent of types, Haskell has
typeclasses which are pretty intuitive, unlike the horrible C++
templates.





-- 
http://mail.python.org/mailman/listinfo/python-list


Streaming files from python cgi

2007-09-27 Thread Salil Kulkarni
Hello,

I am trying to create a cgi which downloads a pdf/tiff file from an
ftpserver using ftplib.
Everything works until this point.
But, once the file has been retrieved, I want to be able to stream the file
to the browser so that the user gets an option to save it, or open it with
the necessary application. However, I am not able to figure out how this can
be done.

The code looks as follows:

 #!/usr/local/python2.1/bin/python

 import Path, cgi, sys, os
 from ftplib import FTP
 print "content-type: application/pdf\n\n"

  ftp = FTP("hostname", "salil", "passwd")

  try:
  ftp.cwd("/home/salil")
  except:
  print "Could change directory on remote server"
  sys.exit(1)


  f = open("temp.pdf", "w")
  ftp.retrbinary("RETR O_F.pdf", f.write)
  f.close()
  f = open("temp.pdf", "r")
 print f.read()


I am using Apache 1.3 for this cgi. It would be great if someone can point
out how this can be accomplished, or if there are any examples out there
which I can refer to.

Thanks,
Salil.
-- 
http://mail.python.org/mailman/listinfo/python-list

Help regarding XML file manipulation

2010-05-25 Thread Salil GK
Hello

  I need to make a quick prototype to process some xml file. I found
xml.dom.minidom much handy and I can get information from the xml file. But
I need to update a filed in the xml file and save the file. I couldn't find
a way to do that. Could some one please help me on this.

Basically this is what I want to do



 
  Hari
  102010
  201010

  Rama
  102010
  201010

 


Here I want to read the Engineer information and then change the NextLeave
information to a new value and save to the same file. How do we do this -
can some one please help me with some sample code for the same.

Thanks
~S
-- 
http://mail.python.org/mailman/listinfo/python-list