StaticPointers to local definitions

Facundo Domínguez facundo.dominguez at tweag.io
Mon May 25 14:08:49 UTC 2015


Hello,
   It is happening in practice that one wants to create a static
pointer in a function and use some local definitions.

> f :: Static (Int -> Int)
> f x = sf
>  where
>    body = (+1)
>    sf = Static body

'body' defines a closed expression, but this is currently rejected
because desugaring the static form would produce a top-level binding
of the form:

> sf_top_level :: Int -> Int
> sf_top_level = body

where the local binding 'body' is not in scope.

Barring inlining, which wouldn't work in more complex examples, one
approach around this is to have the compiler move local definitions to
the top level during desugaring when they are referenced by a static
pointer. Two questions arise:
1) Would this interfere with other aspects of compilation?
2) Would anyone argue there is a better approach to accomplish this?

Thanks,
Facundo


More information about the ghc-devs mailing list