Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Pattern Matching



Actually, let me extend my pattern matching sample almost trivially by
adding another constructor to what used to be called Pair:

>     data Maybe a = Nothing | Just a     -- standard library definition
>     data N       = Singleton Int | Pair Int Int
> 
>     nonZeroValueOf :: Maybe N -> Maybe Int
>     nonZeroValueOf x =
>         case x of
>              Nothing            -> Nothing
>              Just (Singleton 0) -> Nothing
>              Just (Singleton n) -> Just n
>              Just (Pair 0 0)    -> Nothing
>              Just (Pair 0 m)    -> Just m
>              Just (Pair n _)    -> Just n

I'm not sure, but I think the extra two lines I've added here will add
significant complexity to the Clojure implementation.

cjs
-- 
Curt Sampson       <cjs@example.com>        +81 90 7737 2974
           Functional programming in all senses of the word:
                   http://www.starling-software.com


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links