0

Is there a standard type (especially in the stdlib) for a Stream type (by which I mean a potentially infinite, lazy sequence) which allows for effects when accessing the next element? Something like this pseudocode (for monad m, element type a)

m (a, m (a, m (a, m (a, ...

I tried modding Stream from the stdlib but kept getting

Error: StreamM is not total, not strictly positive

I'm having difficulty remembering the exact implementation, but here's one without the Monad

data StreamM : (Type -> Type) -> Type -> Type where
  (::) : a -> Inf (m (StreamM m a)) -> StreamM m a

Apparently it's because it can't be seen as total because for all we know m is not strictly positive. It works if I make m something specific like State Nat.

My knowledge of codata is minimal, and I don't know what polarity (positive etc.) means.

Context

I am producing a stream of uniquely-named values, where each value depends on all the previous values (and some other stuff). The monad m generates the names.

joel
  • 6,359
  • 2
  • 30
  • 55
  • Please include your exact definition of `StreamM` that is giving this error message. Also, is this with Idris 1 or Idris 2? – Cactus May 07 '23 at 14:35
  • 1
    @Cactus i've added a non-`Monad` version. I can't remember how I included the `Monad m`, but the error's the same with or without it. – joel May 07 '23 at 16:43
  • @Cactus Idris 2 – joel May 07 '23 at 16:46

0 Answers0