Wednesday, February 23, 2011

Looking for a better way to use guards in lambda expressions

Took a swing at using guards instead of if-then to do flow control in anonymous recursion. After some digging, the cleanest solution I could come up with invokes a single case, expressionless statement against any arbitrary argument.

Surely there's a better way to do this.

-- the Y-combinator
y f = f (y f)

-- factorial in lambda
fac :: Int -> Int
fac = y( \f n -> case () of
_ | n == 0 -> 1
| otherwise -> n*f(n-1) )

1 comment:

  1. If you continue enjoying in} beyond that, find a way to|you probably can} amp up your casino bankroll with four BTC extra throughout your subsequent three deposits, totaling a formidable 5 BTC welcome bundle. Bitstarz additionally be|can be} the one casino on this list the place find a way to|you probably 코인카지노 can} get pleasure from exclusive titles. That said, our prime recreation here was Master of Starz, which additionally be|can be} the most important progressive jackpot find a way to|you probably can} get pleasure from here.