Python from Wise Guy's Viewpoint

Darius ddarius at hotpop.com
Sun Oct 26 01:45:31 EDT 2003


On Sun, 26 Oct 2003 04:11:44 GMT
prunesquallor at comcast.net wrote:

> Darius <ddarius at hotpop.com> writes:
> 
> > data LazyList a
> >   = Nil 
> >   | Cons (forall r. ((a,() -> LazyList a) -> r) -> r)
> 
> I specifically didn't define the LazyList type.  I don't want to write
> type annotations.  I want the type inference engine to deduce them.

This is a data declaration, -not- a type declaration.  For example,
Bool is data Bool = True | False and lists would be data [a] = [] | a
:[a].  If I were to use Java would I not be allowed to use 'class'?
class introduces a type too. 

Furthermore, 'data' doesn't just give you a type.  It also gives you
constructors, destructors (kind of), and recognition.

data Either a b = Left a | Right b
The idiomatic Lisp functions that would correspond to what this
declaration provides would be something like: left, right, leftp,
rightp, eitherp, get-left, get-right.

Also, that type distinction let's me add LazyList to typeclasses like
Show, Read, Eq, Ord, Monad, Num, etc.  Perhaps, I don't like my lazy
lists displaying as #<closure> or my trees as ((3 2) (4)) when what I'd
want is((3 . (2 . ()) . (4 . ())).  Perhaps, I don't want
(equal<the lazy list 1 2 3> <the lazy list 1 2 3>) to return nil because
they aren't the same procedure.

Also, ignoring the testit function, my code with those four laborious
"type annotations" is 16 lines compared to 29 lines of lisp. (Including
it, it's still shorter.)

If all you want to do is show an example in Lisp that won't type check
in most statically typed language without any alterations you could
simply write,(list t 3) or (if t 'a 10).

Finally, I don't want to write some insane continuation passing
sequence.  I want the language to not overevaluate. I guess lazy Lisp or
dynamic Haskell beats us both.




More information about the Python-list mailing list