Haskell or Python!

Andrew Bromage bromage at goaway.cc.monash.edu.au
Thu Feb 3 19:45:40 EST 2000


G'day all.

Sunil Hadap <Sunil.Hadap at cui.unige.ch> writes:

>I am developing an animation system. I was almost convinced that
>Python will be the embedded scripting language for the purpose, till I
>was introduced to Haskell.

Haskell (as of Haskell 98, anyway) has a limitation of its type system
in that it does not allow heterogeneous containers.  For example, you
might have a type class Object which is the class to which all geometric
primitives belong:

	class  Object a  where
		-- insert methods here --

	instance  Object Polygon  where
		-- methods defined for polygons --

	instance  Object NURBS  where
		-- methods defined for NURBS --

or whatever.  You can now create a list (lazy stream?) of Polygons,
but you can't make one of Objects.  To do this, Haskell would need
existential qualtification of types, which is on the wish list,
but not yet implemented.

I think that this problem more than anything else may rule out Haskell
(at the moment, anyway) as your scripting language of choice, but I
could be wrong.  Your application may not need this.

>I am confused which is better language for the purpose. Here are more
>specific questions

>- Can Haskell be used as interpreted language so that the animator
>  can code interactively in the animation software

Hugs is a Haskell interpreter which may suit your needs:

	http://www.haskell.org/hugs/

>- Is Haskell matured to provide good support to libraries such as I/O
>  GUI, network like Python

I/O is there.  The GUI is a debatable point.  The Haskell standard does
not directly support any particular GUI model, there are a number of
bindings which may help:

HOpenGL is a binding to OpenGL and GLUT:

http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/HOpenGL.html

TclHaskell is a binding to Tcl:

http://www.dcs.gla.ac.uk/~meurig/TclHaskell/

Fudgets is a toolkit which links directly to X:

http://www.cs.chalmers.se/ComputingScience/Research/Functional/Fudgets/

Haggis is one of those too, but requires a concurrent implementation
of Haskell to work correctly:

http://www.dcs.gla.ac.uk/fp/software/haggis/

As you can see, some degree of support is there

>- Can I use traditional OO concepts in Haskell though it is Functional

Let's see...

	- Encapsulation:  Yes.  Type classes are your friends.  Note
		that there is no support for attributes, but who needs
		them when you have access methods?

	- Abstraction:  Yes.  Modules are your friends.

	- Inheritance:  Yes, sort of.  Inherited type classes do most
		of it, but see the note above on heterogeneous
		containers which may bite you.

	- Object identity:  Tricky but not insurmountable.  Equality
		(==) in Haskell means _structural_ equality, not object
		identity, so if two objects are distinct, you have to
		explicitly make them distinct.

>- Is it dynamically typed.

No, it's strongly statically typed.

> I mean can I get full information of type and
>  its constituents (members) dynamically.

That's a different question. :-)  You're asking if Haskell supports
run-time type information.  

The answer is "no", because it would break parametric polymorphism.  If
you could peek inside a polymorphic variable, it wouldn't be truly
polymorphic.

The long answer is that you can fake it.  Make a type class which has
methods which peer inside the type and make everything use that.

>- Is it a good idea to mix Python and Haskell

Haskell does speak COM, so there's one possibility.  I don't think
that it speaks CORBA yet.  See also:

	http://www.dcs.gla.ac.uk/fp/software/hdirect/

You have to understand that Haskell was not designed as a scripting
language, but as an application programming language.  You also have
to understand that lazy functional languages haven't been around as
long as traditional Von Neumann languages, so they have to understand
how well-understood features fit into the new framework before it gets
into the language.

For further info, see comp.lang.functional.

For an interesting piece of research which may or may not have anything
to do with your project, see:

	http://www.research.microsoft.com/~conal/Fran/

Cheers,
Andrew Bromage



More information about the Python-list mailing list