Група, до якої ви додаєте допис, - група Usenet. Відтак, будь-хто в Інтернеті бачитиме вашу електронну адресу.
Вашу відповідь не було надіслано.
Ваш допис надіслано
Групи новин: comp.lang.haskell
Від: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Дата: Tue, 20 Oct 2009 23:59:40 +0200
Місцевий час: Ср 21 Жов 2009 00:59
Тема: Re: monads for lambda calculus
jon.gallagher.04 <jon.gallagher...@gmail.com> wrote: BTW, if you define the representation this way, a nice test case is > I have a program that serves a lambda calculus reducer, but I want to > play with it and see what various class representations give, such as > functors and monads. > So consider >> data Lambda a = Var a | Abst a (Lambda a) | Apply (Lambda a) (Lambda a) deriving Eq (\x.x x)(\x.x x). If that doesn't work like it should, you need to improve the alpha-conversion handling :-) > Then, of course fold, BTW, one can define fold and (f)map for every covariant ADT, so that's >> foldLam :: (l -> w) -> (l -> w -> w) -> (w -> w -> w) -> Lambda l -> w >> foldLam var abst app (Var a) = var a >> foldLam var abst app (Abst x m) = abst x (foldLam var abst app m) >> foldLam var abst app (Apply m n) = app (foldLam var abst app m) (foldLam var abst app n) > So that we can give an instance of functor, in no way special to Lambda. Though I think it's a bit roundabout to define map in terms of fold. > Next we can try to write an instance of monads. Why try for a monad here? If you view an ADT as an F-algebra, fold and map are straightforward. A monad, OTOH, needs an adjunction, which is a lot stronger. I can't imagine how a representation of lambda terms should give rise to an adjunction. You might be able to squeeze some variant of the other well-known types of monads in, but that would be somewhat superficial. >>instance Monad Lambda where Exactly :-) And using eta-equivalence, >> return a = Var a >> lam >>= f = joinL (fmap f lam) >> where joinL = foldLam id (\x -> Apply x) Apply >> -- joinL = foldLam id (\x m -> Apply m x) Apply > Yet neither of these really make sense. \x -> Apply x === Apply and so you're really just writing "foldLam Apply Apply" resp. > I did not work out monad laws as of right now, since I wasn't sure I didn't either, but I would expect them to fail. > if this is even a good implementation for which to work them out - Dirk Ви мусите увійти перед публікацією повідомлень.
Аби надіслати допис, будь ласка, спочатку приєднайтеся до цієї групи.
Будь ласка, поновіть своє прізвисько на сторінці налаштування передплати перед тим, як надіслати свій допис.
У вас немає права надсилання дописів до цієї групи.
| ||||||||||||||