[Haskell-cafe] Re: Lightweight sequent calculus and linear abstractions

Conor McBride ctm at cs.nott.ac.uk
Thu Jul 5 14:15:35 EDT 2007


On 5 Jul 2007, at 18:35, Chung-chieh Shan wrote:

> oleg at pobox.com wrote in article  
> <20070705061533.8965EAD43 at Adric.metnet.fnmoc.navy.mil> in  
> gmane.comp.lang.haskell.cafe:
>> Conor McBride has posed an interesting problem:
>>>    implement constructors
>>>      P v      for embedding pure values v
>>>      O        for holes
>>>      f :$ a   for application, left-associative
>>>    and an interpreting function
>>>      emmental
>>>    such that
>>>      emmental (P (+) :$ (P (*) :$ O :$ P 10) :$ O) 4 2 = 42
>
> Hrm!  I don't see the original message where the problem was posed,  
> but
> it is indeed interesting.  Here is my solution, but I don't need "P",
> "O", and ":$" to be constructors, so I rename them to "p", "o", and
> "$:", respectively:
>
>     emmental m = m id
>     p x k = k x
>     o k = k
>     (m $: n) k = m (\f -> n (\x -> k (f x)))
>
>     infixl 0 $:
>     test = emmental (p (+) $: (p (*) $: o $: p 10) $: o) 4 2 -- 42


Very nice!

Thanks

Conor



More information about the Haskell-Cafe mailing list