[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: functional languages ill-suited for large programs?



> > 
> >     In our experience, true state (destructively assignable 
> >     entities) is essential for reasons of program modularity
> >     (which for this discussion I take as meaning: the ability to
> >     change one part of a program in a significant way without
> >     changing the rest of the program). Threaded state, e.g.,
> >     monads as used by Haskell or DCGs as used by Prolog, cannot
> >     substitute for it.
> 
> This is actually a fair critique of Haskell.  You have a choice: write
> programs in the beautiful, purely-functional part of the language (in
> which case you have to use unstable but widely-known hacks to hide
> certain sorts of side effects), or write programs in the much clunkier
> monadic sublanguage, where you need to name all your subexpressions,
> the order of evaluation is fixed, and you can use as many side effects
> as you like.

I'm not sure I see the issue.  If a function signature remains consistent, why would a caller care about the implementation?  Modularity would seem to have little to do with state modification in this case.

Where I do see the lack of destructive updates as being a problem is in things like interfacing with the outside world (I/O), and coding certain types of algorithms efficiently.

One (probably novice-level) question I have about functional style versus Object-Oriented approach is dynamic behavior.  In many partial and fully-functional languages, I often see this type of construct:

(define report-car (x)
  (if (automobile? x)
      (display "You are an automobile")
      (if (truck? x)
          (display "You are a truck!")
          ... )))

In some hypothetical object-oriented language you could do something like:

class automobile (vehicle) is
   print-me "I am a car"

class truck (vehicle) is
   print-me "I am a truck"

function report-car (vehicle v) {
   v.print-me()
}

In a CLOS-style system you could do something similar, but of course, this is a lot of typing.  On the other hand, you just call the proper function name where you want and it does the right thing, rather than having to test for every place you want to print the type of vehicle.

How can you accomplish this using something like Haskell or ML?  Do they provide sufficient dynamic dispatch to allow this kind of activity?

-Brent