Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

There is no currency that will buy your soul peace

Name: Anonymous 2015-03-09 6:23

Please post some Forth programs hear.

Also Lisp and C and Lua are welcome.

NO HASKELL

Name: Anonymous 2015-03-10 0:40

-- static Peano constructors and numerals

data Zero
data Succ n

type One = Succ Zero
type Two = Succ One
type Three = Succ Two
type Four = Succ Three

-- dynamic representatives for static Peanos

zero = undefined :: Zero
one = undefined :: One
two = undefined :: Two
three = undefined :: Three
four = undefined :: Four

-- addition, a la Prolog

class Add a b c | a b -> c where
add :: a -> b -> c

instance Add Zero b b
instance Add a b c => Add (Succ a) b (Succ c)

-- multiplication, a la Prolog

class Mul a b c | a b -> c where
mul :: a -> b -> c

instance Mul Zero b Zero
instance (Mul a b c, Add b c d) => Mul (Succ a) b d

-- factorial, a la Prolog

class Fac a b | a -> b where
fac :: a -> b

instance Fac Zero One
instance (Fac n k, Mul (Succ n) k m) => Fac (Succ n) m

-- try, for "instance" (sorry):
--
-- :t fac four

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List