[PRL] scope of top-level defines

Paul A. Steckler steck at stecksoft.com
Mon Apr 4 22:40:36 EDT 2005


>      (define x y)
>      (define y x)
>      => error: reference to an identifier before its definition: y
> 
> How do you describe the scoping semantics for the latter behavior? It 
> isn't simply that top-level names aren't allowed to be bound to 
> #<undefined> values, because I can say:
> 
>      (define undefined (letrec ([x y] [y x]) x))

If you try to load the following code into GHCi, the 
interactive Haskell interpreter:

  x = y
  y = x

it loads without error.  If you query the type of x (or y):

  :t x

it tells you

  forall t . t

which is as general as you can get.  Of course, if you try to 
evaluate x (or y), it just loops.  Now that's undefined for you!

-- Paul




More information about the PRL mailing list