Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic streaming, request for comments #527

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

phischu
Copy link
Collaborator

@phischu phischu commented Jul 26, 2024

No description provided.

def emit(value) = resume(action(value))
}

// TODO what if the number is negative? undefined behavior?
Copy link
Contributor

@marzipankaiser marzipankaiser Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd want the program to either panic or act as if it is 0. (This is not something where I'd expect forever, and this is a place where I could see myself accidentally passing a negative number when e.g. implementing pad*).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please check and panic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we panic, we have to call it unsafeRepeat. I'm doing nothing for now. I wish we had Nat.


record Indexed[A](index: Int, value: A)

// In Effekt lower bounds are inclusive and upper bounds are exclusive
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this, this should be in effekt.effekt somewhere in the toplevel documentation.

@jiribenes
Copy link
Contributor

jiribenes commented Jul 26, 2024

It would be really nice to have a couple of examples showcasing the various features so that I can get an idea of how to use it :)

@jiribenes
Copy link
Contributor

By the way, here's Unison's Stream effect and Each effect (lazy nondeterminism from a stream)

Each.toList do
  use Nat <
  a = Each.range 0 5
  b = each [1, 2, 3]
  guard (a < b)
  (a, b)

@b-studios
Copy link
Collaborator

Can we maybe translate some Unison examples to Effekt to compare? That would be nice. @phischu could you please look into the Unison implementation as well?

@b-studios
Copy link
Collaborator

b-studios commented Jul 26, 2024

If you comment out the broken functions you can actually write an example which might look like this:

  val (_, l) = gatherList[Int, Unit] {
    for[Int, Unit] { range(0, 5) } { i =>
      for[Int, Unit] { range(1, 3) } { j =>
        do emit(i + j)
      }
    }
  }

  println(l)

Please note the explicit type arguments which are necessary because I need to say WHICH stream I want to handle.

This prints:

Cons(1, Cons(2, Cons(2, Cons(3, Cons(3, Cons(4, Cons(4, Cons(5, Cons(5, Cons(6, Nil()))))))))))

As you might guess, I really do not like having to annotate the types... I also don't like binding and ignoring unit in this example. It is very easy to get this example to something like:

val l = List[Int].collect {
  with i = Stream[Int].for { range(0, 5) }
  with j = Stream[Int].for { range(1, 3) }
  do emit(i + j)
}
println(l)

using a bit of phantom magic.

@phischu
Copy link
Collaborator Author

phischu commented Jul 26, 2024

Please note the explicit type arguments which are necessary because I need to say WHICH stream I want to handle.

How about

on[Int].for { ...

Or we try to fix this at the language level.

@phischu
Copy link
Collaborator Author

phischu commented Jul 26, 2024

(lazy nondeterminism from a stream)

This is planned in Phase 3

@phischu
Copy link
Collaborator Author

phischu commented Jul 26, 2024

could you please look into the Unison implementation as well?

I am looking at the streaming library, which is great.

@b-studios
Copy link
Collaborator

on the language level probably means fixing type inference which is planned but will take a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants