[Haskell-cafe] Is "let" special?

Ryan Ingram ryani.spam at gmail.com
Thu Nov 4 17:50:44 EDT 2010

When you use arrows for your DSL, how do you avoid getting trapped by
"arr"?  It seems like it's hard to avoid people working arbitrary
functions into your computation using it.

  -- ryan

On Thu, Nov 4, 2010 at 2:46 PM, Henning Thielemann
<schlepptop at henning-thielemann.de> wrote:
> Max Bolingbroke schrieb:
>> 2010/11/2 Günther Schmidt <gue.schmidt at web.de>:
>>> I've been given a few hints over time when I asked question concerning DSLs
>>> but regretfully didn't follow them up.
>> I think this is probably to do with observable sharing. The problem in
>> DSLs is if you have:
>> fact :: Term -> Term
>> fact = Factorial
>> instance Num Term where
>>   fromIntegral = Int
>>   (+) = Plus
>> e = let x = fact 2 :: Term
>>     in x + x :: Term
>> (Lets say the terms of our deeply embedded DSL are of type Term). If
>> you pattern match on "e" you will get something like (Factorial (Int
>> 2)) `Plus` (Factorial (Int 2)). This has lost the work sharing
>> implicit in the original term, where the Factorial computation was
>> shared.
>> To recover this sharing, you either need some sort of observable
>> sharing, or some common subexpression elimination (which risks
>> introducing space leaks if your DSL has lazy semantics). Quite a lot
>> of papers have mentioned this issue: the one that springs to mind is
>> Gill's "Type Safe Observable Sharing".
> Actually, I often need some replacement for 'let' in EDSL's - a sharing
> 'let' on the level of the target language. So far I have solved such
> issues by Arrows (fact :: EDSLArrow Term Term). Others have solved it by
> searching and sharing common sub-expressions.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list