[Haskell-cafe] Lambda-case / lambda-if
Dean Herington
heringtonlacey at mindspring.com
Mon Oct 4 23:04:04 EDT 2010
At 12:05 PM +0200 10/4/10, Christopher Done wrote:
>On 4 October 2010 10:55, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
>> Hello Ketil,
>>
>> Monday, October 4, 2010, 11:30:48 AM, you wrote:
>>>> Prelude> (if then "Haskell" else "Cafe") False
>>
>> lambda-if is easily implemented in terms of usual functions.
>> and we even have one named bool:
>>
>> bool: Bool -> a -> a -> a
>
>I agree, in fact I have bool here:
>http://hackage.haskell.org/packages/archive/higherorder/0.0/doc/html/Data-Bool-Higher.html
>
>And the corresponding other types:
>
>bool :: (a -> b) -> (a -> b) -> (a -> Bool) -> a -> b
>list :: b -> ([a] -> b) -> [a] -> b
>maybe :: b -> (a -> b) -> Maybe a -> b
>
>But the case is especially useful for pattern matching.
I agree with others that lambda-if is better provided as a normal
function rather than special syntax, that lambda-case is much more
useful, and that it would be best if lambda-case were simply a
generalization of anonymous lambdas (\ ...).
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
(However, I do rather like the name (??) from Data.Bool.Higher, which
is used for "bool" immediately above. And I would hesitate to use
the name "list" for list destruction rather than construction. So
I'm not about to propose adding these two functions.)
Dean
More information about the Haskell-Cafe
mailing list