Created
February 29, 2020 13:43
-
-
Save atesztoth/63ed371c78b270e50a672c5d735b3554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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