minimized failure

This commit is contained in:
Paul Chiusano 2019-03-25 14:30:19 -04:00
parent 28b95c6647
commit 905e674441

View File

@ -1,28 +1,13 @@
use Optional None Some
drop1 = Text.drop 1
namespace Sequence where
iterateWhile : (a -> Boolean) -> (a -> a) -> a -> [a]
iterateWhile p f a =
unfold a (a -> if p a then Some (a, f a) else None)
unfold : s -> (s -> Optional (a, s)) -> [a]
unfold s f =
go acc s f = case f s of
None -> acc
Some (a,s) -> go (acc `snoc` a) s f
go [] s f
sliding : Nat -> Text -> [Text]
sliding k t =
use Nat.>=
iterateWhile (t -> Text.size t >= k) (Text.drop 1) t
> sliding 2 "Unison"
> drop1 "heyo"
---
gives a runtime error -
unison: user error (type error, expecting N, got True)
unison: user error (type error, expecting N, got "heyo")
which indicates it is going to the runtime stack to get that `1` value,
rather than pulling it from the arguments