Return a Vect from Stream take (#1812)

Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
This commit is contained in:
Joel Berkeley 2021-08-30 16:00:20 +01:00 committed by GitHub
parent cdc157a333
commit 078db21edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 0 deletions

View File

@ -87,6 +87,15 @@ take : (n : Nat)
take 0 xs = Nil
take (S k) (x :: xs) = x :: take k xs
namespace Stream
||| Take precisely n elements from the stream.
||| @ n how many elements to take
||| @ xs the stream
public export
take : (n : Nat) -> (xs : Stream a) -> Vect n a
take Z xs = []
take (S k) (x :: xs) = x :: take k xs
||| Drop the first `n` elements of a Vect.
public export
drop : (n : Nat) -> Vect (n + m) elem -> Vect m elem

View File

@ -0,0 +1,7 @@
import Data.Vect
takeFromStream : List (n ** Vect n Int)
takeFromStream = [(n ** take n [3..]) | n <- [0, 1, 5]]
main : IO ()
main = do printLn takeFromStream

View File

@ -0,0 +1,3 @@
1/1: Building Vect (Vect.idr)
Main> [(0 ** []), (1 ** [3]), (5 ** [3, 4, 5, 6, 7])]
Main> Bye for now!

View File

@ -0,0 +1,2 @@
:exec main
:q

3
tests/base/data_vect001/run Executable file
View File

@ -0,0 +1,3 @@
rm -rf build
$1 --no-banner --no-color --console-width 0 Vect.idr < input