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. Why casinos are rigged - Hertzaman - The Herald
    In apr casino the UK, https://septcasino.com/review/merit-casino/ casino games are rigged and there is evidence of https://deccasino.com/review/merit-casino/ fraud, crime or disorder or an individual's involvement. There are herzamanindir also many

    ReplyDelete