mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-17 08:11:45 +03:00
a972778eab
They don't all pass yet, for minor reasons. Coming shortly... Unfortunately the startup overhead for chez is really noticeable here!
28 lines
673 B
Plaintext
28 lines
673 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 (Delay ones)
|
|
|
|
countFrom : Integer -> Stream Integer
|
|
countFrom $x = Cons x (Delay (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 (Force xs))
|
|
|
|
every2nd : Nat -> Stream $a -> List $a
|
|
every2nd Z $xs = Nil
|
|
every2nd (S $k) (Cons _ (Delay (Cons $x $xs))) = Cons x (every2nd k (Force xs))
|
|
|