Rebindable 'let' for observable sharing?

Now that almost every syntax can be redirected to custom functions (RebindableSyntax, OverloadedStrings), would it make sense to map 'let' to 'fix' ? Would this open a way to implement observable sharing as needed in EDSLs by a custom 'fix'?

On 28 February 2011 10:38, Henning Thielemann
Now that almost every syntax can be redirected to custom functions (RebindableSyntax, OverloadedStrings), would it make sense to map 'let' to 'fix' ?
For the record: are you talking about rewriting: let f = e in b into something like: (\f -> e) `letin` (\f -> b) where `letin` can be overloaded ("rebinded" is probably the better term) and has the default implementation: letin :: (a -> a) -> (a -> b) -> b fe `letin` fb = fb (fix fe) For example the following: let fac = \n -> if n == 0 then 1 else n * fac (n-1) in (fac 3, fac 5) would be translated into: (\fac -> \n -> if n == 0 then 1 else n * fac (n-1)) `letin` (\fac -> (fac 3, fac 5)) Bas

Hi, Bas van Dijk wrote:
For the record: are you talking about rewriting:
let f = e in b
into something like:
(\f -> e) `letin` (\f -> b)
where `letin` can be overloaded ("rebinded" is probably the better term) and has the default implementation:
letin :: (a -> a) -> (a -> b) -> b fe `letin` fb = fb (fix fe)
I don't see how this captures the static semantics of let. In the original code, f can be polymorphic, but in the desugared version, f is monomorphic. Maybe the following works with an appropriate set of extensions enabled: First, infer the type of f in (let f = e in b) and call it T. Then, rewrite (let f = e in b) to ((\f :: T -> e) `letin` (\f -> b)). But Henning's original goal to "open a way to implement observable sharing as needed in EDSLs by a custom 'fix'" might be easier to achieve by desugaring let expressions into let expressions with some extra function applications: let f = e in b would become something like let f = hook1 e in hook2 f b Now, hook1 would default to id, and hook2 would default to (const id). I think this would capture the static and dynamic semantics of let expressions, and it might be enough to implement observable sharing. Tillmann
participants (3)
-
Bas van Dijk
-
Henning Thielemann
-
Tillmann Rendel