Subtyping

Fritz K Ruehr fruehr@willamette.edu
Tue, 21 Aug 2001 14:49:12 -0700 (PDT)


[sorry about that, let's try again...]

Ross Paterson wrote (in regards variations on factorial):

> Another version:
> 
> fac = foldr (*) 1 . unfoldr (\n -> guard (n > 0) >> return (n, n-1))

Thanks for forwarding this; may I quote it on the web site? (with full
attribution, of course) If so, you are welcome to give it a name and
a pithy little "slogan" (also for the one below).

> Also, the combinatory programmer would regard defining y by recursion
> as cheating, and would probably prefer one of these versions:
> 
> newtype SelfApp a = SA (SelfApp a -> a)
> 
> selfApply :: SelfApp a -> a
> selfApply (SA f) = f (SA f)
> 
> yCurry :: (a -> a) -> a
> yCurry f = selfApply (SA (\x -> f (selfApply x)))
> 
> yTuring :: (a -> a) -> a
> yTuring = selfApply (SA (\x f -> f (selfApply x f)))

Yes, this is definitely the right way to go here. I comment on the 
site about the fact that we should really *define* Y (and I felt
a bit guilty about it :) ), but I didn't try hard enough to get 
around the typing issue. You have done so quite elegantly.

Of course, there is also a trade-off at some point between the 
impact of the various examples and their sheer number (I added
an environment-model based interpreter yesterday that started 
to push this boundary). Still, more monads (arrows, even?) are
needed.

  --  Fritz Ruehr

PS: for those who missed it, the site is at:

	<http://www.willamette.edu/~fruehr/haskell/evolution.html>