Subtyping

Ross Paterson ross@soi.city.ac.uk
Tue, 21 Aug 2001 11:25:04 +0100


On Mon, Aug 20, 2001 at 10:35:38AM -0700, Fritz K Ruehr wrote:
> For those who are interested in what exactly is or isn't a beginner or 
> intermediate Haskell programmer's technique, I humbly offer the following
> 
> 	<http://www.willamette.edu/~fruehr/haskell/evolution.html>
> 
> which includes examples of the afore-mentioned approach, along with many
> others, from accumulating parameters to comonads.

Another version:

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

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)))