Created
May 24, 2018 22:47
-
-
Save Chadtech/5e9885a6b03fbc029988c2f3f29f4ef1 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
module Main exposing (main) | |
import Html exposing (Html, text) | |
main : Html msg | |
main = | |
multiply | |
(fromInt 9) | |
(fromInt 5) | |
|> toInt | |
|> toString | |
|> text | |
type Nat | |
= Zero | |
| S Nat | |
add : Nat -> Nat -> Nat | |
add x y = | |
case x of | |
Zero -> | |
y | |
S s -> | |
add s (S y) | |
multiply : Nat -> Nat -> Nat | |
multiply x y = | |
case y of | |
Zero -> | |
y | |
S s -> | |
add x (multiply x s) | |
fromInt : Int -> Nat | |
fromInt int = | |
case int of | |
0 -> | |
Zero | |
_ -> | |
S (fromInt (int - 1)) | |
toInt : Nat -> Int | |
toInt nat = | |
case nat of | |
Zero -> | |
0 | |
S s -> | |
1 + toInt s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment