-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
Git LFS file not shown
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TEST 32|O |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
def test numero fn valor = | ||
unsafePrintChar 'T'; | ||
unsafePrintChar 'E'; | ||
unsafePrintChar 'S'; | ||
unsafePrintChar 'T'; | ||
unsafePrintChar ' '; | ||
unsafePrintInt numero; | ||
unsafePrintChar '|'; | ||
fn valor; | ||
unsafePrintChar '\n' | ||
|
||
def zero z f = z | ||
def suc n z f = f (n z f) | ||
def foldn z f n = n z f | ||
def const x y = x | ||
|
||
def n0 = zero | ||
def n1 = suc n0 | ||
def n2 = suc n1 | ||
def n3 = suc n2 | ||
|
||
def compose f g x = f (g x) | ||
|
||
def true x y = x | ||
def false x y = y | ||
def cond x y z = x y z | ||
|
||
def nil z f = z | ||
def cons x xs z f = f x (xs z f) | ||
|
||
def pair x y f = f x y | ||
def fst p = p true | ||
def snd p = p false | ||
|
||
def foldr z f lst = lst z f | ||
def null = foldr true (compose const const false) | ||
|
||
def tail lst = | ||
snd (foldr (pair nil nil) | ||
(\ x r -> pair (cons x (fst r)) (fst r)) | ||
lst) | ||
|
||
def length lst = length_ lst '_' | ||
def length_ lst = | ||
cond (null lst) | ||
(\ u -> n0) | ||
(\ u -> suc (length_ (tail lst) '_')) | ||
|
||
def printNat n = | ||
foldn (\ u -> unsafePrintChar 'O') | ||
(\ r u -> (unsafePrintChar 'S'; r u)) | ||
n | ||
'_' | ||
|
||
def main = | ||
let l0 = nil in | ||
let l1 = cons n1 nil in | ||
let l2 = cons n1 (cons n2 nil) in | ||
let l3 = cons n1 (cons n2 (cons n3 nil)) in | ||
let ll = cons l3 (cons l2 (cons l1 nil)) in | ||
test 32 printNat (length l0) | ||
|