[Haskell-cafe] overloading show function

Philipp Schneider philipp.schneider5 at gmx.net
Thu Jun 30 20:31:48 CEST 2011


On 06/30/2011 08:25 PM, Philipp Schneider wrote:
> On 06/30/2011 02:36 PM, Holger Siegel wrote:
>> Am 29.06.2011 um 23:50 schrieb Philipp Schneider:
>>
>>> Hi cafe,
>>>
>>> in my program i use a monad of the following type
>>>
>>> newtype M a = M (State -> (a, State))
>>>
>>> i use the monad in two different ways. The type variable "a" can be a
>>> pair as in
>>>
>>> interp :: Term -> Environment -> M (Value,Environment)
>>>
>>> and it can be just a value as in
>>>
>>> type Environment = [(Name, Either Value (M Value))]
>> Simple rule: Never return an environment!
>>
>> An environment contains local variable bindings, so no subcomputation will ever need to return its environment. I don't know anything about the language your program interprets, but I'm sure that you can rewrite function interp as
>>
>>   interp :: Term -> Environment -> M Value
>>
>> The structure of the interpreter will become clearer and your problem will vanish.
>>
> Hello Holger,
>
> I'm giving two lambda interpreters. The first one is a call by value
> interpreter, the second one a call by name interpreter which are
> described in Philip Wadler's paper "The essence of functional
> programming" page 4 and 12. Now my task is to write a lazy lambda
> interpreter. The exercise is more playful than serious since Wadler's
> call by value interpreter is, since written in lazy Haskell, already a
> lazy lambda interpreter. (To get true call by value one would need to
> force evaluations of the arguments with the seq function.)
> For both of Wadler's interpreters the type of the interpertation
> function is:
> interp :: Term -> Environment -> M Value
>
> Now to simulate lazy interpretation i need to do the following: Decide
> is the value I need already evaluated or is it still a computation. In
> the later case I need to evaluate it and save its value in the
> environment. This is the reason I changed the type of the interpretation
> function to:
> interp :: Term -> Environment -> M (Value,Environment)
>
> I appened my full interpreter. If you can find a more elegant way to
> save the newly interpreted values, you are more than welcome to show my
> how to do it.
>
> Cheers,
> Philipp
I forgot to add the interpreter.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazy_lambda_interpreter.hs
Type: text/x-haskell
Size: 3948 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110630/fecd5bdf/attachment.hs>


More information about the Haskell-Cafe mailing list