Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Created May 24, 2018 22:47
Show Gist options
  • Save Chadtech/5e9885a6b03fbc029988c2f3f29f4ef1 to your computer and use it in GitHub Desktop.
Save Chadtech/5e9885a6b03fbc029988c2f3f29f4ef1 to your computer and use it in GitHub Desktop.
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