Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 841f1c17f6
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (37 sloc) 0.967 kb
include "Prelude.e"
{- Depending how much memory you have, you may need to reduce 'nine' -}
main () -> Unit =
printInt(natToInt(fact(nine)))
zero () -> Data = Con 0 ()
one () -> Data = Con 1 (zero)
two () -> Data = Con 1 (one)
three () -> Data = Con 1 (two)
four () -> Data = Con 1 (three)
five () -> Data = Con 1 (four)
six () -> Data = Con 1 (five)
seven () -> Data = Con 1 (six)
eight () -> Data = Con 1 (seven)
nine () -> Data = Con 1 (eight)
ten () -> Data = Con 1 (nine)
natToInt (x:Data) -> Int =
case x of {
Con 0 () -> 0
| Con 1 (k:Data) -> 1+natToInt(k)
}
plus (x:Data, y:Data) -> Data =
case x of {
Con 0 () -> y
| Con 1 (k:Data) -> Con 1 (plus(k, y))
}
mult (x:Data, y:Data) -> Data =
case x of {
Con 0 () -> Con 0 ()
| Con 1 (k:Data) -> plus(y, (mult(k, y)))
}
fact (x:Data) -> Data =
case x of {
Con 0 () -> one()
| Con 1 (k:Data) -> mult(x, fact(k))
}
apply (f:Fun, a:Any) -> Any =
f(a)
Jump to Line
Something went wrong with that request. Please try again.