[Haskell-cafe] Is "let" special?

Henning Thielemann schlepptop at henning-thielemann.de
Thu Nov 4 17:46:59 EDT 2010


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.



More information about the Haskell-Cafe mailing list