Skip to content

Instantly share code, notes, and snippets.

@atesztoth
Created February 29, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atesztoth/63ed371c78b270e50a672c5d735b3554 to your computer and use it in GitHub Desktop.
Save atesztoth/63ed371c78b270e50a672c5d735b3554 to your computer and use it in GitHub Desktop.
data Nat = Zero | Suc Nat deriving (Show)
data List a = Nil | Cons a (List a) deriving (Show)
addNat :: Nat -> Nat -> Nat
addNat Zero x = x
addNat (Suc x) y = Suc (addNat x y)
mulNat :: Nat -> Nat -> Nat
mulNat Zero _ = Zero
mulNat (Suc x) y = addNat y (mulNat x y)
product' :: List Nat -> Nat
product' Nil = Zero
product' (Cons x Nil) = x
product' (Cons x xs) = mulNat x (product' xs)
zero = Zero
one = Suc Zero
two = Suc (Suc Zero)
three = Suc (Suc (Suc Zero))
list = Cons three $ Cons two $ Cons three $ Nil
main = putStrLn "hello, world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment