[Haskell-cafe] Lambda-case / lambda-if
Luke Palmer
lrpalmer at gmail.com
Tue Oct 5 05:36:12 EDT 2010
On Mon, Oct 4, 2010 at 9:04 PM, Dean Herington
<heringtonlacey at mindspring.com> wrote:
> With respect to "datatype destructing" functions, the Prelude has:
>
> maybe :: b -> (a -> b) -> Maybe a -> b
> either :: (a -> c) -> (b -> c) -> Either a b -> c
>
> which suggests the following signatures for the analogues for Bool and list
> types:
>
> bool :: a -> a -> Bool -> a
> list :: b -> (a -> [a] -> b) -> [a] -> b
This suggestion is not so clear to me. Maybe and Either are both
non-recursive, so the Church and Scott encodings coincide. You've
written the Scott encoding of list. The Church encoding should look
familiar:
list :: b -> (a -> b -> b) -> [a] -> b
Intuitively, a Scott encoding peels off one layer of datatype, whereas
a Church encoding flattens down a whole recursive structure. Church
encodings are more powerful -- you can do more without requiring a
fixed point operator.
Just to be clear, I am not arguing anything other than "maybe" and
"either" don't readily generalize to "list" because of list's
recursiveness.
Luke
More information about the Haskell-Cafe
mailing list