Re: OT: functional languages
Eric E Moore <e.e.moore@sheffield.ac.uk> writes:
> "Eric G. Miller" <egm2@jps.net> writes:
>> In C, statements are executed in order. I'm not too up on
>> functional languages, but I seem to recall they need special syntax
>> to execute statements sequentially.
>
> Not really. top level forms in a scheme program are executed
> sequentially, and there's a number of forms that execute their
> statements sequentially. I'm not up on haskell, or other "pure"
> functional languages though :)
Right, in Scheme it's easy enough to do
(begin
(foo)
(bar)
(baz))
to cause things to be executed in order. Haskell doesn't have such a
construct intrinsically. But what it does have is a concept called a
monad, which allows you to attach state to execution. Probably the
most common monad is "IO", which reflects the state of input/output
operations (like printing to the display). The 'do' keyword then
executes statements in order within a monad (doing ugly magic with
lambdas, I think).
I've found that monads are kind of hard to wrap your head around. I
wrote some monad code once upon a time but don't really remember how
it works; what it's supposed to do is pretty obvious. :-) (In
particular, http://web.mit.edu/dmaze/Public/hdc/ has source code for a
non-optimizing compiler for a simple Java-like language to MIPS in
Haskell. Because you all care, I'm sure, and because it seemed like
more fun than my thesis at the time. :-)
--
David Maze dmaze@debian.org http://people.debian.org/~dmaze/
"Theoretical politics is interesting. Politicking should be illegal."
-- Abra Mitchell
Reply to: