Idris2/tests/ttimp/lazy001/LazyInf.yaff
Edwin Brady a972778eab Add test script
They don't all pass yet, for minor reasons. Coming shortly...
Unfortunately the startup overhead for chez is really noticeable here!
2020-05-19 18:25:18 +01:00

27 lines
632 B
Plaintext

data Nat : Type where
Z : Nat
S : Nat -> Nat
namespace Stream
public export
data Stream : Type -> Type where
Cons : $a -> Inf (Stream $a) -> Stream $a
ones : Stream Integer
ones = Cons 1 ones
countFrom : Integer -> Stream Integer
countFrom $x = Cons x (countFrom (prim__add_Integer 1 x))
data List : Type -> Type where
Nil : List $a
Cons : $a -> List $a -> List $ a
take : Nat -> Stream $a -> List $a
take Z $xs = Nil
take (S $k) (Cons $x $xs) = Cons x (take k xs)
every2nd : Nat -> Stream $a -> List $a
every2nd Z $xs = Nil
every2nd (S $k) (Cons _ (Cons $x $xs)) = Cons x (every2nd k xs)