http://lomeo.livejournal.com/ ([identity profile] lomeo.livejournal.com) wrote in [personal profile] lomeo 2006-07-07 07:43 am (UTC)

Я гоню, Cale подсказал как можно сделать монаду:


data S a = S a (S a)

headS (S x _) = x
tailS (S _ x) = x

toList (S x xs) = x : toList xs

instance Functor S where
    fmap f (S x xs) = S (f x) (fmap f xs)

instance Monad S where
    return x = S x (return x)
    m >>= f = joinS $ fmap f m
        where
            joinS (S (S x _) s) = S x (joinS (fmap tailS s))


Все три закона работают. Выбираем диагональные элементы (правда меня коробит, что элементы теряются). Об этом шла речь?

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting