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

[EMAIL PROTECTED] wrote in article <[EMAIL PROTECTED]> 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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to