[Haskell-beginners] Re: Closure

Daniel Fischer daniel.is.fischer at web.de
Sat Aug 15 15:14:39 EDT 2009


Am Samstag 15 August 2009 19:06:42 schrieb Daniel Bastos:
> In article <200908151831.14649.daniel.is.fischer at web.de>,
>
> Daniel Fischer wrote:
> > The plus3 example is a "closure" which is hardcoded and available at
> > compile time.  I think, to say that a language allows closures means
> > it allows closures determined at run time.
>
> Hm. But does Haskell allow me to define a function at run time? I know
> Lisp can, since a function is just a data structure which we can put
> together at run time. But how about Haskell?

Depends on how you interpret it.
In the sense of

... let foo = \y -> f x y in map foo list

where the value of x is supplied at run time (and more complicated constructions depending 
on run time values), sure.
If you write a good parser, you can also

do  putStrLn "Please enter function code:"
    code <- getLine
    let fun = parseFunction code
    use fun   -- may segfault if the entered code isn't good

In which (other) ways can you construct functions at run time in Lisp?




More information about the Beginners mailing list