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

RFC: make print polymorphic and fluent #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oxinabox
Copy link
Contributor

Putting this out there for comments as to if it is a good idea.
If it is then this PR still needs tests added.

  • Making it call show on its input just seems more convient
  • Making it return its input means you can (for debugging purposes) slip it inside some compouind expression
    • e.g. x |> f |>g can become x |> f |> print |> g

idk how useful this really is.

@google-cla google-cla bot added the cla: yes label Dec 29, 2020
@dougalm
Copy link
Collaborator

dougalm commented Dec 29, 2020

An alternative would be to have three different functions, like Haskell:

def putString (s:String) : {State World} Unit = ...

def print (_:Show a) ?=> (x:a) : {State World} Unit =
  putString $ show x

def trace (s:String) : String = unsafeIO do
  putString s
  s

Notice that trace doesn't need the IO effect exposed, because it won't get DCEd as long as its result is used.

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

Successfully merging this pull request may close these issues.

2 participants